fix(client): added true
assertions to methods returning Bool
This commit is contained in:
parent
69f59ab97e
commit
712c1e8348
34 changed files with 197 additions and 53 deletions
|
@ -67,7 +67,7 @@ import { joinChat } from './methods/chats/join-chat.js'
|
|||
import { kickChatMember } from './methods/chats/kick-chat-member.js'
|
||||
import { leaveChat } from './methods/chats/leave-chat.js'
|
||||
import { markChatUnread } from './methods/chats/mark-chat-unread.js'
|
||||
import { openChat } from './methods/chats/open-chat.js'
|
||||
import { closeChat, openChat } from './methods/chats/open-chat.js'
|
||||
import { reorderUsernames } from './methods/chats/reorder-usernames.js'
|
||||
import { restrictChatMember } from './methods/chats/restrict-chat-member.js'
|
||||
import { saveDraft } from './methods/chats/save-draft.js'
|
||||
|
@ -1683,6 +1683,18 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
* @param chat Chat to open
|
||||
*/
|
||||
openChat(chat: InputPeerLike): Promise<void>
|
||||
/**
|
||||
* Inform the library that the user has closed a chat.
|
||||
* Un-does the effect of {@link openChat}.
|
||||
*
|
||||
* Some library logic depends on this, for example, the library will
|
||||
* periodically ping the server to keep the updates flowing.
|
||||
*
|
||||
* **Available**: ✅ both users and bots
|
||||
*
|
||||
* @param chat Chat to open
|
||||
*/
|
||||
closeChat(chat: InputPeerLike): Promise<void>
|
||||
/**
|
||||
* Reorder usernames
|
||||
*
|
||||
|
@ -1732,7 +1744,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
saveDraft(chatId: InputPeerLike, draft: null | Omit<tl.RawDraftMessage, '_' | 'date'>): Promise<void>
|
||||
|
||||
/**
|
||||
* Set chat name/replies color and optionally background pattern
|
||||
* Set peer color and optionally background pattern
|
||||
* **Available**: 👤 users only
|
||||
*
|
||||
*/
|
||||
|
@ -1762,6 +1774,14 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
* Must be an adaptive emoji, otherwise the request will fail.
|
||||
*/
|
||||
backgroundEmojiId?: tl.Long
|
||||
|
||||
/**
|
||||
* Whether to set this color for the profile
|
||||
* header instead of chat name/replies.
|
||||
*
|
||||
* Currently only available for the current user.
|
||||
*/
|
||||
forProfile?: boolean
|
||||
}): Promise<void>
|
||||
/**
|
||||
* Change default chat permissions for all members.
|
||||
|
@ -4582,7 +4602,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
* @param peerId Peer ID whose stories to mark as read
|
||||
* @param ids ID(s) of the stories to increment views of (max 200)
|
||||
*/
|
||||
incrementStoriesViews(peerId: InputPeerLike, ids: MaybeArray<number>): Promise<boolean>
|
||||
incrementStoriesViews(peerId: InputPeerLike, ids: MaybeArray<number>): Promise<void>
|
||||
/**
|
||||
* Iterate over all stories (e.g. to load the top bar)
|
||||
*
|
||||
|
@ -5433,6 +5453,10 @@ TelegramClient.prototype.openChat = function (...args) {
|
|||
return openChat(this, ...args)
|
||||
}
|
||||
|
||||
TelegramClient.prototype.closeChat = function (...args) {
|
||||
return closeChat(this, ...args)
|
||||
}
|
||||
|
||||
TelegramClient.prototype.reorderUsernames = function (...args) {
|
||||
return reorderUsernames(this, ...args)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient, Long } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
import { CallbackQuery } from '../../types/updates/callback-query.js'
|
||||
|
||||
|
@ -49,7 +50,7 @@ export async function answerCallbackQuery(
|
|||
): Promise<void> {
|
||||
const { cacheTime = 0, text, alert, url } = params ?? {}
|
||||
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'messages.setBotCallbackAnswer',
|
||||
queryId: Long.isLong(queryId) ? queryId : queryId.id,
|
||||
cacheTime,
|
||||
|
@ -57,4 +58,6 @@ export async function answerCallbackQuery(
|
|||
message: text,
|
||||
url,
|
||||
})
|
||||
|
||||
assertTrue('messages.setBotCallbackAnswer', r)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient, Long, tl } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
import type { PreCheckoutQuery } from '../../types/updates/pre-checkout-query.js'
|
||||
|
||||
|
@ -17,10 +18,12 @@ export async function answerPreCheckoutQuery(
|
|||
): Promise<void> {
|
||||
const { error } = params ?? {}
|
||||
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'messages.setBotPrecheckoutResults',
|
||||
queryId: Long.isLong(queryId) ? queryId : queryId.queryId,
|
||||
success: !error,
|
||||
error,
|
||||
})
|
||||
|
||||
assertTrue('messages.setBotPrecheckoutResults', r)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
|
@ -34,7 +35,7 @@ export async function setBotInfo(
|
|||
): Promise<void> {
|
||||
const { bot, langCode = '', name, bio, description } = params
|
||||
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'bots.setBotInfo',
|
||||
bot: bot ? toInputUser(await resolvePeer(client, bot), bot) : undefined,
|
||||
langCode: langCode,
|
||||
|
@ -42,4 +43,6 @@ export async function setBotInfo(
|
|||
about: bio,
|
||||
description,
|
||||
})
|
||||
|
||||
assertTrue('bots.setBotInfo', r)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient, tl } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
|
@ -12,9 +13,11 @@ export async function setBotMenuButton(
|
|||
user: InputPeerLike,
|
||||
button: tl.TypeBotMenuButton,
|
||||
): Promise<void> {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'bots.setBotMenuButton',
|
||||
userId: toInputUser(await resolvePeer(client, user), user),
|
||||
button,
|
||||
})
|
||||
|
||||
assertTrue('bots.setBotMenuButton', r)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient, tl } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
import { InputMessageId, InputPeerLike, Message, normalizeInputMessageId } from '../../types/index.js'
|
||||
import { normalizeInlineId } from '../../utils/inline-utils.js'
|
||||
|
@ -93,7 +94,7 @@ export async function setInlineGameScore(
|
|||
|
||||
const id = normalizeInlineId(messageId)
|
||||
|
||||
await client.call(
|
||||
const r = await client.call(
|
||||
{
|
||||
_: 'messages.setInlineGameScore',
|
||||
id,
|
||||
|
@ -104,4 +105,6 @@ export async function setInlineGameScore(
|
|||
},
|
||||
{ dcId: id.dcId },
|
||||
)
|
||||
|
||||
assertTrue('messages.setInlineGameScore', r)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient, tl } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
import { BotCommands } from '../../types/index.js'
|
||||
import { _normalizeCommandScope } from './normalize-command-scope.js'
|
||||
|
@ -38,17 +39,21 @@ export async function setMyCommands(
|
|||
}
|
||||
|
||||
if (params.commands?.length) {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'bots.setBotCommands',
|
||||
commands: params.commands,
|
||||
scope,
|
||||
langCode: params.langCode ?? '',
|
||||
})
|
||||
|
||||
assertTrue('bots.setBotCommands', r)
|
||||
} else {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'bots.resetBotCommands',
|
||||
scope,
|
||||
langCode: params.langCode ?? '',
|
||||
})
|
||||
|
||||
assertTrue('bots.resetBotCommands', r)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient, tl } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
/**
|
||||
* Sets the default chat permissions for the bot in the supergroup or channel.
|
||||
|
@ -14,11 +15,13 @@ export async function setMyDefaultRights(
|
|||
): Promise<void> {
|
||||
const { target, rights } = params
|
||||
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: target === 'group' ? 'bots.setBotGroupDefaultAdminRights' : 'bots.setBotBroadcastDefaultAdminRights',
|
||||
adminRights: {
|
||||
_: 'chatAdminRights',
|
||||
...rights,
|
||||
},
|
||||
})
|
||||
|
||||
assertTrue('bots.setBotGroupDefaultAdminRights', r)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types/index.js'
|
||||
import { isInputPeerChat } from '../../utils/peer-utils.js'
|
||||
|
@ -21,8 +22,10 @@ export async function deleteGroup(client: BaseTelegramClient, chatId: InputPeerL
|
|||
})
|
||||
client.network.handleUpdate(res)
|
||||
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'messages.deleteChat',
|
||||
chatId: chat.chatId,
|
||||
})
|
||||
|
||||
assertTrue('messages.deleteChat', r)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
@ -9,7 +10,7 @@ import { resolvePeer } from '../users/resolve-peer.js'
|
|||
* @param chatId Chat ID
|
||||
*/
|
||||
export async function markChatUnread(client: BaseTelegramClient, chatId: InputPeerLike): Promise<void> {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'messages.markDialogUnread',
|
||||
peer: {
|
||||
_: 'inputDialogPeer',
|
||||
|
@ -17,4 +18,6 @@ export async function markChatUnread(client: BaseTelegramClient, chatId: InputPe
|
|||
},
|
||||
unread: true,
|
||||
})
|
||||
|
||||
assertTrue('messages.markDialogUnread', r)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { isInputPeerChannel, isInputPeerUser, toInputChannel, toInputUser } from '../../utils/index.js'
|
||||
import { assertTrue, isInputPeerChannel, isInputPeerUser, toInputChannel, toInputUser } from '../../utils/index.js'
|
||||
import { getAuthState } from '../auth/_state.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -22,25 +22,31 @@ export async function reorderUsernames(
|
|||
|
||||
if (peer._ === 'inputPeerSelf' || peer.userId === getAuthState(client).userId) {
|
||||
// self
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'account.reorderUsernames',
|
||||
order,
|
||||
})
|
||||
|
||||
assertTrue('account.reorderUsernames', r)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// bot
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'bots.reorderUsernames',
|
||||
bot: toInputUser(peer, peerId),
|
||||
order,
|
||||
})
|
||||
|
||||
assertTrue('bots.reorderUsernames', r)
|
||||
} else if (isInputPeerChannel(peer)) {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'channels.reorderUsernames',
|
||||
channel: toInputChannel(peer, peerId),
|
||||
order,
|
||||
})
|
||||
|
||||
assertTrue('channels.reorderUsernames', r)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import { BaseTelegramClient, MtTypeAssertionError, tl } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types/index.js'
|
||||
import { isInputPeerChannel, isInputPeerUser, toInputChannel } from '../../utils/index.js'
|
||||
import { assertTrue, isInputPeerChannel, isInputPeerUser, toInputChannel } from '../../utils/index.js'
|
||||
import { getAuthState } from '../auth/_state.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
// @available=user
|
||||
/**
|
||||
* Set chat name/replies color and optionally background pattern
|
||||
* Set peer color and optionally background pattern
|
||||
*/
|
||||
export async function setChatColor(
|
||||
client: BaseTelegramClient,
|
||||
|
@ -37,9 +37,17 @@ export async function setChatColor(
|
|||
* Must be an adaptive emoji, otherwise the request will fail.
|
||||
*/
|
||||
backgroundEmojiId?: tl.Long
|
||||
|
||||
/**
|
||||
* Whether to set this color for the profile
|
||||
* header instead of chat name/replies.
|
||||
*
|
||||
* Currently only available for the current user.
|
||||
*/
|
||||
forProfile?: boolean
|
||||
},
|
||||
): Promise<void> {
|
||||
const { color, backgroundEmojiId } = params
|
||||
const { color, backgroundEmojiId, forProfile } = params
|
||||
const peer = await resolvePeer(client, params.peer ?? 'me')
|
||||
|
||||
if (isInputPeerChannel(peer)) {
|
||||
|
@ -60,11 +68,14 @@ export async function setChatColor(
|
|||
throw new MtTypeAssertionError('setChatColor', 'inputPeerSelf | inputPeerUser', peer._)
|
||||
}
|
||||
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'account.updateColor',
|
||||
color,
|
||||
backgroundEmojiId,
|
||||
forProfile,
|
||||
})
|
||||
|
||||
assertTrue('account.updateColor', r)
|
||||
}
|
||||
|
||||
throw new MtInvalidPeerTypeError(peer, 'channel | user')
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
@ -18,9 +19,11 @@ export async function setChatDescription(
|
|||
): Promise<void> {
|
||||
const chat = await resolvePeer(client, chatId)
|
||||
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'messages.editChatAbout',
|
||||
peer: chat,
|
||||
about: description,
|
||||
})
|
||||
|
||||
assertTrue('messages.editChatAbout', r)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
||||
|
@ -17,9 +18,11 @@ export async function setChatUsername(
|
|||
chatId: InputPeerLike,
|
||||
username: string | null,
|
||||
): Promise<void> {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'channels.updateUsername',
|
||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
username: username || '',
|
||||
})
|
||||
|
||||
assertTrue('channels.updateUsername', r)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { isInputPeerChannel, isInputPeerUser, toInputChannel, toInputUser } from '../../utils/index.js'
|
||||
import { assertTrue, isInputPeerChannel, isInputPeerUser, toInputChannel, toInputUser } from '../../utils/index.js'
|
||||
import { getAuthState } from '../auth/_state.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -37,28 +37,34 @@ export async function toggleFragmentUsername(
|
|||
|
||||
if (peer._ === 'inputPeerSelf' || peer.userId === getAuthState(client).userId) {
|
||||
// self
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'account.toggleUsername',
|
||||
username,
|
||||
active,
|
||||
})
|
||||
|
||||
assertTrue('account.toggleUsername', r)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// bot
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'bots.toggleUsername',
|
||||
bot: toInputUser(peer, peerId),
|
||||
username,
|
||||
active,
|
||||
})
|
||||
|
||||
assertTrue('bots.toggleUsername', r)
|
||||
} else if (isInputPeerChannel(peer)) {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'channels.toggleUsername',
|
||||
channel: toInputChannel(peer, peerId),
|
||||
username,
|
||||
active,
|
||||
})
|
||||
|
||||
assertTrue('channels.toggleUsername', r)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient, PartialExcept, tl } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
import { getFolders } from './get-folders.js'
|
||||
|
||||
|
@ -38,11 +39,13 @@ export async function createFolder(
|
|||
id,
|
||||
}
|
||||
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'messages.updateDialogFilter',
|
||||
id,
|
||||
filter,
|
||||
})
|
||||
|
||||
assertTrue('messages.updateDialogFilter', r)
|
||||
|
||||
return filter
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient, tl } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
/**
|
||||
* Delete a folder by its ID
|
||||
|
@ -6,8 +7,10 @@ import { BaseTelegramClient, tl } from '@mtcute/core'
|
|||
* @param id Folder ID or folder itself
|
||||
*/
|
||||
export async function deleteFolder(client: BaseTelegramClient, id: number | tl.RawDialogFilter): Promise<void> {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'messages.updateDialogFilter',
|
||||
id: typeof id === 'number' ? id : id.id,
|
||||
})
|
||||
|
||||
assertTrue('messages.updateDialogFilter', r)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient, MtArgumentError, tl } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
import { getFolders } from './get-folders.js'
|
||||
|
||||
|
@ -44,11 +45,13 @@ export async function editFolder(
|
|||
...modification,
|
||||
}
|
||||
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'messages.updateDialogFilter',
|
||||
id: folder.id,
|
||||
filter,
|
||||
})
|
||||
|
||||
assertTrue('messages.updateDialogFilter', r)
|
||||
|
||||
return filter
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
/**
|
||||
* Reorder folders
|
||||
|
@ -6,8 +7,10 @@ import { BaseTelegramClient } from '@mtcute/core'
|
|||
* @param order New order of folders (folder IDs, where default = 0)
|
||||
*/
|
||||
export async function setFoldersOrder(client: BaseTelegramClient, order: number[]): Promise<void> {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'messages.updateDialogFiltersOrder',
|
||||
order,
|
||||
})
|
||||
|
||||
assertTrue('messages.updateDialogFiltersOrder', r)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { isInputPeerChannel, toInputChannel } from '../../utils/peer-utils.js'
|
||||
|
@ -45,11 +46,13 @@ export async function readHistory(
|
|||
}
|
||||
|
||||
if (isInputPeerChannel(peer)) {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'channels.readHistory',
|
||||
channel: toInputChannel(peer),
|
||||
maxId,
|
||||
})
|
||||
|
||||
assertTrue('channels.readHistory', r)
|
||||
} else {
|
||||
const res = await client.call({
|
||||
_: 'messages.readHistory',
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { assertNever, BaseTelegramClient, tl } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
import { InputPeerLike, TypingStatus } from '../../types/index.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
@ -88,10 +89,12 @@ export async function sendTyping(
|
|||
}
|
||||
}
|
||||
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'messages.setTyping',
|
||||
peer: await resolvePeer(client, chatId),
|
||||
action: status,
|
||||
topMsgId: params?.threadId,
|
||||
})
|
||||
|
||||
assertTrue('messages.setTyping', r)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
/**
|
||||
* Verify an email to use as 2FA recovery method
|
||||
|
@ -6,26 +7,32 @@ import { BaseTelegramClient } from '@mtcute/core'
|
|||
* @param code Code which was sent via email
|
||||
*/
|
||||
export async function verifyPasswordEmail(client: BaseTelegramClient, code: string): Promise<void> {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'account.confirmPasswordEmail',
|
||||
code,
|
||||
})
|
||||
|
||||
assertTrue('account.confirmPasswordEmail', r)
|
||||
}
|
||||
|
||||
/**
|
||||
* Resend the code to verify an email to use as 2FA recovery method.
|
||||
*/
|
||||
export async function resendPasswordEmail(client: BaseTelegramClient): Promise<void> {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'account.resendPasswordEmail',
|
||||
})
|
||||
|
||||
assertTrue('account.resendPasswordEmail', r)
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel the code that was sent to verify an email to use as 2FA recovery method
|
||||
*/
|
||||
export async function cancelPasswordEmail(client: BaseTelegramClient): Promise<void> {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'account.cancelPasswordEmail',
|
||||
})
|
||||
|
||||
assertTrue('account.cancelPasswordEmail', r)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike, InputStickerSet, normalizeInputStickerSet } from '../../types/index.js'
|
||||
import { toInputChannel } from '../../utils/index.js'
|
||||
import { assertTrue, toInputChannel } from '../../utils/index.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -17,9 +17,11 @@ export async function setChatStickerSet(
|
|||
chatId: InputPeerLike,
|
||||
setId: InputStickerSet,
|
||||
): Promise<void> {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'channels.setStickers',
|
||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
stickerset: normalizeInputStickerSet(setId),
|
||||
})
|
||||
|
||||
assertTrue('channels.setStickers', r)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient, MaybeArray } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
@ -16,10 +17,12 @@ export async function incrementStoriesViews(
|
|||
client: BaseTelegramClient,
|
||||
peerId: InputPeerLike,
|
||||
ids: MaybeArray<number>,
|
||||
): Promise<boolean> {
|
||||
return client.call({
|
||||
): Promise<void> {
|
||||
const r = await client.call({
|
||||
_: 'stories.incrementStoryViews',
|
||||
peer: await resolvePeer(client, peerId),
|
||||
id: Array.isArray(ids) ? ids : [ids],
|
||||
})
|
||||
|
||||
assertTrue('stories.incrementStoryViews', r)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient, MaybeArray, tl } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
@ -26,11 +27,13 @@ export async function reportStory(
|
|||
): Promise<void> {
|
||||
const { reason = { _: 'inputReportReasonSpam' }, message = '' } = params ?? {}
|
||||
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'stories.report',
|
||||
peer: await resolvePeer(client, peerId),
|
||||
id: Array.isArray(storyIds) ? storyIds : [storyIds],
|
||||
message,
|
||||
reason,
|
||||
})
|
||||
|
||||
assertTrue('stories.report', r)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
@ -13,9 +14,11 @@ export async function togglePeerStoriesArchived(
|
|||
peerId: InputPeerLike,
|
||||
archived: boolean,
|
||||
): Promise<void> {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'stories.togglePeerStoriesHidden',
|
||||
peer: await resolvePeer(client, peerId),
|
||||
hidden: archived,
|
||||
})
|
||||
|
||||
assertTrue('stories.togglePeerStoriesHidden', r)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { resolvePeer } from './resolve-peer.js'
|
||||
|
@ -9,8 +10,10 @@ import { resolvePeer } from './resolve-peer.js'
|
|||
* @param id User ID, username or phone number
|
||||
*/
|
||||
export async function blockUser(client: BaseTelegramClient, id: InputPeerLike): Promise<void> {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'contacts.block',
|
||||
id: await resolvePeer(client, id),
|
||||
})
|
||||
|
||||
assertTrue('contacts.block', r)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { toInputUser } from '../../utils/index.js'
|
||||
import { assertTrue, toInputUser } from '../../utils/index.js'
|
||||
import { resolvePeerMany } from './resolve-peer-many.js'
|
||||
|
||||
/**
|
||||
|
@ -10,10 +10,12 @@ import { resolvePeerMany } from './resolve-peer-many.js'
|
|||
* @param ids User IDs
|
||||
*/
|
||||
export async function editCloseFriendsRaw(client: BaseTelegramClient, ids: number[]): Promise<void> {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'contacts.editCloseFriends',
|
||||
id: ids,
|
||||
})
|
||||
|
||||
assertTrue('contacts.editCloseFriends', r)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,7 +24,7 @@ export async function editCloseFriendsRaw(client: BaseTelegramClient, ids: numbe
|
|||
* @param ids User IDs
|
||||
*/
|
||||
export async function editCloseFriends(client: BaseTelegramClient, ids: InputPeerLike[]): Promise<void> {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'contacts.editCloseFriends',
|
||||
id: await resolvePeerMany(client, ids, toInputUser).then((r) =>
|
||||
r.map((u) => {
|
||||
|
@ -32,4 +34,6 @@ export async function editCloseFriends(client: BaseTelegramClient, ids: InputPee
|
|||
}),
|
||||
),
|
||||
})
|
||||
|
||||
assertTrue('contacts.editCloseFriends', r)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { BaseTelegramClient, tl } from '@mtcute/core'
|
||||
|
||||
import { normalizeDate } from '../../utils/index.js'
|
||||
import { assertTrue, normalizeDate } from '../../utils/index.js'
|
||||
|
||||
/**
|
||||
* Set an emoji status for the current user
|
||||
|
@ -36,8 +36,10 @@ export async function setEmojiStatus(
|
|||
}
|
||||
}
|
||||
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'account.updateEmojiStatus',
|
||||
emojiStatus,
|
||||
})
|
||||
|
||||
assertTrue('account.updateEmojiStatus', r)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
/**
|
||||
* Changes the current default value of the Time-To-Live setting,
|
||||
|
@ -7,8 +8,10 @@ import { BaseTelegramClient } from '@mtcute/core'
|
|||
* @param period New TTL period, in seconds (or 0 to disable)
|
||||
*/
|
||||
export async function setGlobalTtl(client: BaseTelegramClient, period: number): Promise<void> {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'messages.setDefaultHistoryTTL',
|
||||
period,
|
||||
})
|
||||
|
||||
assertTrue('messages.setDefaultHistoryTTL', r)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
/**
|
||||
* Change user status to offline or online
|
||||
|
@ -6,8 +7,10 @@ import { BaseTelegramClient } from '@mtcute/core'
|
|||
* @param offline Whether the user is currently offline
|
||||
*/
|
||||
export async function setOffline(client: BaseTelegramClient, offline = true): Promise<void> {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'account.updateStatus',
|
||||
offline,
|
||||
})
|
||||
|
||||
assertTrue('account.updateStatus', r)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
import { assertTrue } from '@mtcute/core/utils.js'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { resolvePeer } from './resolve-peer.js'
|
||||
|
@ -9,8 +10,10 @@ import { resolvePeer } from './resolve-peer.js'
|
|||
* @param id User ID, username or phone number
|
||||
*/
|
||||
export async function unblockUser(client: BaseTelegramClient, id: InputPeerLike): Promise<void> {
|
||||
await client.call({
|
||||
const r = await client.call({
|
||||
_: 'contacts.unblock',
|
||||
id: await resolvePeer(client, id),
|
||||
})
|
||||
|
||||
assertTrue('contacts.unblock', r)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { BaseTelegramClient, MustEqual, RpcCallOptions, tl } from '@mtcute/core'
|
||||
|
||||
import { makeInspectable } from '../../utils/index.js'
|
||||
import { assertTrue, makeInspectable } from '../../utils/index.js'
|
||||
|
||||
/**
|
||||
* Account takeout session
|
||||
|
@ -87,10 +87,12 @@ export class TakeoutSession {
|
|||
* @param success Whether the data was successfully exported
|
||||
*/
|
||||
async finish(success = true): Promise<void> {
|
||||
await this.call({
|
||||
const r = await this.call({
|
||||
_: 'account.finishTakeoutSession',
|
||||
success,
|
||||
})
|
||||
|
||||
assertTrue('account.finishTakeoutSession', r)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -79,3 +79,9 @@ export function mtpAssertTypeIs<T extends mtp.TlObject, K extends T['_']>(
|
|||
throw new MtTypeAssertionError(context, expected, obj._)
|
||||
}
|
||||
}
|
||||
|
||||
export function assertTrue(context: string, cond: boolean): asserts cond {
|
||||
if (!cond) {
|
||||
throw new MtTypeAssertionError(context, 'true', 'false')
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue