aboutsummaryrefslogtreecommitdiff
path: root/telegram/commands.go
diff options
context:
space:
mode:
authorbodqhrohro <bodqhrohro@gmail.com>2019-12-08 21:44:17 +0300
committerbodqhrohro <bodqhrohro@gmail.com>2019-12-08 21:44:17 +0300
commit503e3e0b628ee4cac1bbb6c72fbefe6e07466656 (patch)
treed524cb8430516480e1d9d061854d9a8312a16960 /telegram/commands.go
parentad1beafeb3e59df8fb759fd89fcdbfc7b2cfef4f (diff)
Add /members command
Diffstat (limited to 'telegram/commands.go')
-rw-r--r--telegram/commands.go34
1 files changed, 33 insertions, 1 deletions
diff --git a/telegram/commands.go b/telegram/commands.go
index 12bf187..c41da29 100644
--- a/telegram/commands.go
+++ b/telegram/commands.go
@@ -49,7 +49,7 @@ var chatCommands = map[string]command{
"leave": command{"", "leave current chat"},
"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)"},
+ "members": command{"[query]", "search members [by optional query] in current chat (requires admin rights)"},
}
var transportConfigurationOptions = map[string]configurationOption{
@@ -639,6 +639,38 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
}
c.sendMessagesReverse(chatID, messages.Messages)
+ // members list (for admins)
+ case "members":
+ var query string
+ if len(args) > 0 {
+ query = args[0]
+ }
+
+ members, err := c.client.SearchChatMembers(&client.SearchChatMembersRequest{
+ ChatId: chatID,
+ Limit: 9999,
+ Query: query,
+ Filter: &client.ChatMembersFilterMembers{},
+ })
+ if err != nil {
+ return err.Error(), true
+ }
+
+ var entries []string
+ for _, member := range members.Members {
+ entries = append(entries, fmt.Sprintf(
+ "%v | role: %v",
+ c.formatContact(int64(member.UserId)),
+ member.Status.ChatMemberStatusType(),
+ ))
+ }
+
+ gateway.SendMessage(
+ c.jid,
+ strconv.FormatInt(chatID, 10),
+ strings.Join(entries, "\n"),
+ c.xmpp,
+ )
case "help":
return helpString(helpTypeChat), true
default: