diff options
author | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2022-02-03 21:51:27 +0300 |
---|---|---|
committer | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2022-02-03 21:51:27 +0300 |
commit | 6701335302e5f03402d10aa53984c7c2bd9c4bf3 (patch) | |
tree | ae1a81a4023eeebd468601d54609896b73530cbb | |
parent | 9b4830b98020d75c9c3b4656872e00d202f873b1 (diff) |
Add /unban / /promote commands
-rw-r--r-- | telegram/commands.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/telegram/commands.go b/telegram/commands.go index 238b774..fc3064c 100644 --- a/telegram/commands.go +++ b/telegram/commands.go @@ -17,6 +17,17 @@ import ( const notEnoughArguments string = "Not enough arguments" const telegramNotInitialized string = "Telegram connection is not initialized yet" const notOnline string = "Not online" +var permissionsAdmin = client.ChatMemberStatusAdministrator{ + CanBeEdited: true, + CanChangeInfo: true, + CanPostMessages: true, + CanEditMessages: true, + CanDeleteMessages: true, + CanInviteUsers: true, + CanRestrictMembers: true, + CanPinMessages: true, + CanPromoteMembers: false, +} var permissionsMember = client.ChatPermissions{ CanSendMessages: true, CanSendMediaMessages: true, @@ -60,6 +71,8 @@ var chatCommands = map[string]command{ "mute": command{"id or @username [hours]", "mute user in current chat"}, "unmute": command{"id or @username", "unrestrict user from current chat"}, "ban": command{"id or @username [hours]", "restrict @username from current chat for [hours] or forever"}, + "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"}, "close": command{"", "close current secret chat"}, "delete": command{"", "delete current chat from chat list"}, @@ -661,6 +674,51 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) if err != nil { return err.Error(), true } + // unban @username + case "unban": + if len(args) < 1 { + return notEnoughArguments, true + } + + contact, _, err := c.GetContactByUsername(args[0]) + if err != nil { + return err.Error(), true + } + + _, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{ + ChatId: chatID, + MemberId: &client.MessageSenderUser{UserId: contact.Id}, + Status: &client.ChatMemberStatusMember{}, + }) + if err != nil { + return err.Error(), true + } + // promote @username to admin + case "promote": + if len(args) < 1 { + return notEnoughArguments, true + } + + contact, _, err := c.GetContactByUsername(args[0]) + if err != nil { + return err.Error(), true + } + + // clone the permissions + status := permissionsAdmin + + if len(args) > 1 { + status.CustomTitle = args[1] + } + + _, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{ + ChatId: chatID, + MemberId: &client.MessageSenderUser{UserId: contact.Id}, + Status: &status, + }) + if err != nil { + return err.Error(), true + } // leave current chat case "leave": _, err := c.client.LeaveChat(&client.LeaveChatRequest{ |