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