Add /members command

This commit is contained in:
bodqhrohro 2019-12-08 20:44:17 +02:00
parent ad1beafeb3
commit 503e3e0b62

View file

@ -49,7 +49,7 @@ var chatCommands = map[string]command{
"leave": command{"", "leave current chat"}, "leave": command{"", "leave current chat"},
"close": command{"", "close current secret chat"}, "close": command{"", "close current secret chat"},
"delete": command{"", "delete current chat from chat list"}, "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{ var transportConfigurationOptions = map[string]configurationOption{
@ -639,6 +639,38 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
} }
c.sendMessagesReverse(chatID, messages.Messages) 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": case "help":
return helpString(helpTypeChat), true return helpString(helpTypeChat), true
default: default: