aboutsummaryrefslogtreecommitdiff
path: root/telegram
diff options
context:
space:
mode:
authorbodqhrohro <bodqhrohro@gmail.com>2019-12-08 18:08:55 +0300
committerbodqhrohro <bodqhrohro@gmail.com>2019-12-08 18:08:55 +0300
commit49423147e3a2ecb4affede4ece5af659b096f87f (patch)
tree6356a35afdd19342f24e76814959cb2d2c8b9406 /telegram
parent354887d724ce22f463032c22d47d239284c70e94 (diff)
Add /leave command
Diffstat (limited to 'telegram')
-rw-r--r--telegram/commands.go25
1 files changed, 24 insertions, 1 deletions
diff --git a/telegram/commands.go b/telegram/commands.go
index 0f579dc..ad82cb6 100644
--- a/telegram/commands.go
+++ b/telegram/commands.go
@@ -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: