1
0
mirror of https://github.com/Rudi9719/kbtui.git synced 2026-03-22 11:07:22 +00:00

Fix crash from not supplying ID

This commit is contained in:
Gregory Rudolph
2019-10-04 13:20:24 -04:00
parent 5068fd62e1
commit b6e108f3f0

View File

@ -9,7 +9,7 @@ import (
func init() { func init() {
command := Command{ command := Command{
Cmd: []string{"delete", "del"}, Cmd: []string{"delete", "del", "-"},
Description: "$messageId - Delete a message by $messageId", Description: "$messageId - Delete a message by $messageId",
Help: "", Help: "",
Exec: cmdDelete, Exec: cmdDelete,
@ -18,7 +18,13 @@ func init() {
RegisterCommand(command) RegisterCommand(command)
} }
func cmdDelete(cmd []string) { func cmdDelete(cmd []string) {
messageID, _ := strconv.Atoi(cmd[1]) var messageID int
if len(cmd) > 1 {
messageID, _ = strconv.Atoi(cmd[1])
} else {
messageID = lastMessage.ID
}
chat := k.NewChat(channel) chat := k.NewChat(channel)
_, err := chat.Delete(messageID) _, err := chat.Delete(messageID)
if err != nil { if err != nil {