Skip to content

Commit

Permalink
feat: adapt satorijs/satori#196
Browse files Browse the repository at this point in the history
  • Loading branch information
ilharp committed Dec 23, 2023
1 parent 2d86b1f commit 22d913b
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/bot/message.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -18,12 +18,21 @@ export class OneBotMessageEncoder<C extends Context = Context> extends MessageEn
stack: State[] = [new State('message')]
children: CQCode[] = []

override async prepare(): Promise<void> {
super.prepare()

this.session.isDirect = this.channelId.startsWith('private:')
this.session.channel.type = this.session.isDirect ? Channel.Type.DIRECT : Channel.Type.TEXT

Check failure on line 25 in src/bot/message.ts

View workflow job for this annotation

GitHub Actions / build

Property 'type' does not exist on type 'Observed<never>'.

Check failure on line 25 in src/bot/message.ts

View workflow job for this annotation

GitHub Actions / build

Property 'Type' does not exist on type 'typeof Channel'.

Check failure on line 25 in src/bot/message.ts

View workflow job for this annotation

GitHub Actions / build

Property 'Type' does not exist on type 'typeof Channel'.

Check failure on line 25 in src/bot/message.ts

View workflow job for this annotation

GitHub Actions / build

Property 'type' does not exist on type 'Observed<never>'.

Check failure on line 25 in src/bot/message.ts

View workflow job for this annotation

GitHub Actions / build

Property 'Type' does not exist on type 'typeof Channel'.

Check failure on line 25 in src/bot/message.ts

View workflow job for this annotation

GitHub Actions / build

Property 'Type' does not exist on type 'typeof Channel'.
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
Expand Down Expand Up @@ -81,9 +90,9 @@ export class OneBotMessageEncoder<C extends Context = Context> 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
Expand Down

0 comments on commit 22d913b

Please sign in to comment.