Add /ban command
This commit is contained in:
parent
4b099fba41
commit
354887d724
|
@ -7,6 +7,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"dev.narayana.im/narayana/telegabber/xmpp/gateway"
|
"dev.narayana.im/narayana/telegabber/xmpp/gateway"
|
||||||
|
|
||||||
|
@ -31,20 +32,20 @@ var transportCommands = map[string]command{
|
||||||
|
|
||||||
var chatCommands = map[string]command{
|
var chatCommands = map[string]command{
|
||||||
"d": command{"[n]", "delete your last message(s)"},
|
"d": command{"[n]", "delete your last message(s)"},
|
||||||
//"s": command{"regex replace", "edit your last message"},
|
"s": command{"regex replace", "edit your last message"},
|
||||||
//"add": command{"@username", "add @username to your chat list"},
|
"add": command{"@username", "add @username to your chat list"},
|
||||||
//"join": command{"https://t.me/invite_link", "join to chat via invite link"},
|
"join": command{"https://t.me/invite_link", "join to chat via invite link"},
|
||||||
//"group": command{"title", "create groupchat «title» with current user"},
|
"group": command{"title", "create groupchat «title» with current user"},
|
||||||
//"supergroup": command{"title description", "create new supergroup «title» with «description»"},
|
"supergroup": command{"title description", "create new supergroup «title» with «description»"},
|
||||||
//"channel": command{"title description", "create new channel «title» with «description»"},
|
"channel": command{"title description", "create new channel «title» with «description»"},
|
||||||
//"secret": command{"", "create secretchat with current user"},
|
"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"},
|
//"history": command{"[limit]", "get last [limit] messages from current chat"},
|
||||||
//"block": command{"", "blacklist current user"},
|
"block": command{"", "blacklist current user"},
|
||||||
//"unblock": command{"", "unblacklist current user"},
|
"unblock": command{"", "unblacklist current user"},
|
||||||
//"invite": command{"id or @username", "add user to current chat"},
|
"invite": command{"id or @username", "add user to current chat"},
|
||||||
//"kick": command{"id or @username", "remove 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"},
|
"ban": command{"id or @username [hours]", "restrict @username from current chat for [hours] or forever"},
|
||||||
//"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"},
|
||||||
|
@ -505,6 +506,37 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
|
||||||
return err.Error(), true
|
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":
|
case "help":
|
||||||
return helpString(helpTypeChat), true
|
return helpString(helpTypeChat), true
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue