From 3eb114307c467d9212b286421bb421e65f198e2d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 5 Apr 2024 16:22:52 +0000 Subject: [PATCH] 8c23ff10aeb78da310283f3f5f678e59fa60e2af --- esm/client/0_utilities.d.ts | 6 +++ esm/client/0_utilities.js | 32 +++++++++++++++ esm/client/2_message_manager.js | 37 +++++++++++++---- esm/client/3_callback_query_manager.js | 2 + esm/client/3_inline_query_manager.js | 2 + esm/client/3_story_manager.js | 4 +- script/client/0_utilities.d.ts | 6 +++ script/client/0_utilities.js | 40 +++++++++++++++++- script/client/2_message_manager.js | 49 +++++++++++++++++------ script/client/3_callback_query_manager.js | 2 + script/client/3_inline_query_manager.js | 2 + script/client/3_story_manager.js | 2 + 12 files changed, 162 insertions(+), 22 deletions(-) diff --git a/esm/client/0_utilities.d.ts b/esm/client/0_utilities.d.ts index d7675c9..353f79e 100644 --- a/esm/client/0_utilities.d.ts +++ b/esm/client/0_utilities.d.ts @@ -4,3 +4,9 @@ export declare function getFileContents(source: FileSource, fileName?: string): export declare function isHttpUrl(string: string): boolean; export declare function getUsername(string: string): string; export declare function getChatListId(chatList: string): 0 | 1; +export declare function checkMessageId(messageId: number): number; +export declare function checkStoryId(storyId: number): number; +export declare function checkPollOption(option: string): void; +export declare function checkArray(array: T[], check: (value: T) => void): void; +export declare function checkCallbackQueryId(id: string): void; +export declare function checkInlineQueryId(id: string): void; diff --git a/esm/client/0_utilities.js b/esm/client/0_utilities.js index de2e4fa..f27755b 100644 --- a/esm/client/0_utilities.js +++ b/esm/client/0_utilities.js @@ -126,3 +126,35 @@ export function getChatListId(chatList) { UNREACHABLE(); } } +export function checkMessageId(messageId) { + if (typeof messageId !== "number" || isNaN(messageId) || !messageId) { + throw new InputError("Invalid message ID"); + } + return messageId; +} +export function checkStoryId(storyId) { + if (typeof storyId !== "number" || isNaN(storyId) || !storyId) { + throw new InputError("Invalid story ID"); + } + return storyId; +} +export function checkPollOption(option) { + if (!option.trim()) { + throw new InputError("Poll option must not be empty."); + } +} +export function checkArray(array, check) { + for (const item of array) { + check(item); + } +} +export function checkCallbackQueryId(id) { + if (typeof id !== "string" || !id.trim()) { + throw new InputError("Invalid callback query ID."); + } +} +export function checkInlineQueryId(id) { + if (typeof id !== "string" || !id.trim()) { + throw new InputError("Invalid inline query ID."); + } +} diff --git a/esm/client/2_message_manager.js b/esm/client/2_message_manager.js index cbdf6a9..34693f7 100644 --- a/esm/client/2_message_manager.js +++ b/esm/client/2_message_manager.js @@ -19,6 +19,8 @@ import { assertMessageType, chatMemberRightsToTlObject, constructChatMember, con import { messageSearchFilterToTlObject } from "../types/0_message_search_filter.js"; import { parseHtml } from "./0_html.js"; import { parseMarkdown } from "./0_markdown.js"; +import { checkMessageId } from "./0_utilities.js"; +import { checkArray } from "./0_utilities.js"; import { getFileContents, isHttpUrl } from "./0_utilities.js"; const FALLBACK_MIME_TYPE = "application/octet-stream"; const STICKER_MIME_TYPES = ["image/webp", "video/webm", "application/x-tgsticker"]; @@ -41,6 +43,7 @@ export class MessageManager { __classPrivateFieldSet(this, _MessageManager_LresolveFileId, L.branch("resolveFileId"), "f"); } async getMessages(chatId, messageIds) { + checkArray(messageIds, checkMessageId); const peer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId); let messages_ = new Array(); const chatId_ = peerToChatId(peer); @@ -119,6 +122,9 @@ export class MessageManager { --entity.length; } } + if (!text.length) { + throw new InputError("Text must not be empty."); + } return [text, entities]; } async parseText(text_, params) { @@ -130,6 +136,7 @@ export class MessageManager { return await constructMessage_(message_, __classPrivateFieldGet(this, _MessageManager_c, "f").getEntity, this.getMessage.bind(this), __classPrivateFieldGet(this, _MessageManager_c, "f").fileManager.getStickerSetName.bind(__classPrivateFieldGet(this, _MessageManager_c, "f").fileManager), r, business); } async forwardMessages(from, to, messageIds, params) { + checkArray(messageIds, checkMessageId); const result = await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.forwardMessages({ from_peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(from), to_peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(to), @@ -456,6 +463,13 @@ export class MessageManager { return null; } async sendPoll(chatId, question, options, params) { + question = question?.trim(); + if (!question) { + throw new Error("Question must not be empty."); + } + if (!Array.isArray(options) || options.length < 2) { + throw new Error("There must be at least two options."); + } const peer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId); const randomId = getRandomId(); const silent = params?.disableNotification ? true : undefined; @@ -500,7 +514,7 @@ export class MessageManager { } async editMessageReplyMarkup(chatId, messageId, params) { const result = await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.editMessage({ - id: messageId, + id: checkMessageId(messageId), peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId), reply_markup: await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_constructReplyMarkup).call(this, params), }); @@ -528,7 +542,7 @@ export class MessageManager { }); } const result = await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.editMessage({ - id: messageId, + id: checkMessageId(messageId), peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId), entities, message, @@ -565,6 +579,7 @@ export class MessageManager { }); } async deleteMessages(chatId, messageIds, params) { + checkArray(messageIds, checkMessageId); const peer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId); if (peer instanceof types.InputPeerChannel) { await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.deleteMessages({ channel: new types.InputChannel(peer), id: messageIds }); @@ -581,7 +596,7 @@ export class MessageManager { async pinMessage(chatId, messageId, params) { await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.updatePinnedMessage({ peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId), - id: messageId, + id: checkMessageId(messageId), silent: params?.disableNotification ? true : undefined, pm_oneside: params?.bothSides ? undefined : true, }); @@ -589,7 +604,7 @@ export class MessageManager { async unpinMessage(chatId, messageId) { await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.updatePinnedMessage({ peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId), - id: messageId, + id: checkMessageId(messageId), unpin: true, }); } @@ -607,7 +622,11 @@ export class MessageManager { await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_sendReaction).call(this, chatId, messageId, reactions, params); } async addReaction(chatId, messageId, reaction, params) { - const chosenReactions = await this.getMessage(chatId, messageId).then((v) => v?.reactions ?? []).then((v) => v.filter((v) => v.chosen)); + const message = await this.getMessage(chatId, messageId); + if (!message) { + throw new InputError("Message not found."); + } + const chosenReactions = (message.reactions ?? []).filter((v) => v.chosen); for (const r of chosenReactions) { if (reactionEqual(r.reaction, reaction)) { return; @@ -617,7 +636,11 @@ export class MessageManager { await this.setReactions(chatId, messageId, reactions, params); } async removeReaction(chatId, messageId, reaction) { - const chosenReactions = await this.getMessage(chatId, messageId).then((v) => v?.reactions ?? []).then((v) => v.filter((v) => v.chosen)); + const message = await this.getMessage(chatId, messageId); + if (!message) { + throw new InputError("Message not found."); + } + const chosenReactions = (message.reactions ?? []).filter((v) => v.chosen); for (const r of chosenReactions) { if (reactionEqual(r.reaction, reaction)) { const reactions = chosenReactions.filter((v) => v != r).map((v) => v.reaction); @@ -1194,7 +1217,7 @@ _MessageManager_c = new WeakMap(), _MessageManager_LresolveFileId = new WeakMap( }, _MessageManager_sendReaction = async function _MessageManager_sendReaction(chatId, messageId, reactions, params) { await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.sendReaction({ peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId), - msg_id: messageId, + msg_id: checkMessageId(messageId), reaction: reactions.map((v) => reactionToTlObject(v)), big: params?.big ? true : undefined, add_to_recent: params?.addToRecents ? true : undefined, diff --git a/esm/client/3_callback_query_manager.js b/esm/client/3_callback_query_manager.js index e734e40..68d7466 100644 --- a/esm/client/3_callback_query_manager.js +++ b/esm/client/3_callback_query_manager.js @@ -12,6 +12,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function ( var _CallbackQueryManager_c; import { types } from "../2_tl.js"; import { constructCallbackQuery } from "../3_types.js"; +import { checkCallbackQueryId } from "./0_utilities.js"; export class CallbackQueryManager { constructor(c) { _CallbackQueryManager_c.set(this, void 0); @@ -19,6 +20,7 @@ export class CallbackQueryManager { } async answerCallbackQuery(id, params) { await __classPrivateFieldGet(this, _CallbackQueryManager_c, "f").storage.assertBot("answerCallbackQuery"); + checkCallbackQueryId(id); await __classPrivateFieldGet(this, _CallbackQueryManager_c, "f").api.messages.setBotCallbackAnswer({ query_id: BigInt(id), cache_time: params?.cacheTime ?? 0, diff --git a/esm/client/3_inline_query_manager.js b/esm/client/3_inline_query_manager.js index cfd3faa..5baddf9 100644 --- a/esm/client/3_inline_query_manager.js +++ b/esm/client/3_inline_query_manager.js @@ -13,6 +13,7 @@ var _InlineQueryManager_c; import { UNREACHABLE } from "../1_utilities.js"; import { types } from "../2_tl.js"; import { constructChosenInlineResult, constructInlineQuery, inlineQueryResultToTlObject } from "../3_types.js"; +import { checkInlineQueryId } from "./0_utilities.js"; export class InlineQueryManager { constructor(c) { _InlineQueryManager_c.set(this, void 0); @@ -20,6 +21,7 @@ export class InlineQueryManager { } async answerInlineQuery(id, results, params) { await __classPrivateFieldGet(this, _InlineQueryManager_c, "f").storage.assertBot("answerInlineQuery"); + checkInlineQueryId(id); await __classPrivateFieldGet(this, _InlineQueryManager_c, "f").api.messages.setInlineBotResults({ query_id: BigInt(id), results: await Promise.all(results.map((v) => inlineQueryResultToTlObject(v, __classPrivateFieldGet(this, _InlineQueryManager_c, "f").messageManager.parseText.bind(__classPrivateFieldGet(this, _InlineQueryManager_c, "f").messageManager), __classPrivateFieldGet(this, _InlineQueryManager_c, "f").messageManager.usernameResolver.bind(__classPrivateFieldGet(this, _InlineQueryManager_c, "f").messageManager)))), diff --git a/esm/client/3_story_manager.js b/esm/client/3_story_manager.js index 7f748d9..5813bd2 100644 --- a/esm/client/3_story_manager.js +++ b/esm/client/3_story_manager.js @@ -15,7 +15,7 @@ import { InputError } from "../0_errors.js"; import { getRandomId, UNREACHABLE } from "../1_utilities.js"; import { as, inputPeerToPeer, peerToChatId, types } from "../2_tl.js"; import { constructStory, FileType, storyInteractiveAreaToTlObject, storyPrivacyToTlObject } from "../3_types.js"; -import { getFileContents, isHttpUrl } from "./0_utilities.js"; +import { checkArray, checkStoryId, getFileContents, isHttpUrl } from "./0_utilities.js"; export class StoryManager { constructor(c) { _StoryManager_instances.add(this); @@ -84,6 +84,7 @@ export class StoryManager { } async getStories(chatId, storyIds) { await __classPrivateFieldGet(this, _StoryManager_c, "f").storage.assertUser("getStories"); + checkArray(storyIds, checkStoryId); const peer = await __classPrivateFieldGet(this, _StoryManager_c, "f").getInputPeer(chatId); const stories_ = await __classPrivateFieldGet(this, _StoryManager_c, "f").api.stories.getStoriesByID({ peer, id: storyIds }); const stories = new Array(); @@ -148,6 +149,7 @@ _StoryManager_c = new WeakMap(), _StoryManager_instances = new WeakSet(), _Story } UNREACHABLE(); }, _StoryManager_togglePinned = async function _StoryManager_togglePinned(chatId, storyIds, pinned) { + checkArray(storyIds, checkStoryId); const peer = await __classPrivateFieldGet(this, _StoryManager_c, "f").getInputPeer(chatId); await __classPrivateFieldGet(this, _StoryManager_c, "f").api.stories.togglePinned({ peer, id: storyIds, pinned }); }; diff --git a/script/client/0_utilities.d.ts b/script/client/0_utilities.d.ts index d7675c9..353f79e 100644 --- a/script/client/0_utilities.d.ts +++ b/script/client/0_utilities.d.ts @@ -4,3 +4,9 @@ export declare function getFileContents(source: FileSource, fileName?: string): export declare function isHttpUrl(string: string): boolean; export declare function getUsername(string: string): string; export declare function getChatListId(chatList: string): 0 | 1; +export declare function checkMessageId(messageId: number): number; +export declare function checkStoryId(storyId: number): number; +export declare function checkPollOption(option: string): void; +export declare function checkArray(array: T[], check: (value: T) => void): void; +export declare function checkCallbackQueryId(id: string): void; +export declare function checkInlineQueryId(id: string): void; diff --git a/script/client/0_utilities.js b/script/client/0_utilities.js index fa0b3a1..ad795f0 100644 --- a/script/client/0_utilities.js +++ b/script/client/0_utilities.js @@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.getChatListId = exports.getUsername = exports.isHttpUrl = exports.getFileContents = exports.resolve = void 0; +exports.checkInlineQueryId = exports.checkCallbackQueryId = exports.checkArray = exports.checkPollOption = exports.checkStoryId = exports.checkMessageId = exports.getChatListId = exports.getUsername = exports.isHttpUrl = exports.getFileContents = exports.resolve = void 0; const dntShim = __importStar(require("../_dnt.shims.js")); const _0_deps_js_1 = require("../0_deps.js"); const _0_errors_js_1 = require("../0_errors.js"); @@ -157,3 +157,41 @@ function getChatListId(chatList) { } } exports.getChatListId = getChatListId; +function checkMessageId(messageId) { + if (typeof messageId !== "number" || isNaN(messageId) || !messageId) { + throw new _0_errors_js_1.InputError("Invalid message ID"); + } + return messageId; +} +exports.checkMessageId = checkMessageId; +function checkStoryId(storyId) { + if (typeof storyId !== "number" || isNaN(storyId) || !storyId) { + throw new _0_errors_js_1.InputError("Invalid story ID"); + } + return storyId; +} +exports.checkStoryId = checkStoryId; +function checkPollOption(option) { + if (!option.trim()) { + throw new _0_errors_js_1.InputError("Poll option must not be empty."); + } +} +exports.checkPollOption = checkPollOption; +function checkArray(array, check) { + for (const item of array) { + check(item); + } +} +exports.checkArray = checkArray; +function checkCallbackQueryId(id) { + if (typeof id !== "string" || !id.trim()) { + throw new _0_errors_js_1.InputError("Invalid callback query ID."); + } +} +exports.checkCallbackQueryId = checkCallbackQueryId; +function checkInlineQueryId(id) { + if (typeof id !== "string" || !id.trim()) { + throw new _0_errors_js_1.InputError("Invalid inline query ID."); + } +} +exports.checkInlineQueryId = checkInlineQueryId; diff --git a/script/client/2_message_manager.js b/script/client/2_message_manager.js index 45074f4..c38924b 100644 --- a/script/client/2_message_manager.js +++ b/script/client/2_message_manager.js @@ -23,6 +23,8 @@ const _0_message_search_filter_js_1 = require("../types/0_message_search_filter. const _0_html_js_1 = require("./0_html.js"); const _0_markdown_js_1 = require("./0_markdown.js"); const _0_utilities_js_1 = require("./0_utilities.js"); +const _0_utilities_js_2 = require("./0_utilities.js"); +const _0_utilities_js_3 = require("./0_utilities.js"); const FALLBACK_MIME_TYPE = "application/octet-stream"; const STICKER_MIME_TYPES = ["image/webp", "video/webm", "application/x-tgsticker"]; class MessageManager { @@ -44,6 +46,7 @@ class MessageManager { __classPrivateFieldSet(this, _MessageManager_LresolveFileId, L.branch("resolveFileId"), "f"); } async getMessages(chatId, messageIds) { + (0, _0_utilities_js_2.checkArray)(messageIds, _0_utilities_js_1.checkMessageId); const peer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId); let messages_ = new Array(); const chatId_ = (0, _2_tl_js_1.peerToChatId)(peer); @@ -122,6 +125,9 @@ class MessageManager { --entity.length; } } + if (!text.length) { + throw new _0_errors_js_1.InputError("Text must not be empty."); + } return [text, entities]; } async parseText(text_, params) { @@ -133,6 +139,7 @@ class MessageManager { return await (0, _3_types_js_2.constructMessage)(message_, __classPrivateFieldGet(this, _MessageManager_c, "f").getEntity, this.getMessage.bind(this), __classPrivateFieldGet(this, _MessageManager_c, "f").fileManager.getStickerSetName.bind(__classPrivateFieldGet(this, _MessageManager_c, "f").fileManager), r, business); } async forwardMessages(from, to, messageIds, params) { + (0, _0_utilities_js_2.checkArray)(messageIds, _0_utilities_js_1.checkMessageId); const result = await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.forwardMessages({ from_peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(from), to_peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(to), @@ -425,11 +432,11 @@ class MessageManager { } } if (media == null) { - if (typeof photo === "string" && (0, _0_utilities_js_1.isHttpUrl)(photo)) { + if (typeof photo === "string" && (0, _0_utilities_js_3.isHttpUrl)(photo)) { media = new _2_tl_js_1.types.InputMediaPhotoExternal({ url: photo, spoiler }); } else { - const [contents, fileName] = await (0, _0_utilities_js_1.getFileContents)(photo); + const [contents, fileName] = await (0, _0_utilities_js_3.getFileContents)(photo); const file = await __classPrivateFieldGet(this, _MessageManager_c, "f").fileManager.upload(contents, { fileName, chunkSize: params?.chunkSize, signal: params?.signal }); media = new _2_tl_js_1.types.InputMediaUploadedPhoto({ file, spoiler }); } @@ -459,6 +466,13 @@ class MessageManager { return null; } async sendPoll(chatId, question, options, params) { + question = question?.trim(); + if (!question) { + throw new Error("Question must not be empty."); + } + if (!Array.isArray(options) || options.length < 2) { + throw new Error("There must be at least two options."); + } const peer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId); const randomId = (0, _1_utilities_js_1.getRandomId)(); const silent = params?.disableNotification ? true : undefined; @@ -503,7 +517,7 @@ class MessageManager { } async editMessageReplyMarkup(chatId, messageId, params) { const result = await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.editMessage({ - id: messageId, + id: (0, _0_utilities_js_1.checkMessageId)(messageId), peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId), reply_markup: await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_constructReplyMarkup).call(this, params), }); @@ -531,7 +545,7 @@ class MessageManager { }); } const result = await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.editMessage({ - id: messageId, + id: (0, _0_utilities_js_1.checkMessageId)(messageId), peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId), entities, message, @@ -568,6 +582,7 @@ class MessageManager { }); } async deleteMessages(chatId, messageIds, params) { + (0, _0_utilities_js_2.checkArray)(messageIds, _0_utilities_js_1.checkMessageId); const peer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId); if (peer instanceof _2_tl_js_1.types.InputPeerChannel) { await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.deleteMessages({ channel: new _2_tl_js_1.types.InputChannel(peer), id: messageIds }); @@ -584,7 +599,7 @@ class MessageManager { async pinMessage(chatId, messageId, params) { await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.updatePinnedMessage({ peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId), - id: messageId, + id: (0, _0_utilities_js_1.checkMessageId)(messageId), silent: params?.disableNotification ? true : undefined, pm_oneside: params?.bothSides ? undefined : true, }); @@ -592,7 +607,7 @@ class MessageManager { async unpinMessage(chatId, messageId) { await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.updatePinnedMessage({ peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId), - id: messageId, + id: (0, _0_utilities_js_1.checkMessageId)(messageId), unpin: true, }); } @@ -610,7 +625,11 @@ class MessageManager { await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_sendReaction).call(this, chatId, messageId, reactions, params); } async addReaction(chatId, messageId, reaction, params) { - const chosenReactions = await this.getMessage(chatId, messageId).then((v) => v?.reactions ?? []).then((v) => v.filter((v) => v.chosen)); + const message = await this.getMessage(chatId, messageId); + if (!message) { + throw new _0_errors_js_1.InputError("Message not found."); + } + const chosenReactions = (message.reactions ?? []).filter((v) => v.chosen); for (const r of chosenReactions) { if ((0, _3_types_js_2.reactionEqual)(r.reaction, reaction)) { return; @@ -620,7 +639,11 @@ class MessageManager { await this.setReactions(chatId, messageId, reactions, params); } async removeReaction(chatId, messageId, reaction) { - const chosenReactions = await this.getMessage(chatId, messageId).then((v) => v?.reactions ?? []).then((v) => v.filter((v) => v.chosen)); + const message = await this.getMessage(chatId, messageId); + if (!message) { + throw new _0_errors_js_1.InputError("Message not found."); + } + const chosenReactions = (message.reactions ?? []).filter((v) => v.chosen); for (const r of chosenReactions) { if ((0, _3_types_js_2.reactionEqual)(r.reaction, reaction)) { const reactions = chosenReactions.filter((v) => v != r).map((v) => v.reaction); @@ -771,7 +794,7 @@ class MessageManager { if (!(peer instanceof _2_tl_js_1.types.InputPeerChannel) && !(peer instanceof _2_tl_js_1.types.InputPeerChat)) { (0, _1_utilities_js_1.UNREACHABLE)(); } - const [contents, fileName] = await (0, _0_utilities_js_1.getFileContents)(photo); + const [contents, fileName] = await (0, _0_utilities_js_3.getFileContents)(photo); const file = await __classPrivateFieldGet(this, _MessageManager_c, "f").fileManager.upload(contents, { fileName: params?.fileName ?? fileName, chunkSize: params?.chunkSize, signal: params?.signal }); const photo_ = new _2_tl_js_1.types.InputChatUploadedPhoto({ file }); if (peer instanceof _2_tl_js_1.types.InputPeerChannel) { @@ -1137,14 +1160,14 @@ _MessageManager_c = new WeakMap(), _MessageManager_LresolveFileId = new WeakMap( } } if (media == null) { - if (typeof document === "string" && (0, _0_utilities_js_1.isHttpUrl)(document)) { + if (typeof document === "string" && (0, _0_utilities_js_3.isHttpUrl)(document)) { if (!urlSupported) { throw new _0_errors_js_1.InputError("URL not supported."); } media = new _2_tl_js_1.types.InputMediaDocumentExternal({ url: document, spoiler }); } else { - const [contents, fileName_] = await (0, _0_utilities_js_1.getFileContents)(document); + const [contents, fileName_] = await (0, _0_utilities_js_3.getFileContents)(document); let fileName = params?.fileName ?? fileName_; const mimeType = params?.mimeType ?? (0, _0_deps_js_1.contentType)(fileName.split(".").slice(-1)[0]) ?? FALLBACK_MIME_TYPE; if (expectedMimeTypes && !expectedMimeTypes.includes(mimeType)) { @@ -1156,7 +1179,7 @@ _MessageManager_c = new WeakMap(), _MessageManager_LresolveFileId = new WeakMap( const file = await __classPrivateFieldGet(this, _MessageManager_c, "f").fileManager.upload(contents, { fileName, chunkSize: params?.chunkSize, signal: params?.signal }); let thumb = undefined; if (params?.thumbnail) { - const [thumbContents, fileName__] = await (0, _0_utilities_js_1.getFileContents)(params.thumbnail); + const [thumbContents, fileName__] = await (0, _0_utilities_js_3.getFileContents)(params.thumbnail); thumb = await __classPrivateFieldGet(this, _MessageManager_c, "f").fileManager.upload(thumbContents, { fileName: fileName__, chunkSize: params?.chunkSize, signal: params?.signal }); } media = new _2_tl_js_1.types.InputMediaUploadedDocument({ @@ -1198,7 +1221,7 @@ _MessageManager_c = new WeakMap(), _MessageManager_LresolveFileId = new WeakMap( }, _MessageManager_sendReaction = async function _MessageManager_sendReaction(chatId, messageId, reactions, params) { await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.sendReaction({ peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId), - msg_id: messageId, + msg_id: (0, _0_utilities_js_1.checkMessageId)(messageId), reaction: reactions.map((v) => (0, _3_types_js_2.reactionToTlObject)(v)), big: params?.big ? true : undefined, add_to_recent: params?.addToRecents ? true : undefined, diff --git a/script/client/3_callback_query_manager.js b/script/client/3_callback_query_manager.js index 4dc1841..5774240 100644 --- a/script/client/3_callback_query_manager.js +++ b/script/client/3_callback_query_manager.js @@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.CallbackQueryManager = void 0; const _2_tl_js_1 = require("../2_tl.js"); const _3_types_js_1 = require("../3_types.js"); +const _0_utilities_js_1 = require("./0_utilities.js"); class CallbackQueryManager { constructor(c) { _CallbackQueryManager_c.set(this, void 0); @@ -22,6 +23,7 @@ class CallbackQueryManager { } async answerCallbackQuery(id, params) { await __classPrivateFieldGet(this, _CallbackQueryManager_c, "f").storage.assertBot("answerCallbackQuery"); + (0, _0_utilities_js_1.checkCallbackQueryId)(id); await __classPrivateFieldGet(this, _CallbackQueryManager_c, "f").api.messages.setBotCallbackAnswer({ query_id: BigInt(id), cache_time: params?.cacheTime ?? 0, diff --git a/script/client/3_inline_query_manager.js b/script/client/3_inline_query_manager.js index 09a3fae..f1b623b 100644 --- a/script/client/3_inline_query_manager.js +++ b/script/client/3_inline_query_manager.js @@ -16,6 +16,7 @@ exports.InlineQueryManager = void 0; const _1_utilities_js_1 = require("../1_utilities.js"); const _2_tl_js_1 = require("../2_tl.js"); const _3_types_js_1 = require("../3_types.js"); +const _0_utilities_js_1 = require("./0_utilities.js"); class InlineQueryManager { constructor(c) { _InlineQueryManager_c.set(this, void 0); @@ -23,6 +24,7 @@ class InlineQueryManager { } async answerInlineQuery(id, results, params) { await __classPrivateFieldGet(this, _InlineQueryManager_c, "f").storage.assertBot("answerInlineQuery"); + (0, _0_utilities_js_1.checkInlineQueryId)(id); await __classPrivateFieldGet(this, _InlineQueryManager_c, "f").api.messages.setInlineBotResults({ query_id: BigInt(id), results: await Promise.all(results.map((v) => (0, _3_types_js_1.inlineQueryResultToTlObject)(v, __classPrivateFieldGet(this, _InlineQueryManager_c, "f").messageManager.parseText.bind(__classPrivateFieldGet(this, _InlineQueryManager_c, "f").messageManager), __classPrivateFieldGet(this, _InlineQueryManager_c, "f").messageManager.usernameResolver.bind(__classPrivateFieldGet(this, _InlineQueryManager_c, "f").messageManager)))), diff --git a/script/client/3_story_manager.js b/script/client/3_story_manager.js index e1c12ab..0c08233 100644 --- a/script/client/3_story_manager.js +++ b/script/client/3_story_manager.js @@ -87,6 +87,7 @@ class StoryManager { } async getStories(chatId, storyIds) { await __classPrivateFieldGet(this, _StoryManager_c, "f").storage.assertUser("getStories"); + (0, _0_utilities_js_1.checkArray)(storyIds, _0_utilities_js_1.checkStoryId); const peer = await __classPrivateFieldGet(this, _StoryManager_c, "f").getInputPeer(chatId); const stories_ = await __classPrivateFieldGet(this, _StoryManager_c, "f").api.stories.getStoriesByID({ peer, id: storyIds }); const stories = new Array(); @@ -152,6 +153,7 @@ _StoryManager_c = new WeakMap(), _StoryManager_instances = new WeakSet(), _Story } (0, _1_utilities_js_1.UNREACHABLE)(); }, _StoryManager_togglePinned = async function _StoryManager_togglePinned(chatId, storyIds, pinned) { + (0, _0_utilities_js_1.checkArray)(storyIds, _0_utilities_js_1.checkStoryId); const peer = await __classPrivateFieldGet(this, _StoryManager_c, "f").getInputPeer(chatId); await __classPrivateFieldGet(this, _StoryManager_c, "f").api.stories.togglePinned({ peer, id: storyIds, pinned }); };