Skip to content

Commit

Permalink
fix: 修正Scene为friend
Browse files Browse the repository at this point in the history
  • Loading branch information
CakmLexi committed Jul 2, 2024
1 parent 127cb03 commit 9695e75
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/adapter/input/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
},
Expand Down
12 changes: 6 additions & 6 deletions src/adapter/kritor/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class KritorGrpc {
},
elements: this.AdapterConvertKarin(kritorData.elements as Array<kritor.common.Element>),
contact: {
scene: scene as 'private' | 'group',
scene: scene as 'friend' | 'group',
peer: contact.peer + '',
sub_peer: contact.sub_peer + '',
},
Expand Down Expand Up @@ -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: '',
}
Expand Down Expand Up @@ -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: '',
}
Expand Down Expand Up @@ -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: '',
}
Expand Down Expand Up @@ -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',
Expand All @@ -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]
Expand Down
9 changes: 4 additions & 5 deletions src/adapter/onebot/onebot11.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
},
Expand Down Expand Up @@ -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: '',
}
Expand Down Expand Up @@ -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: '',
},
Expand Down Expand Up @@ -875,7 +875,6 @@ export class AdapterOneBot11 implements KarinAdapter {
* 获取消息
* @param _contact - ob11无需提供contact参数
* @param message_id - 消息ID
* @returns {Promise<object>} - 消息内容
*/

async GetMessage (_contact: contact, message_id: string) {
Expand All @@ -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: {
Expand Down
33 changes: 32 additions & 1 deletion src/core/karin.ts
Original file line number Diff line number Diff line change
@@ -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<boolean>
type FncElement = string | KarinElement | Array<KarinElement>
Expand Down Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion src/event/message.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down
2 changes: 1 addition & 1 deletion src/event/notice.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down
2 changes: 1 addition & 1 deletion src/event/request.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down
2 changes: 1 addition & 1 deletion src/types/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
* - 类型映射
Expand Down

0 comments on commit 9695e75

Please sign in to comment.