You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
530 B
26 lines
530 B
package auth |
|
|
|
import ( |
|
"context" |
|
|
|
"github.com/go-faster/errors" |
|
|
|
"github.com/gotd/td/tg" |
|
) |
|
|
|
// self returns current user. |
|
// |
|
// You can use tg.User.Bot to check whether current user is bot. |
|
func (c *Client) self(ctx context.Context) (*tg.User, error) { |
|
users, err := c.api.UsersGetUsers(ctx, []tg.InputUserClass{&tg.InputUserSelf{}}) |
|
if err != nil { |
|
return nil, err |
|
} |
|
|
|
user, ok := tg.UserClassArray(users).FirstAsNotEmpty() |
|
if !ok { |
|
return nil, errors.Errorf("users response count: %v", users) |
|
} |
|
|
|
return user, nil |
|
}
|
|
|