diff options
author | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2022-02-03 22:29:16 +0300 |
---|---|---|
committer | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2022-02-03 22:29:16 +0300 |
commit | fe5ca09c7c6827eaeecd09ad3448d0c0b3901427 (patch) | |
tree | 387bd9fcaeb4e65b1687c7115033fcc27f1f332f | |
parent | 6701335302e5f03402d10aa53984c7c2bd9c4bf3 (diff) |
Add leave! command to leave group as owner
-rw-r--r-- | telegram/commands.go | 33 |
1 files 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 |