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
|
||||
*/
|
||||
text?: string | FormattedString
|
||||
text?: string | FormattedString<any>
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
text?: string | FormattedString
|
||||
text?: string | FormattedString<any>
|
||||
|
||||
/**
|
||||
* 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
|
||||
* result in an error
|
||||
*/
|
||||
caption?: string | FormattedString
|
||||
caption?: string | FormattedString<any>
|
||||
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
caption?: string | FormattedString
|
||||
caption?: string | FormattedString<any>
|
||||
|
||||
/**
|
||||
* 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
|
||||
* or when using existing InputMedia objects.
|
||||
*/
|
||||
caption?: string | FormattedString
|
||||
caption?: string | FormattedString<any>
|
||||
|
||||
/**
|
||||
* Override entities for `media`.
|
||||
|
@ -2896,7 +2896,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
*/
|
||||
sendText(
|
||||
chatId: InputPeerLike,
|
||||
text: string | FormattedString,
|
||||
text: string | FormattedString<any>,
|
||||
params?: {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
text?: string | FormattedString
|
||||
text?: string | FormattedString<any>
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
text?: string | FormattedString
|
||||
text?: string | FormattedString<any>
|
||||
|
||||
/**
|
||||
* 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
|
||||
* result in an error
|
||||
*/
|
||||
caption?: string | FormattedString
|
||||
caption?: string | FormattedString<any>
|
||||
|
||||
/**
|
||||
* 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
|
||||
* result in an error
|
||||
*/
|
||||
caption?: string | FormattedString
|
||||
caption?: string | FormattedString<any>
|
||||
|
||||
/**
|
||||
* Optionally, a media caption for your forwarded message(s).
|
||||
|
|
|
@ -8,7 +8,7 @@ const empty: [string, undefined] = ['', undefined]
|
|||
/** @internal */
|
||||
export async function _parseEntities(
|
||||
this: TelegramClient,
|
||||
text?: string | FormattedString,
|
||||
text?: string | FormattedString<any>,
|
||||
mode?: string | null,
|
||||
entities?: tl.TypeMessageEntity[]
|
||||
): Promise<[string, tl.TypeMessageEntity[] | undefined]> {
|
||||
|
|
|
@ -44,7 +44,7 @@ export async function sendCopy(
|
|||
/**
|
||||
* New message caption (only used for media)
|
||||
*/
|
||||
caption?: string | FormattedString
|
||||
caption?: string | FormattedString<any>
|
||||
|
||||
/**
|
||||
* 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
|
||||
* or when using existing InputMedia objects.
|
||||
*/
|
||||
caption?: string | FormattedString
|
||||
caption?: string | FormattedString<any>
|
||||
|
||||
/**
|
||||
* Override entities for `media`.
|
||||
|
|
|
@ -27,7 +27,7 @@ import { createDummyUpdate } from '../../utils/updates-utils'
|
|||
export async function sendText(
|
||||
this: TelegramClient,
|
||||
chatId: InputPeerLike,
|
||||
text: string | FormattedString,
|
||||
text: string | FormattedString<any>,
|
||||
params?: {
|
||||
/**
|
||||
* Message to reply to. Either a message object or message ID.
|
||||
|
|
|
@ -13,7 +13,7 @@ interface BaseInputMedia {
|
|||
/**
|
||||
* Caption of the media
|
||||
*/
|
||||
caption?: string | FormattedString
|
||||
caption?: string | FormattedString<any>
|
||||
|
||||
/**
|
||||
* Caption entities of the media.
|
||||
|
@ -522,7 +522,7 @@ export interface InputMediaQuiz extends Omit<InputMediaPoll, 'type'> {
|
|||
/**
|
||||
* Explanation of the quiz solution
|
||||
*/
|
||||
solution?: string | FormattedString
|
||||
solution?: string | FormattedString<any>
|
||||
|
||||
/**
|
||||
* Format entities for `solution`.
|
||||
|
|
|
@ -494,7 +494,7 @@ export class Chat {
|
|||
/** @internal */
|
||||
static _parseFull(
|
||||
client: TelegramClient,
|
||||
full: tl.messages.RawChatFull | tl.users.TypeUserFull,
|
||||
full: tl.messages.RawChatFull | tl.users.TypeUserFull
|
||||
): Chat {
|
||||
if (full._ === 'users.userFull') {
|
||||
const user = full.users.find((it) => it.id === full.fullUser.id)
|
||||
|
@ -551,7 +551,10 @@ export class Chat {
|
|||
* 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 (text === undefined && this.username) {
|
||||
|
@ -561,17 +564,20 @@ export class Chat {
|
|||
if (!text) text = this.displayName
|
||||
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',
|
||||
offset: 0,
|
||||
length: text.length,
|
||||
url: `https://t.me/${this.username}`
|
||||
url: `https://t.me/${this.username}`,
|
||||
},
|
||||
]), parseMode!)
|
||||
]),
|
||||
parseMode!
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -645,6 +651,7 @@ export class Chat {
|
|||
): ReturnType<TelegramClient['sendMedia']> {
|
||||
return this.client.sendMedia(this.inputPeer, media, params)
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a media group in this chat.
|
||||
*
|
||||
|
|
|
@ -286,16 +286,16 @@ export class User {
|
|||
* msg.replyText(`Hello, ${msg.sender.mention()`)
|
||||
* ```
|
||||
*/
|
||||
mention(
|
||||
mention<T extends string = any>(
|
||||
text?: string | null,
|
||||
parseMode?: string | null
|
||||
): string | FormattedString {
|
||||
parseMode?: T | null
|
||||
): string | FormattedString<T> {
|
||||
if (text === undefined && this.username) {
|
||||
return `@${this.username}`
|
||||
}
|
||||
|
||||
if (!text) text = this.displayName
|
||||
if (!parseMode) parseMode = this.client['_defaultParseMode']
|
||||
if (!parseMode) parseMode = this.client['_defaultParseMode'] as T
|
||||
|
||||
return new FormattedString(
|
||||
this.client.getParseMode(parseMode).unparse(text, [
|
||||
|
@ -341,15 +341,15 @@ export class User {
|
|||
* @param text Mention text
|
||||
* @param parseMode Parse mode to use when creating mention
|
||||
*/
|
||||
permanentMention(
|
||||
permanentMention<T extends string = any>(
|
||||
text?: string | null,
|
||||
parseMode?: string | null
|
||||
): FormattedString {
|
||||
parseMode?: T | null
|
||||
): FormattedString<T> {
|
||||
if (!this.raw.accessHash)
|
||||
throw new MtArgumentError("user's access hash is not available!")
|
||||
|
||||
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,
|
||||
// we can use this hack to create a valid link through our parse mode
|
||||
|
|
Loading…
Reference in a new issue