calls
Bohdan Horbeshko 2 years ago
parent fe7346a530
commit ec49d5d412

@ -122,15 +122,15 @@ func NewClient(conf config.TelegramConfig, jid string, component *xmpp.Component
}
return &Client{
parameters: &parameters,
resource: resource,
xmpp: component,
jid: jid,
Session: session,
resources: make(map[string]bool),
content: &conf.Content,
cache: cache.NewCache(),
options: options,
parameters: &parameters,
resource: resource,
xmpp: component,
jid: jid,
Session: session,
resources: make(map[string]bool),
content: &conf.Content,
cache: cache.NewCache(),
options: options,
DelayedStatuses: make(map[int64]*DelayedStatus),
locks: clientLocks{
chatMessageLocks: make(map[int64]*sync.Mutex),

@ -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

@ -134,7 +134,7 @@ func (c *Client) Connect(resource string) error {
go func() {
_, err = c.client.GetChats(&client.GetChatsRequest{
Limit: chatsLimit,
Limit: chatsLimit,
})
if err != nil {
log.Errorf("Could not retrieve chats: %v", err)

@ -212,7 +212,7 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o
c.cache.SetStatus(chatID, show, status)
newArgs := []args.V {
newArgs := []args.V{
gateway.SPFrom(strconv.FormatInt(chatID, 10)),
gateway.SPShow(show),
gateway.SPStatus(status),
@ -331,7 +331,7 @@ func (c *Client) formatForward(fwd *client.MessageForwardInfo) string {
if originChat.AuthorSignature != "" {
signature = fmt.Sprintf(" (%s)", originChat.AuthorSignature)
}
return c.formatContact(originChat.SenderChatId)+signature
return c.formatContact(originChat.SenderChatId) + signature
case client.TypeMessageForwardOriginHiddenUser:
originUser := fwd.Origin.(*client.MessageForwardOriginHiddenUser)
return originUser.SenderName
@ -341,7 +341,7 @@ func (c *Client) formatForward(fwd *client.MessageForwardInfo) string {
if channel.AuthorSignature != "" {
signature = fmt.Sprintf(" (%s)", channel.AuthorSignature)
}
return c.formatContact(channel.ChatId)+signature
return c.formatContact(channel.ChatId) + signature
case client.TypeMessageForwardOriginMessageImport:
originImport := fwd.Origin.(*client.MessageForwardOriginMessageImport)
return originImport.SenderName

@ -37,9 +37,9 @@ func NewComponent(conf config.XMPPConfig, tc config.TelegramConfig) (*xmpp.Strea
Address: conf.Host + ":" + conf.Port,
Domain: conf.Jid,
},
Domain: conf.Jid,
Secret: conf.Password,
Name: "telegabber",
Domain: conf.Jid,
Secret: conf.Password,
Name: "telegabber",
}
router := xmpp.NewRouter()

@ -26,12 +26,12 @@ type PresenceXVCardUpdatePhoto struct {
// IqVcardTemp is from XEP-0054
type IqVcardTemp struct {
XMLName xml.Name `xml:"vcard-temp vCard"`
Fn IqVcardFn
Nickname IqVcardNickname
N IqVcardN
Tel IqVcardTel
Photo IqVcardPhoto
XMLName xml.Name `xml:"vcard-temp vCard"`
Fn IqVcardFn
Nickname IqVcardNickname
N IqVcardN
Tel IqVcardTel
Photo IqVcardPhoto
ResultSet *stanza.ResultSet `xml:"set,omitempty"`
}

@ -305,8 +305,8 @@ func handleGetDiscoInfo(s xmpp.Sender, iq *stanza.IQ) {
answer, err := stanza.NewIQ(stanza.Attrs{
Type: stanza.IQTypeResult,
From: iq.To,
To: iq.From,
Id: iq.Id,
To: iq.From,
Id: iq.Id,
Lang: "en",
})
if err != nil {

Loading…
Cancel
Save