feat(core): getCollectibleInfo method

This commit is contained in:
alina 🌸 2024-05-05 20:59:03 +03:00
parent e8a09ec270
commit e9d5158451
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
7 changed files with 156 additions and 14 deletions

View file

@ -168,6 +168,7 @@ import { translateMessage } from './methods/messages/translate-message.js'
import { translateText } from './methods/messages/translate-text.js' import { translateText } from './methods/messages/translate-text.js'
import { unpinAllMessages } from './methods/messages/unpin-all-messages.js' import { unpinAllMessages } from './methods/messages/unpin-all-messages.js'
import { unpinMessage } from './methods/messages/unpin-message.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 { initTakeoutSession } from './methods/misc/init-takeout-session.js'
import { _normalizePrivacyRules } from './methods/misc/normalize-privacy-rules.js' import { _normalizePrivacyRules } from './methods/misc/normalize-privacy-rules.js'
import { withParams } from './methods/misc/with-params.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 { deleteStickerFromSet } from './methods/stickers/delete-sticker-from-set.js'
import { getCustomEmojis, getCustomEmojisFromMessages } from './methods/stickers/get-custom-emojis.js' import { getCustomEmojis, getCustomEmojisFromMessages } from './methods/stickers/get-custom-emojis.js'
import { getInstalledStickers } from './methods/stickers/get-installed-stickers.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 { getStickerSet } from './methods/stickers/get-sticker-set.js'
import { moveStickerInSet } from './methods/stickers/move-sticker-in-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 { setChatStickerSet } from './methods/stickers/set-chat-sticker-set.js'
import { setStickerSetThumb } from './methods/stickers/set-sticker-set-thumb.js' import { setStickerSetThumb } from './methods/stickers/set-sticker-set-thumb.js'
import { canSendStory, CanSendStoryResult } from './methods/stories/can-send-story.js' import { canSendStory, CanSendStoryResult } from './methods/stories/can-send-story.js'
@ -263,6 +266,7 @@ import {
ChatMemberUpdate, ChatMemberUpdate,
ChatPreview, ChatPreview,
ChosenInlineResult, ChosenInlineResult,
CollectibleInfo,
DeleteMessageUpdate, DeleteMessageUpdate,
DeleteStoryUpdate, DeleteStoryUpdate,
Dialog, Dialog,
@ -3593,6 +3597,11 @@ export interface TelegramClient extends ITelegramClient {
* Only return messages older than this date * Only return messages older than this date
*/ */
maxDate?: Date | number maxDate?: Date | number
/**
* Whether to only search across broadcast channels
*/
onlyChannels?: boolean
}): Promise<ArrayPaginated<Message, SearchGlobalOffset>> }): Promise<ArrayPaginated<Message, SearchGlobalOffset>>
/** /**
* Search for messages inside a specific chat * Search for messages inside a specific chat
@ -4072,6 +4081,13 @@ export interface TelegramClient extends ITelegramClient {
* @param messageId Message ID * @param messageId Message ID
*/ */
unpinMessage(params: InputMessageId): Promise<void> unpinMessage(params: InputMessageId): Promise<void>
/**
* Get information about a fragment collectible
* **Available**: 👤 users only
*
*/
getCollectibleInfo(kind: 'phone' | 'username', item: string): Promise<CollectibleInfo>
/** /**
* Create a new takeout session * Create a new takeout session
* *
@ -4338,8 +4354,7 @@ export interface TelegramClient extends ITelegramClient {
/** /**
* Add a sticker to a sticker set. * Add a sticker to a sticker set.
* *
* Only for bots, and the sticker set must * For bots the sticker set must have been created by this bot.
* have been created by this bot.
* *
* **Available**: both users and bots * **Available**: both users and bots
* *
@ -4364,9 +4379,6 @@ export interface TelegramClient extends ITelegramClient {
/** /**
* Create a new sticker set. * 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 * **Available**: both users and bots
* *
* @param params * @param params
@ -4447,8 +4459,7 @@ export interface TelegramClient extends ITelegramClient {
/** /**
* Delete a sticker from a sticker set * Delete a sticker from a sticker set
* *
* Only for bots, and the sticker set must * For bots the sticker set must have been created by this bot.
* have been created by this bot.
* *
* **Available**: both users and bots * **Available**: both users and bots
* *
@ -4479,26 +4490,36 @@ export interface TelegramClient extends ITelegramClient {
* *
* > **Note**: This method returns *brief* meta information about * > **Note**: This method returns *brief* meta information about
* > the packs, that does not include the stickers themselves. * > the packs, that does not include the stickers themselves.
* > Use {@link StickerSet.getFull} or {@link getStickerSet} * > Use {@link getStickerSet} to get a stickerset that will include the stickers
* > to get a stickerset that will include the stickers
* **Available**: 👤 users only * **Available**: 👤 users only
* *
*/ */
getInstalledStickers(): Promise<StickerSet[]> getInstalledStickers(): Promise<StickerSet[]>
/** /**
* 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<ArrayPaginated<StickerSet, Long>>
/**
* Get a sticker set and stickers inside of it.
* *
* **Available**: both users and bots * **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<StickerSet> getStickerSet(setId: InputStickerSet): Promise<StickerSet>
/** /**
* Move a sticker in a sticker set * Move a sticker in a sticker set
* to another position * to another position
* *
* Only for bots, and the sticker set must * For bots the sticker set must have been created by this bot.
* have been created by this bot.
* *
* **Available**: both users and bots * **Available**: both users and bots
* *
@ -4506,12 +4527,39 @@ export interface TelegramClient extends ITelegramClient {
* TDLib and Bot API compatible File ID, or a * TDLib and Bot API compatible File ID, or a
* TL object representing a sticker to be removed * TL object representing a sticker to be removed
* @param position New sticker position (starting from 0) * @param position New sticker position (starting from 0)
* @returns Modfiied sticker set * @returns Modified sticker set
*/ */
moveStickerInSet( moveStickerInSet(
sticker: string | tdFileId.RawFullRemoteFileLocation | tl.TypeInputDocument, sticker: string | tdFileId.RawFullRemoteFileLocation | tl.TypeInputDocument,
position: number, position: number,
): Promise<StickerSet> ): Promise<StickerSet>
/**
* 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<StickerSet>
/** /**
* Set group sticker set for a supergroup * Set group sticker set for a supergroup
* *
@ -5836,6 +5884,9 @@ TelegramClient.prototype.unpinAllMessages = function (...args) {
TelegramClient.prototype.unpinMessage = function (...args) { TelegramClient.prototype.unpinMessage = function (...args) {
return unpinMessage(this._client, ...args) return unpinMessage(this._client, ...args)
} }
TelegramClient.prototype.getCollectibleInfo = function (...args) {
return getCollectibleInfo(this._client, ...args)
}
TelegramClient.prototype.initTakeoutSession = function (...args) { TelegramClient.prototype.initTakeoutSession = function (...args) {
return initTakeoutSession(this._client, ...args) return initTakeoutSession(this._client, ...args)
} }
@ -5914,12 +5965,18 @@ TelegramClient.prototype.getCustomEmojisFromMessages = function (...args) {
TelegramClient.prototype.getInstalledStickers = function (...args) { TelegramClient.prototype.getInstalledStickers = function (...args) {
return getInstalledStickers(this._client, ...args) return getInstalledStickers(this._client, ...args)
} }
TelegramClient.prototype.getMyStickerSets = function (...args) {
return getMyStickerSets(this._client, ...args)
}
TelegramClient.prototype.getStickerSet = function (...args) { TelegramClient.prototype.getStickerSet = function (...args) {
return getStickerSet(this._client, ...args) return getStickerSet(this._client, ...args)
} }
TelegramClient.prototype.moveStickerInSet = function (...args) { TelegramClient.prototype.moveStickerInSet = function (...args) {
return moveStickerInSet(this._client, ...args) return moveStickerInSet(this._client, ...args)
} }
TelegramClient.prototype.replaceStickerInSet = function (...args) {
return replaceStickerInSet(this._client, ...args)
}
TelegramClient.prototype.setChatStickerSet = function (...args) { TelegramClient.prototype.setChatStickerSet = function (...args) {
return setChatStickerSet(this._client, ...args) return setChatStickerSet(this._client, ...args)
} }

View file

@ -181,6 +181,7 @@ export { translateMessage } from './methods/messages/translate-message.js'
export { translateText } from './methods/messages/translate-text.js' export { translateText } from './methods/messages/translate-text.js'
export { unpinAllMessages } from './methods/messages/unpin-all-messages.js' export { unpinAllMessages } from './methods/messages/unpin-all-messages.js'
export { unpinMessage } from './methods/messages/unpin-message.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 { initTakeoutSession } from './methods/misc/init-takeout-session.js'
export { _normalizePrivacyRules } from './methods/misc/normalize-privacy-rules.js' export { _normalizePrivacyRules } from './methods/misc/normalize-privacy-rules.js'
export { changeCloudPassword } from './methods/password/change-cloud-password.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 { getCustomEmojis } from './methods/stickers/get-custom-emojis.js'
export { getCustomEmojisFromMessages } 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 { 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 { getStickerSet } from './methods/stickers/get-sticker-set.js'
export { moveStickerInSet } from './methods/stickers/move-sticker-in-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 { setChatStickerSet } from './methods/stickers/set-chat-sticker-set.js'
export { setStickerSetThumb } from './methods/stickers/set-sticker-set-thumb.js' export { setStickerSetThumb } from './methods/stickers/set-sticker-set-thumb.js'
export type { CanSendStoryResult } from './methods/stories/can-send-story.js' export type { CanSendStoryResult } from './methods/stories/can-send-story.js'

View file

@ -38,6 +38,7 @@ import {
ChatMemberUpdate, ChatMemberUpdate,
ChatPreview, ChatPreview,
ChosenInlineResult, ChosenInlineResult,
CollectibleInfo,
DeleteMessageUpdate, DeleteMessageUpdate,
DeleteStoryUpdate, DeleteStoryUpdate,
Dialog, Dialog,

View file

@ -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<CollectibleInfo> {
const res = await client.call({
_: 'fragment.getCollectibleInfo',
collectible:
kind === 'phone' ?
{
_: 'inputCollectiblePhone',
phone: normalizePhoneNumber(item),
} :
{
_: 'inputCollectibleUsername',
username: item,
},
})
return new CollectibleInfo(res)
}

View file

@ -6,6 +6,7 @@ import { InputStickerSetItem, StickerSet } from '../../types/index.js'
import { fileIdToInputDocument } from '../../utils/convert-file-id.js' import { fileIdToInputDocument } from '../../utils/convert-file-id.js'
import { _normalizeInputStickerSetItem } from './_utils.js' import { _normalizeInputStickerSetItem } from './_utils.js'
// @available=both
/** /**
* Replace a sticker in a sticker set with another sticker * Replace a sticker in a sticker set with another sticker
* *

View file

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

View file

@ -1,4 +1,5 @@
export * from './app-config.js' export * from './app-config.js'
export * from './collectible-info.js'
export * from './entities.js' export * from './entities.js'
export * from './input-privacy-rule/index.js' export * from './input-privacy-rule/index.js'
export * from './sticker-set.js' export * from './sticker-set.js'