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 {