diff --git a/go.mod b/go.mod index a20dc3d..1bb878e 100644 --- a/go.mod +++ b/go.mod @@ -8,10 +8,9 @@ require ( github.com/santhosh-tekuri/jsonschema v1.2.4 github.com/sirupsen/logrus v1.4.2 github.com/soheilhy/args v0.0.0-20150720134047-6bcf4c78e87e - github.com/godcong/go-tdlib v0.1.0 + github.com/zelenin/go-tdlib v0.5.2 gopkg.in/yaml.v2 v2.2.4 gosrc.io/xmpp v0.5.2-0.20211214110136-5f99e1cd06e1 ) replace gosrc.io/xmpp => github.com/bodqhrohro/go-xmpp v0.2.1-0.20211218153313-a8aadd78b65b -replace github.com/godcong/go-tdlib => github.com/bodqhrohro/go-tdlib v0.4.4-0.20211229000346-ee6018be8ec0 diff --git a/go.sum b/go.sum index fa8290a..c2185b1 100644 --- a/go.sum +++ b/go.sum @@ -90,6 +90,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P github.com/twitchyliquid64/golang-asm v0.0.0-20190126203739-365674df15fc/go.mod h1:NoCfSFWosfqMqmmD7hApkirIK9ozpHjxRnRxs1l413A= github.com/zelenin/go-tdlib v0.1.0 h1:Qq+FGE0/EWdsRB6m26ULDndu2DtW558aFXNzi0Y/FqQ= github.com/zelenin/go-tdlib v0.1.0/go.mod h1:Xs8fXbk5n7VaPyrSs9DP7QYoBScWYsjX+lUcWmx1DIU= +github.com/zelenin/go-tdlib v0.5.2 h1:inEATEM0Pz6/HBI3wTlhd+brDHpmoXGgwdSb8/V6GiA= +github.com/zelenin/go-tdlib v0.5.2/go.mod h1:Xs8fXbk5n7VaPyrSs9DP7QYoBScWYsjX+lUcWmx1DIU= go.coder.com/go-tools v0.0.0-20190317003359-0c6a35b74a16/go.mod h1:iKV5yK9t+J5nG9O3uF6KYdPEz3dyfMyB15MN1rbQ8Qw= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= diff --git a/telegram/cache/cache.go b/telegram/cache/cache.go index 3144ca9..3d9608d 100644 --- a/telegram/cache/cache.go +++ b/telegram/cache/cache.go @@ -3,7 +3,7 @@ package cache import ( "sync" - "github.com/godcong/go-tdlib/client" + "github.com/zelenin/go-tdlib/client" ) // Status stores formatted data for XMPP presence diff --git a/telegram/client.go b/telegram/client.go index 097354d..4995597 100644 --- a/telegram/client.go +++ b/telegram/client.go @@ -11,7 +11,7 @@ import ( "dev.narayana.im/narayana/telegabber/persistence" "dev.narayana.im/narayana/telegabber/telegram/cache" - "github.com/godcong/go-tdlib/client" + "github.com/zelenin/go-tdlib/client" "gosrc.io/xmpp" ) @@ -73,7 +73,7 @@ func NewClient(conf config.TelegramConfig, jid string, component *xmpp.Component )) } - apiID, err := strconv.Atoi(conf.Tdlib.Client.APIID) + apiID, err := strconv.ParseInt(conf.Tdlib.Client.APIID, 10, 32) if err != nil { return &Client{}, errors.Wrap(err, "Wrong api_id") } @@ -89,7 +89,7 @@ func NewClient(conf config.TelegramConfig, jid string, component *xmpp.Component UseMessageDatabase: true, UseSecretChats: conf.Tdlib.Client.UseSecretChats, - ApiID: int64(apiID), + ApiId: int32(apiID), ApiHash: conf.Tdlib.Client.APIHash, SystemLanguageCode: "en", diff --git a/telegram/commands.go b/telegram/commands.go index 9a7cf19..378c666 100644 --- a/telegram/commands.go +++ b/telegram/commands.go @@ -11,7 +11,7 @@ import ( "dev.narayana.im/narayana/telegabber/xmpp/gateway" log "github.com/sirupsen/logrus" - "github.com/godcong/go-tdlib/client" + "github.com/zelenin/go-tdlib/client" ) const notEnoughArguments string = "Not enough arguments" @@ -163,7 +163,7 @@ func (c *Client) usernameOrIDToID(username string) (int64, error) { return 0, err } - userID = chat.ID + userID = chat.Id if userID <= 0 { return 0, errors.New("Not a user") } @@ -363,7 +363,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) limit = 1 } - messages, err := c.getLastMessages(chatID, "", c.me.ID, limit) + messages, err := c.getLastMessages(chatID, "", c.me.Id, limit) if err != nil { return err.Error(), true } @@ -372,13 +372,13 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) var messageIds []int64 for _, message := range messages.Messages { if message != nil { - messageIds = append(messageIds, message.ID) + messageIds = append(messageIds, message.Id) } } _, err = c.client.DeleteMessages(&client.DeleteMessagesRequest{ - ChatID: chatID, - MessageIDs: messageIds, + ChatId: chatID, + MessageIds: messageIds, Revoke: true, }) if err != nil { @@ -393,7 +393,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) return "Not enough arguments", true } - messages, err := c.getLastMessages(chatID, "", c.me.ID, 1) + messages, err := c.getLastMessages(chatID, "", c.me.Id, 1) if err != nil { return err.Error(), true } @@ -410,8 +410,8 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) if content != nil { c.client.EditMessageText(&client.EditMessageTextRequest{ - ChatID: chatID, - MessageID: message.ID, + ChatId: chatID, + MessageId: message.Id, InputMessageContent: content, }) } else { @@ -436,7 +436,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) gateway.SendPresence( c.xmpp, c.jid, - gateway.SPFrom(strconv.FormatInt(chat.ID, 10)), + gateway.SPFrom(strconv.FormatInt(chat.Id, 10)), gateway.SPType("subscribe"), ) // join https://t.me/publichat @@ -481,7 +481,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) // create new secret chat with current user case "secret": _, err := c.client.CreateNewSecretChat(&client.CreateNewSecretChatRequest{ - UserID: chatID, + UserId: chatID, }) if err != nil { return err.Error(), true @@ -493,7 +493,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) } _, err := c.client.CreateNewBasicGroupChat(&client.CreateNewBasicGroupChatRequest{ - UserIDs: []int64{chatID}, + UserIds: []int64{chatID}, Title: args[0], }) if err != nil { @@ -502,7 +502,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) // blacklists current user case "block": _, err := c.client.ToggleMessageSenderIsBlocked(&client.ToggleMessageSenderIsBlockedRequest{ - Sender: &client.MessageSenderUser{UserID: chatID}, + SenderId: &client.MessageSenderUser{UserId: chatID}, IsBlocked: true, }) if err != nil { @@ -511,7 +511,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) // unblacklists current user case "unblock": _, err := c.client.ToggleMessageSenderIsBlocked(&client.ToggleMessageSenderIsBlockedRequest{ - Sender: &client.MessageSenderUser{UserID: chatID}, + SenderId: &client.MessageSenderUser{UserId: chatID}, IsBlocked: false, }) if err != nil { @@ -529,8 +529,8 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) } _, err = c.client.AddChatMember(&client.AddChatMemberRequest{ - ChatID: chatID, - UserID: contact.ID, + ChatId: chatID, + UserId: contact.Id, ForwardLimit: 100, }) if err != nil { @@ -548,9 +548,9 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) } _, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{ - ChatID: chatID, - UserID: contact.ID, - Status: c.formatRestrict(false, 0), + ChatId: chatID, + MemberId: &client.MessageSenderUser{UserId: contact.Id}, + Status: c.formatRestrict(false, 0), }) if err != nil { return err.Error(), true @@ -575,8 +575,8 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) } _, err = c.client.SetChatMemberStatus(&client.SetChatMemberStatusRequest{ - ChatID: chatID, - UserID: contact.ID, + ChatId: chatID, + MemberId: &client.MessageSenderUser{UserId: contact.Id}, Status: c.formatRestrict(true, hours), }) if err != nil { @@ -585,7 +585,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) // leave current chat case "leave": _, err := c.client.LeaveChat(&client.LeaveChatRequest{ - ChatID: chatID, + ChatId: chatID, }) if err != nil { return err.Error(), true @@ -603,7 +603,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) if chatType == client.TypeChatTypeSecret { chatTypeSecret, _ := chat.Type.(*client.ChatTypeSecret) _, err = c.client.CloseSecretChat(&client.CloseSecretChatRequest{ - SecretChatID: chatTypeSecret.SecretChatID, + SecretChatId: chatTypeSecret.SecretChatId, }) if err != nil { return err.Error(), true @@ -614,7 +614,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) // delete current chat case "delete": _, err := c.client.DeleteChatHistory(&client.DeleteChatHistoryRequest{ - ChatID: chatID, + ChatId: chatID, RemoveFromChatList: true, Revoke: true, }) @@ -658,7 +658,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) var err error for _ = range make([]struct{}, 2) { messages, err = c.client.GetChatHistory(&client.GetChatHistoryRequest{ - ChatID: chatID, + ChatId: chatID, Limit: limit, }) if err != nil { @@ -680,7 +680,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) } members, err := c.client.SearchChatMembers(&client.SearchChatMembersRequest{ - ChatID: chatID, + ChatId: chatID, Limit: 9999, Query: query, Filter: &client.ChatMembersFilterMembers{}, @@ -692,13 +692,13 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool) var entries []string for _, member := range members.Members { var senderId int64 - switch member.MemberID.MessageSenderType() { + switch member.MemberId.MessageSenderType() { case client.TypeMessageSenderUser: - memberUser, _ := member.MemberID.(*client.MessageSenderUser) - senderId = memberUser.UserID + memberUser, _ := member.MemberId.(*client.MessageSenderUser) + senderId = memberUser.UserId case client.TypeMessageSenderChat: - memberChat, _ := member.MemberID.(*client.MessageSenderChat) - senderId = memberChat.ChatID + memberChat, _ := member.MemberId.(*client.MessageSenderChat) + senderId = memberChat.ChatId } entries = append(entries, fmt.Sprintf( "%v | role: %v", diff --git a/telegram/connect.go b/telegram/connect.go index f2ea01d..94154d8 100644 --- a/telegram/connect.go +++ b/telegram/connect.go @@ -2,13 +2,12 @@ package telegram import ( "github.com/pkg/errors" - "math" "strconv" "dev.narayana.im/narayana/telegabber/xmpp/gateway" log "github.com/sirupsen/logrus" - "github.com/godcong/go-tdlib/client" + "github.com/zelenin/go-tdlib/client" ) const chatsLimit int32 = 999 @@ -135,7 +134,6 @@ func (c *Client) Connect(resource string) error { go func() { _, err = c.client.GetChats(&client.GetChatsRequest{ - OffsetOrder: client.JsonInt64(math.MaxInt64), Limit: chatsLimit, }) if err != nil { diff --git a/telegram/formatter/formatter.go b/telegram/formatter/formatter.go index 355d393..2946a55 100644 --- a/telegram/formatter/formatter.go +++ b/telegram/formatter/formatter.go @@ -4,7 +4,7 @@ import ( "sort" log "github.com/sirupsen/logrus" - "github.com/godcong/go-tdlib/client" + "github.com/zelenin/go-tdlib/client" ) // Insertion is a piece of text in given position diff --git a/telegram/formatter/formatter_test.go b/telegram/formatter/formatter_test.go index 5c93ea0..63337d6 100644 --- a/telegram/formatter/formatter_test.go +++ b/telegram/formatter/formatter_test.go @@ -3,7 +3,7 @@ package formatter import ( "testing" - "github.com/godcong/go-tdlib/client" + "github.com/zelenin/go-tdlib/client" ) func TestNoFormatting(t *testing.T) { diff --git a/telegram/handlers.go b/telegram/handlers.go index b76ea23..a28d5da 100644 --- a/telegram/handlers.go +++ b/telegram/handlers.go @@ -13,7 +13,7 @@ import ( "dev.narayana.im/narayana/telegabber/xmpp/gateway" log "github.com/sirupsen/logrus" - "github.com/godcong/go-tdlib/client" + "github.com/zelenin/go-tdlib/client" ) func uhOh() { @@ -119,15 +119,15 @@ func (c *Client) updateHandler() { // new user discovered func (c *Client) updateUser(update *client.UpdateUser) { - c.cache.SetUser(update.User.ID, update.User) + c.cache.SetUser(update.User.Id, update.User) show, status := c.userStatusToText(update.User.Status) - go c.ProcessStatusUpdate(update.User.ID, status, show) + go c.ProcessStatusUpdate(update.User.Id, status, show) } // user status changed func (c *Client) updateUserStatus(update *client.UpdateUserStatus) { show, status := c.userStatusToText(update.Status) - go c.ProcessStatusUpdate(update.UserID, status, show, gateway.SPImmed(false)) + go c.ProcessStatusUpdate(update.UserId, status, show, gateway.SPImmed(false)) } // new chat discovered @@ -135,7 +135,7 @@ func (c *Client) updateNewChat(update *client.UpdateNewChat) { go func() { if update.Chat != nil && update.Chat.Photo != nil && update.Chat.Photo.Small != nil { _, err := c.client.DownloadFile(&client.DownloadFileRequest{ - FileID: update.Chat.Photo.Small.ID, + FileId: update.Chat.Photo.Small.Id, Priority: 32, Synchronous: false, }) @@ -145,7 +145,7 @@ func (c *Client) updateNewChat(update *client.UpdateNewChat) { } } - c.cache.SetChat(update.Chat.ID, update.Chat) + c.cache.SetChat(update.Chat.Id, update.Chat) var isChannel = false if update.Chat.Type.ChatTypeType() == client.TypeChatTypeSupergroup { @@ -156,18 +156,18 @@ func (c *Client) updateNewChat(update *client.UpdateNewChat) { isChannel = typeSupergroup.IsChannel } - if !(isChannel && update.Chat.LastReadInboxMessageID == 0) { + if !(isChannel && update.Chat.LastReadInboxMessageId == 0) { gateway.SendPresence( c.xmpp, c.jid, - gateway.SPFrom(strconv.FormatInt(update.Chat.ID, 10)), + gateway.SPFrom(strconv.FormatInt(update.Chat.Id, 10)), gateway.SPType("subscribe"), gateway.SPNickname(update.Chat.Title), ) } - if update.Chat.ID < 0 { - c.ProcessStatusUpdate(update.Chat.ID, update.Chat.Title, "chat") + if update.Chat.Id < 0 { + c.ProcessStatusUpdate(update.Chat.Id, update.Chat.Title, "chat") } }() } @@ -176,7 +176,7 @@ func (c *Client) updateNewChat(update *client.UpdateNewChat) { func (c *Client) updateNewMessage(update *client.UpdateNewMessage) { go func() { // guarantee sequential message delivering per chat - lock := c.getChatMessageLock(update.Message.ChatID) + lock := c.getChatMessageLock(update.Message.ChatId) lock.Lock() defer lock.Unlock() @@ -188,7 +188,7 @@ func (c *Client) updateNewMessage(update *client.UpdateNewMessage) { } log.WithFields(log.Fields{ - "chat_id": update.Message.ChatID, + "chat_id": update.Message.ChatId, }).Warn("New message from chat") text := c.messageToText(update.Message) @@ -197,7 +197,7 @@ func (c *Client) updateNewMessage(update *client.UpdateNewMessage) { // download file(s) if file != nil && !file.Local.IsDownloadingCompleted { c.client.DownloadFile(&client.DownloadFileRequest{ - FileID: file.ID, + FileId: file.Id, Priority: 10, Synchronous: false, }) @@ -208,9 +208,9 @@ func (c *Client) updateNewMessage(update *client.UpdateNewMessage) { prefix.WriteString(c.messageToPrefix(update.Message, c.formatContent(file, filename))) if text != "" { // \n if it is groupchat and message is not empty - if update.Message.ChatID < 0 { + if update.Message.ChatId < 0 { prefix.WriteString("\n") - } else if update.Message.ChatID > 0 { + } else if update.Message.ChatId > 0 { prefix.WriteString(" | ") } @@ -222,12 +222,12 @@ func (c *Client) updateNewMessage(update *client.UpdateNewMessage) { // mark message as read c.client.ViewMessages(&client.ViewMessagesRequest{ - ChatID: update.Message.ChatID, - MessageIDs: []int64{update.Message.ID}, + ChatId: update.Message.ChatId, + MessageIds: []int64{update.Message.Id}, ForceRead: true, }) // forward message to XMPP - gateway.SendMessage(c.jid, strconv.FormatInt(update.Message.ChatID, 10), text, c.xmpp) + gateway.SendMessage(c.jid, strconv.FormatInt(update.Message.ChatId, 10), text, c.xmpp) }() } @@ -236,20 +236,20 @@ func (c *Client) updateMessageContent(update *client.UpdateMessageContent) { markupFunction := formatter.EntityToXEP0393 if update.NewContent.MessageContentType() == client.TypeMessageText { textContent := update.NewContent.(*client.MessageText) - text := fmt.Sprintf("✎ %v | %s", update.MessageID, formatter.Format( + text := fmt.Sprintf("✎ %v | %s", update.MessageId, formatter.Format( textContent.Text.Text, formatter.SortEntities(textContent.Text.Entities), markupFunction, )) - gateway.SendMessage(c.jid, strconv.FormatInt(update.ChatID, 10), text, c.xmpp) + gateway.SendMessage(c.jid, strconv.FormatInt(update.ChatId, 10), text, c.xmpp) } } // message(s) deleted func (c *Client) updateDeleteMessages(update *client.UpdateDeleteMessages) { if update.IsPermanent { - text := "✗ " + strings.Join(int64SliceToStringSlice(update.MessageIDs), ",") - gateway.SendMessage(c.jid, strconv.FormatInt(update.ChatID, 10), text, c.xmpp) + text := "✗ " + strings.Join(int64SliceToStringSlice(update.MessageIds), ",") + gateway.SendMessage(c.jid, strconv.FormatInt(update.ChatId, 10), text, c.xmpp) } } @@ -265,7 +265,7 @@ func (c *Client) updateFile(update *client.UpdateFile) { fmt.Sprintf( "%s/%s%s", c.content.Path, - fmt.Sprintf("%x", sha256.Sum256([]byte(update.File.Remote.ID))), + fmt.Sprintf("%x", sha256.Sum256([]byte(update.File.Remote.Id))), filepath.Ext(update.File.Local.Path), ), ) diff --git a/telegram/utils.go b/telegram/utils.go index 556b1a7..63a880e 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -19,7 +19,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/soheilhy/args" - "github.com/godcong/go-tdlib/client" + "github.com/zelenin/go-tdlib/client" ) var errOffline = errors.New("TDlib instance is offline") @@ -43,7 +43,7 @@ func (c *Client) GetContactByUsername(username string) (*client.Chat, *client.Us return nil, nil, err } - return c.GetContactByID(chat.ID, chat) + return c.GetContactByID(chat.Id, chat) } // GetContactByID gets user and chat information from cache (or tries to retrieve it, if missing) @@ -60,7 +60,7 @@ func (c *Client) GetContactByID(id int64, chat *client.Chat) (*client.Chat, *cli user, ok = c.cache.GetUser(id) if !ok && id > 0 { user, err = c.client.GetUser(&client.GetUserRequest{ - UserID: id, + UserId: id, }) if err == nil { c.cache.SetUser(id, user) @@ -71,7 +71,7 @@ func (c *Client) GetContactByID(id int64, chat *client.Chat) (*client.Chat, *cli if !ok { if chat == nil { cacheChat, err = c.client.GetChat(&client.GetChatRequest{ - ChatID: id, + ChatId: id, }) if err != nil { // error is irrelevant if the user was found successfully @@ -194,11 +194,11 @@ func (c *Client) formatContact(chatID int64) string { var str string if chat != nil { - str = fmt.Sprintf("%s (%v)", chat.Title, chat.ID) + str = fmt.Sprintf("%s (%v)", chat.Title, chat.Id) } else if user != nil { username := user.Username if username == "" { - username = strconv.FormatInt(user.ID, 10) + username = strconv.FormatInt(user.Id, 10) } str = fmt.Sprintf("%s %s (%v)", user.FirstName, user.LastName, username) @@ -215,8 +215,8 @@ func (c *Client) formatMessage(chatID int64, messageID int64, preview bool, mess var err error if message == nil { message, err = c.client.GetMessage(&client.GetMessageRequest{ - ChatID: chatID, - MessageID: messageID, + ChatId: chatID, + MessageId: messageID, }) if err != nil { return fmt.Sprintf("", err.Error()) @@ -229,15 +229,15 @@ func (c *Client) formatMessage(chatID int64, messageID int64, preview bool, mess var str strings.Builder var senderId int64 - switch message.Sender.MessageSenderType() { + switch message.SenderId.MessageSenderType() { case client.TypeMessageSenderUser: - senderUser, _ := message.Sender.(*client.MessageSenderUser) - senderId = senderUser.UserID + senderUser, _ := message.SenderId.(*client.MessageSenderUser) + senderId = senderUser.UserId case client.TypeMessageSenderChat: - senderChat, _ := message.Sender.(*client.MessageSenderChat) - senderId = senderChat.ChatID + senderChat, _ := message.SenderId.(*client.MessageSenderChat) + senderId = senderChat.ChatId } - str.WriteString(fmt.Sprintf("%v | %s | ", message.ID, c.formatContact(senderId))) + str.WriteString(fmt.Sprintf("%v | %s | ", message.Id, c.formatContact(senderId))) if !preview { str.WriteString( time.Unix(int64(message.Date), 0). @@ -275,14 +275,14 @@ func (c *Client) formatForward(fwd *client.MessageForwardInfo) string { switch fwd.Origin.MessageForwardOriginType() { case client.TypeMessageForwardOriginUser: originUser := fwd.Origin.(*client.MessageForwardOriginUser) - return c.formatContact(originUser.SenderUserID) + return c.formatContact(originUser.SenderUserId) case client.TypeMessageForwardOriginChat: originChat := fwd.Origin.(*client.MessageForwardOriginChat) var signature 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 @@ -292,7 +292,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 } return "Unknown forward type" } @@ -307,7 +307,7 @@ func (c *Client) formatContent(file *client.File, filename string) string { filename, file.Size/1024, c.content.Link, - fmt.Sprintf("%x", sha256.Sum256([]byte(file.Remote.ID))), + fmt.Sprintf("%x", sha256.Sum256([]byte(file.Remote.Id))), filepath.Ext(filename), ) } @@ -346,17 +346,17 @@ func (c *Client) messageToText(message *client.Message) string { addMembers, _ := message.Content.(*client.MessageChatAddMembers) text := "invited " - if len(addMembers.MemberUserIDs) > 0 { - text += c.formatContact(addMembers.MemberUserIDs[0]) + if len(addMembers.MemberUserIds) > 0 { + text += c.formatContact(addMembers.MemberUserIds[0]) } return text case client.TypeMessageChatDeleteMember: deleteMember, _ := message.Content.(*client.MessageChatDeleteMember) - return "kicked " + c.formatContact(deleteMember.UserID) + return "kicked " + c.formatContact(deleteMember.UserId) case client.TypeMessagePinMessage: pinMessage, _ := message.Content.(*client.MessagePinMessage) - return "pinned message: " + c.formatMessage(message.ChatID, pinMessage.MessageID, false, nil) + return "pinned message: " + c.formatMessage(message.ChatId, pinMessage.MessageId, false, nil) case client.TypeMessageChatChangeTitle: changeTitle, _ := message.Content.(*client.MessageChatChangeTitle) return "chat title set to: " + changeTitle.Title @@ -448,7 +448,7 @@ func (c *Client) contentToFilename(content client.MessageContent) (*client.File, sizes := photo.Photo.Sizes if len(sizes) > 1 { file := sizes[len(sizes)-1].Photo - return file, strconv.FormatInt(file.ID, 10) + ".jpg" + return file, strconv.FormatInt(int64(file.Id), 10) + ".jpg" } return nil, "" case client.TypeMessageAudio: @@ -474,23 +474,23 @@ func (c *Client) messageToPrefix(message *client.Message, fileString string) str } else { directionChar = "⇽ " } - prefix = append(prefix, directionChar+strconv.FormatInt(message.ID, 10)) + prefix = append(prefix, directionChar+strconv.FormatInt(message.Id, 10)) // show sender in group chats - if message.ChatID < 0 && message.Sender != nil { + if message.ChatId < 0 && message.SenderId != nil { var senderId int64 - switch message.Sender.MessageSenderType() { + switch message.SenderId.MessageSenderType() { case client.TypeMessageSenderUser: - senderUser, _ := message.Sender.(*client.MessageSenderUser) - senderId = senderUser.UserID + senderUser, _ := message.SenderId.(*client.MessageSenderUser) + senderId = senderUser.UserId case client.TypeMessageSenderChat: - senderChat, _ := message.Sender.(*client.MessageSenderChat) - senderId = senderChat.ChatID + senderChat, _ := message.SenderId.(*client.MessageSenderChat) + senderId = senderChat.ChatId } prefix = append(prefix, c.formatContact(senderId)) } // reply to - if message.ReplyToMessageID != 0 { - prefix = append(prefix, "reply: "+c.formatMessage(message.ChatID, message.ReplyToMessageID, true, nil)) + if message.ReplyToMessageId != 0 { + prefix = append(prefix, "reply: "+c.formatMessage(message.ChatId, message.ReplyToMessageId, true, nil)) } if message.ForwardInfo != nil { prefix = append(prefix, "fwd: "+c.formatForward(message.ForwardInfo)) @@ -535,7 +535,7 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, returnJid str var file *client.InputFileRemote if chatID != 0 && c.content.Upload != "" && strings.HasPrefix(text, c.content.Upload) { file = &client.InputFileRemote{ - ID: text, + Id: text, } } @@ -567,8 +567,8 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, returnJid str if chatID != 0 { _, err := c.client.SendMessage(&client.SendMessageRequest{ - ChatID: chatID, - ReplyToMessageID: reply, + ChatId: chatID, + ReplyToMessageId: reply, InputMessageContent: message, }) if err != nil { @@ -628,10 +628,10 @@ func (c *Client) roster(resource string) { func (c *Client) getLastMessages(id int64, query string, from int64, count int32) (*client.Messages, error) { return c.client.SearchChatMessages(&client.SearchChatMessagesRequest{ - ChatID: id, - Query: query, - Sender: &client.MessageSenderUser{UserID: from}, - Filter: &client.SearchMessagesFilterEmpty{}, - Limit: count, + ChatId: id, + Query: query, + SenderId: &client.MessageSenderUser{UserId: from}, + Filter: &client.SearchMessagesFilterEmpty{}, + Limit: count, }) } diff --git a/telegram/utils_test.go b/telegram/utils_test.go index dc250a6..69124fc 100644 --- a/telegram/utils_test.go +++ b/telegram/utils_test.go @@ -7,7 +7,7 @@ import ( "dev.narayana.im/narayana/telegabber/config" "dev.narayana.im/narayana/telegabber/persistence" - "github.com/godcong/go-tdlib/client" + "github.com/zelenin/go-tdlib/client" ) const testTimeFormat string = "15:04 02/01/2006"