build: preparing for publish x5
at this point i'm way too tired to describe what happened. stuff added, stuff removed, stuff fixed, i don't even remember anymore lol
This commit is contained in:
parent
bcce752dfd
commit
c46f113f1f
8 changed files with 66 additions and 50 deletions
|
@ -9,3 +9,4 @@ export * from '@mtcute/tl/errors'
|
||||||
export * from './parser'
|
export * from './parser'
|
||||||
export * from './types'
|
export * from './types'
|
||||||
export * from './client'
|
export * from './client'
|
||||||
|
export * from './utils/peer-utils'
|
||||||
|
|
|
@ -897,6 +897,8 @@ export function catchUp(this: TelegramClient): Promise<void> {
|
||||||
// we also use a lock here so new updates are not processed
|
// we also use a lock here so new updates are not processed
|
||||||
// while we are catching up with older ones
|
// while we are catching up with older ones
|
||||||
|
|
||||||
|
this._catchUpChannels = true
|
||||||
|
|
||||||
return this._updLock
|
return this._updLock
|
||||||
.acquire()
|
.acquire()
|
||||||
.then(() => _loadDifference.call(this))
|
.then(() => _loadDifference.call(this))
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike, MtCuteNotFoundError } from '../../types'
|
import { InputPeerLike, MtCuteNotFoundError } from '../../types'
|
||||||
import { getBasicPeerType, MAX_CHANNEL_ID } from '@mtcute/core'
|
import { getBasicPeerType, getMarkedPeerId, MAX_CHANNEL_ID } from '@mtcute/core'
|
||||||
import bigInt from 'big-integer'
|
import bigInt from 'big-integer'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
||||||
import { assertTypeIs } from '../../utils/type-assertion'
|
import { assertTypeIs } from '../../utils/type-assertion'
|
||||||
|
@ -18,7 +18,13 @@ export async function resolvePeer(
|
||||||
peerId: InputPeerLike
|
peerId: InputPeerLike
|
||||||
): Promise<tl.TypeInputPeer> {
|
): Promise<tl.TypeInputPeer> {
|
||||||
// for convenience we also accept tl objects directly
|
// for convenience we also accept tl objects directly
|
||||||
if (typeof peerId === 'object') return normalizeToInputPeer(peerId)
|
if (typeof peerId === 'object') {
|
||||||
|
if (tl.isAnyPeer(peerId)) {
|
||||||
|
peerId = getMarkedPeerId(peerId)
|
||||||
|
} else {
|
||||||
|
return normalizeToInputPeer(peerId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof peerId === 'number') {
|
if (typeof peerId === 'number') {
|
||||||
const fromStorage = await this.storage.getPeerById(peerId)
|
const fromStorage = await this.storage.getPeerById(peerId)
|
||||||
|
|
|
@ -5,17 +5,17 @@ import { makeInspectable } from '../utils'
|
||||||
* Represents the permissions of a user in a {@link Chat}.
|
* Represents the permissions of a user in a {@link Chat}.
|
||||||
*/
|
*/
|
||||||
export class ChatPermissions {
|
export class ChatPermissions {
|
||||||
readonly _bannedRights: tl.RawChatBannedRights
|
readonly raw: tl.RawChatBannedRights
|
||||||
|
|
||||||
constructor(bannedRights: tl.RawChatBannedRights) {
|
constructor(bannedRights: tl.RawChatBannedRights) {
|
||||||
this._bannedRights = bannedRights
|
this.raw = bannedRights
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether users can view messages
|
* Whether users can view messages
|
||||||
*/
|
*/
|
||||||
get canViewMessages(): boolean {
|
get canViewMessages(): boolean {
|
||||||
return !this._bannedRights.viewMessages
|
return !this.raw.viewMessages
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,7 +23,7 @@ export class ChatPermissions {
|
||||||
* contacts, locations and venues
|
* contacts, locations and venues
|
||||||
*/
|
*/
|
||||||
get canSendMessages(): boolean {
|
get canSendMessages(): boolean {
|
||||||
return !this._bannedRights.sendMessages
|
return !this.raw.sendMessages
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,7 +33,7 @@ export class ChatPermissions {
|
||||||
* Implies {@link canSendMessages}
|
* Implies {@link canSendMessages}
|
||||||
*/
|
*/
|
||||||
get canSendMedia(): boolean {
|
get canSendMedia(): boolean {
|
||||||
return !this._bannedRights.sendMedia
|
return !this.raw.sendMedia
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,7 +42,7 @@ export class ChatPermissions {
|
||||||
* Implies {@link canSendMedia}
|
* Implies {@link canSendMedia}
|
||||||
*/
|
*/
|
||||||
get canSendStickers(): boolean {
|
get canSendStickers(): boolean {
|
||||||
return !this._bannedRights.sendStickers
|
return !this.raw.sendStickers
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,7 +51,7 @@ export class ChatPermissions {
|
||||||
* Implies {@link canSendMedia}
|
* Implies {@link canSendMedia}
|
||||||
*/
|
*/
|
||||||
get canSendGifs(): boolean {
|
get canSendGifs(): boolean {
|
||||||
return !this._bannedRights.sendGifs
|
return !this.raw.sendGifs
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,7 +60,7 @@ export class ChatPermissions {
|
||||||
* Implies {@link canSendMedia}
|
* Implies {@link canSendMedia}
|
||||||
*/
|
*/
|
||||||
get canSendGames(): boolean {
|
get canSendGames(): boolean {
|
||||||
return !this._bannedRights.sendGames
|
return !this.raw.sendGames
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,7 +69,7 @@ export class ChatPermissions {
|
||||||
* Implies {@link canSendMedia}
|
* Implies {@link canSendMedia}
|
||||||
*/
|
*/
|
||||||
get canUseInline(): boolean {
|
get canUseInline(): boolean {
|
||||||
return !this._bannedRights.sendInline
|
return !this.raw.sendInline
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,7 +78,7 @@ export class ChatPermissions {
|
||||||
* Implies {@link canSendMedia}
|
* Implies {@link canSendMedia}
|
||||||
*/
|
*/
|
||||||
get canAddWebPreviews(): boolean {
|
get canAddWebPreviews(): boolean {
|
||||||
return !this._bannedRights.embedLinks
|
return !this.raw.embedLinks
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,7 +87,7 @@ export class ChatPermissions {
|
||||||
* Implies {@link canSendMessages}
|
* Implies {@link canSendMessages}
|
||||||
*/
|
*/
|
||||||
get canSendPolls(): boolean {
|
get canSendPolls(): boolean {
|
||||||
return !this._bannedRights.sendPolls
|
return !this.raw.sendPolls
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,21 +95,21 @@ export class ChatPermissions {
|
||||||
* photo and other settings.
|
* photo and other settings.
|
||||||
*/
|
*/
|
||||||
get canChangeInfo(): boolean {
|
get canChangeInfo(): boolean {
|
||||||
return !this._bannedRights.changeInfo
|
return !this.raw.changeInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether users can invite other users to the chat
|
* Whether users can invite other users to the chat
|
||||||
*/
|
*/
|
||||||
get canInviteUsers(): boolean {
|
get canInviteUsers(): boolean {
|
||||||
return !this._bannedRights.inviteUsers
|
return !this.raw.inviteUsers
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether users can pin messages
|
* Whether users can pin messages
|
||||||
*/
|
*/
|
||||||
get canPinMessages(): boolean {
|
get canPinMessages(): boolean {
|
||||||
return !this._bannedRights.pinMessages
|
return !this.raw.pinMessages
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,9 +120,9 @@ export class ChatPermissions {
|
||||||
* will be lifted from a {@link ChatMember}
|
* will be lifted from a {@link ChatMember}
|
||||||
*/
|
*/
|
||||||
get untilDate(): Date | null {
|
get untilDate(): Date | null {
|
||||||
return this._bannedRights.untilDate === 0
|
return this.raw.untilDate === 0
|
||||||
? null
|
? null
|
||||||
: new Date(this._bannedRights.untilDate * 1000)
|
: new Date(this.raw.untilDate * 1000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ export type PeerType = 'user' | 'bot' | 'group' | 'channel' | 'supergroup'
|
||||||
export type InputPeerLike =
|
export type InputPeerLike =
|
||||||
| string
|
| string
|
||||||
| number
|
| number
|
||||||
|
| tl.TypePeer
|
||||||
| tl.TypeInputPeer
|
| tl.TypeInputPeer
|
||||||
| tl.TypeInputUser
|
| tl.TypeInputUser
|
||||||
| tl.TypeInputChannel
|
| tl.TypeInputChannel
|
||||||
|
|
|
@ -40,48 +40,48 @@ export class User {
|
||||||
/**
|
/**
|
||||||
* Underlying raw TL object
|
* Underlying raw TL object
|
||||||
*/
|
*/
|
||||||
private _user: tl.RawUser
|
readonly raw: tl.RawUser
|
||||||
|
|
||||||
constructor(client: TelegramClient, user: tl.TypeUser) {
|
constructor(client: TelegramClient, user: tl.TypeUser) {
|
||||||
assertTypeIs('User#init', user, 'user')
|
assertTypeIs('User#init', user, 'user')
|
||||||
|
|
||||||
this.client = client
|
this.client = client
|
||||||
this._user = user
|
this.raw = user
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Unique identifier for this user or bot */
|
/** Unique identifier for this user or bot */
|
||||||
get id(): number {
|
get id(): number {
|
||||||
return this._user.id
|
return this.raw.id
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether this user is you yourself */
|
/** Whether this user is you yourself */
|
||||||
get isSelf(): boolean {
|
get isSelf(): boolean {
|
||||||
return this._user.self!
|
return this.raw.self!
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether this user is in your contacts */
|
/** Whether this user is in your contacts */
|
||||||
get isContact(): boolean {
|
get isContact(): boolean {
|
||||||
return this._user.contact!
|
return this.raw.contact!
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether you both have each other's contact */
|
/** Whether you both have each other's contact */
|
||||||
get isMutualContact(): boolean {
|
get isMutualContact(): boolean {
|
||||||
return this._user.mutualContact!
|
return this.raw.mutualContact!
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether this user is deleted */
|
/** Whether this user is deleted */
|
||||||
get isDeleted(): boolean {
|
get isDeleted(): boolean {
|
||||||
return this._user.deleted!
|
return this.raw.deleted!
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether this user is a bot */
|
/** Whether this user is a bot */
|
||||||
get isBot(): boolean {
|
get isBot(): boolean {
|
||||||
return this._user.bot!
|
return this.raw.bot!
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether this user has been verified by Telegram */
|
/** Whether this user has been verified by Telegram */
|
||||||
get isVerified(): boolean {
|
get isVerified(): boolean {
|
||||||
return this._user.verified!
|
return this.raw.verified!
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,32 +89,32 @@ export class User {
|
||||||
* See {@link restrictionReason} for details
|
* See {@link restrictionReason} for details
|
||||||
*/
|
*/
|
||||||
get isRestricted(): boolean {
|
get isRestricted(): boolean {
|
||||||
return this._user.restricted!
|
return this.raw.restricted!
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether this user has been flagged for scam */
|
/** Whether this user has been flagged for scam */
|
||||||
get isScam(): boolean {
|
get isScam(): boolean {
|
||||||
return this._user.scam!
|
return this.raw.scam!
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether this user has been flagged for impersonation */
|
/** Whether this user has been flagged for impersonation */
|
||||||
get isFake(): boolean {
|
get isFake(): boolean {
|
||||||
return this._user.fake!
|
return this.raw.fake!
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether this user is part of the Telegram support team */
|
/** Whether this user is part of the Telegram support team */
|
||||||
get isSupport(): boolean {
|
get isSupport(): boolean {
|
||||||
return this._user.support!
|
return this.raw.support!
|
||||||
}
|
}
|
||||||
|
|
||||||
/** User's or bot's first name */
|
/** User's or bot's first name */
|
||||||
get firstName(): string {
|
get firstName(): string {
|
||||||
return this._user.firstName ?? 'Deleted Account'
|
return this.raw.firstName ?? 'Deleted Account'
|
||||||
}
|
}
|
||||||
|
|
||||||
/** User's or bot's last name */
|
/** User's or bot's last name */
|
||||||
get lastName(): string | null {
|
get lastName(): string | null {
|
||||||
return this._user.lastName ?? null
|
return this.raw.lastName ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
static parseStatus(
|
static parseStatus(
|
||||||
|
@ -163,8 +163,8 @@ export class User {
|
||||||
private _parsedStatus?: User.ParsedStatus
|
private _parsedStatus?: User.ParsedStatus
|
||||||
private _parseStatus() {
|
private _parseStatus() {
|
||||||
this._parsedStatus = User.parseStatus(
|
this._parsedStatus = User.parseStatus(
|
||||||
this._user.status!,
|
this.raw.status!,
|
||||||
this._user.bot
|
this.raw.bot
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,12 +194,12 @@ export class User {
|
||||||
|
|
||||||
/** User's or bot's username */
|
/** User's or bot's username */
|
||||||
get username(): string | null {
|
get username(): string | null {
|
||||||
return this._user.username ?? null
|
return this.raw.username ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
/** IETF language tag of the user's language */
|
/** IETF language tag of the user's language */
|
||||||
get language(): string | null {
|
get language(): string | null {
|
||||||
return this._user.langCode ?? null
|
return this.raw.langCode ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -213,27 +213,27 @@ export class User {
|
||||||
* More info at [Pyrogram FAQ](https://docs.pyrogram.org/faq#what-are-the-ip-addresses-of-telegram-data-centers).
|
* More info at [Pyrogram FAQ](https://docs.pyrogram.org/faq#what-are-the-ip-addresses-of-telegram-data-centers).
|
||||||
*/
|
*/
|
||||||
get dcId(): number | null {
|
get dcId(): number | null {
|
||||||
return (this._user.photo as any)?.dcId ?? null
|
return (this.raw.photo as any)?.dcId ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
/** User's phone number */
|
/** User's phone number */
|
||||||
get phoneNumber(): string | null {
|
get phoneNumber(): string | null {
|
||||||
return this._user.phone ?? null
|
return this.raw.phone ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get this user's input peer for advanced use-cases.
|
* Get this user's input peer for advanced use-cases.
|
||||||
*/
|
*/
|
||||||
get inputPeer(): tl.TypeInputPeer {
|
get inputPeer(): tl.TypeInputPeer {
|
||||||
if (!this._user.accessHash)
|
if (!this.raw.accessHash)
|
||||||
throw new MtCuteArgumentError(
|
throw new MtCuteArgumentError(
|
||||||
"user's access hash is not available!"
|
"user's access hash is not available!"
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
_: 'inputPeerUser',
|
_: 'inputPeerUser',
|
||||||
userId: this._user.id,
|
userId: this.raw.id,
|
||||||
accessHash: this._user.accessHash,
|
accessHash: this.raw.accessHash,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,13 +243,13 @@ export class User {
|
||||||
* Suitable for downloads only
|
* Suitable for downloads only
|
||||||
*/
|
*/
|
||||||
get photo(): ChatPhoto | null {
|
get photo(): ChatPhoto | null {
|
||||||
if (this._user.photo?._ !== 'userProfilePhoto') return null
|
if (this.raw.photo?._ !== 'userProfilePhoto') return null
|
||||||
|
|
||||||
if (!this._photo) {
|
if (!this._photo) {
|
||||||
this._photo = new ChatPhoto(
|
this._photo = new ChatPhoto(
|
||||||
this.client,
|
this.client,
|
||||||
this.inputPeer,
|
this.inputPeer,
|
||||||
this._user.photo
|
this.raw.photo
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ export class User {
|
||||||
* This field is available only in case *isRestricted* is `true`
|
* This field is available only in case *isRestricted* is `true`
|
||||||
*/
|
*/
|
||||||
get restrictions(): ReadonlyArray<tl.RawRestrictionReason> | null {
|
get restrictions(): ReadonlyArray<tl.RawRestrictionReason> | null {
|
||||||
return this._user.restrictionReason ?? null
|
return this.raw.restrictionReason ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -334,7 +334,7 @@ export class User {
|
||||||
* @param parseMode Parse mode to use when creating mention
|
* @param parseMode Parse mode to use when creating mention
|
||||||
*/
|
*/
|
||||||
permanentMention(text?: string | null, parseMode?: string | null): string {
|
permanentMention(text?: string | null, parseMode?: string | null): string {
|
||||||
if (!this._user.accessHash)
|
if (!this.raw.accessHash)
|
||||||
throw new MtCuteArgumentError(
|
throw new MtCuteArgumentError(
|
||||||
"user's access hash is not available!"
|
"user's access hash is not available!"
|
||||||
)
|
)
|
||||||
|
@ -352,7 +352,7 @@ export class User {
|
||||||
length: text.length,
|
length: text.length,
|
||||||
url: `tg://user?id=${
|
url: `tg://user?id=${
|
||||||
this.id
|
this.id
|
||||||
}&hash=${this._user.accessHash.toString(16)}`,
|
}&hash=${this.raw.accessHash.toString(16)}`,
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,6 @@ function getAllGettersNames(obj: object): string[] {
|
||||||
* > **Note**: This means that all getters must be pure!
|
* > **Note**: This means that all getters must be pure!
|
||||||
* > (getter that caches after its first invocation is also
|
* > (getter that caches after its first invocation is also
|
||||||
* > considered pure in this case)
|
* > considered pure in this case)
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
*/
|
||||||
export function makeInspectable(
|
export function makeInspectable(
|
||||||
obj: Function,
|
obj: Function,
|
||||||
|
@ -66,7 +64,7 @@ export function makeInspectable(
|
||||||
}
|
}
|
||||||
ret[it] = val
|
ret[it] = val
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
ret[it] = e.message
|
ret[it] = "Error: " + e.message
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return ret
|
return ret
|
||||||
|
|
|
@ -306,6 +306,14 @@ export namespace filters {
|
||||||
}> => (msg) =>
|
}> => (msg) =>
|
||||||
msg.chat.type === type
|
msg.chat.type === type
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter messages by chat ID
|
||||||
|
*/
|
||||||
|
export const chatId = (
|
||||||
|
id: number
|
||||||
|
): UpdateFilter<Message> => (msg) =>
|
||||||
|
msg.chat.id === id
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter incoming messages.
|
* Filter incoming messages.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue