From e9d5158451b6015295ecba3e9dba69aa804e4a85 Mon Sep 17 00:00:00 2001 From: alina sireneva Date: Sun, 5 May 2024 20:59:03 +0300 Subject: [PATCH] feat(core): getCollectibleInfo method --- packages/core/src/highlevel/client.ts | 85 ++++++++++++++++--- packages/core/src/highlevel/methods.ts | 3 + .../core/src/highlevel/methods/_imports.ts | 1 + .../methods/misc/get-collectible-info.ts | 29 +++++++ .../stickers/replace-sticker-in-set.ts | 1 + .../highlevel/types/misc/collectible-info.ts | 50 +++++++++++ .../core/src/highlevel/types/misc/index.ts | 1 + 7 files changed, 156 insertions(+), 14 deletions(-) create mode 100644 packages/core/src/highlevel/methods/misc/get-collectible-info.ts create mode 100644 packages/core/src/highlevel/types/misc/collectible-info.ts diff --git a/packages/core/src/highlevel/client.ts b/packages/core/src/highlevel/client.ts index 254ae746..f5d70440 100644 --- a/packages/core/src/highlevel/client.ts +++ b/packages/core/src/highlevel/client.ts @@ -168,6 +168,7 @@ import { translateMessage } from './methods/messages/translate-message.js' import { translateText } from './methods/messages/translate-text.js' import { unpinAllMessages } from './methods/messages/unpin-all-messages.js' import { unpinMessage } from './methods/messages/unpin-message.js' +import { getCollectibleInfo } from './methods/misc/get-collectible-info.js' import { initTakeoutSession } from './methods/misc/init-takeout-session.js' import { _normalizePrivacyRules } from './methods/misc/normalize-privacy-rules.js' import { withParams } from './methods/misc/with-params.js' @@ -191,8 +192,10 @@ import { createStickerSet } from './methods/stickers/create-sticker-set.js' import { deleteStickerFromSet } from './methods/stickers/delete-sticker-from-set.js' import { getCustomEmojis, getCustomEmojisFromMessages } from './methods/stickers/get-custom-emojis.js' import { getInstalledStickers } from './methods/stickers/get-installed-stickers.js' +import { getMyStickerSets } from './methods/stickers/get-my-sticker-sets.js' import { getStickerSet } from './methods/stickers/get-sticker-set.js' import { moveStickerInSet } from './methods/stickers/move-sticker-in-set.js' +import { replaceStickerInSet } from './methods/stickers/replace-sticker-in-set.js' import { setChatStickerSet } from './methods/stickers/set-chat-sticker-set.js' import { setStickerSetThumb } from './methods/stickers/set-sticker-set-thumb.js' import { canSendStory, CanSendStoryResult } from './methods/stories/can-send-story.js' @@ -263,6 +266,7 @@ import { ChatMemberUpdate, ChatPreview, ChosenInlineResult, + CollectibleInfo, DeleteMessageUpdate, DeleteStoryUpdate, Dialog, @@ -3593,6 +3597,11 @@ export interface TelegramClient extends ITelegramClient { * Only return messages older than this date */ maxDate?: Date | number + + /** + * Whether to only search across broadcast channels + */ + onlyChannels?: boolean }): Promise> /** * Search for messages inside a specific chat @@ -4072,6 +4081,13 @@ export interface TelegramClient extends ITelegramClient { * @param messageId Message ID */ unpinMessage(params: InputMessageId): Promise + + /** + * Get information about a fragment collectible + * **Available**: 👤 users only + * + */ + getCollectibleInfo(kind: 'phone' | 'username', item: string): Promise /** * Create a new takeout session * @@ -4338,8 +4354,7 @@ export interface TelegramClient extends ITelegramClient { /** * Add a sticker to a sticker set. * - * Only for bots, and the sticker set must - * have been created by this bot. + * For bots the sticker set must have been created by this bot. * * **Available**: ✅ both users and bots * @@ -4364,9 +4379,6 @@ export interface TelegramClient extends ITelegramClient { /** * Create a new sticker set. * - * This is the only sticker-related method that - * users can use (they allowed it with the "import stickers" update) - * * **Available**: ✅ both users and bots * * @param params @@ -4447,8 +4459,7 @@ export interface TelegramClient extends ITelegramClient { /** * Delete a sticker from a sticker set * - * Only for bots, and the sticker set must - * have been created by this bot. + * For bots the sticker set must have been created by this bot. * * **Available**: ✅ both users and bots * @@ -4479,26 +4490,36 @@ export interface TelegramClient extends ITelegramClient { * * > **Note**: This method returns *brief* meta information about * > the packs, that does not include the stickers themselves. - * > Use {@link StickerSet.getFull} or {@link getStickerSet} - * > to get a stickerset that will include the stickers + * > Use {@link getStickerSet} to get a stickerset that will include the stickers * **Available**: 👤 users only * */ getInstalledStickers(): Promise + /** - * Get a sticker pack and stickers inside of it. + * Get the list of sticker sets that were created by the current user + * **Available**: 👤 users only + * + */ + getMyStickerSets(params?: { + /** Offset for pagination */ + offset?: Long + /** Limit for pagination */ + limit?: number + }): Promise> + /** + * Get a sticker set and stickers inside of it. * * **Available**: ✅ both users and bots * - * @param setId Sticker pack short name, dice emoji, `"emoji"` for animated emojis or input ID + * @param setId Sticker set identifier */ getStickerSet(setId: InputStickerSet): Promise /** * Move a sticker in a sticker set * to another position * - * Only for bots, and the sticker set must - * have been created by this bot. + * For bots the sticker set must have been created by this bot. * * **Available**: ✅ both users and bots * @@ -4506,12 +4527,39 @@ export interface TelegramClient extends ITelegramClient { * TDLib and Bot API compatible File ID, or a * TL object representing a sticker to be removed * @param position New sticker position (starting from 0) - * @returns Modfiied sticker set + * @returns Modified sticker set */ moveStickerInSet( sticker: string | tdFileId.RawFullRemoteFileLocation | tl.TypeInputDocument, position: number, ): Promise + + /** + * Replace a sticker in a sticker set with another sticker + * + * For bots the sticker set must have been created by this bot. + * + * **Available**: ✅ both users and bots + * + * @param sticker + * TDLib and Bot API compatible File ID, or a + * TL object representing a sticker to be removed + * @param newSticker New sticker to replace the old one with + * @returns Modfiied sticker set + */ + replaceStickerInSet( + sticker: string | tdFileId.RawFullRemoteFileLocation | tl.TypeInputDocument, + newSticker: InputStickerSetItem, + params?: { + /** + * Upload progress callback + * + * @param uploaded Number of bytes uploaded + * @param total Total file size + */ + progressCallback?: (uploaded: number, total: number) => void + }, + ): Promise /** * Set group sticker set for a supergroup * @@ -5836,6 +5884,9 @@ TelegramClient.prototype.unpinAllMessages = function (...args) { TelegramClient.prototype.unpinMessage = function (...args) { return unpinMessage(this._client, ...args) } +TelegramClient.prototype.getCollectibleInfo = function (...args) { + return getCollectibleInfo(this._client, ...args) +} TelegramClient.prototype.initTakeoutSession = function (...args) { return initTakeoutSession(this._client, ...args) } @@ -5914,12 +5965,18 @@ TelegramClient.prototype.getCustomEmojisFromMessages = function (...args) { TelegramClient.prototype.getInstalledStickers = function (...args) { return getInstalledStickers(this._client, ...args) } +TelegramClient.prototype.getMyStickerSets = function (...args) { + return getMyStickerSets(this._client, ...args) +} TelegramClient.prototype.getStickerSet = function (...args) { return getStickerSet(this._client, ...args) } TelegramClient.prototype.moveStickerInSet = function (...args) { return moveStickerInSet(this._client, ...args) } +TelegramClient.prototype.replaceStickerInSet = function (...args) { + return replaceStickerInSet(this._client, ...args) +} TelegramClient.prototype.setChatStickerSet = function (...args) { return setChatStickerSet(this._client, ...args) } diff --git a/packages/core/src/highlevel/methods.ts b/packages/core/src/highlevel/methods.ts index 070738f5..70368a04 100644 --- a/packages/core/src/highlevel/methods.ts +++ b/packages/core/src/highlevel/methods.ts @@ -181,6 +181,7 @@ export { translateMessage } from './methods/messages/translate-message.js' export { translateText } from './methods/messages/translate-text.js' export { unpinAllMessages } from './methods/messages/unpin-all-messages.js' export { unpinMessage } from './methods/messages/unpin-message.js' +export { getCollectibleInfo } from './methods/misc/get-collectible-info.js' export { initTakeoutSession } from './methods/misc/init-takeout-session.js' export { _normalizePrivacyRules } from './methods/misc/normalize-privacy-rules.js' export { changeCloudPassword } from './methods/password/change-cloud-password.js' @@ -208,8 +209,10 @@ export { deleteStickerFromSet } from './methods/stickers/delete-sticker-from-set export { getCustomEmojis } from './methods/stickers/get-custom-emojis.js' export { getCustomEmojisFromMessages } from './methods/stickers/get-custom-emojis.js' export { getInstalledStickers } from './methods/stickers/get-installed-stickers.js' +export { getMyStickerSets } from './methods/stickers/get-my-sticker-sets.js' export { getStickerSet } from './methods/stickers/get-sticker-set.js' export { moveStickerInSet } from './methods/stickers/move-sticker-in-set.js' +export { replaceStickerInSet } from './methods/stickers/replace-sticker-in-set.js' export { setChatStickerSet } from './methods/stickers/set-chat-sticker-set.js' export { setStickerSetThumb } from './methods/stickers/set-sticker-set-thumb.js' export type { CanSendStoryResult } from './methods/stories/can-send-story.js' diff --git a/packages/core/src/highlevel/methods/_imports.ts b/packages/core/src/highlevel/methods/_imports.ts index be4722f1..428784c3 100644 --- a/packages/core/src/highlevel/methods/_imports.ts +++ b/packages/core/src/highlevel/methods/_imports.ts @@ -38,6 +38,7 @@ import { ChatMemberUpdate, ChatPreview, ChosenInlineResult, + CollectibleInfo, DeleteMessageUpdate, DeleteStoryUpdate, Dialog, diff --git a/packages/core/src/highlevel/methods/misc/get-collectible-info.ts b/packages/core/src/highlevel/methods/misc/get-collectible-info.ts new file mode 100644 index 00000000..4410dcf0 --- /dev/null +++ b/packages/core/src/highlevel/methods/misc/get-collectible-info.ts @@ -0,0 +1,29 @@ +import { ITelegramClient } from '../../client.types.js' +import { CollectibleInfo } from '../../types/misc/collectible-info.js' +import { normalizePhoneNumber } from '../../utils/misc-utils.js' + +// @available=user +/** + * Get information about a fragment collectible + */ +export async function getCollectibleInfo( + client: ITelegramClient, + kind: 'phone' | 'username', + item: string, +): Promise { + const res = await client.call({ + _: 'fragment.getCollectibleInfo', + collectible: + kind === 'phone' ? + { + _: 'inputCollectiblePhone', + phone: normalizePhoneNumber(item), + } : + { + _: 'inputCollectibleUsername', + username: item, + }, + }) + + return new CollectibleInfo(res) +} diff --git a/packages/core/src/highlevel/methods/stickers/replace-sticker-in-set.ts b/packages/core/src/highlevel/methods/stickers/replace-sticker-in-set.ts index 1cfc5c33..b3809046 100644 --- a/packages/core/src/highlevel/methods/stickers/replace-sticker-in-set.ts +++ b/packages/core/src/highlevel/methods/stickers/replace-sticker-in-set.ts @@ -6,6 +6,7 @@ import { InputStickerSetItem, StickerSet } from '../../types/index.js' import { fileIdToInputDocument } from '../../utils/convert-file-id.js' import { _normalizeInputStickerSetItem } from './_utils.js' +// @available=both /** * Replace a sticker in a sticker set with another sticker * diff --git a/packages/core/src/highlevel/types/misc/collectible-info.ts b/packages/core/src/highlevel/types/misc/collectible-info.ts new file mode 100644 index 00000000..d5634391 --- /dev/null +++ b/packages/core/src/highlevel/types/misc/collectible-info.ts @@ -0,0 +1,50 @@ +import Long from 'long' + +import { tl } from '@mtcute/tl' + +import { makeInspectable } from '../../utils/inspectable.js' + +/** + * Information about a Fragment collectible + */ +export class CollectibleInfo { + constructor(readonly raw: tl.fragment.RawCollectibleInfo) {} + + /** Date when the item was purchased */ + get purchaseDate(): Date { + return new Date(this.raw.purchaseDate * 1000) + } + + /** Crypto currency used to purchase the item */ + get cryptoCurrency(): string { + return this.raw.cryptoCurrency + } + + /** + * Amount of crypto currency used to purchase the item, + * in the smallest units + */ + get cryptoAmount(): Long { + return this.raw.cryptoAmount + } + + /** Fiat currency to which the crypto currency was converted */ + get currency(): string { + return this.raw.currency + } + + /** + * Converted amount in fiat currency, + * in the smallest units (e.g. cents) + */ + get amount(): Long { + return this.raw.amount + } + + /** URL to the collectible on Fragment */ + get url(): string { + return this.raw.url + } +} + +makeInspectable(CollectibleInfo) diff --git a/packages/core/src/highlevel/types/misc/index.ts b/packages/core/src/highlevel/types/misc/index.ts index 7c2b764f..8d5a71b3 100644 --- a/packages/core/src/highlevel/types/misc/index.ts +++ b/packages/core/src/highlevel/types/misc/index.ts @@ -1,4 +1,5 @@ export * from './app-config.js' +export * from './collectible-info.js' export * from './entities.js' export * from './input-privacy-rule/index.js' export * from './sticker-set.js'