From 8aaf9c02dc6796fd7f92d01e87078163718e1c1d Mon Sep 17 00:00:00 2001 From: Shigma Date: Sun, 31 Dec 2023 02:22:12 +0800 Subject: [PATCH] feat(core): drop legacy encoder.guildId --- adapters/discord/src/message.ts | 5 +++-- adapters/kook/src/message.ts | 2 ++ adapters/telegram/src/message.ts | 11 ++++++----- adapters/zulip/src/message.ts | 2 +- packages/core/src/message.ts | 12 +++++------- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/adapters/discord/src/message.ts b/adapters/discord/src/message.ts index 4522cc6b..4ac20a93 100644 --- a/adapters/discord/src/message.ts +++ b/adapters/discord/src/message.ts @@ -330,17 +330,18 @@ export class DiscordMessageEncoder extends MessageE } } else { // quote - let replyId = attrs.id, channelId = this.channelId + let replyId = attrs.id, guildId = this.session.guildId, channelId = this.channelId if (this.stack[0].type === 'forward' && this.stack[0].fakeMessageMap[attrs.id]?.length >= 1) { // quote to fake message, eg. 1st message has id (in channel or thread), later message quote to it replyId = this.stack[0].fakeMessageMap[attrs.id][0].id + guildId = this.stack[0].fakeMessageMap[attrs.id][0].guild.id channelId = this.stack[0].fakeMessageMap[attrs.id][0].channel.id } const quote = await this.bot.getMessage(channelId, replyId) this.addition.embeds = [{ description: [ sanitize(parse(quote.elements.filter(v => v.type === 'text').join('')).slice(0, 30)), - ` [[ ↑ ]](https://discord.com/channels/${this.guildId}/${channelId}/${replyId})`, + ` [[ ↑ ]](https://discord.com/channels/${guildId}/${channelId}/${replyId})`, ].join('\n\n'), author: { name: quote.user.name, diff --git a/adapters/kook/src/message.ts b/adapters/kook/src/message.ts index 7449ec3f..0e76fed2 100644 --- a/adapters/kook/src/message.ts +++ b/adapters/kook/src/message.ts @@ -20,9 +20,11 @@ export class KookMessageEncoder extends MessageEnco async prepare() { if (isDirectChannel(this.session.channelId)) { + this.session.isDirect = true this.params.chat_code = this.session.channelId this.path = '/user-chat/create-msg' } else { + this.session.isDirect = false this.params.target_id = this.session.channelId this.path = '/message/create' } diff --git a/adapters/telegram/src/message.ts b/adapters/telegram/src/message.ts index 2a5181e3..0b32385c 100644 --- a/adapters/telegram/src/message.ts +++ b/adapters/telegram/src/message.ts @@ -1,4 +1,4 @@ -import { Context, Dict, h, MessageEncoder, Universal } from '@satorijs/satori' +import { Context, Dict, h, MessageEncoder } from '@satorijs/satori' import FormData from 'form-data' import { TelegramBot } from './bot' import * as Telegram from './utils' @@ -35,11 +35,12 @@ export class TelegramMessageEncoder extends Message private mode: RenderMode = 'default' private rows: Telegram.InlineKeyboardButton[][] = [] - constructor(bot: TelegramBot, channelId: string, guildId?: string, options?: Universal.SendOptions) { - super(bot, channelId, guildId, options) - const chat_id = guildId || channelId + async prepare() { + const chat_id = this.session.guildId || this.channelId this.payload = { chat_id, parse_mode: 'html', caption: '' } - if (guildId && channelId !== guildId) this.payload.message_thread_id = +channelId + if (this.session.guildId && this.channelId !== this.session.guildId) { + this.payload.message_thread_id = +this.channelId + } } async addResult(result: Telegram.Message) { diff --git a/adapters/zulip/src/message.ts b/adapters/zulip/src/message.ts index c0bffff5..bdc9af0a 100644 --- a/adapters/zulip/src/message.ts +++ b/adapters/zulip/src/message.ts @@ -88,7 +88,7 @@ export class ZulipMessageEncoder extends MessageEnc } else if (type === 'quote') { const quoteMsg = await this.bot.internal.getMessage(attrs.id) const suffix = '/near/' + encodeHashComponent(attrs.id) - const path = by_stream_topic_url(Number(this.guildId), this.channelId) + suffix + const path = by_stream_topic_url(+this.session.guildId, this.channelId) + suffix this.buffer = `@_**${quoteMsg.message.sender_full_name}|${quoteMsg.message.sender_id}** [Said](${path}):\n` + '```quote\n' + quoteMsg.raw_content + '\n```\n\n' + this.buffer diff --git a/packages/core/src/message.ts b/packages/core/src/message.ts index eb4837fe..a791ec04 100644 --- a/packages/core/src/message.ts +++ b/packages/core/src/message.ts @@ -1,5 +1,5 @@ import { Bot } from './bot' -import { Channel, Message, SendOptions } from '@satorijs/protocol' +import { Message, SendOptions } from '@satorijs/protocol' import h from '@satorijs/element' import { Context } from '.' @@ -14,9 +14,9 @@ export abstract class MessageEncoder abstract visit(element: h): Promise @@ -31,12 +31,10 @@ export abstract class MessageEncoder