From 54fca4b85b8aba8e7e1f0753dfe3cb25f8ee0da4 Mon Sep 17 00:00:00 2001 From: CakmLexi Date: Tue, 18 Jun 2024 07:48:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E5=A5=BD=E5=8F=8B?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E9=94=99=E8=AF=AF=20=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/defSet/pm2.yaml | 3 +++ lib/adapter/onebot/OneBot11.js | 24 ++++++++++++------------ lib/bot/KarinElement.js | 6 +++--- lib/bot/KarinEvent.js | 2 +- lib/bot/KarinRequest.js | 2 +- lib/core/listener.js | 6 +++--- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/config/defSet/pm2.yaml b/config/defSet/pm2.yaml index 696e85fd..f7ed3c23 100644 --- a/config/defSet/pm2.yaml +++ b/config/defSet/pm2.yaml @@ -1,3 +1,6 @@ +# 最多显示多少行日志 +lines: 1000 + apps: - name: "Karin" # 入口 diff --git a/lib/adapter/onebot/OneBot11.js b/lib/adapter/onebot/OneBot11.js index 77a94ada..3a4f2800 100644 --- a/lib/adapter/onebot/OneBot11.js +++ b/lib/adapter/onebot/OneBot11.js @@ -237,7 +237,7 @@ export class OneBot11 extends KarinAdapter { this.logger('trace', `[心跳]:${JSON.stringify(data.status, null, 2)}`) break case 'lifecycle': - this.logger('debug', `[生命周期]:${{ enable: 'OneBot启用', disable: 'OneBot停用', connect: 'WebSocket连接成功' }[data.sub_event]}`) + this.logger('debug', `[生命周期]:${{ enable: 'OneBot启用', disable: 'OneBot停用', connect: 'WebSocket连接成功' }[data.sub_type]}`) break } @@ -322,14 +322,14 @@ export class OneBot11 extends KarinAdapter { group_id: data.group_id, target_uid: data.user_id, target_uin: data.user_id, - is_admin: data.sub_event === 'set', + is_admin: data.sub_type === 'set', } data = new KarinGroupAdminChangedNotice({ time, self_id, content }) break } case 'group_decrease': { const content = { group_id: data.group_id } - switch (data.sub_event) { + switch (data.sub_type) { // 主动退群 case 'leave': content.type = 0 @@ -361,7 +361,7 @@ export class OneBot11 extends KarinAdapter { operator_uin: data.operator_id, target_uid: data.user_id, target_uin: data.user_id, - type: data.sub_event === 'approve' ? 0 : 1, + type: data.sub_type === 'approve' ? 0 : 1, } data = new KarinGroupMemberIncreasedNotice({ time, self_id, content }) break @@ -374,7 +374,7 @@ export class OneBot11 extends KarinAdapter { target_uid: data.user_id, target_uin: data.user_id, duration: data.duration, - type: data.sub_event === 'ban' ? 1 : 0, + type: data.sub_type === 'ban' ? 1 : 0, } data = new KarinGroupMemberBanNotice({ time, self_id, content }) break @@ -408,7 +408,7 @@ export class OneBot11 extends KarinAdapter { break } case 'notify': - switch (data.sub_event) { + switch (data.sub_type) { case 'poke': { const content = { group_id: data.group_id, @@ -476,8 +476,8 @@ export class OneBot11 extends KarinAdapter { * @param {string} remark 拒绝理由(仅在拒绝时有效) */ data.approve = async (approve, remark) => { - const { flag, sub_event } = data - const obj = { flag, sub_event, approve, remark } + const { flag, sub_type } = data + const obj = { flag, sub_type, approve, remark } if (!remark) delete obj.remark return await this.SendApi('set_group_add_request', obj) } @@ -1013,12 +1013,12 @@ export class OneBot11 extends KarinAdapter { /** * 处理加群请求/邀请 * @param {string} flag - 加群请求的 flag(需从上报的数据中获得) - * @param {string} sub_event - add 或 invite,请求类型(需要和上报消息中的 sub_event 字段相符) + * @param {string} sub_type - add 或 invite,请求类型(需要和上报消息中的 sub_type 字段相符) * @param {boolean} [approve=true] - 是否同意请求/邀请 * @param {string} [reason=''] - 拒绝理由(仅在拒绝时有效) */ - async set_group_add_request (flag, sub_event, approve = true, reason = '') { - await this.SendApi('set_group_add_request', { flag, sub_event, approve, reason }) + async set_group_add_request (flag, sub_type, approve = true, reason = '') { + await this.SendApi('set_group_add_request', { flag, sub_type, approve, reason }) } /** @@ -1223,7 +1223,7 @@ export class OneBot11 extends KarinAdapter { * @param {boolean} [options.refresh] - 是否刷新缓存 * @returns {Promise} - 获取群荣誉信息操作的响应 */ - async get_group_honor_info (options) { + async GetGroupHonor (options) { const { group_id } = options /** * @typedef {{user_id: number, nickname: string, avatar: string, description: string}} GroupHonor diff --git a/lib/bot/KarinElement.js b/lib/bot/KarinElement.js index 7ebb8f59..413bc39e 100644 --- a/lib/bot/KarinElement.js +++ b/lib/bot/KarinElement.js @@ -851,7 +851,7 @@ export class GiftElement extends KarinElement { */ export class KarinContact { /** - * @param {'private'|'group'} scene - 场景 + * @param {'group'|'friend'|'guild'|'nearby'|'stranger'|'stranger_from_group'} scene - 场景 * @param {string} peer - 场景对应ID * @param {string?} sub_peer - 场景子ID */ @@ -862,7 +862,7 @@ export class KarinContact { } /** - * @type {'private'|'group'} - 场景名称 + * @type {'group'|'friend'|'guild'|'nearby'|'stranger'|'stranger_from_group'} - 场景名称 */ scene @@ -892,6 +892,6 @@ export class KarinContact { * @return {KarinContact} */ static private (peer, sub_peer) { - return new KarinContact('private', peer + '', sub_peer ? sub_peer + '' : undefined) + return new KarinContact('friend', peer + '', sub_peer ? sub_peer + '' : undefined) } } diff --git a/lib/bot/KarinEvent.js b/lib/bot/KarinEvent.js index 9021223b..edf3fd10 100644 --- a/lib/bot/KarinEvent.js +++ b/lib/bot/KarinEvent.js @@ -12,7 +12,7 @@ export class KarinEvent { * group_id?: string, * time: number, * contact: { - * scene: 'group'|'private'|'guild'|'nearby'|'stranger'|'stranger_from_group', + * scene: 'group'|'friend'|'guild'|'nearby'|'stranger'|'stranger_from_group', * peer: string, * sub_peer?: string * }, diff --git a/lib/bot/KarinRequest.js b/lib/bot/KarinRequest.js index 765c4ef7..7d518bbb 100644 --- a/lib/bot/KarinRequest.js +++ b/lib/bot/KarinRequest.js @@ -14,7 +14,7 @@ export class KarinRequest extends KarinEvent { * time: number, * raw_message: string, * contact: { - * scene: 'group'|'friend', + * scene: 'group'|'friend'|'guild'|'nearby'|'stranger'|'stranger_from_group', * peer: string, * sub_peer?: string * }, diff --git a/lib/core/listener.js b/lib/core/listener.js index 5f65f7d9..1d2199dd 100644 --- a/lib/core/listener.js +++ b/lib/core/listener.js @@ -110,12 +110,12 @@ export default class Listeners extends EventEmitter { /** * 通过Bot uid 获取Bot * @param {string} [uid] - Bot的uid 未传入则返回第一个Bot - * @returns {import('../adapter/adapter.js').KarinAdapter|false} + * @returns {import('../adapter/adapter.js').KarinAdapter} */ getBot (uid = '') { if (this.list.length === 0) { this.#logger.error('[Bot管理][UID] 当前Bot列表为空') - return false + return undefined } if (!uid) return this.list[0].bot @@ -123,7 +123,7 @@ export default class Listeners extends EventEmitter { const index = this.list.findIndex(item => item.bot.account.uid === uid) if (index === -1) { this.#logger.error('[Bot管理][UID] 无法找到对应的 Bot 实例') - return false + return undefined } return this.list[index].bot