Add /search command

calls
bodqhrohro 4 years ago
parent 2d3e8ebbb6
commit fb36f53f3a

@ -39,7 +39,7 @@ var chatCommands = map[string]command{
"supergroup": command{"title description", "create new supergroup «title» with «description»"},
"channel": command{"title description", "create new channel «title» with «description»"},
"secret": command{"", "create secretchat with current user"},
//"search": command{"string [limit]", "search <string> in current chat"},
"search": command{"string [limit]", "search <string> in current chat"},
//"history": command{"[limit]", "get last [limit] messages from current chat"},
"block": command{"", "blacklist current user"},
"unblock": command{"", "unblacklist current user"},
@ -335,12 +335,6 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
SenderUserId: c.me.Id,
Filter: &client.SearchMessagesFilterEmpty{},
})
log.Debugf("%#v", client.SearchChatMessagesRequest{
ChatId: chatID,
Limit: 1,
SenderUserId: c.me.Id,
Filter: &client.SearchMessagesFilterEmpty{},
})
if err != nil {
return err.Error(), true
}
@ -589,6 +583,40 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
}
c.unsubscribe(chatID)
// search messages within current chat
case "search":
var limit int32 = 10
if len(args) > 1 {
newLimit, err := strconv.ParseInt(args[1], 10, 32)
if err == nil {
limit = int32(newLimit)
}
}
var query string
if len(args) > 0 {
query = args[0]
}
messages, err := c.client.SearchChatMessages(&client.SearchChatMessagesRequest{
ChatId: chatID,
Query: query,
Limit: limit,
SenderUserId: c.me.Id,
Filter: &client.SearchMessagesFilterEmpty{},
})
if err != nil {
return err.Error(), true
}
for i := len(messages.Messages) - 1; i >= 0; i-- {
gateway.SendMessage(
c.jid,
strconv.FormatInt(chatID, 10),
c.formatMessage(0, 0, false, messages.Messages[i]),
c.xmpp,
)
}
case "help":
return helpString(helpTypeChat), true
default:

Loading…
Cancel
Save