Skip to content

Commit

Permalink
chore: fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Apr 20, 2024
1 parent 1c1716e commit 0dcd916
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
20 changes: 10 additions & 10 deletions adapters/telegram/src/message.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -50,26 +50,27 @@ export class TelegramMessageEncoder<C extends Context = Context> 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({
filename: (i++) + filename,
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,
})
}

Expand All @@ -83,7 +84,7 @@ export class TelegramMessageEncoder<C extends Context = Context> 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])
Expand All @@ -96,8 +97,7 @@ export class TelegramMessageEncoder<C extends Context = Context> 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({
Expand Down Expand Up @@ -132,7 +132,7 @@ export class TelegramMessageEncoder<C extends Context = Context> 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)
Expand Down
13 changes: 6 additions & 7 deletions adapters/telegram/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const decodeGuildMember = (data: Telegram.ChatMember): Universal.GuildMem
})

const mediaGroupMap = new Map<string, [Date, {
id: number,
id: number
elements: h[]
}[]]>()

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0dcd916

Please sign in to comment.