aboutsummaryrefslogtreecommitdiff
path: root/telegram/commands.go
diff options
context:
space:
mode:
authorbodqhrohro <bodqhrohro@gmail.com>2019-12-08 19:04:26 +0300
committerbodqhrohro <bodqhrohro@gmail.com>2019-12-08 19:04:26 +0300
commitfb36f53f3a9e73ff6892cea9f6327238be5850e6 (patch)
treef370e782d4d6552deb7ed11fc47052146726b0d7 /telegram/commands.go
parent2d3e8ebbb663a95e750206bc66f309427c6750b9 (diff)
Add /search command
Diffstat (limited to 'telegram/commands.go')
-rw-r--r--telegram/commands.go42
1 files changed, 35 insertions, 7 deletions
diff --git a/telegram/commands.go b/telegram/commands.go
index 8718955..f4e0c62 100644
--- a/telegram/commands.go
+++ b/telegram/commands.go
@@ -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: