fix(client): fixed usage of FormattedString type
This commit is contained in:
parent
1ef1c0669d
commit
e02763dcdd
11 changed files with 43 additions and 36 deletions
|
@ -2025,7 +2025,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
*
|
*
|
||||||
* When `media` is passed, `media.caption` is used instead
|
* When `media` is passed, `media.caption` is used instead
|
||||||
*/
|
*/
|
||||||
text?: string | FormattedString
|
text?: string | FormattedString<any>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse mode to use to parse entities before sending
|
* Parse mode to use to parse entities before sending
|
||||||
|
@ -2086,7 +2086,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
*
|
*
|
||||||
* When `media` is passed, `media.caption` is used instead
|
* When `media` is passed, `media.caption` is used instead
|
||||||
*/
|
*/
|
||||||
text?: string | FormattedString
|
text?: string | FormattedString<any>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse mode to use to parse entities before sending
|
* Parse mode to use to parse entities before sending
|
||||||
|
@ -2194,7 +2194,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
* You can either pass `caption` or `captionMedia`, passing both will
|
* You can either pass `caption` or `captionMedia`, passing both will
|
||||||
* result in an error
|
* result in an error
|
||||||
*/
|
*/
|
||||||
caption?: string | FormattedString
|
caption?: string | FormattedString<any>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optionally, a media caption for your forwarded message(s).
|
* Optionally, a media caption for your forwarded message(s).
|
||||||
|
@ -2622,7 +2622,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
/**
|
/**
|
||||||
* New message caption (only used for media)
|
* New message caption (only used for media)
|
||||||
*/
|
*/
|
||||||
caption?: string | FormattedString
|
caption?: string | FormattedString<any>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse mode to use to parse `text` entities before sending
|
* Parse mode to use to parse `text` entities before sending
|
||||||
|
@ -2784,7 +2784,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
* Can be used, for example. when using File IDs
|
* Can be used, for example. when using File IDs
|
||||||
* or when using existing InputMedia objects.
|
* or when using existing InputMedia objects.
|
||||||
*/
|
*/
|
||||||
caption?: string | FormattedString
|
caption?: string | FormattedString<any>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override entities for `media`.
|
* Override entities for `media`.
|
||||||
|
@ -2896,7 +2896,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
*/
|
*/
|
||||||
sendText(
|
sendText(
|
||||||
chatId: InputPeerLike,
|
chatId: InputPeerLike,
|
||||||
text: string | FormattedString,
|
text: string | FormattedString<any>,
|
||||||
params?: {
|
params?: {
|
||||||
/**
|
/**
|
||||||
* Message to reply to. Either a message object or message ID.
|
* Message to reply to. Either a message object or message ID.
|
||||||
|
|
|
@ -20,7 +20,7 @@ export async function editInlineMessage(
|
||||||
*
|
*
|
||||||
* When `media` is passed, `media.caption` is used instead
|
* When `media` is passed, `media.caption` is used instead
|
||||||
*/
|
*/
|
||||||
text?: string | FormattedString
|
text?: string | FormattedString<any>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse mode to use to parse entities before sending
|
* Parse mode to use to parse entities before sending
|
||||||
|
|
|
@ -26,7 +26,7 @@ export async function editMessage(
|
||||||
*
|
*
|
||||||
* When `media` is passed, `media.caption` is used instead
|
* When `media` is passed, `media.caption` is used instead
|
||||||
*/
|
*/
|
||||||
text?: string | FormattedString
|
text?: string | FormattedString<any>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse mode to use to parse entities before sending
|
* Parse mode to use to parse entities before sending
|
||||||
|
|
|
@ -74,7 +74,7 @@ export async function forwardMessages(
|
||||||
* You can either pass `caption` or `captionMedia`, passing both will
|
* You can either pass `caption` or `captionMedia`, passing both will
|
||||||
* result in an error
|
* result in an error
|
||||||
*/
|
*/
|
||||||
caption?: string | FormattedString
|
caption?: string | FormattedString<any>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optionally, a media caption for your forwarded message(s).
|
* Optionally, a media caption for your forwarded message(s).
|
||||||
|
@ -139,7 +139,7 @@ export async function forwardMessages(
|
||||||
* You can either pass `caption` or `captionMedia`, passing both will
|
* You can either pass `caption` or `captionMedia`, passing both will
|
||||||
* result in an error
|
* result in an error
|
||||||
*/
|
*/
|
||||||
caption?: string | FormattedString
|
caption?: string | FormattedString<any>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optionally, a media caption for your forwarded message(s).
|
* Optionally, a media caption for your forwarded message(s).
|
||||||
|
|
|
@ -8,7 +8,7 @@ const empty: [string, undefined] = ['', undefined]
|
||||||
/** @internal */
|
/** @internal */
|
||||||
export async function _parseEntities(
|
export async function _parseEntities(
|
||||||
this: TelegramClient,
|
this: TelegramClient,
|
||||||
text?: string | FormattedString,
|
text?: string | FormattedString<any>,
|
||||||
mode?: string | null,
|
mode?: string | null,
|
||||||
entities?: tl.TypeMessageEntity[]
|
entities?: tl.TypeMessageEntity[]
|
||||||
): Promise<[string, tl.TypeMessageEntity[] | undefined]> {
|
): Promise<[string, tl.TypeMessageEntity[] | undefined]> {
|
||||||
|
|
|
@ -44,7 +44,7 @@ export async function sendCopy(
|
||||||
/**
|
/**
|
||||||
* New message caption (only used for media)
|
* New message caption (only used for media)
|
||||||
*/
|
*/
|
||||||
caption?: string | FormattedString
|
caption?: string | FormattedString<any>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse mode to use to parse `text` entities before sending
|
* Parse mode to use to parse `text` entities before sending
|
||||||
|
|
|
@ -35,7 +35,7 @@ export async function sendMedia(
|
||||||
* Can be used, for example. when using File IDs
|
* Can be used, for example. when using File IDs
|
||||||
* or when using existing InputMedia objects.
|
* or when using existing InputMedia objects.
|
||||||
*/
|
*/
|
||||||
caption?: string | FormattedString
|
caption?: string | FormattedString<any>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override entities for `media`.
|
* Override entities for `media`.
|
||||||
|
|
|
@ -27,7 +27,7 @@ import { createDummyUpdate } from '../../utils/updates-utils'
|
||||||
export async function sendText(
|
export async function sendText(
|
||||||
this: TelegramClient,
|
this: TelegramClient,
|
||||||
chatId: InputPeerLike,
|
chatId: InputPeerLike,
|
||||||
text: string | FormattedString,
|
text: string | FormattedString<any>,
|
||||||
params?: {
|
params?: {
|
||||||
/**
|
/**
|
||||||
* Message to reply to. Either a message object or message ID.
|
* Message to reply to. Either a message object or message ID.
|
||||||
|
|
|
@ -13,7 +13,7 @@ interface BaseInputMedia {
|
||||||
/**
|
/**
|
||||||
* Caption of the media
|
* Caption of the media
|
||||||
*/
|
*/
|
||||||
caption?: string | FormattedString
|
caption?: string | FormattedString<any>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caption entities of the media.
|
* Caption entities of the media.
|
||||||
|
@ -522,7 +522,7 @@ export interface InputMediaQuiz extends Omit<InputMediaPoll, 'type'> {
|
||||||
/**
|
/**
|
||||||
* Explanation of the quiz solution
|
* Explanation of the quiz solution
|
||||||
*/
|
*/
|
||||||
solution?: string | FormattedString
|
solution?: string | FormattedString<any>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format entities for `solution`.
|
* Format entities for `solution`.
|
||||||
|
|
|
@ -494,7 +494,7 @@ export class Chat {
|
||||||
/** @internal */
|
/** @internal */
|
||||||
static _parseFull(
|
static _parseFull(
|
||||||
client: TelegramClient,
|
client: TelegramClient,
|
||||||
full: tl.messages.RawChatFull | tl.users.TypeUserFull,
|
full: tl.messages.RawChatFull | tl.users.TypeUserFull
|
||||||
): Chat {
|
): Chat {
|
||||||
if (full._ === 'users.userFull') {
|
if (full._ === 'users.userFull') {
|
||||||
const user = full.users.find((it) => it.id === full.fullUser.id)
|
const user = full.users.find((it) => it.id === full.fullUser.id)
|
||||||
|
@ -551,7 +551,10 @@ export class Chat {
|
||||||
* msg.replyText(`Hello, ${msg.chat.mention()`)
|
* msg.replyText(`Hello, ${msg.chat.mention()`)
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
mention(text?: string | null, parseMode?: string | null): string | FormattedString {
|
mention<T extends string = any>(
|
||||||
|
text?: string | null,
|
||||||
|
parseMode?: T | null
|
||||||
|
): string | FormattedString<T> {
|
||||||
if (this.user) return this.user.mention(text, parseMode)
|
if (this.user) return this.user.mention(text, parseMode)
|
||||||
|
|
||||||
if (text === undefined && this.username) {
|
if (text === undefined && this.username) {
|
||||||
|
@ -561,17 +564,20 @@ export class Chat {
|
||||||
if (!text) text = this.displayName
|
if (!text) text = this.displayName
|
||||||
if (!this.username) return text
|
if (!this.username) return text
|
||||||
|
|
||||||
if (!parseMode) parseMode = this.client['_defaultParseMode']
|
if (!parseMode) parseMode = this.client['_defaultParseMode'] as T
|
||||||
|
|
||||||
return new FormattedString(this.client.getParseMode(parseMode).unparse(text, [
|
return new FormattedString(
|
||||||
{
|
this.client.getParseMode(parseMode).unparse(text, [
|
||||||
raw: undefined as any,
|
{
|
||||||
type: 'text_link',
|
raw: undefined as any,
|
||||||
offset: 0,
|
type: 'text_link',
|
||||||
length: text.length,
|
offset: 0,
|
||||||
url: `https://t.me/${this.username}`
|
length: text.length,
|
||||||
},
|
url: `https://t.me/${this.username}`,
|
||||||
]), parseMode!)
|
},
|
||||||
|
]),
|
||||||
|
parseMode!
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -645,6 +651,7 @@ export class Chat {
|
||||||
): ReturnType<TelegramClient['sendMedia']> {
|
): ReturnType<TelegramClient['sendMedia']> {
|
||||||
return this.client.sendMedia(this.inputPeer, media, params)
|
return this.client.sendMedia(this.inputPeer, media, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a media group in this chat.
|
* Send a media group in this chat.
|
||||||
*
|
*
|
||||||
|
|
|
@ -286,16 +286,16 @@ export class User {
|
||||||
* msg.replyText(`Hello, ${msg.sender.mention()`)
|
* msg.replyText(`Hello, ${msg.sender.mention()`)
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
mention(
|
mention<T extends string = any>(
|
||||||
text?: string | null,
|
text?: string | null,
|
||||||
parseMode?: string | null
|
parseMode?: T | null
|
||||||
): string | FormattedString {
|
): string | FormattedString<T> {
|
||||||
if (text === undefined && this.username) {
|
if (text === undefined && this.username) {
|
||||||
return `@${this.username}`
|
return `@${this.username}`
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!text) text = this.displayName
|
if (!text) text = this.displayName
|
||||||
if (!parseMode) parseMode = this.client['_defaultParseMode']
|
if (!parseMode) parseMode = this.client['_defaultParseMode'] as T
|
||||||
|
|
||||||
return new FormattedString(
|
return new FormattedString(
|
||||||
this.client.getParseMode(parseMode).unparse(text, [
|
this.client.getParseMode(parseMode).unparse(text, [
|
||||||
|
@ -341,15 +341,15 @@ export class User {
|
||||||
* @param text Mention text
|
* @param text Mention text
|
||||||
* @param parseMode Parse mode to use when creating mention
|
* @param parseMode Parse mode to use when creating mention
|
||||||
*/
|
*/
|
||||||
permanentMention(
|
permanentMention<T extends string = any>(
|
||||||
text?: string | null,
|
text?: string | null,
|
||||||
parseMode?: string | null
|
parseMode?: T | null
|
||||||
): FormattedString {
|
): FormattedString<T> {
|
||||||
if (!this.raw.accessHash)
|
if (!this.raw.accessHash)
|
||||||
throw new MtArgumentError("user's access hash is not available!")
|
throw new MtArgumentError("user's access hash is not available!")
|
||||||
|
|
||||||
if (!text) text = this.displayName
|
if (!text) text = this.displayName
|
||||||
if (!parseMode) parseMode = this.client['_defaultParseMode']
|
if (!parseMode) parseMode = this.client['_defaultParseMode'] as T
|
||||||
|
|
||||||
// since we are just creating a link and not actual tg entity,
|
// since we are just creating a link and not actual tg entity,
|
||||||
// we can use this hack to create a valid link through our parse mode
|
// we can use this hack to create a valid link through our parse mode
|
||||||
|
|
Loading…
Reference in a new issue