From 22d913b4fb0656d267f6cce065b4d4fffdf0545b Mon Sep 17 00:00:00 2001 From: Il Harper Date: Sun, 24 Dec 2023 02:29:34 +0800 Subject: [PATCH] feat: adapt https://github.com/satorijs/satori/pull/196 --- src/bot/message.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/bot/message.ts b/src/bot/message.ts index bd8e276..edb6b62 100644 --- a/src/bot/message.ts +++ b/src/bot/message.ts @@ -1,4 +1,4 @@ -import { Context, h, MessageEncoder, pick, Universal } from 'koishi' +import { Channel, Context, h, MessageEncoder, pick, Universal } from 'koishi' import { BaseBot } from './base' import { CQCode } from './cqcode' @@ -18,12 +18,21 @@ export class OneBotMessageEncoder extends MessageEn stack: State[] = [new State('message')] children: CQCode[] = [] + override async prepare(): Promise { + super.prepare() + + this.session.isDirect = this.channelId.startsWith('private:') + this.session.channel.type = this.session.isDirect ? Channel.Type.DIRECT : Channel.Type.TEXT + this.session.subtype = this.session.isDirect ? 'private' : 'group' + if (!this.session.isDirect) this.guildId = this.channelId + } + async forward() { if (!this.stack[0].children.length) return const session = this.bot.session() - session.messageId = this.guildId - ? '' + await this.bot.internal.sendGroupForwardMsg(this.guildId, this.stack[0].children) - : '' + await this.bot.internal.sendPrivateForwardMsg(this.channelId.slice(8), this.stack[0].children) + session.messageId = this.session.isDirect + ? '' + await this.bot.internal.sendPrivateForwardMsg(this.channelId.slice(8), this.stack[0].children) + : '' + await this.bot.internal.sendGroupForwardMsg(this.guildId, this.stack[0].children) session.userId = this.bot.selfId session.channelId = this.session.channelId session.guildId = this.session.guildId @@ -81,9 +90,9 @@ export class OneBotMessageEncoder extends MessageEn const session = this.bot.session() session.messageId = this.bot.parent ? '' + await this.bot.internal.sendGuildChannelMsg(this.guildId, this.channelId, this.children) - : this.guildId - ? '' + await this.bot.internal.sendGroupMsg(this.guildId, this.children) - : '' + await this.bot.internal.sendPrivateMsg(this.channelId.slice(8), this.children) + : this.session.isDirect + ? '' + await this.bot.internal.sendPrivateMsg(this.channelId.slice(8), this.children) + : '' + await this.bot.internal.sendGroupMsg(this.guildId, this.children) session.userId = this.bot.selfId session.channelId = this.session.channelId session.guildId = this.session.guildId