|
|
|
@ -17,6 +17,7 @@ import (
|
|
|
|
|
const notEnoughArguments string = "Not enough arguments"
|
|
|
|
|
const telegramNotInitialized string = "Telegram connection is not initialized yet"
|
|
|
|
|
const notOnline string = "Not online"
|
|
|
|
|
|
|
|
|
|
var permissionsAdmin = client.ChatMemberStatusAdministrator{
|
|
|
|
|
CanBeEdited: true,
|
|
|
|
|
CanChangeInfo: true,
|
|
|
|
@ -82,8 +83,8 @@ var chatCommands = map[string]command{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var transportConfigurationOptions = map[string]configurationOption{
|
|
|
|
|
"timezone": configurationOption{"<timezone>", "adjust timezone for Telegram user statuses (example: +02:00)"},
|
|
|
|
|
"keeponline": configurationOption{"<bool>", "always keep telegram session online and rely on jabber offline messages (example: true)"},
|
|
|
|
|
"timezone": configurationOption{"<timezone>", "adjust timezone for Telegram user statuses (example: +02:00)"},
|
|
|
|
|
"keeponline": configurationOption{"<bool>", "always keep telegram session online and rely on jabber offline messages (example: true)"},
|
|
|
|
|
"rawmessages": configurationOption{"<bool>", "do not add additional info (message id, origin etc.) to incoming messages (example: true)"},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -144,13 +145,13 @@ func parseCommand(cmdline string) (string, []string) {
|
|
|
|
|
return bodyFields[0][1:], bodyFields[1:]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func rawCmdArguments(cmdline string, start uint8) (string) {
|
|
|
|
|
func rawCmdArguments(cmdline string, start uint8) string {
|
|
|
|
|
var state uint
|
|
|
|
|
// /cmd ababa galamaga
|
|
|
|
|
// 01 2 3 45
|
|
|
|
|
startState := uint(3 + 2 * start)
|
|
|
|
|
startState := uint(3 + 2*start)
|
|
|
|
|
for i, r := range cmdline {
|
|
|
|
|
isOdd := state % 2 == 1
|
|
|
|
|
isOdd := state%2 == 1
|
|
|
|
|
isSpace := unicode.IsSpace(r)
|
|
|
|
|
if (!isOdd && !isSpace) || (isOdd && isSpace) {
|
|
|
|
|
state += 1
|
|
|
|
@ -611,7 +612,7 @@ 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: &client.ChatMemberStatusRestricted{
|
|
|
|
|
Status: &client.ChatMemberStatusRestricted{
|
|
|
|
|
IsMember: true,
|
|
|
|
|
RestrictedUntilDate: c.formatBantime(hours),
|
|
|
|
|
Permissions: &permissionsReadonly,
|
|
|
|
@ -634,7 +635,7 @@ 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: &client.ChatMemberStatusRestricted{
|
|
|
|
|
Status: &client.ChatMemberStatusRestricted{
|
|
|
|
|
IsMember: true,
|
|
|
|
|
RestrictedUntilDate: 0,
|
|
|
|
|
Permissions: &permissionsMember,
|
|
|
|
@ -663,7 +664,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{
|
|
|
|
|
ChatId: chatID,
|
|
|
|
|
ChatId: chatID,
|
|
|
|
|
MemberId: &client.MessageSenderUser{UserId: contact.Id},
|
|
|
|
|
Status: &client.ChatMemberStatusBanned{
|
|
|
|
|
BannedUntilDate: c.formatBantime(hours),
|
|
|
|
@ -684,9 +685,9 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{
|
|
|
|
|
ChatId: chatID,
|
|
|
|
|
ChatId: chatID,
|
|
|
|
|
MemberId: &client.MessageSenderUser{UserId: contact.Id},
|
|
|
|
|
Status: &client.ChatMemberStatusMember{},
|
|
|
|
|
Status: &client.ChatMemberStatusMember{},
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err.Error(), true
|
|
|
|
@ -710,9 +711,9 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{
|
|
|
|
|
ChatId: chatID,
|
|
|
|
|
ChatId: chatID,
|
|
|
|
|
MemberId: &client.MessageSenderUser{UserId: contact.Id},
|
|
|
|
|
Status: &status,
|
|
|
|
|
Status: &status,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err.Error(), true
|
|
|
|
|