aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2022-02-02 15:49:05 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2022-02-02 15:49:05 +0300
commit9b4830b98020d75c9c3b4656872e00d202f873b1 (patch)
treec80ff6ec5832acebfceede5f16da1e22478d62cf
parent9a49d662798be02e39b3bd88f64b4a8d40497ad2 (diff)
Support passing user ids to commands that accept @usernames
-rw-r--r--telegram/utils.go24
1 files changed, 18 insertions, 6 deletions
diff --git a/telegram/utils.go b/telegram/utils.go
index ca1884c..48460e7 100644
--- a/telegram/utils.go
+++ b/telegram/utils.go
@@ -35,15 +35,27 @@ func (c *Client) GetContactByUsername(username string) (*client.Chat, *client.Us
return nil, nil, errOffline
}
- chat, err := c.client.SearchPublicChat(&client.SearchPublicChatRequest{
- Username: username,
- })
+ var chat *client.Chat
+ var err error
+ var userID int64
+ if strings.HasPrefix(username, "@") {
+ chat, err = c.client.SearchPublicChat(&client.SearchPublicChatRequest{
+ Username: username,
+ })
- if err != nil {
- return nil, nil, err
+ if err != nil {
+ return nil, nil, err
+ }
+
+ userID = chat.Id
+ } else {
+ userID, err = strconv.ParseInt(username, 10, 64)
+ if err != nil {
+ return nil, nil, err
+ }
}
- return c.GetContactByID(chat.Id, chat)
+ return c.GetContactByID(userID, chat)
}
// GetContactByID gets user and chat information from cache (or tries to retrieve it, if missing)