From 5dd60450c28e602865e94bd28898eb4e61594a54 Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Sun, 18 Feb 2024 02:48:57 -0500 Subject: [PATCH] Fix crashes in commands due to not found contacts --- telegram/commands.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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 {