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 './types'
|
||||
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
|
||||
// while we are catching up with older ones
|
||||
|
||||
this._catchUpChannels = true
|
||||
|
||||
return this._updLock
|
||||
.acquire()
|
||||
.then(() => _loadDifference.call(this))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { tl } from '@mtcute/tl'
|
||||
import { TelegramClient } from '../../client'
|
||||
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 { normalizeToInputPeer } from '../../utils/peer-utils'
|
||||
import { assertTypeIs } from '../../utils/type-assertion'
|
||||
|
@ -18,7 +18,13 @@ export async function resolvePeer(
|
|||
peerId: InputPeerLike
|
||||
): Promise<tl.TypeInputPeer> {
|
||||
// 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') {
|
||||
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}.
|
||||
*/
|
||||
export class ChatPermissions {
|
||||
readonly _bannedRights: tl.RawChatBannedRights
|
||||
readonly raw: tl.RawChatBannedRights
|
||||
|
||||
constructor(bannedRights: tl.RawChatBannedRights) {
|
||||
this._bannedRights = bannedRights
|
||||
this.raw = bannedRights
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether users can view messages
|
||||
*/
|
||||
get canViewMessages(): boolean {
|
||||
return !this._bannedRights.viewMessages
|
||||
return !this.raw.viewMessages
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,7 +23,7 @@ export class ChatPermissions {
|
|||
* contacts, locations and venues
|
||||
*/
|
||||
get canSendMessages(): boolean {
|
||||
return !this._bannedRights.sendMessages
|
||||
return !this.raw.sendMessages
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,7 +33,7 @@ export class ChatPermissions {
|
|||
* Implies {@link canSendMessages}
|
||||
*/
|
||||
get canSendMedia(): boolean {
|
||||
return !this._bannedRights.sendMedia
|
||||
return !this.raw.sendMedia
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,7 +42,7 @@ export class ChatPermissions {
|
|||
* Implies {@link canSendMedia}
|
||||
*/
|
||||
get canSendStickers(): boolean {
|
||||
return !this._bannedRights.sendStickers
|
||||
return !this.raw.sendStickers
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,7 +51,7 @@ export class ChatPermissions {
|
|||
* Implies {@link canSendMedia}
|
||||
*/
|
||||
get canSendGifs(): boolean {
|
||||
return !this._bannedRights.sendGifs
|
||||
return !this.raw.sendGifs
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,7 +60,7 @@ export class ChatPermissions {
|
|||
* Implies {@link canSendMedia}
|
||||
*/
|
||||
get canSendGames(): boolean {
|
||||
return !this._bannedRights.sendGames
|
||||
return !this.raw.sendGames
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,7 +69,7 @@ export class ChatPermissions {
|
|||
* Implies {@link canSendMedia}
|
||||
*/
|
||||
get canUseInline(): boolean {
|
||||
return !this._bannedRights.sendInline
|
||||
return !this.raw.sendInline
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,7 +78,7 @@ export class ChatPermissions {
|
|||
* Implies {@link canSendMedia}
|
||||
*/
|
||||
get canAddWebPreviews(): boolean {
|
||||
return !this._bannedRights.embedLinks
|
||||
return !this.raw.embedLinks
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,7 +87,7 @@ export class ChatPermissions {
|
|||
* Implies {@link canSendMessages}
|
||||
*/
|
||||
get canSendPolls(): boolean {
|
||||
return !this._bannedRights.sendPolls
|
||||
return !this.raw.sendPolls
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,21 +95,21 @@ export class ChatPermissions {
|
|||
* photo and other settings.
|
||||
*/
|
||||
get canChangeInfo(): boolean {
|
||||
return !this._bannedRights.changeInfo
|
||||
return !this.raw.changeInfo
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether users can invite other users to the chat
|
||||
*/
|
||||
get canInviteUsers(): boolean {
|
||||
return !this._bannedRights.inviteUsers
|
||||
return !this.raw.inviteUsers
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether users can pin messages
|
||||
*/
|
||||
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}
|
||||
*/
|
||||
get untilDate(): Date | null {
|
||||
return this._bannedRights.untilDate === 0
|
||||
return this.raw.untilDate === 0
|
||||
? 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 =
|
||||
| string
|
||||
| number
|
||||
| tl.TypePeer
|
||||
| tl.TypeInputPeer
|
||||
| tl.TypeInputUser
|
||||
| tl.TypeInputChannel
|
||||
|
|
|
@ -40,48 +40,48 @@ export class User {
|
|||
/**
|
||||
* Underlying raw TL object
|
||||
*/
|
||||
private _user: tl.RawUser
|
||||
readonly raw: tl.RawUser
|
||||
|
||||
constructor(client: TelegramClient, user: tl.TypeUser) {
|
||||
assertTypeIs('User#init', user, 'user')
|
||||
|
||||
this.client = client
|
||||
this._user = user
|
||||
this.raw = user
|
||||
}
|
||||
|
||||
/** Unique identifier for this user or bot */
|
||||
get id(): number {
|
||||
return this._user.id
|
||||
return this.raw.id
|
||||
}
|
||||
|
||||
/** Whether this user is you yourself */
|
||||
get isSelf(): boolean {
|
||||
return this._user.self!
|
||||
return this.raw.self!
|
||||
}
|
||||
|
||||
/** Whether this user is in your contacts */
|
||||
get isContact(): boolean {
|
||||
return this._user.contact!
|
||||
return this.raw.contact!
|
||||
}
|
||||
|
||||
/** Whether you both have each other's contact */
|
||||
get isMutualContact(): boolean {
|
||||
return this._user.mutualContact!
|
||||
return this.raw.mutualContact!
|
||||
}
|
||||
|
||||
/** Whether this user is deleted */
|
||||
get isDeleted(): boolean {
|
||||
return this._user.deleted!
|
||||
return this.raw.deleted!
|
||||
}
|
||||
|
||||
/** Whether this user is a bot */
|
||||
get isBot(): boolean {
|
||||
return this._user.bot!
|
||||
return this.raw.bot!
|
||||
}
|
||||
|
||||
/** Whether this user has been verified by Telegram */
|
||||
get isVerified(): boolean {
|
||||
return this._user.verified!
|
||||
return this.raw.verified!
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,32 +89,32 @@ export class User {
|
|||
* See {@link restrictionReason} for details
|
||||
*/
|
||||
get isRestricted(): boolean {
|
||||
return this._user.restricted!
|
||||
return this.raw.restricted!
|
||||
}
|
||||
|
||||
/** Whether this user has been flagged for scam */
|
||||
get isScam(): boolean {
|
||||
return this._user.scam!
|
||||
return this.raw.scam!
|
||||
}
|
||||
|
||||
/** Whether this user has been flagged for impersonation */
|
||||
get isFake(): boolean {
|
||||
return this._user.fake!
|
||||
return this.raw.fake!
|
||||
}
|
||||
|
||||
/** Whether this user is part of the Telegram support team */
|
||||
get isSupport(): boolean {
|
||||
return this._user.support!
|
||||
return this.raw.support!
|
||||
}
|
||||
|
||||
/** User's or bot's first name */
|
||||
get firstName(): string {
|
||||
return this._user.firstName ?? 'Deleted Account'
|
||||
return this.raw.firstName ?? 'Deleted Account'
|
||||
}
|
||||
|
||||
/** User's or bot's last name */
|
||||
get lastName(): string | null {
|
||||
return this._user.lastName ?? null
|
||||
return this.raw.lastName ?? null
|
||||
}
|
||||
|
||||
static parseStatus(
|
||||
|
@ -163,8 +163,8 @@ export class User {
|
|||
private _parsedStatus?: User.ParsedStatus
|
||||
private _parseStatus() {
|
||||
this._parsedStatus = User.parseStatus(
|
||||
this._user.status!,
|
||||
this._user.bot
|
||||
this.raw.status!,
|
||||
this.raw.bot
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -194,12 +194,12 @@ export class User {
|
|||
|
||||
/** User's or bot's username */
|
||||
get username(): string | null {
|
||||
return this._user.username ?? null
|
||||
return this.raw.username ?? null
|
||||
}
|
||||
|
||||
/** IETF language tag of the user's language */
|
||||
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).
|
||||
*/
|
||||
get dcId(): number | null {
|
||||
return (this._user.photo as any)?.dcId ?? null
|
||||
return (this.raw.photo as any)?.dcId ?? null
|
||||
}
|
||||
|
||||
/** User's phone number */
|
||||
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 inputPeer(): tl.TypeInputPeer {
|
||||
if (!this._user.accessHash)
|
||||
if (!this.raw.accessHash)
|
||||
throw new MtCuteArgumentError(
|
||||
"user's access hash is not available!"
|
||||
)
|
||||
|
||||
return {
|
||||
_: 'inputPeerUser',
|
||||
userId: this._user.id,
|
||||
accessHash: this._user.accessHash,
|
||||
userId: this.raw.id,
|
||||
accessHash: this.raw.accessHash,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -243,13 +243,13 @@ export class User {
|
|||
* Suitable for downloads only
|
||||
*/
|
||||
get photo(): ChatPhoto | null {
|
||||
if (this._user.photo?._ !== 'userProfilePhoto') return null
|
||||
if (this.raw.photo?._ !== 'userProfilePhoto') return null
|
||||
|
||||
if (!this._photo) {
|
||||
this._photo = new ChatPhoto(
|
||||
this.client,
|
||||
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`
|
||||
*/
|
||||
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
|
||||
*/
|
||||
permanentMention(text?: string | null, parseMode?: string | null): string {
|
||||
if (!this._user.accessHash)
|
||||
if (!this.raw.accessHash)
|
||||
throw new MtCuteArgumentError(
|
||||
"user's access hash is not available!"
|
||||
)
|
||||
|
@ -352,7 +352,7 @@ export class User {
|
|||
length: text.length,
|
||||
url: `tg://user?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!
|
||||
* > (getter that caches after its first invocation is also
|
||||
* > considered pure in this case)
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export function makeInspectable(
|
||||
obj: Function,
|
||||
|
@ -66,7 +64,7 @@ export function makeInspectable(
|
|||
}
|
||||
ret[it] = val
|
||||
} catch (e) {
|
||||
ret[it] = e.message
|
||||
ret[it] = "Error: " + e.message
|
||||
}
|
||||
})
|
||||
return ret
|
||||
|
|
|
@ -306,6 +306,14 @@ export namespace filters {
|
|||
}> => (msg) =>
|
||||
msg.chat.type === type
|
||||
|
||||
/**
|
||||
* Filter messages by chat ID
|
||||
*/
|
||||
export const chatId = (
|
||||
id: number
|
||||
): UpdateFilter<Message> => (msg) =>
|
||||
msg.chat.id === id
|
||||
|
||||
/**
|
||||
* Filter incoming messages.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue