Add /leave command

This commit is contained in:
bodqhrohro 2019-12-08 17:08:55 +02:00
parent 354887d724
commit 49423147e3

View file

@ -46,7 +46,7 @@ var chatCommands = map[string]command{
"invite": command{"id or @username", "add user to current chat"}, "invite": command{"id or @username", "add user to current chat"},
"kick": command{"id or @username", "remove user to current chat"}, "kick": command{"id or @username", "remove user to current chat"},
"ban": command{"id or @username [hours]", "restrict @username from current chat for [hours] or forever"}, "ban": command{"id or @username [hours]", "restrict @username from current chat for [hours] or forever"},
//"leave": command{"", "leave current chat"}, "leave": command{"", "leave current chat"},
//"close": command{"", "close current secret chat"}, //"close": command{"", "close current secret chat"},
//"delete": command{"", "delete current chat from chat list"}, //"delete": command{"", "delete current chat from chat list"},
//"members": command{"[query]", "search members [by optional query] in current chat (requires admin rights)"}, //"members": command{"[query]", "search members [by optional query] in current chat (requires admin rights)"},
@ -537,6 +537,29 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
return err.Error(), true return err.Error(), true
} }
} }
// leave current chat
case "leave":
chat, _, err := c.GetContactByID(chatID, nil)
if err != nil {
return err.Error(), true
}
chatType := chat.Type.ChatTypeType()
if chatType == client.TypeChatTypeBasicGroup || chatType == client.TypeChatTypeSupergroup {
_, err = c.client.LeaveChat(&client.LeaveChatRequest{
ChatId: chatID,
})
if err != nil {
return err.Error(), true
}
gateway.SendPresence(
c.xmpp,
c.jid,
gateway.SPFrom(strconv.FormatInt(chatID, 10)),
gateway.SPType("unsubscribed"),
)
}
case "help": case "help":
return helpString(helpTypeChat), true return helpString(helpTypeChat), true
default: default: