Skip to content

Commit

Permalink
fix: detecting private messages
Browse files Browse the repository at this point in the history
  • Loading branch information
idranme committed Sep 3, 2024
1 parent 579a144 commit d21a069
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/bot/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Context, Dict, h, MessageEncoder, pick, Universal } from 'koishi'
import { BaseBot } from './base'
import { CQCode } from './cqcode'
import { fileURLToPath } from 'node:url'
import { PRIVATE_PFX } from '../utils'

export interface Author extends Universal.User {
time?: string | number
Expand All @@ -15,8 +16,6 @@ class State {
constructor(public type: 'message' | 'forward' | 'reply') { }
}

export const PRIVATE_PFX = 'private:'

export class OneBotMessageEncoder<C extends Context = Context> extends MessageEncoder<C, BaseBot<C>> {
stack: State[] = [new State('message')]
children: CQCode[] = []
Expand Down
8 changes: 5 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as qface from 'qface'
import { BaseBot, CQCode } from './bot'
import * as OneBot from './types'

export const PRIVATE_PFX = 'private:'

export * from './types'

export const decodeUser = (user: OneBot.AccountInfo): Universal.User => ({
Expand Down Expand Up @@ -121,10 +123,10 @@ export async function adaptMessage(
const decodeGuildChannelId = (data: OneBot.Message) => {
if (data.guild_id) {
return [data.guild_id, data.channel_id]
} else if (data.group_id) {
return [data.group_id.toString(), data.group_id.toString()]
} else if (data.message_type === 'private') {
return [undefined, PRIVATE_PFX + data.sender.user_id]
} else {
return [undefined, 'private:' + data.sender.user_id]
return [data.group_id.toString(), data.group_id.toString()]
}
}

Expand Down

0 comments on commit d21a069

Please sign in to comment.