aboutsummaryrefslogtreecommitdiff
path: root/telegram/commands.go
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2022-02-01 07:57:17 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2022-02-01 07:57:17 +0300
commit9a49d662798be02e39b3bd88f64b4a8d40497ad2 (patch)
tree7786a0807dde54225c127ce5f32a2a3a411ca49d /telegram/commands.go
parentde31fa0ad210bef630aafda68a65a482044fc88b (diff)
Add /mute / /unmute commands
Diffstat (limited to 'telegram/commands.go')
-rw-r--r--telegram/commands.go73
1 files changed, 71 insertions, 2 deletions
diff --git a/telegram/commands.go b/telegram/commands.go
index 133e99b..238b774 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 permissionsMember = client.ChatPermissions{
+ CanSendMessages: true,
+ CanSendMediaMessages: true,
+ CanSendPolls: true,
+ CanSendOtherMessages: true,
+ CanAddWebPagePreviews: true,
+ CanChangeInfo: true,
+ CanInviteUsers: true,
+ CanPinMessages: true,
+}
+var permissionsReadonly = client.ChatPermissions{}
var transportCommands = map[string]command{
"login": command{"phone", "sign in"},
@@ -46,6 +57,8 @@ var chatCommands = map[string]command{
"invite": command{"id or @username", "add user to current chat"},
"link": command{"", "get invite link for current chat"},
"kick": command{"id or @username", "remove user to current chat"},
+ "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"},
"leave": command{"", "leave current chat"},
"close": command{"", "close current secret chat"},
@@ -560,7 +573,61 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
_, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{
ChatId: chatID,
MemberId: &client.MessageSenderUser{UserId: contact.Id},
- Status: c.formatRestrict(false, 0),
+ Status: &client.ChatMemberStatusLeft{},
+ })
+ if err != nil {
+ return err.Error(), true
+ }
+ // mute @username [n hours]
+ case "mute":
+ if len(args) < 1 {
+ return notEnoughArguments, true
+ }
+
+ contact, _, err := c.GetContactByUsername(args[0])
+ if err != nil {
+ return err.Error(), true
+ }
+
+ var hours int64
+ if len(args) > 1 {
+ hours, err = strconv.ParseInt(args[1], 10, 32)
+ if err != nil {
+ return "Invalid number of hours", true
+ }
+ }
+
+ _, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{
+ ChatId: chatID,
+ MemberId: &client.MessageSenderUser{UserId: contact.Id},
+ Status: &client.ChatMemberStatusRestricted{
+ IsMember: true,
+ RestrictedUntilDate: c.formatBantime(hours),
+ Permissions: &permissionsReadonly,
+ },
+ })
+ if err != nil {
+ return err.Error(), true
+ }
+ // unmute @username
+ case "unmute":
+ 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.ChatMemberStatusRestricted{
+ IsMember: true,
+ RestrictedUntilDate: 0,
+ Permissions: &permissionsMember,
+ },
})
if err != nil {
return err.Error(), true
@@ -587,7 +654,9 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
_, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{
ChatId: chatID,
MemberId: &client.MessageSenderUser{UserId: contact.Id},
- Status: c.formatRestrict(true, hours),
+ Status: &client.ChatMemberStatusBanned{
+ BannedUntilDate: c.formatBantime(hours),
+ },
})
if err != nil {
return err.Error(), true