build: updated to 179 layer
This commit is contained in:
parent
cb0dbb712a
commit
8b80a3ddbe
10 changed files with 91 additions and 43 deletions
|
@ -9,6 +9,7 @@ import { ITelegramClient } from '../../client.types.js'
|
||||||
import { isUploadedFile } from '../../types/files/uploaded-file.js'
|
import { isUploadedFile } from '../../types/files/uploaded-file.js'
|
||||||
import { UploadFileLike } from '../../types/files/utils.js'
|
import { UploadFileLike } from '../../types/files/utils.js'
|
||||||
import { InputMediaLike } from '../../types/media/input-media/types.js'
|
import { InputMediaLike } from '../../types/media/input-media/types.js'
|
||||||
|
import { inputTextToTl } from '../../types/misc/entities.js'
|
||||||
import { fileIdToInputDocument, fileIdToInputPhoto } from '../../utils/convert-file-id.js'
|
import { fileIdToInputDocument, fileIdToInputPhoto } from '../../utils/convert-file-id.js'
|
||||||
import { normalizeDate } from '../../utils/misc-utils.js'
|
import { normalizeDate } from '../../utils/misc-utils.js'
|
||||||
import { encodeWaveform } from '../../utils/voice-utils.js'
|
import { encodeWaveform } from '../../utils/voice-utils.js'
|
||||||
|
@ -151,16 +152,14 @@ export async function _normalizeInputMedia(
|
||||||
|
|
||||||
if (media.type === 'poll' || media.type === 'quiz') {
|
if (media.type === 'poll' || media.type === 'quiz') {
|
||||||
const answers: tl.TypePollAnswer[] = media.answers.map((ans, idx) => {
|
const answers: tl.TypePollAnswer[] = media.answers.map((ans, idx) => {
|
||||||
if (typeof ans === 'string') {
|
if (typeof ans === 'object' && tl.isAnyPollAnswer(ans)) return ans
|
||||||
return {
|
|
||||||
_: 'pollAnswer',
|
|
||||||
text: ans,
|
|
||||||
// emulate the behaviour of most implementations
|
|
||||||
option: new Uint8Array([48 /* '0' */ + idx]),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ans
|
return {
|
||||||
|
_: 'pollAnswer',
|
||||||
|
text: inputTextToTl(ans),
|
||||||
|
// emulate the behaviour of most implementations
|
||||||
|
option: new Uint8Array([48 /* '0' */ + idx]),
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
let correct: Uint8Array[] | undefined = undefined
|
let correct: Uint8Array[] | undefined = undefined
|
||||||
|
@ -192,7 +191,7 @@ export async function _normalizeInputMedia(
|
||||||
publicVoters: media.public,
|
publicVoters: media.public,
|
||||||
multipleChoice: media.multiple,
|
multipleChoice: media.multiple,
|
||||||
quiz: media.type === 'quiz',
|
quiz: media.type === 'quiz',
|
||||||
question: media.question,
|
question: inputTextToTl(media.question),
|
||||||
answers,
|
answers,
|
||||||
closePeriod: media.closePeriod,
|
closePeriod: media.closePeriod,
|
||||||
closeDate: normalizeDate(media.closeDate),
|
closeDate: normalizeDate(media.closeDate),
|
||||||
|
|
|
@ -35,7 +35,7 @@ export async function closePoll(
|
||||||
_: 'poll',
|
_: 'poll',
|
||||||
id: Long.ZERO,
|
id: Long.ZERO,
|
||||||
closed: true,
|
closed: true,
|
||||||
question: '',
|
question: { _: 'textWithEntities', text: '', entities: [] },
|
||||||
answers: [],
|
answers: [],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -12,6 +12,8 @@ const sentCodeMap: Record<tl.auth.TypeSentCodeType['_'], SentCodeDeliveryType> =
|
||||||
'auth.sentCodeTypeSetUpEmailRequired': 'email_required',
|
'auth.sentCodeTypeSetUpEmailRequired': 'email_required',
|
||||||
'auth.sentCodeTypeFragmentSms': 'fragment',
|
'auth.sentCodeTypeFragmentSms': 'fragment',
|
||||||
'auth.sentCodeTypeFirebaseSms': 'firebase',
|
'auth.sentCodeTypeFirebaseSms': 'firebase',
|
||||||
|
'auth.sentCodeTypeSmsWord': 'sms_word',
|
||||||
|
'auth.sentCodeTypeSmsPhrase': 'sms_phrase',
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextCodeMap: Record<tl.auth.TypeCodeType['_'], NextCodeDeliveryType> = {
|
const nextCodeMap: Record<tl.auth.TypeCodeType['_'], NextCodeDeliveryType> = {
|
||||||
|
@ -33,7 +35,8 @@ const nextCodeMap: Record<tl.auth.TypeCodeType['_'], NextCodeDeliveryType> = {
|
||||||
* - `email_required`: Code sending via email setup is required
|
* - `email_required`: Code sending via email setup is required
|
||||||
* - `fragment`: Code is sent via Fragment anonymous numbers
|
* - `fragment`: Code is sent via Fragment anonymous numbers
|
||||||
* - `firebase`: Code is sent via Firebase
|
* - `firebase`: Code is sent via Firebase
|
||||||
* - `Success`: Code is not needed, you're already logged in (only for future auth tokens)
|
* - `sms_word`, `sms_phrase`: Code is sent via SMS with a word/phrase (see {@link SentCode#beginning})
|
||||||
|
* - `success`: Code is not needed, you're already logged in (only for future auth tokens)
|
||||||
*/
|
*/
|
||||||
export type SentCodeDeliveryType =
|
export type SentCodeDeliveryType =
|
||||||
| 'app'
|
| 'app'
|
||||||
|
@ -45,6 +48,8 @@ export type SentCodeDeliveryType =
|
||||||
| 'email_required'
|
| 'email_required'
|
||||||
| 'fragment'
|
| 'fragment'
|
||||||
| 'firebase'
|
| 'firebase'
|
||||||
|
| 'sms_word'
|
||||||
|
| 'sms_phrase'
|
||||||
| 'success'
|
| 'success'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,6 +96,19 @@ export class SentCode {
|
||||||
return this.raw.timeout ?? 0
|
return this.raw.timeout ?? 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the code is sent via SMS with a word/phrase, this field *may* contain the beginning of the message
|
||||||
|
*/
|
||||||
|
get beginning(): string | undefined {
|
||||||
|
switch (this.raw.type._) {
|
||||||
|
case 'auth.sentCodeTypeSmsPhrase':
|
||||||
|
case 'auth.sentCodeTypeSmsWord':
|
||||||
|
return this.raw.type.beginning
|
||||||
|
default:
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Length of the code (0 for flash calls)
|
* Length of the code (0 for flash calls)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -460,7 +460,7 @@ export interface InputMediaPoll extends CaptionMixin {
|
||||||
/**
|
/**
|
||||||
* Question of the poll (1-255 chars for users, 1-300 chars for bots)
|
* Question of the poll (1-255 chars for users, 1-300 chars for bots)
|
||||||
*/
|
*/
|
||||||
question: string
|
question: InputText
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Answers of the poll.
|
* Answers of the poll.
|
||||||
|
@ -471,7 +471,7 @@ export interface InputMediaPoll extends CaptionMixin {
|
||||||
* objects, with a single=byte incrementing
|
* objects, with a single=byte incrementing
|
||||||
* `option` value.
|
* `option` value.
|
||||||
*/
|
*/
|
||||||
answers: (string | tl.TypePollAnswer)[]
|
answers: (InputText | tl.TypePollAnswer)[]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether this is poll is closed
|
* Whether this is poll is closed
|
||||||
|
|
|
@ -7,17 +7,32 @@ import { memoizeGetters } from '../../utils/memoize.js'
|
||||||
import { MessageEntity } from '../messages/message-entity.js'
|
import { MessageEntity } from '../messages/message-entity.js'
|
||||||
import { PeersIndex } from '../peers/peers-index.js'
|
import { PeersIndex } from '../peers/peers-index.js'
|
||||||
|
|
||||||
export interface PollAnswer {
|
export class PollAnswer {
|
||||||
|
constructor(
|
||||||
|
readonly raw: tl.TypePollAnswer,
|
||||||
|
readonly result?: tl.TypePollAnswerVoters,
|
||||||
|
) {}
|
||||||
/**
|
/**
|
||||||
* Answer text
|
* Answer text
|
||||||
*/
|
*/
|
||||||
text: string
|
get text(): string {
|
||||||
|
return this.raw.text.text
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format entities for {@link text}, currently may only contain custom emojis
|
||||||
|
*/
|
||||||
|
get textEntities(): ReadonlyArray<MessageEntity> {
|
||||||
|
return this.raw.text.entities.map((ent) => new MessageEntity(ent, this.raw.text.text))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Answer data, to be passed to
|
* Answer data, to be passed to
|
||||||
* {@link TelegramClient.sendVote}
|
* {@link TelegramClient.sendVote}
|
||||||
*/
|
*/
|
||||||
data: Uint8Array
|
get data(): Uint8Array {
|
||||||
|
return this.raw.option
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of people who has chosen this result.
|
* Number of people who has chosen this result.
|
||||||
|
@ -25,12 +40,16 @@ export interface PollAnswer {
|
||||||
*
|
*
|
||||||
* @default `0`
|
* @default `0`
|
||||||
*/
|
*/
|
||||||
voters: number
|
get voters(): number {
|
||||||
|
return this.result?.voters ?? 0
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether this answer was chosen by the current user
|
* Whether this answer was chosen by the current user
|
||||||
*/
|
*/
|
||||||
chosen: boolean
|
get chosen(): boolean {
|
||||||
|
return Boolean(this.result?.chosen)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether this answer is correct (for quizzes).
|
* Whether this answer is correct (for quizzes).
|
||||||
|
@ -38,9 +57,14 @@ export interface PollAnswer {
|
||||||
*
|
*
|
||||||
* @default `false`
|
* @default `false`
|
||||||
*/
|
*/
|
||||||
correct: boolean
|
get correct(): boolean {
|
||||||
|
return Boolean(this.result?.correct)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memoizeGetters(PollAnswer, ['textEntities'])
|
||||||
|
makeInspectable(PollAnswer)
|
||||||
|
|
||||||
export class Poll {
|
export class Poll {
|
||||||
readonly type = 'poll' as const
|
readonly type = 'poll' as const
|
||||||
|
|
||||||
|
@ -61,7 +85,14 @@ export class Poll {
|
||||||
* Poll question
|
* Poll question
|
||||||
*/
|
*/
|
||||||
get question(): string {
|
get question(): string {
|
||||||
return this.raw.question
|
return this.raw.question.text
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format entities for {@link question} (currently may only contain custom emojis)
|
||||||
|
*/
|
||||||
|
get questionEntities(): ReadonlyArray<MessageEntity> {
|
||||||
|
return this.raw.question.entities.map((ent) => new MessageEntity(ent, this.raw.question.text))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,24 +103,10 @@ export class Poll {
|
||||||
|
|
||||||
return this.raw.answers.map((ans, idx) => {
|
return this.raw.answers.map((ans, idx) => {
|
||||||
if (results) {
|
if (results) {
|
||||||
const res = results[idx]
|
return new PollAnswer(ans, results[idx])
|
||||||
|
|
||||||
return {
|
|
||||||
text: ans.text,
|
|
||||||
data: ans.option,
|
|
||||||
voters: res.voters,
|
|
||||||
chosen: Boolean(res.chosen),
|
|
||||||
correct: Boolean(res.correct),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return new PollAnswer(ans)
|
||||||
text: ans.text,
|
|
||||||
data: ans.option,
|
|
||||||
voters: 0,
|
|
||||||
chosen: false,
|
|
||||||
correct: false,
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,5 +206,5 @@ export class Poll {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
memoizeGetters(Poll, ['answers', 'solutionEntities'])
|
memoizeGetters(Poll, ['answers', 'solutionEntities', 'questionEntities'])
|
||||||
makeInspectable(Poll, undefined, ['inputMedia'])
|
makeInspectable(Poll, undefined, ['inputMedia'])
|
||||||
|
|
|
@ -15,3 +15,17 @@ export interface TextWithEntities {
|
||||||
* Can be either a plain string or an object with `text` and `entities` fields.
|
* Can be either a plain string or an object with `text` and `entities` fields.
|
||||||
*/
|
*/
|
||||||
export type InputText = string | TextWithEntities
|
export type InputText = string | TextWithEntities
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert {@link InputText} to a {@link tl.RawTextWithEntities} object
|
||||||
|
*
|
||||||
|
* @param text Input text
|
||||||
|
* @returns TL object
|
||||||
|
*/
|
||||||
|
export function inputTextToTl(text: InputText): tl.RawTextWithEntities {
|
||||||
|
return {
|
||||||
|
_: 'textWithEntities',
|
||||||
|
text: typeof text === 'string' ? text : text.text,
|
||||||
|
entities: typeof text === 'string' ? [] : text.entities ?? [],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -55,11 +55,11 @@ export class PollUpdate {
|
||||||
poll = {
|
poll = {
|
||||||
_: 'poll',
|
_: 'poll',
|
||||||
id: this.raw.pollId,
|
id: this.raw.pollId,
|
||||||
question: '',
|
question: { _: 'textWithEntities', text: '', entities: [] },
|
||||||
answers:
|
answers:
|
||||||
this.raw.results.results?.map((res) => ({
|
this.raw.results.results?.map((res) => ({
|
||||||
_: 'pollAnswer',
|
_: 'pollAnswer',
|
||||||
text: '',
|
text: { _: 'textWithEntities', text: '', entities: [] },
|
||||||
option: res.option,
|
option: res.option,
|
||||||
})) ?? [],
|
})) ?? [],
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
TL schema and related utils used for mtcute.
|
TL schema and related utils used for mtcute.
|
||||||
|
|
||||||
Generated from TL layer **177** (last updated on 01.04.2024).
|
Generated from TL layer **179** (last updated on 03.05.2024).
|
||||||
|
|
||||||
## About
|
## About
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@mtcute/tl",
|
"name": "@mtcute/tl",
|
||||||
"version": "177.0.0",
|
"version": "179.0.0",
|
||||||
"description": "TL schema used for mtcute",
|
"description": "TL schema used for mtcute",
|
||||||
"author": "alina sireneva <alina@tei.su>",
|
"author": "alina sireneva <alina@tei.su>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
Loading…
Reference in a new issue