Support passing user ids to commands that accept @usernames
This commit is contained in:
parent
9a49d66279
commit
9b4830b980
|
@ -35,7 +35,11 @@ func (c *Client) GetContactByUsername(username string) (*client.Chat, *client.Us
|
|||
return nil, nil, errOffline
|
||||
}
|
||||
|
||||
chat, err := c.client.SearchPublicChat(&client.SearchPublicChatRequest{
|
||||
var chat *client.Chat
|
||||
var err error
|
||||
var userID int64
|
||||
if strings.HasPrefix(username, "@") {
|
||||
chat, err = c.client.SearchPublicChat(&client.SearchPublicChatRequest{
|
||||
Username: username,
|
||||
})
|
||||
|
||||
|
@ -43,7 +47,15 @@ func (c *Client) GetContactByUsername(username string) (*client.Chat, *client.Us
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
return c.GetContactByID(chat.Id, chat)
|
||||
userID = chat.Id
|
||||
} else {
|
||||
userID, err = strconv.ParseInt(username, 10, 64)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return c.GetContactByID(userID, chat)
|
||||
}
|
||||
|
||||
// GetContactByID gets user and chat information from cache (or tries to retrieve it, if missing)
|
||||
|
|
Loading…
Reference in a new issue