UNPKG

tgsnake

Version:

Telegram MTProto framework for nodejs.

154 lines (153 loc) 6.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Update = void 0; const TL_js_1 = require("../TL.js"); const platform_node_js_1 = require("../../platform.node.js"); const index_js_1 = require("../Messages/index.js"); const Poll_js_1 = require("../Messages/Medias/Poll.js"); const callbackQuery_js_1 = require("./callbackQuery.js"); const chatMember_js_1 = require("./chatMember.js"); const chatJoinRequest_js_1 = require("./chatJoinRequest.js"); const Logger_js_1 = require("../../Context/Logger.js"); class Update extends TL_js_1.TLObject { message; editedMessage; channelPost; editedChannelPost; inlineQuery; chosenInlineResult; callbackQuery; shippingQuery; preCheckoutQuery; poll; pollAnswer; chatJoinRequest; myChatMember; chatMember; secretChat; constructor({ message, editedMessage, channelPost, editedChannelPost, inlineQuery, chosenInlineResult, callbackQuery, shippingQuery, preCheckoutQuery, poll, pollAnswer, chatJoinRequest, myChatMember, chatMember, secretChat, }, client) { super(client); this.message = message; this.editedMessage = editedMessage; this.channelPost = channelPost; this.editedChannelPost = editedChannelPost; this.inlineQuery = inlineQuery; this.chosenInlineResult = chosenInlineResult; this.callbackQuery = callbackQuery; this.shippingQuery = shippingQuery; this.preCheckoutQuery = preCheckoutQuery; this.poll = poll; this.pollAnswer = pollAnswer; this.chatJoinRequest = chatJoinRequest; this.myChatMember = myChatMember; this.chatMember = chatMember; this.secretChat = secretChat; } static async parse(client, update, chats, users) { Logger_js_1.Logger.debug(`Parsing update: ${update.className}`); if (update instanceof platform_node_js_1.Raws.Raw.UpdateNewMessage || update instanceof platform_node_js_1.Raws.Raw.UpdateNewChannelMessage) { return Update.updateNewMessage(client, update, chats, users); } if (update instanceof platform_node_js_1.Raws.Raw.UpdateEditMessage || update instanceof platform_node_js_1.Raws.Raw.UpdateEditChannelMessage) { return Update.updateEditMessage(client, update, chats, users); } if (update instanceof platform_node_js_1.Raws.Raw.UpdateBotCallbackQuery || update instanceof platform_node_js_1.Raws.Raw.UpdateInlineBotCallbackQuery) { return new Update({ callbackQuery: await callbackQuery_js_1.CallbackQuery.parse(client, update, chats, users), }, client); } if (update instanceof platform_node_js_1.Raws.UpdateSecretChatMessage) { return new Update({ secretChat: update, }, client); } if (update instanceof platform_node_js_1.Raws.Raw.UpdateChannelParticipant || update instanceof platform_node_js_1.Raws.Raw.UpdateChatParticipant) { const chatmember = chatMember_js_1.ChatMemberUpdated.parse(client, update, chats, users); if (chatmember.from.isSelf) { return new Update({ myChatMember: chatmember, }, client); } return new Update({ chatMember: chatmember, }, client); } if (update instanceof platform_node_js_1.Raws.Raw.UpdateBotChatInviteRequester) { return new Update({ chatJoinRequest: await chatJoinRequest_js_1.ChatJoinRequest.parse(client, update, chats, users), }, client); } if (update instanceof platform_node_js_1.Raws.Raw.UpdateMessagePoll) { return new Update({ poll: Poll_js_1.Poll.parse(client, update), }, client); } if (update instanceof platform_node_js_1.Raws.Raw.UpdateMessagePollVote) { return new Update({ pollAnswer: Poll_js_1.PollAnswer.parseUpdate(client, update, chats, users), }, client); } if (update instanceof platform_node_js_1.Raws.Raw.UpdateBotInlineQuery) { return new Update({ inlineQuery: index_js_1.InlineQuery.parse(client, update, users), }, client); } if (update instanceof platform_node_js_1.Raws.Raw.UpdateBotInlineSend) { return new Update({ chosenInlineResult: index_js_1.ChosenInlineResult.parse(client, update, users), }, client); } if (update instanceof platform_node_js_1.Raws.Raw.UpdateBotShippingQuery) { return new Update({ shippingQuery: index_js_1.ShippingQuery.parse(client, update, users), }, client); } if (update instanceof platform_node_js_1.Raws.Raw.UpdateBotPrecheckoutQuery) { return new Update({ preCheckoutQuery: index_js_1.PreCheckoutQuery.parse(client, update, users), }, client); } return; } static async updateNewMessage(client, update, chats, users) { if (update.message instanceof platform_node_js_1.Raws.Raw.Message && update.message.post) { return new Update({ channelPost: await index_js_1.Message.parse(client, update.message, chats, users), }, client); } return new Update({ message: await index_js_1.Message.parse(client, update.message, chats, users), }, client); } static async updateEditMessage(client, update, chats, users) { if (update instanceof platform_node_js_1.Raws.Raw.UpdateEditChannelMessage) { return new Update({ editedChannelPost: await index_js_1.Message.parse(client, update.message, chats, users), }, client); } return new Update({ editedMessage: await index_js_1.Message.parse(client, update.message, chats, users), }, client); } get msg() { if (this.channelPost) return this.channelPost; if (this.editedChannelPost) return this.editedChannelPost; if (this.editedMessage) return this.editedMessage; if (this.message) return this.message; if (this.callbackQuery?.message) return this.callbackQuery.message; return; } get _me() { return this.client._me; } } exports.Update = Update;