Add /unban / /promote commands
This commit is contained in:
parent
9b4830b980
commit
6701335302
|
@ -17,6 +17,17 @@ import (
|
||||||
const notEnoughArguments string = "Not enough arguments"
|
const notEnoughArguments string = "Not enough arguments"
|
||||||
const telegramNotInitialized string = "Telegram connection is not initialized yet"
|
const telegramNotInitialized string = "Telegram connection is not initialized yet"
|
||||||
const notOnline string = "Not online"
|
const notOnline string = "Not online"
|
||||||
|
var permissionsAdmin = client.ChatMemberStatusAdministrator{
|
||||||
|
CanBeEdited: true,
|
||||||
|
CanChangeInfo: true,
|
||||||
|
CanPostMessages: true,
|
||||||
|
CanEditMessages: true,
|
||||||
|
CanDeleteMessages: true,
|
||||||
|
CanInviteUsers: true,
|
||||||
|
CanRestrictMembers: true,
|
||||||
|
CanPinMessages: true,
|
||||||
|
CanPromoteMembers: false,
|
||||||
|
}
|
||||||
var permissionsMember = client.ChatPermissions{
|
var permissionsMember = client.ChatPermissions{
|
||||||
CanSendMessages: true,
|
CanSendMessages: true,
|
||||||
CanSendMediaMessages: true,
|
CanSendMediaMessages: true,
|
||||||
|
@ -60,6 +71,8 @@ var chatCommands = map[string]command{
|
||||||
"mute": command{"id or @username [hours]", "mute user in current chat"},
|
"mute": command{"id or @username [hours]", "mute user in current chat"},
|
||||||
"unmute": command{"id or @username", "unrestrict user from current chat"},
|
"unmute": command{"id or @username", "unrestrict user from 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"},
|
||||||
|
"unban": command{"id or @username", "unbans @username in current chat (and devotes from admins)"},
|
||||||
|
"promote": command{"id or @username [title]", "promote user to admin in current chat"},
|
||||||
"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"},
|
||||||
|
@ -661,6 +674,51 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error(), true
|
return err.Error(), true
|
||||||
}
|
}
|
||||||
|
// unban @username
|
||||||
|
case "unban":
|
||||||
|
if len(args) < 1 {
|
||||||
|
return notEnoughArguments, true
|
||||||
|
}
|
||||||
|
|
||||||
|
contact, _, err := c.GetContactByUsername(args[0])
|
||||||
|
if err != nil {
|
||||||
|
return err.Error(), true
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{
|
||||||
|
ChatId: chatID,
|
||||||
|
MemberId: &client.MessageSenderUser{UserId: contact.Id},
|
||||||
|
Status: &client.ChatMemberStatusMember{},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err.Error(), true
|
||||||
|
}
|
||||||
|
// promote @username to admin
|
||||||
|
case "promote":
|
||||||
|
if len(args) < 1 {
|
||||||
|
return notEnoughArguments, true
|
||||||
|
}
|
||||||
|
|
||||||
|
contact, _, err := c.GetContactByUsername(args[0])
|
||||||
|
if err != nil {
|
||||||
|
return err.Error(), true
|
||||||
|
}
|
||||||
|
|
||||||
|
// clone the permissions
|
||||||
|
status := permissionsAdmin
|
||||||
|
|
||||||
|
if len(args) > 1 {
|
||||||
|
status.CustomTitle = args[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{
|
||||||
|
ChatId: chatID,
|
||||||
|
MemberId: &client.MessageSenderUser{UserId: contact.Id},
|
||||||
|
Status: &status,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err.Error(), true
|
||||||
|
}
|
||||||
// leave current chat
|
// leave current chat
|
||||||
case "leave":
|
case "leave":
|
||||||
_, err := c.client.LeaveChat(&client.LeaveChatRequest{
|
_, err := c.client.LeaveChat(&client.LeaveChatRequest{
|
||||||
|
|
Loading…
Reference in a new issue