From 0dcd91657a967e9bcb1578c5f845a50492323669 Mon Sep 17 00:00:00 2001 From: Shigma Date: Sun, 21 Apr 2024 01:44:41 +0800 Subject: [PATCH] chore: fix lint --- adapters/telegram/src/message.ts | 20 ++++++++++---------- adapters/telegram/src/utils.ts | 13 ++++++------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/adapters/telegram/src/message.ts b/adapters/telegram/src/message.ts index ceb13fde..ab825396 100644 --- a/adapters/telegram/src/message.ts +++ b/adapters/telegram/src/message.ts @@ -1,4 +1,4 @@ -import { Context, Dict, Element, file, h, MessageEncoder } from '@satorijs/satori' +import { Context, Dict, Element, h, MessageEncoder } from '@satorijs/satori' import { TelegramBot } from './bot' import * as Telegram from './utils' @@ -50,7 +50,7 @@ export class TelegramMessageEncoder extends Message file: 'document', } - let i = 0; + let i = 0 for (const element of this.asset) { const { filename, data, mime } = await this.bot.ctx.http.file(element.attrs.src || element.attrs.url, element.attrs) files.push({ @@ -58,18 +58,19 @@ export class TelegramMessageEncoder extends Message data, mime, type: filename.endsWith('gif') ? 'animation' : typeMap[element.type] ?? element.type, - element + element, }) } // Array of InputMediaAudio, InputMediaDocument, InputMediaPhoto and InputMediaVideo const inputFiles: Telegram.InputFile[] = [] - for (const { filename, data, mime, type, element } of files) { + for (const { filename, type, element } of files) { const media = 'attach://' + filename inputFiles.push({ - media, type, - has_spoiler: element.attrs.spoiler + media, + type, + has_spoiler: element.attrs.spoiler, }) } @@ -83,7 +84,7 @@ export class TelegramMessageEncoder extends Message chat_id: this.payload.chat_id, reply_to_message_id: this.payload.reply_to_message_id, message_thread_id: this.payload.message_thread_id, - media: JSON.stringify(inputFiles) + media: JSON.stringify(inputFiles), } for (const key in data) { form.append(key, data[key]) @@ -96,8 +97,7 @@ export class TelegramMessageEncoder extends Message // @ts-ignore const result = await this.bot.internal.sendMediaGroup(form) - for (const x of result) - await this.addResult(x) + for (const x of result) { await this.addResult(x) } if (this.rows.length > 0 && this.rows[0].length > 0) { const result2 = await this.bot.internal.sendMessage({ @@ -132,7 +132,7 @@ export class TelegramMessageEncoder extends Message ['document', ['sendDocument', 'document']], ['', ['sendDocument', 'document']], ] as const - const [_, [method, dataKey]] = sendMap.find(([key]) => files[0].type.startsWith(key)) || [] + const [, [method, dataKey]] = sendMap.find(([key]) => files[0].type.startsWith(key)) || [] const formData = new FormData() formData.append('chat_id', this.payload.chat_id) diff --git a/adapters/telegram/src/utils.ts b/adapters/telegram/src/utils.ts index 508567ae..5a278c90 100644 --- a/adapters/telegram/src/utils.ts +++ b/adapters/telegram/src/utils.ts @@ -17,7 +17,7 @@ export const decodeGuildMember = (data: Telegram.ChatMember): Universal.GuildMem }) const mediaGroupMap = new Map() @@ -55,20 +55,19 @@ export async function handleUpdate(update: Telegram.Update, bot: TelegramBot) { session.content = session.content.slice(1) } else if (message) { if (update.message?.media_group_id) { - if (!mediaGroupMap.has(update.message.media_group_id)) - mediaGroupMap.set(update.message.media_group_id, [new Date(), []]) + if (!mediaGroupMap.has(update.message.media_group_id)) { mediaGroupMap.set(update.message.media_group_id, [new Date(), []]) } - const [date, updates] = mediaGroupMap.get(update.message.media_group_id) + const [, updates] = mediaGroupMap.get(update.message.media_group_id) session.type = update.message || update.channel_post ? 'message' : 'message-updated' await decodeMessage(bot, message, session.event.message = {}, session.event) updates.push({ id: update.message.message_id, - elements: session.event.message.elements + elements: session.event.message.elements, }) - let thisUpdateTime = new Date() + const thisUpdateTime = new Date() mediaGroupMap.set(update.message.media_group_id, [thisUpdateTime, updates]) - await new Promise(r => setTimeout(r, 1200)) + await new Promise(resolve => setTimeout(resolve, 1200)) if (mediaGroupMap.get(update.message.media_group_id)[0] === thisUpdateTime) { mediaGroupMap.delete(update.message.media_group_id) // merge all messages