|
|
|
@ -17,6 +17,17 @@ import (
|
|
|
|
|
const notEnoughArguments string = "Not enough arguments"
|
|
|
|
|
const telegramNotInitialized string = "Telegram connection is not initialized yet"
|
|
|
|
|
const notOnline string = "Not online"
|
|
|
|
|
var permissionsMember = client.ChatPermissions{
|
|
|
|
|
CanSendMessages: true,
|
|
|
|
|
CanSendMediaMessages: true,
|
|
|
|
|
CanSendPolls: true,
|
|
|
|
|
CanSendOtherMessages: true,
|
|
|
|
|
CanAddWebPagePreviews: true,
|
|
|
|
|
CanChangeInfo: true,
|
|
|
|
|
CanInviteUsers: true,
|
|
|
|
|
CanPinMessages: true,
|
|
|
|
|
}
|
|
|
|
|
var permissionsReadonly = client.ChatPermissions{}
|
|
|
|
|
|
|
|
|
|
var transportCommands = map[string]command{
|
|
|
|
|
"login": command{"phone", "sign in"},
|
|
|
|
@ -46,6 +57,8 @@ var chatCommands = map[string]command{
|
|
|
|
|
"invite": command{"id or @username", "add user to current chat"},
|
|
|
|
|
"link": command{"", "get invite link for current chat"},
|
|
|
|
|
"kick": command{"id or @username", "remove user to current chat"},
|
|
|
|
|
"mute": command{"id or @username [hours]", "mute user in 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"},
|
|
|
|
|
"leave": command{"", "leave current chat"},
|
|
|
|
|
"close": command{"", "close current secret chat"},
|
|
|
|
@ -560,7 +573,61 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
|
|
|
|
|
_, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{
|
|
|
|
|
ChatId: chatID,
|
|
|
|
|
MemberId: &client.MessageSenderUser{UserId: contact.Id},
|
|
|
|
|
Status: c.formatRestrict(false, 0),
|
|
|
|
|
Status: &client.ChatMemberStatusLeft{},
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err.Error(), true
|
|
|
|
|
}
|
|
|
|
|
// mute @username [n hours]
|
|
|
|
|
case "mute":
|
|
|
|
|
if len(args) < 1 {
|
|
|
|
|
return notEnoughArguments, true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contact, _, err := c.GetContactByUsername(args[0])
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err.Error(), true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var hours int64
|
|
|
|
|
if len(args) > 1 {
|
|
|
|
|
hours, err = strconv.ParseInt(args[1], 10, 32)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "Invalid number of hours", true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{
|
|
|
|
|
ChatId: chatID,
|
|
|
|
|
MemberId: &client.MessageSenderUser{UserId: contact.Id},
|
|
|
|
|
Status: &client.ChatMemberStatusRestricted{
|
|
|
|
|
IsMember: true,
|
|
|
|
|
RestrictedUntilDate: c.formatBantime(hours),
|
|
|
|
|
Permissions: &permissionsReadonly,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err.Error(), true
|
|
|
|
|
}
|
|
|
|
|
// unmute @username
|
|
|
|
|
case "unmute":
|
|
|
|
|
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.ChatMemberStatusRestricted{
|
|
|
|
|
IsMember: true,
|
|
|
|
|
RestrictedUntilDate: 0,
|
|
|
|
|
Permissions: &permissionsMember,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err.Error(), true
|
|
|
|
@ -587,7 +654,9 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
|
|
|
|
|
_, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{
|
|
|
|
|
ChatId: chatID,
|
|
|
|
|
MemberId: &client.MessageSenderUser{UserId: contact.Id},
|
|
|
|
|
Status: c.formatRestrict(true, hours),
|
|
|
|
|
Status: &client.ChatMemberStatusBanned{
|
|
|
|
|
BannedUntilDate: c.formatBantime(hours),
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err.Error(), true
|
|
|
|
|