From fe5ca09c7c6827eaeecd09ad3448d0c0b3901427 Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Thu, 3 Feb 2022 14:29:16 -0500 Subject: [PATCH] Add leave! command to leave group as owner --- telegram/commands.go | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/telegram/commands.go b/telegram/commands.go index fc3064c..fbed7cd 100644 --- a/telegram/commands.go +++ b/telegram/commands.go @@ -74,6 +74,7 @@ var chatCommands = map[string]command{ "unban": command{"id or @username", "unbans @username in current chat (and devotes from admins)"}, "promote": command{"id or @username [title]", "promote user to admin in current chat"}, "leave": command{"", "leave current chat"}, + "leave!": command{"", "leave current chat (for owners)"}, "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)"}, @@ -159,8 +160,8 @@ func rawCmdArguments(cmdline string, start uint8) (string) { return "" } -func (c *Client) unsubscribe(chatID int64) { - gateway.SendPresence( +func (c *Client) unsubscribe(chatID int64) error { + return gateway.SendPresence( c.xmpp, c.jid, gateway.SPFrom(strconv.FormatInt(chatID, 10)), @@ -728,7 +729,23 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) return err.Error(), true } - c.unsubscribe(chatID) + err = c.unsubscribe(chatID) + if err != nil { + return err.Error(), true + } + // leave current chat (for owners) + case "leave!": + _, err := c.client.DeleteChat(&client.DeleteChatRequest{ + ChatId: chatID, + }) + if err != nil { + return err.Error(), true + } + + err = c.unsubscribe(chatID) + if err != nil { + return err.Error(), true + } // close secret chat case "close": chat, _, err := c.GetContactByID(chatID, nil) @@ -746,7 +763,10 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) return err.Error(), true } - c.unsubscribe(chatID) + err = c.unsubscribe(chatID) + if err != nil { + return err.Error(), true + } } // delete current chat case "delete": @@ -759,7 +779,10 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) return err.Error(), true } - c.unsubscribe(chatID) + err = c.unsubscribe(chatID) + if err != nil { + return err.Error(), true + } // message search case "search": var limit int32 = 100