Skip to content

Commit

Permalink
fix: 修正好友判断错误 类型描述错误
Browse files Browse the repository at this point in the history
  • Loading branch information
CakmLexi committed Jun 17, 2024
1 parent 5b1b913 commit 54fca4b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
3 changes: 3 additions & 0 deletions config/defSet/pm2.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 最多显示多少行日志
lines: 1000

apps:
- name: "Karin"
# 入口
Expand Down
24 changes: 12 additions & 12 deletions lib/adapter/onebot/OneBot11.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 })
}

/**
Expand Down Expand Up @@ -1223,7 +1223,7 @@ export class OneBot11 extends KarinAdapter {
* @param {boolean} [options.refresh] - 是否刷新缓存
* @returns {Promise<IGroupHonorInfo[]>} - 获取群荣誉信息操作的响应
*/
async get_group_honor_info (options) {
async GetGroupHonor (options) {
const { group_id } = options
/**
* @typedef {{user_id: number, nickname: string, avatar: string, description: string}} GroupHonor
Expand Down
6 changes: 3 additions & 3 deletions lib/bot/KarinElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -862,7 +862,7 @@ export class KarinContact {
}

/**
* @type {'private'|'group'} - 场景名称
* @type {'group'|'friend'|'guild'|'nearby'|'stranger'|'stranger_from_group'} - 场景名称
*/
scene

Expand Down Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion lib/bot/KarinEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
* },
Expand Down
2 changes: 1 addition & 1 deletion lib/bot/KarinRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
* },
Expand Down
6 changes: 3 additions & 3 deletions lib/core/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,20 @@ 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

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
Expand Down

0 comments on commit 54fca4b

Please sign in to comment.