Add /leave command

calls
bodqhrohro 4 years ago
parent 354887d724
commit 49423147e3

@ -46,7 +46,7 @@ var chatCommands = map[string]command{
"invite": command{"id or @username", "add 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"},
//"leave": command{"", "leave current chat"},
"leave": command{"", "leave current chat"},
//"close": command{"", "close current secret chat"},
//"delete": command{"", "delete current chat from chat list"},
//"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
}
}
// 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":
return helpString(helpTypeChat), true
default:

Loading…
Cancel
Save