Prevent possible segfault on picking message IDs for deletion

This commit is contained in:
bodqhrohro 2019-12-07 16:48:26 +02:00
parent 0013baa247
commit 3e791db201

View file

@ -251,6 +251,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
if c.me == nil { if c.me == nil {
return "@me is not initialized", true return "@me is not initialized", true
} }
var limit int32 var limit int32
if len(args) > 0 { if len(args) > 0 {
limit64, err := strconv.ParseInt(args[0], 10, 32) limit64, err := strconv.ParseInt(args[0], 10, 32)
@ -275,8 +276,10 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
var messageIds []int64 var messageIds []int64
for _, message := range messages.Messages { for _, message := range messages.Messages {
if message != nil {
messageIds = append(messageIds, message.Id) messageIds = append(messageIds, message.Id)
} }
}
_, err = c.client.DeleteMessages(&client.DeleteMessagesRequest{ _, err = c.client.DeleteMessages(&client.DeleteMessagesRequest{
ChatId: chatID, ChatId: chatID,