Add /ttl command to set time-to-live of messages in secret chats

This commit is contained in:
Bohdan Horbeshko 2022-02-08 15:22:11 -05:00
parent 2a5af5a264
commit fe7346a530

View file

@ -75,6 +75,7 @@ var chatCommands = map[string]command{
"promote": command{"id or @username [title]", "promote user to admin in current chat"},
"leave": command{"", "leave current chat"},
"leave!": command{"", "leave current chat (for owners)"},
"ttl": command{"", "set secret chat messages TTL before self-destroying (in seconds)"},
"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)"},
@ -739,6 +740,24 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
}
err = c.unsubscribe(chatID)
if err != nil {
return err.Error(), true
}
// set TTL
case "ttl":
var ttl int64
var err error
if len(args) > 0 {
ttl, err = strconv.ParseInt(args[0], 10, 32)
if err != nil {
return "Invalid TTL", true
}
}
_, err = c.client.SetChatMessageTtl(&client.SetChatMessageTtlRequest{
ChatId: chatID,
Ttl: int32(ttl),
})
if err != nil {
return err.Error(), true
}