build: updated to 179 layer

This commit is contained in:
alina 🌸 2024-05-03 05:28:49 +03:00
parent cb0dbb712a
commit 8b80a3ddbe
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
10 changed files with 91 additions and 43 deletions

View file

@ -9,6 +9,7 @@ import { ITelegramClient } from '../../client.types.js'
import { isUploadedFile } from '../../types/files/uploaded-file.js'
import { UploadFileLike } from '../../types/files/utils.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 { normalizeDate } from '../../utils/misc-utils.js'
import { encodeWaveform } from '../../utils/voice-utils.js'
@ -151,16 +152,14 @@ export async function _normalizeInputMedia(
if (media.type === 'poll' || media.type === 'quiz') {
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,
text: inputTextToTl(ans),
// emulate the behaviour of most implementations
option: new Uint8Array([48 /* '0' */ + idx]),
}
}
return ans
})
let correct: Uint8Array[] | undefined = undefined
@ -192,7 +191,7 @@ export async function _normalizeInputMedia(
publicVoters: media.public,
multipleChoice: media.multiple,
quiz: media.type === 'quiz',
question: media.question,
question: inputTextToTl(media.question),
answers,
closePeriod: media.closePeriod,
closeDate: normalizeDate(media.closeDate),

View file

@ -35,7 +35,7 @@ export async function closePoll(
_: 'poll',
id: Long.ZERO,
closed: true,
question: '',
question: { _: 'textWithEntities', text: '', entities: [] },
answers: [],
},
},

View file

@ -12,6 +12,8 @@ const sentCodeMap: Record<tl.auth.TypeSentCodeType['_'], SentCodeDeliveryType> =
'auth.sentCodeTypeSetUpEmailRequired': 'email_required',
'auth.sentCodeTypeFragmentSms': 'fragment',
'auth.sentCodeTypeFirebaseSms': 'firebase',
'auth.sentCodeTypeSmsWord': 'sms_word',
'auth.sentCodeTypeSmsPhrase': 'sms_phrase',
}
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
* - `fragment`: Code is sent via Fragment anonymous numbers
* - `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 =
| 'app'
@ -45,6 +48,8 @@ export type SentCodeDeliveryType =
| 'email_required'
| 'fragment'
| 'firebase'
| 'sms_word'
| 'sms_phrase'
| 'success'
/**
@ -91,6 +96,19 @@ export class SentCode {
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)
*/

View file

@ -460,7 +460,7 @@ export interface InputMediaPoll extends CaptionMixin {
/**
* Question of the poll (1-255 chars for users, 1-300 chars for bots)
*/
question: string
question: InputText
/**
* Answers of the poll.
@ -471,7 +471,7 @@ export interface InputMediaPoll extends CaptionMixin {
* objects, with a single=byte incrementing
* `option` value.
*/
answers: (string | tl.TypePollAnswer)[]
answers: (InputText | tl.TypePollAnswer)[]
/**
* Whether this is poll is closed

View file

@ -7,17 +7,32 @@ import { memoizeGetters } from '../../utils/memoize.js'
import { MessageEntity } from '../messages/message-entity.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
*/
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
* {@link TelegramClient.sendVote}
*/
data: Uint8Array
get data(): Uint8Array {
return this.raw.option
}
/**
* Number of people who has chosen this result.
@ -25,12 +40,16 @@ export interface PollAnswer {
*
* @default `0`
*/
voters: number
get voters(): number {
return this.result?.voters ?? 0
}
/**
* 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).
@ -38,8 +57,13 @@ export interface PollAnswer {
*
* @default `false`
*/
correct: boolean
get correct(): boolean {
return Boolean(this.result?.correct)
}
}
memoizeGetters(PollAnswer, ['textEntities'])
makeInspectable(PollAnswer)
export class Poll {
readonly type = 'poll' as const
@ -61,7 +85,14 @@ export class Poll {
* Poll question
*/
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) => {
if (results) {
const res = results[idx]
return {
text: ans.text,
data: ans.option,
voters: res.voters,
chosen: Boolean(res.chosen),
correct: Boolean(res.correct),
}
return new PollAnswer(ans, results[idx])
}
return {
text: ans.text,
data: ans.option,
voters: 0,
chosen: false,
correct: false,
}
return new PollAnswer(ans)
})
}
@ -189,5 +206,5 @@ export class Poll {
}
}
memoizeGetters(Poll, ['answers', 'solutionEntities'])
memoizeGetters(Poll, ['answers', 'solutionEntities', 'questionEntities'])
makeInspectable(Poll, undefined, ['inputMedia'])

View file

@ -15,3 +15,17 @@ export interface TextWithEntities {
* Can be either a plain string or an object with `text` and `entities` fields.
*/
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 ?? [],
}
}

View file

@ -55,11 +55,11 @@ export class PollUpdate {
poll = {
_: 'poll',
id: this.raw.pollId,
question: '',
question: { _: 'textWithEntities', text: '', entities: [] },
answers:
this.raw.results.results?.map((res) => ({
_: 'pollAnswer',
text: '',
text: { _: 'textWithEntities', text: '', entities: [] },
option: res.option,
})) ?? [],
}

View file

@ -2,7 +2,7 @@
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

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{
"name": "@mtcute/tl",
"version": "177.0.0",
"version": "179.0.0",
"description": "TL schema used for mtcute",
"author": "alina sireneva <alina@tei.su>",
"license": "MIT",