aboutsummaryrefslogtreecommitdiff
path: root/telegram/commands.go
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2024-05-10 02:32:57 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2024-05-10 02:32:57 +0300
commit4eae44b9a27da488b8f6b4c5c057ff472051b087 (patch)
tree6bc21a6a9829313a419f475a93065f8dd4daa953 /telegram/commands.go
parent43f9603b887a2395a9a14234bd078170b3bd0926 (diff)
parenta74e2bcb7d3262073d05aa89140b1d202b7f179d (diff)
Merge branch 'master' into adhoc
Diffstat (limited to 'telegram/commands.go')
-rw-r--r--telegram/commands.go106
1 files changed, 60 insertions, 46 deletions
diff --git a/telegram/commands.go b/telegram/commands.go
index 039798f..397ba91 100644
--- a/telegram/commands.go
+++ b/telegram/commands.go
@@ -94,8 +94,8 @@ var chatCommands = map[string]command{
"invite": command{1, []string{"id or @username"}, "add user to current chat", &notForPM},
"link": command{0, []string{}, "get invite link for current chat", &notForPM},
"kick": command{1, []string{"id or @username"}, "remove user from current chat", &notForPM},
- "mute": command{1, []string{"id or @username", "hours"}, "mute user in current chat", &notForPMAndBasic},
- "unmute": command{1, []string{"id or @username"}, "unrestrict user from current chat", &notForPMAndBasic},
+ "mute": command{0, []string{"id or @username", "hours"}, "mute the whole chat or a user in current chat", &notForPMAndBasic},
+ "unmute": command{0, []string{"id or @username"}, "unmute the whole chat or a user in the current chat", &notForPMAndBasic},
"ban": command{1, []string{"id or @username", "hours"}, "restrict @username from current chat for [hours] or forever", &notForPM},
"unban": command{1, []string{"id or @username"}, "unbans @username in current chat (and devotes from admins)", &notForPM},
"promote": command{1, []string{"id or @username", "title"}, "promote user to admin in current chat", &notForPM},
@@ -847,57 +847,71 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool,
if err != nil {
return err.Error(), true, false
}
- // mute @username [n hours]
+ // mute [@username [n hours]]
case "mute":
- contact, _, err := c.GetContactByUsername(args[0])
- if err != nil {
- return err.Error(), true, false
- }
- if contact == nil {
- return "Contact not found", true, false
- }
-
- var hours int64
- if len(args) > 1 {
- hours, err = strconv.ParseInt(args[1], 10, 32)
+ if len(args) > 0 {
+ contact, _, err := c.GetContactByUsername(args[0])
if err != nil {
- return "Invalid number of hours", true, false
+ return err.Error(), true, false
+ }
+ if contact == nil {
+ return "Contact not found", true, false
}
- }
- _, 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, false
+ var hours int64
+ if len(args) > 1 {
+ hours, err = strconv.ParseInt(args[1], 10, 32)
+ if err != nil {
+ return "Invalid number of hours", true, false
+ }
+ }
+
+ _, 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, false
+ }
+ } else {
+ if !c.Session.IgnoreChat(chatID) {
+ return "Chat is already ignored", true, false
+ }
+ gateway.DirtySessions = true
}
- // unmute @username
+ // unmute [@username]
case "unmute":
- contact, _, err := c.GetContactByUsername(args[0])
- if err != nil {
- return err.Error(), true, false
- }
- if contact == nil {
- return "Contact not found", true, false
- }
+ if len(args) > 0 {
+ contact, _, err := c.GetContactByUsername(args[0])
+ if err != nil {
+ return err.Error(), true, false
+ }
+ if contact == nil {
+ return "Contact not found", true, false
+ }
- _, 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, false
+ _, 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, false
+ }
+ } else {
+ if !c.Session.UnignoreChat(chatID) {
+ return "Chat wasn't ignored", true, false
+ }
+ gateway.DirtySessions = true
}
// ban @username from current chat [for N hours]
case "ban":