refactor: prettier-ed code, rearranged imports, fixed tests

This commit is contained in:
teidesu 2022-06-30 16:32:56 +03:00
parent f2eb033e91
commit e68c9f4bb5
318 changed files with 1623 additions and 1708 deletions

View file

@ -6,3 +6,6 @@ src/tl/types.d.ts
src/tl/types.js
src/tl/binary/reader.js
src/tl/binary/writer.js
**/dist
*.d.ts

View file

@ -6,10 +6,9 @@
"license": "LGPL-3.0",
"author": "Alisa Sireneva <me@tei.su>",
"scripts": {
"test": "lerna run test",
"build": "lerna run build",
"lint": "eslint packages/**/*.ts",
"format": "prettier --write packages/**/*.ts",
"test-all": "pnpm run -r test",
"lint": "eslint \"packages/**/*.ts\"",
"format": "prettier --write \"packages/**/*.ts\"",
"publish-all": "node scripts/publish.js all"
},
"dependencies": {
@ -29,9 +28,9 @@
"mocha": "^9.2.2",
"node-forge": "^1.3.1",
"prettier": "^2.6.2",
"ts-node": "^10.7.0",
"typedoc": "^0.22.15",
"typescript": "^4.6.4",
"ts-node": "^10.8.1",
"typedoc": "^0.23.2",
"typescript": "^4.7.4",
"nyc": "^15.1.0",
"rimraf": "^3.0.2",
"dotenv-flow": "^3.2.0",

View file

@ -7,7 +7,7 @@
"license": "LGPL-3.0",
"main": "src/index.ts",
"scripts": {
"test": "mocha -r ts-node/register tests/**/*.spec.ts",
"test": "mocha -r ts-node/register \"tests/**/*.spec.ts\"",
"docs": "npx typedoc",
"build": "tsc"
},

View file

@ -3,7 +3,7 @@ export {
JsonFileStorage,
LocalstorageStorage,
tl,
defaultDcs
defaultDcs,
} from '@mtcute/core'
export * from './types'

View file

@ -1,6 +1,7 @@
import { computeSrpParams } from '@mtcute/core'
import { TelegramClient } from '../../client'
import { User } from '../../types'
import { computeSrpParams } from '@mtcute/core'
import { assertTypeIs } from '../../utils/type-assertion'
/**

View file

@ -9,9 +9,7 @@ import { TelegramClient } from '../../client'
* @returns On success, `true` is returned
* @internal
*/
export async function logOut(
this: TelegramClient
): Promise<true> {
export async function logOut(this: TelegramClient): Promise<true> {
await this.call({ _: 'auth.logOut' })
this._userId = null

View file

@ -1,5 +1,5 @@
import { SentCode } from '../../types'
import { TelegramClient } from '../../client'
import { SentCode } from '../../types'
import { normalizePhoneNumber } from '../../utils/misc-utils'
/**

View file

@ -1,5 +1,5 @@
import { SentCode } from '../../types'
import { TelegramClient } from '../../client'
import { SentCode } from '../../types'
import { normalizePhoneNumber } from '../../utils/misc-utils'
/**

View file

@ -1,5 +1,5 @@
import { User } from '../../types'
import { TelegramClient } from '../../client'
import { User } from '../../types'
import { assertTypeIs } from '../../utils/type-assertion'
/**

View file

@ -1,5 +1,5 @@
import { User, TermsOfService } from '../../types'
import { TelegramClient } from '../../client'
import { User, TermsOfService } from '../../types'
import { assertTypeIs } from '../../utils/type-assertion'
import { normalizePhoneNumber } from '../../utils/misc-utils'

View file

@ -1,7 +1,7 @@
import { TelegramClient } from '../../client'
import { User } from '../../types'
import { normalizePhoneNumber } from '../../utils/misc-utils'
import { assertTypeIs } from '../../utils/type-assertion'
import { User } from '../../types'
/**
* Register a new user in Telegram.

View file

@ -1,5 +1,5 @@
import { MaybeDynamic, MtArgumentError, User } from '../../types'
import { TelegramClient } from '../../client'
import { MaybeDynamic, MtArgumentError, User } from '../../types'
/**
* Utility function to quickly authorize on test DC

View file

@ -1,3 +1,6 @@
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import {
MaybeDynamic,
MtArgumentError,
@ -6,12 +9,10 @@ import {
User,
MaybeAsync,
} from '../../types'
import { TelegramClient } from '../../client'
import {
resolveMaybeDynamic,
normalizePhoneNumber,
} from '../../utils/misc-utils'
import { tl } from '@mtcute/tl'
/**
* Start the client in an interactive and declarative manner,

View file

@ -1,6 +1,7 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
/**
* Send an answer to a callback query.
*

View file

@ -1,5 +1,6 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { BotInline, InputInlineResult } from '../../types'
/**

View file

@ -1,5 +1,6 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { BotCommands } from '../../types'
/**

View file

@ -1,7 +1,8 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
import { InputPeerLike, MtInvalidPeerTypeError } from "../../types";
import { normalizeToInputUser } from "../../utils/peer-utils";
import { TelegramClient } from '../../client'
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
import { normalizeToInputUser } from '../../utils/peer-utils'
/**
* Fetches the menu button set for the given user.

View file

@ -1,8 +1,9 @@
import { TelegramClient } from '../../client'
import { InputPeerLike } from '../../types'
import { tl } from '@mtcute/tl'
import { computeSrpParams } from '@mtcute/core'
import { TelegramClient } from '../../client'
import { InputPeerLike } from '../../types'
/**
* Request a callback answer from a bot,
* i.e. click an inline button that contains data.

View file

@ -1,3 +1,5 @@
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import {
InputPeerLike,
@ -5,7 +7,6 @@ import {
GameHighScore,
PeersIndex,
} from '../../types'
import { tl } from '@mtcute/tl'
import { normalizeToInputUser } from '../../utils/peer-utils'
/**

View file

@ -1,5 +1,6 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { BotCommands } from '../../types'
/**

View file

@ -1,9 +1,10 @@
import { tl } from '@mtcute/tl'
import { BotCommands, MtInvalidPeerTypeError } from '../../types'
import { TelegramClient } from '../../client'
import { normalizeToInputUser } from '../../utils/peer-utils'
import { assertNever } from '@mtcute/core'
import { TelegramClient } from '../../client'
import { BotCommands, MtInvalidPeerTypeError } from '../../types'
import { normalizeToInputUser } from '../../utils/peer-utils'
/** @internal */
export async function _normalizeCommandScope(
this: TelegramClient,
@ -17,21 +18,25 @@ export async function _normalizeCommandScope(
const peer = await this.resolvePeer(scope.peer)
return {
_: scope.type === 'peer' ? 'botCommandScopePeer' : 'botCommandScopePeerAdmins',
peer
_:
scope.type === 'peer'
? 'botCommandScopePeer'
: 'botCommandScopePeerAdmins',
peer,
}
}
case 'member': {
const chat = await this.resolvePeer(scope.chat)
const user = normalizeToInputUser(await this.resolvePeer(scope.user))
const user = normalizeToInputUser(
await this.resolvePeer(scope.user)
)
if (!user)
throw new MtInvalidPeerTypeError(scope.user, 'user')
if (!user) throw new MtInvalidPeerTypeError(scope.user, 'user')
return {
_: 'botCommandScopePeerUser',
peer: chat,
userId: user
userId: user,
}
}
default:

View file

@ -1,7 +1,8 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
import { InputPeerLike, MtInvalidPeerTypeError } from "../../types";
import { normalizeToInputUser } from "../../utils/peer-utils";
import { TelegramClient } from '../../client'
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
import { normalizeToInputUser } from '../../utils/peer-utils'
/**
* Sets a menu button for the given user.
@ -21,6 +22,6 @@ export async function setBotMenuButton(
await this.call({
_: 'bots.setBotMenuButton',
userId,
button
button,
})
}

View file

@ -1,8 +1,9 @@
import { InputPeerLike, Message, MtInvalidPeerTypeError } from '../../types'
import { TelegramClient } from '../../client'
import { normalizeToInputUser } from '../../utils/peer-utils'
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { InputPeerLike, Message, MtInvalidPeerTypeError } from '../../types'
import { normalizeToInputUser } from '../../utils/peer-utils'
/**
* Set a score of a user in a game
*

View file

@ -1,5 +1,6 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { BotCommands } from '../../types'
/**

View file

@ -1,6 +1,7 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
/**
* Sets the default chat permissions for the bot in the supergroup or channel.
*
@ -14,10 +15,13 @@ export async function setMyDefaultRights(
rights: Omit<tl.RawChatAdminRights, '_'>
): Promise<void> {
await this.call({
_: target === 'group' ? 'bots.setBotGroupDefaultAdminRights' : 'bots.setBotBroadcastDefaultAdminRights',
_:
target === 'group'
? 'bots.setBotGroupDefaultAdminRights'
: 'bots.setBotBroadcastDefaultAdminRights',
adminRights: {
_: 'chatAdminRights',
...rights
...rights,
},
})
}

View file

@ -1,6 +1,7 @@
import { MaybeArray } from '@mtcute/core'
import { TelegramClient } from '../../client'
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
import { MaybeArray } from '@mtcute/core'
import {
isInputPeerChannel,
isInputPeerChat,

View file

@ -1,8 +1,9 @@
import { TelegramClient } from '../../client'
import { MaybeArray } from '@mtcute/core'
import { InputPeerLike } from '../../types'
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { InputPeerLike } from '../../types'
/**
* Archive one or more chats
*

View file

@ -1,5 +1,6 @@
import { TelegramClient } from '../../client'
import { MaybeArray } from '@mtcute/core'
import { TelegramClient } from '../../client'
import { Chat, InputPeerLike } from '../../types'
import { normalizeToInputUser } from '../../utils/peer-utils'
import { assertIsUpdatesGroup } from '../../utils/updates-utils'

View file

@ -1,5 +1,5 @@
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
import { TelegramClient } from '../../client'
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
import { normalizeToInputChannel } from '../../utils/peer-utils'
// @alias=deleteSupergroup

View file

@ -13,8 +13,7 @@ export async function deleteGroup(
chatId: InputPeerLike
): Promise<void> {
const chat = await this.resolvePeer(chatId)
if (!isInputPeerChat(chat))
throw new MtInvalidPeerTypeError(chatId, 'chat')
if (!isInputPeerChat(chat)) throw new MtInvalidPeerTypeError(chatId, 'chat')
const res = await this.call({
_: 'messages.deleteChatUser',

View file

@ -1,8 +1,9 @@
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { InputPeerLike } from '../../types'
import { normalizeToInputChannel } from '../../utils/peer-utils'
import { createDummyUpdate } from '../../utils/updates-utils'
import { tl } from '@mtcute/tl'
/**
* Delete communication history (for private chats

View file

@ -1,10 +1,11 @@
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
import {
normalizeToInputChannel,
normalizeToInputPeer,
} from '../../utils/peer-utils'
import { tl } from '@mtcute/tl'
import { createDummyUpdate } from '../../utils/updates-utils'
/**

View file

@ -1,6 +1,7 @@
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
import { tl } from '@mtcute/tl'
import {
normalizeToInputChannel,
normalizeToInputUser,

View file

@ -1,16 +1,18 @@
import Long from 'long'
import { tl } from '@mtcute/tl'
import { assertNever, MaybeArray } from '@mtcute/core'
import { TelegramClient } from '../../client'
import {
InputPeerLike,
MtInvalidPeerTypeError,
ChatEvent, PeersIndex,
ChatEvent,
PeersIndex,
} from '../../types'
import { tl } from '@mtcute/tl'
import { assertNever, MaybeArray } from "@mtcute/core";
import {
normalizeToInputChannel,
normalizeToInputUser,
} from '../../utils/peer-utils'
import Long from 'long'
/**
* Get chat event log ("Recent actions" in official

View file

@ -1,3 +1,5 @@
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { InputPeerLike, MtInvalidPeerTypeError, PeersIndex } from '../../types'
import {
@ -7,7 +9,6 @@ import {
normalizeToInputChannel,
} from '../../utils/peer-utils'
import { assertTypeIs } from '../../utils/type-assertion'
import { tl } from '@mtcute/tl'
import { ChatMember } from '../../types'
/**

View file

@ -1,20 +1,21 @@
import Long from 'long'
import { tl } from '@mtcute/tl'
import { assertNever } from '@mtcute/core'
import { TelegramClient } from '../../client'
import {
ChatMember,
InputPeerLike,
MtInvalidPeerTypeError,
PeersIndex,
} from '../../types'
import { TelegramClient } from '../../client'
import {
isInputPeerChannel,
isInputPeerChat,
normalizeToInputChannel,
} from '../../utils/peer-utils'
import { assertTypeIs } from '../../utils/type-assertion'
import { tl } from '@mtcute/tl'
import { ArrayWithTotal } from '../../types'
import Long from 'long'
import { assertNever } from '@mtcute/core'
/**
* Get a chunk of members of some chat.

View file

@ -1,5 +1,5 @@
import { MtArgumentError, MtNotFoundError } from '../../types'
import { TelegramClient } from '../../client'
import { MtArgumentError, MtNotFoundError } from '../../types'
import { INVITE_LINK_REGEX } from '../../utils/peer-utils'
import { ChatPreview } from '../../types'

View file

@ -1,3 +1,5 @@
import { tl } from '@mtcute/tl'
import { Chat, InputPeerLike, MtArgumentError } from '../../types'
import { TelegramClient } from '../../client'
import {
@ -8,7 +10,6 @@ import {
normalizeToInputChannel,
normalizeToInputUser,
} from '../../utils/peer-utils'
import { tl } from '@mtcute/tl'
/**
* Get basic information about a chat.

View file

@ -1,5 +1,7 @@
import { Chat, InputPeerLike, MtArgumentError } from '../../types'
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { Chat, InputPeerLike, MtArgumentError } from '../../types'
import {
INVITE_LINK_REGEX,
isInputPeerChannel,
@ -8,7 +10,6 @@ import {
normalizeToInputChannel,
normalizeToInputUser,
} from '../../utils/peer-utils'
import { tl } from '@mtcute/tl'
/**
* Get full information about a chat.

View file

@ -1,8 +1,9 @@
import { tl } from '@mtcute/tl'
import { getMarkedPeerId } from '@mtcute/core'
import { TelegramClient } from '../../client'
import { Chat } from '../../types'
import { assertTypeIs } from '../../utils/type-assertion'
import { getMarkedPeerId } from '@mtcute/core'
import { tl } from '@mtcute/tl'
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
/**

View file

@ -1,7 +1,8 @@
import { sleep } from '@mtcute/core'
import { TelegramClient } from '../../client'
import { InputPeerLike } from '../../types'
import { isInputPeerChannel } from '../../utils/peer-utils'
import { sleep } from '@mtcute/core'
/**
* Kick a user from a chat.

View file

@ -1,5 +1,5 @@
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
import { TelegramClient } from '../../client'
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
import {
isInputPeerChannel,
isInputPeerChat,

View file

@ -1,10 +1,11 @@
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
import {
isInputPeerChannel,
normalizeToInputChannel,
} from '../../utils/peer-utils'
import { tl } from '@mtcute/tl'
import { normalizeDate } from '../../utils/misc-utils'
/**

View file

@ -1,6 +1,7 @@
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { InputPeerLike } from '../../types'
import { tl } from '@mtcute/tl'
/**
* Save or delete a draft message associated with some chat

View file

@ -1,6 +1,7 @@
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { Chat, InputPeerLike } from '../../types'
import { tl } from '@mtcute/tl'
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
/**

View file

@ -1,3 +1,6 @@
import { tl } from '@mtcute/tl'
import { fileIdToInputPhoto, tdFileId } from '@mtcute/file-id'
import { TelegramClient } from '../../client'
import {
InputFileLike,
@ -11,8 +14,6 @@ import {
isInputPeerChat,
normalizeToInputChannel,
} from '../../utils/peer-utils'
import { tl } from '@mtcute/tl'
import { fileIdToInputPhoto, tdFileId } from '@mtcute/file-id'
/**
* Set a new chat photo or video.
@ -46,7 +47,7 @@ export async function setChatPhoto(
throw new MtArgumentError("Chat photo can't be external")
if (typeof media === 'string' && media.match(/^file:/)) {
const uploaded = await this.uploadFile({
file: media.substr(5),
file: media.substring(5),
})
inputFile = uploaded.inputFile
} else {

View file

@ -1,7 +1,8 @@
import { TelegramClient } from '../../client'
import { MaybeArray } from '@mtcute/core'
import { InputPeerLike } from '../../types'
import { tl } from '@mtcute/tl'
import { MaybeArray } from '@mtcute/core'
import { TelegramClient } from '../../client'
import { InputPeerLike } from '../../types'
/**
* Unarchive one or more chats

View file

@ -1,9 +1,5 @@
import { TelegramClient } from '../../client'
import {
InputPeerLike,
MtInvalidPeerTypeError,
User,
} from '../../types'
import { InputPeerLike, MtInvalidPeerTypeError, User } from '../../types'
import { normalizeToInputUser } from '../../utils/peer-utils'
import { assertIsUpdatesGroup } from '../../utils/updates-utils'

View file

@ -1,10 +1,7 @@
import { TelegramClient } from '../../client'
import { MaybeArray } from '@mtcute/core'
import {
InputPeerLike,
MtInvalidPeerTypeError,
User,
} from '../../types'
import { TelegramClient } from '../../client'
import { InputPeerLike, MtInvalidPeerTypeError, User } from '../../types'
import { normalizeToInputUser } from '../../utils/peer-utils'
import { assertIsUpdatesGroup } from '../../utils/updates-utils'

View file

@ -1,7 +1,8 @@
import Long from 'long'
import { TelegramClient } from '../../client'
import { User } from '../../types'
import { assertTypeIs } from '../../utils/type-assertion'
import Long from 'long'
/**
* Get list of contacts from your Telegram contacts list.

View file

@ -1,7 +1,8 @@
import { TelegramClient } from '../../client'
import Long from 'long'
import { tl } from '@mtcute/tl'
import { PartialOnly } from '@mtcute/core'
import Long from 'long'
import { TelegramClient } from '../../client'
/**
* Import contacts to your Telegram contacts list.

View file

@ -1,6 +1,7 @@
import { getMarkedPeerId } from '@mtcute/core'
import { TelegramClient } from '../../client'
import { Conversation, Message } from '../../types'
import { getMarkedPeerId } from '@mtcute/core'
// @extension
interface ConversationsState {

View file

@ -1,7 +1,8 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
import { PartialExcept } from '@mtcute/core'
import { TelegramClient } from '../../client'
/**
* Create a folder from given parameters
*

View file

@ -1,6 +1,7 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
/**
* Delete a folder by its ID
*

View file

@ -1,5 +1,6 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { MtArgumentError } from '../../types'
/**
@ -24,7 +25,11 @@ export async function editFolder(
}
if (typeof folder === 'number' || typeof folder === 'string') {
const old = await this.getFolders()
const found = old.find((it) => it._ === 'dialogFilter' && (it.id === folder || it.title === folder))
const found = old.find(
(it) =>
it._ === 'dialogFilter' &&
(it.id === folder || it.title === folder)
)
if (!found)
throw new MtArgumentError(`Could not find a folder ${folder}`)

View file

@ -1,5 +1,6 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { MtArgumentError } from '../../types'
/**
@ -26,13 +27,13 @@ export async function findFolder(
const folders = await this.getFolders()
return (
folders.find((it) => {
(folders.find((it) => {
if (it._ === 'dialogFilterDefault') return false
if (params.id && it.id !== params.id) return false
if (params.title && it.title !== params.title) return false
if (params.emoji && it.emoticon !== params.emoji) return false
return true
}) as tl.RawDialogFilter ?? null
}) as tl.RawDialogFilter) ?? null
)
}

View file

@ -1,11 +1,9 @@
import { TelegramClient } from '../../client'
import {
Dialog,
MtArgumentError,
} from '../../types'
import { normalizeDate } from '../../utils/misc-utils'
import { tl } from '@mtcute/tl'
import Long from 'long'
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { Dialog, MtArgumentError } from '../../types'
import { normalizeDate } from '../../utils/misc-utils'
/**
* Iterate over dialogs.
@ -127,16 +125,14 @@ export async function* getDialogs(
) {
const folders = await this.getFolders()
const found = folders.find((it) => {
if (it._ === 'dialogFilterDefault' ) {
if (it._ === 'dialogFilterDefault') {
return params!.folder === 0
}
return it.id === params!.folder || it.title === params!.folder
})
if (!found)
throw new MtArgumentError(
`Could not find folder ${params.folder}`
)
throw new MtArgumentError(`Could not find folder ${params.folder}`)
filters = found as tl.RawDialogFilter
} else {
@ -151,34 +147,42 @@ export async function* getDialogs(
}
} else {
filters = {
_: 'dialogFilterDefault'
_: 'dialogFilterDefault',
}
}
}
const fetchPinnedDialogsFromFolder = async (): Promise<tl.messages.RawPeerDialogs | null> => {
if (!filters || filters._ === 'dialogFilterDefault' || !filters.pinnedPeers.length) return null
const res = await this.call({
_: 'messages.getPeerDialogs',
peers: filters.pinnedPeers.map((peer) => ({
_: 'inputDialogPeer',
peer,
})),
})
const fetchPinnedDialogsFromFolder =
async (): Promise<tl.messages.RawPeerDialogs | null> => {
if (
!filters ||
filters._ === 'dialogFilterDefault' ||
!filters.pinnedPeers.length
)
return null
const res = await this.call({
_: 'messages.getPeerDialogs',
peers: filters.pinnedPeers.map((peer) => ({
_: 'inputDialogPeer',
peer,
})),
})
res.dialogs.forEach(
(dialog: tl.Mutable<tl.TypeDialog>) => (dialog.pinned = true)
)
return res
}
res.dialogs.forEach(
(dialog: tl.Mutable<tl.TypeDialog>) => (dialog.pinned = true)
)
return res
}
const pinned = params.pinned ?? 'include'
let archived = params.archived ?? 'exclude'
if (filters) {
archived = filters._ !== 'dialogFilterDefault' && filters.excludeArchived ? 'exclude' : 'keep'
archived =
filters._ !== 'dialogFilterDefault' && filters.excludeArchived
? 'exclude'
: 'keep'
}
if (pinned === 'only') {
@ -203,7 +207,12 @@ export async function* getDialogs(
let offsetDate = normalizeDate(params.offsetDate) ?? 0
let offsetPeer = params.offsetPeer ?? { _: 'inputPeerEmpty' }
if (filters && filters._ !== 'dialogFilterDefault' && filters.pinnedPeers.length && pinned === 'include') {
if (
filters &&
filters._ !== 'dialogFilterDefault' &&
filters.pinnedPeers.length &&
pinned === 'include'
) {
const res = await fetchPinnedDialogsFromFolder()
if (res) {
const dialogs = this._parseDialogs(res)

View file

@ -1,6 +1,7 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
/**
* Get list of folders.
* @internal

View file

@ -1,10 +1,8 @@
import { TelegramClient } from '../../client'
import {
Dialog,
InputPeerLike,
} from '../../types'
import { MaybeArray } from '@mtcute/core'
import { TelegramClient } from '../../client'
import { Dialog, InputPeerLike } from '../../types'
/**
* Get dialogs with certain peers.
*

View file

@ -1,8 +1,9 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
import { Dialog, MtTypeAssertionError, PeersIndex } from '../../types'
import { getMarkedPeerId } from '@mtcute/core'
import { TelegramClient } from '../../client'
import { Dialog, MtTypeAssertionError, PeersIndex } from '../../types'
/** @internal */
export function _parseDialogs(
this: TelegramClient,

View file

@ -1,5 +1,4 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
/**
* Reorder folders
@ -14,6 +13,6 @@ export async function setFoldersOrder(
): Promise<void> {
await this.call({
_: 'messages.updateDialogFiltersOrder',
order
order,
})
}

View file

@ -1,5 +1,5 @@
import { FileDownloadParameters, FileLocation } from '../../types'
import { TelegramClient } from '../../client'
import { FileDownloadParameters, FileLocation } from '../../types'
/**
* Download a file and return its contents as a Buffer.

View file

@ -1,17 +1,18 @@
import { tl } from '@mtcute/tl'
import {
fileIdToInputFileLocation,
fileIdToInputWebFileLocation,
parseFileId,
} from '@mtcute/file-id'
import { TelegramClient } from '../../client'
import { determinePartSize } from '../../utils/file-utils'
import { tl } from '@mtcute/tl'
import {
MtArgumentError,
MtUnsupportedError,
FileDownloadParameters,
FileLocation,
} from '../../types'
import {
fileIdToInputFileLocation,
fileIdToInputWebFileLocation,
parseFileId,
} from '@mtcute/file-id'
/**
* Download a file and return it as an iterable, which yields file contents

View file

@ -1,4 +1,5 @@
import { Readable } from 'stream'
import { TelegramClient } from '../../client'
import { FileLocation, FileDownloadParameters } from '../../types'
import { bufferToStream } from '../../utils/stream-utils'

View file

@ -1,6 +1,7 @@
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { InputFileLike } from '../../types'
import { tl } from '@mtcute/tl'
import { assertTypeIs } from '../../utils/type-assertion'
/**

View file

@ -1,8 +1,9 @@
import { TelegramClient } from '../../client'
import { InputFileLike, isUploadedFile, MtArgumentError } from '../../types'
import { tl } from '@mtcute/tl'
import { tdFileId } from '@mtcute/file-id'
import { TelegramClient } from '../../client'
import { InputFileLike, isUploadedFile, MtArgumentError } from '../../types'
/**
* Normalize a {@link InputFileLike} to `InputFile`,
* uploading it if needed.
@ -26,7 +27,7 @@ export async function _normalizeInputFile(
} else if (tdFileId.isFileIdLike(input)) {
if (typeof input === 'string' && input.match(/^file:/)) {
const uploaded = await this.uploadFile({
file: input.substr(5),
file: input.substring(5),
...params,
})
return uploaded.inputFile

View file

@ -1,9 +1,4 @@
import { TelegramClient } from '../../client'
import {
InputMediaLike,
isUploadedFile,
UploadFileLike,
} from '../../types'
import Long from 'long'
import { tl } from '@mtcute/tl'
import {
fileIdToInputDocument,
@ -11,11 +6,13 @@ import {
parseFileId,
tdFileId,
} from '@mtcute/file-id'
import { TelegramClient } from '../../client'
import { InputMediaLike, isUploadedFile, UploadFileLike } from '../../types'
import { extractFileName } from '../../utils/file-utils'
import { assertTypeIs } from '../../utils/type-assertion'
import { normalizeDate } from '../../utils/misc-utils'
import { encodeWaveform } from '../../utils/voice-utils'
import Long from 'long'
/**
* Normalize an {@link InputMediaLike} to `InputMedia`,
@ -292,7 +289,7 @@ export async function _normalizeInputMedia(
media.type === 'photo'
)
} else if (typeof input === 'string' && input.match(/^file:/)) {
await upload(input.substr(5))
await upload(input.substring(5))
} else {
const parsed =
typeof input === 'string' ? parseFileId(input) : input

View file

@ -1,17 +1,18 @@
import type { ReadStream } from 'fs'
import { Readable } from 'stream'
import { fromBuffer } from 'file-type'
import { tl } from '@mtcute/tl'
import { randomLong } from '@mtcute/core'
import { TelegramClient } from '../../client'
import {
bufferToStream,
convertWebStreamToNodeReadable,
readBytesFromStream,
readStreamUntilEnd,
} from '../../utils/stream-utils'
import type { ReadStream } from 'fs'
import { Readable } from 'stream'
import { determinePartSize, isProbablyPlainText } from '../../utils/file-utils'
import { fromBuffer } from 'file-type'
import { tl } from '@mtcute/tl'
import { MtArgumentError, UploadFileLike, UploadedFile } from '../../types'
import { TelegramClient } from '../../client'
import { randomLong } from '@mtcute/core'
let fs: any = null
let path: any = null
@ -20,7 +21,6 @@ try {
path = require('path')
} catch (e) {}
const OVERRIDE_MIME: Record<string, string> = {
// tg doesn't interpret `audio/opus` files as voice messages for some reason
'audio/opus': 'audio/ogg',
@ -135,7 +135,12 @@ export async function uploadFile(
file = convertWebStreamToNodeReadable(file)
}
if (typeof file === 'object' && 'headers' in file && 'body' in file && 'url' in file) {
if (
typeof file === 'object' &&
'headers' in file &&
'body' in file &&
'url' in file
) {
// fetch() response
const length = parseInt(file.headers.get('content-length') || '0')
if (!isNaN(length) && length) fileSize = length
@ -187,9 +192,7 @@ export async function uploadFile(
}
if (!(file instanceof Readable))
throw new MtArgumentError(
'Could not convert input `file` to stream!'
)
throw new MtArgumentError('Could not convert input `file` to stream!')
const partSizeKb = params.partSize ?? determinePartSize(fileSize)
if (partSizeKb > 512)

View file

@ -1,15 +1,17 @@
import { assertNever } from '@mtcute/core'
import { TelegramClient } from '../../client'
import {
InputMediaLike,
InputPeerLike,
MessageMedia,
MtArgumentError,
MtTypeAssertionError,
Photo, RawDocument,
Photo,
RawDocument,
} from '../../types'
import { TelegramClient } from '../../client'
import { assertTypeIs } from '../../utils/type-assertion'
import { parseDocument } from '../../types/media/document-utils'
import { assertNever } from '@mtcute/core'
/**
* Upload a media to Telegram servers, without actually

View file

@ -43,7 +43,7 @@ export async function createInviteLink(
peer: await this.resolvePeer(chatId),
expireDate: normalizeDate(params.expires),
usageLimit: params.usageLimit,
requestNeeded: params.withApproval
requestNeeded: params.withApproval,
})
return new ChatInviteLink(this, res)

View file

@ -46,7 +46,7 @@ export async function editInviteLink(
link,
expireDate: normalizeDate(params.expires),
usageLimit: params.usageLimit,
requestNeeded: params.withApproval
requestNeeded: params.withApproval,
})
const peers = PeersIndex.from(res)

View file

@ -1,6 +1,7 @@
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { ChatInviteLink, InputPeerLike, PeersIndex, User } from '../../types'
import { tl } from '@mtcute/tl'
/**
* Iterate over users who have joined
@ -49,8 +50,8 @@ export async function* getInviteLinkMembers(
for (;;) {
// for some reason ts needs annotation, idk
const res: tl.RpcCallReturn['messages.getChatInviteImporters'] = await this.call(
{
const res: tl.RpcCallReturn['messages.getChatInviteImporters'] =
await this.call({
_: 'messages.getChatInviteImporters',
limit: Math.min(100, limit - current),
peer,
@ -59,8 +60,7 @@ export async function* getInviteLinkMembers(
q: params.requestedSearch,
offsetDate,
offsetUser,
}
)
})
if (!res.importers.length) break
@ -82,7 +82,7 @@ export async function* getInviteLinkMembers(
date: new Date(it.date * 1000),
isPendingRequest: it.requested!,
bio: it.about,
approvedBy: it.approvedBy
approvedBy: it.approvedBy,
}
}

View file

@ -1,12 +1,14 @@
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import {
ChatInviteLink,
InputPeerLike,
MtInvalidPeerTypeError, MtTypeAssertionError,
PeersIndex
} from "../../types";
MtInvalidPeerTypeError,
MtTypeAssertionError,
PeersIndex,
} from '../../types'
import { normalizeToInputUser } from '../../utils/peer-utils'
import { tl } from '@mtcute/tl'
/**
* Get invite links created by some administrator in the chat.
@ -59,16 +61,15 @@ export async function* getInviteLinks(
let offsetLink: string | undefined = undefined
for (;;) {
const res: tl.RpcCallReturn['messages.getExportedChatInvites'] = await this.call(
{
const res: tl.RpcCallReturn['messages.getExportedChatInvites'] =
await this.call({
_: 'messages.getExportedChatInvites',
peer,
adminId: admin,
limit: Math.min(chunkSize, total - current),
offsetDate,
offsetLink,
}
)
})
if (!res.invites.length) break
@ -76,7 +77,11 @@ export async function* getInviteLinks(
const last = res.invites[res.invites.length - 1]
if (last._ === 'chatInvitePublicJoinRequests') {
throw new MtTypeAssertionError('getInviteLinks', 'chatInviteExported', last._)
throw new MtTypeAssertionError(
'getInviteLinks',
'chatInviteExported',
last._
)
}
offsetDate = last.date
offsetLink = last.link

View file

@ -2,7 +2,8 @@ import { TelegramClient } from '../../client'
import {
ChatInviteLink,
InputPeerLike,
MtTypeAssertionError, PeersIndex,
MtTypeAssertionError,
PeersIndex,
} from '../../types'
/**

View file

@ -1,8 +1,14 @@
import Long from 'long'
import { TelegramClient } from '../../client'
import { InputPeerLike, MtTypeAssertionError, PeersIndex, Poll } from '../../types'
import {
InputPeerLike,
MtTypeAssertionError,
PeersIndex,
Poll,
} from '../../types'
import { assertTypeIs } from '../../utils/type-assertion'
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
import Long from 'long'
/**
* Close a poll sent by you.

View file

@ -1,6 +1,7 @@
import { MaybeArray } from '@mtcute/core'
import { TelegramClient } from '../../client'
import { InputPeerLike } from '../../types'
import { MaybeArray } from '@mtcute/core'
import {
isInputPeerChannel,
normalizeToInputChannel,

View file

@ -1,6 +1,7 @@
import { MaybeArray } from '@mtcute/core'
import { TelegramClient } from '../../client'
import { InputPeerLike } from '../../types'
import { MaybeArray } from '@mtcute/core'
/**
* Delete scheduled messages.
@ -12,7 +13,7 @@ import { MaybeArray } from '@mtcute/core'
export async function deleteScheduledMessages(
this: TelegramClient,
chatId: InputPeerLike,
ids: MaybeArray<number>,
ids: MaybeArray<number>
): Promise<void> {
if (!Array.isArray(ids)) ids = [ids]
@ -21,7 +22,7 @@ export async function deleteScheduledMessages(
const res = await this.call({
_: 'messages.deleteScheduledMessages',
peer,
id: ids
id: ids,
})
this._handleUpdate(res)

View file

@ -1,7 +1,13 @@
import { TelegramClient } from '../../client'
import { BotKeyboard, FormattedString, InputMediaLike, ReplyMarkup } from '../../types'
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import {
BotKeyboard,
FormattedString,
InputMediaLike,
ReplyMarkup,
} from '../../types'
/**
* Edit sent inline message text, media and reply markup.
*

View file

@ -1,12 +1,14 @@
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import {
BotKeyboard, FormattedString,
BotKeyboard,
FormattedString,
InputMediaLike,
InputPeerLike,
Message,
ReplyMarkup,
} from '../../types'
import { tl } from '@mtcute/tl'
/**
* Edit message text, media, reply markup and schedule date.

View file

@ -1,5 +1,6 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { Message, MtTypeAssertionError, PeersIndex } from '../../types'
import { assertIsUpdatesGroup } from '../../utils/updates-utils'

View file

@ -1,3 +1,6 @@
import { tl } from '@mtcute/tl'
import { MaybeArray, randomLong } from '@mtcute/core'
import { TelegramClient } from '../../client'
import {
FormattedString,
@ -7,8 +10,6 @@ import {
MtArgumentError,
PeersIndex,
} from '../../types'
import { MaybeArray, randomLong } from '@mtcute/core'
import { tl } from '@mtcute/tl'
import { normalizeDate } from '../../utils/misc-utils'
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
@ -317,7 +318,7 @@ export async function forwardMessages(
schedule: params.schedule,
clearDraft: params.clearDraft,
forbidForwards: params.forbidForwards,
sendAs: params.sendAs
sendAs: params.sendAs,
})
} else if (params.captionMedia) {
captionMessage = await this.sendMedia(toPeer, params.captionMedia, {
@ -326,7 +327,7 @@ export async function forwardMessages(
schedule: params.schedule,
clearDraft: params.clearDraft,
forbidForwards: params.forbidForwards,
sendAs: params.sendAs
sendAs: params.sendAs,
})
}
@ -343,7 +344,9 @@ export async function forwardMessages(
dropAuthor: params.noAuthor,
dropMediaCaptions: params.noCaption,
noforwards: params.forbidForwards,
sendAs: params.sendAs ? await this.resolvePeer(params.sendAs) : undefined
sendAs: params.sendAs
? await this.resolvePeer(params.sendAs)
: undefined,
})
assertIsUpdatesGroup('messages.forwardMessages', res)

View file

@ -1,8 +1,14 @@
import { TelegramClient } from '../../client'
import { InputPeerLike, Message, MtTypeAssertionError, PeersIndex } from '../../types'
import { normalizeDate } from '../../utils/misc-utils'
import Long from 'long'
import { TelegramClient } from '../../client'
import {
InputPeerLike,
Message,
MtTypeAssertionError,
PeersIndex,
} from '../../types'
import { normalizeDate } from '../../utils/misc-utils'
/**
* Retrieve a chunk of the chat history.
*

View file

@ -1,7 +1,8 @@
import { getMarkedPeerId, MaybeArray } from '@mtcute/core'
import { TelegramClient } from '../../client'
import { InputPeerLike, PeersIndex, MessageReactions } from '../../types'
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
import { getMarkedPeerId, MaybeArray } from '@mtcute/core'
import { assertTypeIs } from '../../utils/type-assertion'
/**

View file

@ -1,6 +1,7 @@
import { TelegramClient } from '../../client'
import { MaybeArray } from '@mtcute/core'
import { tl } from '@mtcute/tl'
import { MaybeArray } from '@mtcute/core'
import { TelegramClient } from '../../client'
import { Message, MtTypeAssertionError, PeersIndex } from '../../types'
/**

View file

@ -1,11 +1,17 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
import { MaybeArray } from '@mtcute/core'
import { TelegramClient } from '../../client'
import {
isInputPeerChannel,
normalizeToInputChannel,
} from '../../utils/peer-utils'
import { tl } from '@mtcute/tl'
import { Message, InputPeerLike, MtTypeAssertionError, PeersIndex } from '../../types'
import {
Message,
InputPeerLike,
MtTypeAssertionError,
PeersIndex,
} from '../../types'
/**
* Get a single message in chat by its ID
@ -93,18 +99,33 @@ export async function getMessages(
// (channels have their own message numbering)
switch (peer._) {
case 'inputPeerSelf':
if (!(msg.peerId._ === 'peerUser' && msg.peerId.userId === this._userId))
if (
!(
msg.peerId._ === 'peerUser' &&
msg.peerId.userId === this._userId
)
)
return null
break;
break
case 'inputPeerUser':
case 'inputPeerUserFromMessage':
if (!(msg.peerId._ === 'peerUser' && msg.peerId.userId === peer.userId))
if (
!(
msg.peerId._ === 'peerUser' &&
msg.peerId.userId === peer.userId
)
)
return null
break;
break
case 'inputPeerChat':
if (!(msg.peerId._ === 'peerChat' && msg.peerId.chatId === peer.chatId))
if (
!(
msg.peerId._ === 'peerChat' &&
msg.peerId.chatId === peer.chatId
)
)
return null
break;
break
}
}

View file

@ -1,11 +1,8 @@
import { TelegramClient } from '../../client'
import {
InputPeerLike,
PeerReaction,
PeersIndex,
} from '../../types'
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { InputPeerLike, PeerReaction, PeersIndex } from '../../types'
/**
* Get users who have reacted to the message.
*

View file

@ -1,5 +1,6 @@
import { TelegramClient } from '../../client'
import { MaybeArray } from '@mtcute/core'
import { TelegramClient } from '../../client'
import {
Message,
InputPeerLike,

View file

@ -1,6 +1,7 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
import { SessionConnection } from '@mtcute/core'
import { TelegramClient } from '../../client'
import { parseInlineMessageId } from '../../utils/inline-utils'
// @extension
@ -25,9 +26,8 @@ export async function _normalizeInline(
let connection = this.primaryConnection
if (id.dcId !== connection.params.dc.id) {
if (!(id.dcId in this._connectionsForInline)) {
this._connectionsForInline[
id.dcId
] = await this.createAdditionalConnection(id.dcId)
this._connectionsForInline[id.dcId] =
await this.createAdditionalConnection(id.dcId)
}
connection = this._connectionsForInline[id.dcId]
}

View file

@ -1,4 +1,5 @@
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { normalizeToInputUser } from '../../utils/peer-utils'
import { FormattedString, MtClientError } from '../../types'
@ -32,7 +33,7 @@ export async function _parseEntities(
throw new MtClientError(`Parse mode ${mode} is not registered.`)
}
;[text, entities] = await this._parseModes[mode].parse(text)
;[text, entities] = this._parseModes[mode].parse(text)
}
// replace mentionName entities with input ones

View file

@ -10,11 +10,11 @@ import { createDummyUpdate } from '../../utils/updates-utils'
*/
export async function readReactions(
this: TelegramClient,
chatId: InputPeerLike,
chatId: InputPeerLike
): Promise<void> {
const res = await this.call({
_: 'messages.readReactions',
peer: await this.resolvePeer(chatId)
peer: await this.resolvePeer(chatId),
})
this._handleUpdate(createDummyUpdate(res.pts, res.ptsCount))
}

View file

@ -1,6 +1,7 @@
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import { Message, MtTypeAssertionError, PeersIndex } from '../../types'
import { tl } from '@mtcute/tl'
import { SearchFilters } from '../../types'
/**
@ -85,7 +86,8 @@ export async function* searchGlobal(
if (!msgs.length) break
const last = msgs[msgs.length - 1]
offsetRate = (res as tl.messages.RawMessagesSlice).nextRate ?? last.raw.date
offsetRate =
(res as tl.messages.RawMessagesSlice).nextRate ?? last.raw.date
offsetPeer = last.chat.inputPeer
offsetId = last.id

View file

@ -1,8 +1,14 @@
import { TelegramClient } from '../../client'
import { InputPeerLike, Message, MtTypeAssertionError, PeersIndex } from '../../types'
import { tl } from '@mtcute/tl'
import { SearchFilters } from '../../types'
import Long from 'long'
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import {
InputPeerLike,
Message,
MtTypeAssertionError,
PeersIndex,
} from '../../types'
import { SearchFilters } from '../../types'
/**
* Search for messages inside a specific chat

View file

@ -1,7 +1,13 @@
import { TelegramClient } from '../../client'
import { InputPeerLike, Message, FormattedString, ReplyMarkup } from '../../types'
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import {
InputPeerLike,
Message,
FormattedString,
ReplyMarkup,
} from '../../types'
/**
* Copy a message (i.e. send the same message,
* but do not forward it).

View file

@ -1,18 +1,18 @@
import { tl } from '@mtcute/tl'
import { randomLong } from '@mtcute/core'
import { TelegramClient } from '../../client'
import {
BotKeyboard, InputFileLike,
BotKeyboard,
InputMediaLike,
InputPeerLike,
Message, MtArgumentError, PeersIndex,
Message,
MtArgumentError,
PeersIndex,
ReplyMarkup,
} from '../../types'
import {
normalizeDate,
normalizeMessageId,
} from '../../utils/misc-utils'
import { tl } from '@mtcute/tl'
import { normalizeDate, normalizeMessageId } from '../../utils/misc-utils'
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
import { randomLong } from '@mtcute/core'
/**
* Send a group of media.
@ -141,8 +141,7 @@ export async function sendMediaGroup(
const msg = await this.getMessages(peer, replyTo)
if (!msg)
throw new tl.errors.MessageNotFoundError()
if (!msg) throw new tl.errors.MessageNotFoundError()
}
const multiMedia: tl.RawInputSingleMedia[] = []
@ -157,13 +156,17 @@ export async function sendMediaGroup(
}
}
const inputMedia = await this._normalizeInputMedia(media, {
progressCallback: params.progressCallback?.bind(null, i),
// i have no fucking clue why we should upload it manually,
// but otherwise Telegram throws MEDIA_INVALID
// fuck my life
uploadPeer: peer
}, true)
const inputMedia = await this._normalizeInputMedia(
media,
{
progressCallback: params.progressCallback?.bind(null, i),
// i have no fucking clue why we should upload it manually,
// but otherwise Telegram throws MEDIA_INVALID
// fuck my life
uploadPeer: peer,
},
true
)
const [message, entities] = await this._parseEntities(
// some types dont have `caption` field, and ts warns us,
@ -194,7 +197,9 @@ export async function sendMediaGroup(
replyMarkup,
clearDraft: params.clearDraft,
noforwards: params.forbidForwards,
sendAs: params.sendAs ? await this.resolvePeer(params.sendAs) : undefined
sendAs: params.sendAs
? await this.resolvePeer(params.sendAs)
: undefined,
})
assertIsUpdatesGroup('_findMessageInUpdate', res)

View file

@ -1,3 +1,6 @@
import { tl } from '@mtcute/tl'
import { randomLong } from '@mtcute/core'
import { TelegramClient } from '../../client'
import {
BotKeyboard,
@ -9,8 +12,6 @@ import {
ReplyMarkup,
} from '../../types'
import { normalizeDate, normalizeMessageId } from '../../utils/misc-utils'
import { tl } from '@mtcute/tl'
import { randomLong } from '@mtcute/core'
/**
* Send a single media (a photo or a document-based media)
@ -184,7 +185,9 @@ export async function sendMedia(
entities,
clearDraft: params.clearDraft,
noforwards: params.forbidForwards,
sendAs: params.sendAs ? await this.resolvePeer(params.sendAs) : undefined
sendAs: params.sendAs
? await this.resolvePeer(params.sendAs)
: undefined,
})
const msg = this._findMessageInUpdate(res)

View file

@ -1,3 +1,5 @@
import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client'
import {
InputPeerLike,
@ -6,7 +8,6 @@ import {
PeersIndex,
} from '../../types'
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
import { tl } from '@mtcute/tl'
/**
* Send or remove a reaction.

View file

@ -1,5 +1,6 @@
import { InputPeerLike, Message, PeersIndex } from '../../types'
import { MaybeArray } from '@mtcute/core'
import { InputPeerLike, Message, PeersIndex } from '../../types'
import { TelegramClient } from '../../client'
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
@ -49,7 +50,7 @@ export async function sendScheduled(
const res = await this.call({
_: 'messages.sendScheduledMessages',
peer: await this.resolvePeer(peer),
id: (ids as number[])
id: ids as number[],
})
assertIsUpdatesGroup('sendScheduled', res)
@ -60,17 +61,9 @@ export async function sendScheduled(
const msgs = res.updates
.filter(
(u) =>
u._ === 'updateNewMessage' ||
u._ === 'updateNewChannelMessage'
)
.map(
(u) =>
new Message(
this,
(u as any).message,
peers
)
u._ === 'updateNewMessage' || u._ === 'updateNewChannelMessage'
)
.map((u) => new Message(this, (u as any).message, peers))
this._pushConversationMessage(msgs[msgs.length - 1])

View file

@ -1,19 +1,19 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
import { getMarkedPeerId, randomLong } from '@mtcute/core'
import { TelegramClient } from '../../client'
import { inputPeerToPeer } from '../../utils/peer-utils'
import {
normalizeDate,
normalizeMessageId,
} from '../../utils/misc-utils'
import { normalizeDate, normalizeMessageId } from '../../utils/misc-utils'
import {
InputPeerLike,
Message,
BotKeyboard,
ReplyMarkup,
MtTypeAssertionError,
MtArgumentError, FormattedString, PeersIndex,
MtArgumentError,
FormattedString,
PeersIndex,
} from '../../types'
import { getMarkedPeerId, randomLong } from '@mtcute/core'
import { createDummyUpdate } from '../../utils/updates-utils'
/**
@ -143,8 +143,7 @@ export async function sendText(
const msg = await this.getMessages(peer, replyTo)
if (!msg)
throw new tl.errors.MessageNotFoundError()
if (!msg) throw new tl.errors.MessageNotFoundError()
}
const res = await this.call({
@ -160,7 +159,9 @@ export async function sendText(
entities,
clearDraft: params.clearDraft,
noforwards: params.forbidForwards,
sendAs: params.sendAs ? await this.resolvePeer(params.sendAs) : undefined
sendAs: params.sendAs
? await this.resolvePeer(params.sendAs)
: undefined,
})
if (res._ === 'updateShortSentMessage') {

View file

@ -1,8 +1,9 @@
import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl'
import { InputPeerLike, TypingStatus } from '../../types'
import { assertNever } from '@mtcute/core'
import { TelegramClient } from '../../client'
import { InputPeerLike, TypingStatus } from '../../types'
/**
* Sends a current user/bot typing event
* to a conversation partner or group.

View file

@ -1,3 +1,6 @@
import { tl } from '@mtcute/tl'
import { MaybeArray } from '@mtcute/core'
import { TelegramClient } from '../../client'
import {
InputPeerLike,
@ -6,10 +9,8 @@ import {
PeersIndex,
Poll,
} from '../../types'
import { MaybeArray } from '@mtcute/core'
import { assertTypeIs } from '../../utils/type-assertion'
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
import { tl } from '@mtcute/tl'
/**
* Send or retract a vote in a poll.
@ -41,9 +42,7 @@ export async function sendVote(
if (!msg) throw new tl.errors.MessageNotFoundError()
if (!(msg.media instanceof Poll))
throw new MtArgumentError(
'This message does not contain a poll'
)
throw new MtArgumentError('This message does not contain a poll')
poll = msg.media
options = options.map((opt) => {

Some files were not shown because too many files have changed in this diff Show more