Add /ban command

calls
bodqhrohro 4 years ago
parent 4b099fba41
commit 354887d724

@ -7,6 +7,7 @@ import (
"regexp"
"strconv"
"strings"
"time"
"dev.narayana.im/narayana/telegabber/xmpp/gateway"
@ -30,21 +31,21 @@ var transportCommands = map[string]command{
}
var chatCommands = map[string]command{
"d": command{"[n]", "delete your last message(s)"},
//"s": command{"regex replace", "edit your last message"},
//"add": command{"@username", "add @username to your chat list"},
//"join": command{"https://t.me/invite_link", "join to chat via invite link"},
//"group": command{"title", "create groupchat «title» with current user"},
//"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"},
"d": command{"[n]", "delete your last message(s)"},
"s": command{"regex replace", "edit your last message"},
"add": command{"@username", "add @username to your chat list"},
"join": command{"https://t.me/invite_link", "join to chat via invite link"},
"group": command{"title", "create groupchat «title» with current user"},
"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"},
//"history": command{"[limit]", "get last [limit] messages from current chat"},
//"block": command{"", "blacklist current user"},
//"unblock": command{"", "unblacklist current user"},
//"invite": command{"id or @username", "add user to current chat"},
//"kick": command{"id or @username", "remove user to current chat"},
//"ban": command{"id or @username [hours]", "restrict @username from current chat for [hours] or forever"},
"block": command{"", "blacklist current user"},
"unblock": command{"", "unblacklist current user"},
"invite": command{"id or @username", "add user to current chat"},
"kick": command{"id or @username", "remove user to current chat"},
"ban": command{"id or @username [hours]", "restrict @username from current chat for [hours] or forever"},
//"leave": command{"", "leave current chat"},
//"close": command{"", "close current secret chat"},
//"delete": command{"", "delete current chat from chat list"},
@ -505,6 +506,37 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
return err.Error(), true
}
}
// ban @username from current chat [for N hours]
case "ban":
if len(args) < 1 {
return notEnoughArguments, true
}
if chatID < 0 {
userID, err := c.usernameOrIdToId(args[0])
if err != nil {
return err.Error(), true
}
var until int32
if len(args) > 1 {
hours, err := strconv.ParseInt(args[1], 10, 32)
if err != nil {
until = int32(time.Now().Unix() + hours*3600)
}
}
_, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{
ChatId: chatID,
UserId: userID,
Status: &client.ChatMemberStatusBanned{
BannedUntilDate: until,
},
})
if err != nil {
return err.Error(), true
}
}
case "help":
return helpString(helpTypeChat), true
default:

Loading…
Cancel
Save