diff options
author | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2024-02-18 10:48:57 +0300 |
---|---|---|
committer | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2024-02-18 10:48:57 +0300 |
commit | 5dd60450c28e602865e94bd28898eb4e61594a54 (patch) | |
tree | b8c521220ce357983ceeb87034763eb2014eb967 /telegram/commands.go | |
parent | 0b1cbda1cc20361b90846b6e8534e016288c301f (diff) |
Fix crashes in commands due to not found contacts
Diffstat (limited to 'telegram/commands.go')
-rw-r--r-- | telegram/commands.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/telegram/commands.go b/telegram/commands.go index 3c899ed..596f4a9 100644 --- a/telegram/commands.go +++ b/telegram/commands.go @@ -504,6 +504,9 @@ func (c *Client) ProcessTransportCommand(cmdline string, resource string) string if err != nil { return err.Error() } + if contact == nil { + return "Contact not found" + } text := rawCmdArguments(cmdline, 1) _, err = c.client.ReportChat(&client.ReportChatRequest{ @@ -812,6 +815,9 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) if err != nil { return err.Error(), true } + if contact == nil { + return "Contact not found", true + } _, err = c.client.AddChatMember(&client.AddChatMemberRequest{ ChatId: chatID, @@ -836,6 +842,9 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) if err != nil { return err.Error(), true } + if contact == nil { + return "Contact not found", true + } _, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{ ChatId: chatID, @@ -851,6 +860,9 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) if err != nil { return err.Error(), true } + if contact == nil { + return "Contact not found", true + } var hours int64 if len(args) > 1 { @@ -878,6 +890,9 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) if err != nil { return err.Error(), true } + if contact == nil { + return "Contact not found", true + } _, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{ ChatId: chatID, @@ -897,6 +912,9 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) if err != nil { return err.Error(), true } + if contact == nil { + return "Contact not found", true + } var hours int64 if len(args) > 1 { @@ -922,6 +940,9 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) if err != nil { return err.Error(), true } + if contact == nil { + return "Contact not found", true + } _, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{ ChatId: chatID, @@ -937,6 +958,9 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) if err != nil { return err.Error(), true } + if contact == nil { + return "Contact not found", true + } // clone the permissions status := client.ChatMemberStatusAdministrator{ @@ -1006,6 +1030,9 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) if err != nil { return err.Error(), true } + if chat == nil { + return "Chat not found", true + } chatType := chat.Type.ChatTypeType() if chatType == client.TypeChatTypeSecret { |