diff --git a/src/adapter/input/index.ts b/src/adapter/input/index.ts index ac54ef3..39154f1 100644 --- a/src/adapter/input/index.ts +++ b/src/adapter/input/index.ts @@ -84,7 +84,7 @@ export class AdapterInput implements KarinAdapter { }, elements: [{ type: 'text', text: elements }] as KarinElement[], contact: { - scene: 'private' as 'private' | 'group', + scene: 'friend' as 'friend', peer: 'input', sub_peer: '', }, diff --git a/src/adapter/kritor/grpc.ts b/src/adapter/kritor/grpc.ts index 94d58dc..6ecc751 100644 --- a/src/adapter/kritor/grpc.ts +++ b/src/adapter/kritor/grpc.ts @@ -98,7 +98,7 @@ export class KritorGrpc { }, elements: this.AdapterConvertKarin(kritorData.elements as Array), contact: { - scene: scene as 'private' | 'group', + scene: scene as 'friend' | 'group', peer: contact.peer + '', sub_peer: contact.sub_peer + '', }, @@ -135,7 +135,7 @@ export class KritorGrpc { const uin = data.operator_uin const contact = { - scene: 'private' as 'private', + scene: 'friend' as 'friend', peer: uid, sub_peer: '', } @@ -176,7 +176,7 @@ export class KritorGrpc { const uin = data.operator_uin const contact = { - scene: 'private' as 'private', + scene: 'friend' as 'friend', peer: uid, sub_peer: '', } @@ -213,7 +213,7 @@ export class KritorGrpc { const uin = data.operator_uin const contact = { - scene: 'private' as 'private', + scene: 'friend' as 'friend', peer: uid, sub_peer: '', } @@ -838,7 +838,7 @@ export class KritorGrpc { /** scene映射表 */ const sceneMap = { [kritor.common.Scene.GROUP]: 'group', - [kritor.common.Scene.FRIEND]: 'private', + [kritor.common.Scene.FRIEND]: 'friend', [kritor.common.Scene.GUILD]: 'guild', [kritor.common.Scene.NEARBY]: 'nearby', [kritor.common.Scene.STRANGER]: 'stranger', @@ -854,7 +854,7 @@ export class KritorGrpc { /* 0=群聊 1=私聊 2=频道 5=附近的人 6=陌生人 10=群临时会话 - 0=group 1=private 2=guild 5=nearby 6=stranger 10=stranger_from_group + 0=group 1=friend 2=guild 5=nearby 6=stranger 10=stranger_from_group */ const scene = sceneMap[contact.scene as kritor.common.Scene] const role = roleMap[sender.role as kritor.common.Role] diff --git a/src/adapter/onebot/onebot11.ts b/src/adapter/onebot/onebot11.ts index 1a14fed..ccccc7c 100644 --- a/src/adapter/onebot/onebot11.ts +++ b/src/adapter/onebot/onebot11.ts @@ -222,7 +222,7 @@ export class AdapterOneBot11 implements KarinAdapter { }, elements: this.AdapterConvertKarin(data.message), contact: { - scene: (data.message_type === 'private' ? 'private' : 'group') as 'private' | 'group', + scene: (data.message_type === 'private' ? 'friend' : 'group') as 'friend' | 'group', peer: data.message_type === 'private' ? data.sender.user_id : data.group_id, sub_peer: '', }, @@ -275,7 +275,7 @@ export class AdapterOneBot11 implements KarinAdapter { } const contact = { - scene: ('group_id' in data ? 'group' : 'private') as Scene, + scene: ('group_id' in data ? 'group' : 'friend') as Scene, peer: 'group_id' in data ? data.group_id : data.user_id, sub_peer: '', } @@ -528,7 +528,7 @@ export class AdapterOneBot11 implements KarinAdapter { user_id: data.user_id + '', time: data.time, contact: { - scene: 'private', + scene: 'friend', peer: data.user_id + '', sub_peer: '', }, @@ -875,7 +875,6 @@ export class AdapterOneBot11 implements KarinAdapter { * 获取消息 * @param _contact - ob11无需提供contact参数 * @param message_id - 消息ID - * @returns {Promise} - 消息内容 */ async GetMessage (_contact: contact, message_id: string) { @@ -885,7 +884,7 @@ export class AdapterOneBot11 implements KarinAdapter { message_id: res.message_id, message_seq: res.message_id, contact: { - scene: res.message_type === 'group' ? 'group' : 'private', + scene: res.message_type === 'group' ? 'group' : 'friend', peer: res.sender.user_id, // 拿不到group_id... }, sender: { diff --git a/src/core/karin.ts b/src/core/karin.ts index 534de36..9824f76 100644 --- a/src/core/karin.ts +++ b/src/core/karin.ts @@ -1,7 +1,8 @@ import PluginApp from './plugin.app' import { common } from 'karin/utils' import { KarinMessage } from 'karin/event/message' -import { Permission, PluginApps, KarinElement } from 'karin/types' +import { Permission, PluginApps, KarinElement, contact, KarinRenderType } from 'karin/types' +import { render } from 'karin/render' type FncFunction = (e: KarinMessage) => Promise type FncElement = string | KarinElement | Array @@ -206,4 +207,34 @@ export class Karin { return PluginApp(data) } + + /** + * 构建contact + * @param peer - 群号或者id + * @param isGroup - 是否是群聊 + * @param sub_peer - 子id + */ + contact (peer: string, isGroup: boolean = true, sub_peer?: string): contact { + if (isGroup) { + return { + scene: 'group', + peer, + sub_peer: sub_peer || '', + } + } + + return { + scene: 'friend', + peer, + sub_peer: sub_peer || '', + } + } + + /** + * - 渲染 + * @param options - 渲染参数 + */ + render (options: KarinRenderType) { + return render.render(options) + } } diff --git a/src/event/message.handler.ts b/src/event/message.handler.ts index e948fed..4112e72 100644 --- a/src/event/message.handler.ts +++ b/src/event/message.handler.ts @@ -212,7 +212,7 @@ export class MessageHandler extends EventHandler { this.e.isAdmin = true } - if (this.e.contact.scene === 'private') { + if (this.e.contact.scene === 'friend') { this.e.isPrivate = true this.e.logText = `[Private:${this.e.sender.nick || ''}(${this.e.user_id})]` logger.bot('info', this.e.self_id, `私聊:[${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`) diff --git a/src/event/notice.handler.ts b/src/event/notice.handler.ts index 74dc3a9..7a5f8bc 100644 --- a/src/event/notice.handler.ts +++ b/src/event/notice.handler.ts @@ -35,7 +35,7 @@ export default class NoticeHandler extends EventHandler { this.e.isAdmin = true } - if (this.e.contact.scene === 'private') { + if (this.e.contact.scene === 'friend') { this.e.isPrivate = true this.e.logText = `[Private:${this.e.sender.nick || ''}(${this.e.user_id})]` logger.bot('info', this.e.self_id, `${logger.green('私聊通知: ')}[${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`) diff --git a/src/event/request.handler.ts b/src/event/request.handler.ts index 6e672c2..0579403 100644 --- a/src/event/request.handler.ts +++ b/src/event/request.handler.ts @@ -35,7 +35,7 @@ export default class RequestHandler extends EventHandler { this.e.isAdmin = true } - if (this.e.contact.scene === 'private') { + if (this.e.contact.scene === 'friend') { this.e.isPrivate = true this.e.logText = `[Private:${this.e.sender.nick || ''}(${this.e.user_id})]` logger.bot('info', this.e.self_id, `${logger.green('私聊请求: ')}[${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`) diff --git a/src/types/event.ts b/src/types/event.ts index 236c564..cbaaae8 100644 --- a/src/types/event.ts +++ b/src/types/event.ts @@ -10,7 +10,7 @@ export type Event = 'message' | 'notice' | 'request' | 'meta_event' | 'message_s /** * - 事件来源 */ -export type Scene = 'group' | 'private' | 'guild' | 'nearby' | 'stranger' | 'stranger_from_group' +export type Scene = 'group' | 'friend' | 'guild' | 'nearby' | 'stranger' | 'stranger_from_group' /** * - 类型映射