diff --git a/lib/adapter/onebot/OneBot11.js b/lib/adapter/onebot/OneBot11.js index f69f1459..1c9ab30b 100644 --- a/lib/adapter/onebot/OneBot11.js +++ b/lib/adapter/onebot/OneBot11.js @@ -24,6 +24,7 @@ import { KarinGroupAdminChangedNotice, KarinGroupMemberBanNotice, KarinGroupFileUploadedNotice, + KarinGroupMessagReactionNotice, } from '../../bot/KarinNotice.js' import WebSocket from 'ws' @@ -430,6 +431,22 @@ export class OneBot11 extends KarinAdapter { break } break + case 'group_msg_emoji_like': { + const content = { + group_id: data.group_id, + operator_uid: data.user_id, + operator_uin: data.user_id, + message_id: data.message_id, + face_id: data.likes[0].emoji_id, + // llob目前只有上报点击 没有取消 暂时默认为true + is_emoji: true, + } + data = new KarinGroupMessagReactionNotice({ time, self_id, content }) + break + } + default: { + return this.#logger.error('未知通知事件:', JSON.stringify(data)) + } } this.#listener.emit('notice', data) @@ -1278,6 +1295,16 @@ export class OneBot11 extends KarinAdapter { return result } + /** + * 对消息进行表情回应 + * @param {KarinContact} Contact - 联系人信息 + * @param {string} message_id - 消息ID + * @param {string} face_id - 表情ID + */ + async ReactMessageWithEmojiRequest (Contact, message_id, face_id, is_set = true) { + return await this.SendApi('set_msg_emoji_like', { message_id, emoji_id: face_id, is_set }) + } + /** * 获取 Cookies * @param {string} domain - 需要获取 cookies 的域名 diff --git a/lib/bot/KarinElement.js b/lib/bot/KarinElement.js index 2c9a0601..7ebb8f59 100644 --- a/lib/bot/KarinElement.js +++ b/lib/bot/KarinElement.js @@ -496,22 +496,22 @@ export class KarinNodeElement extends KarinElement { export class KarinXmlElement extends KarinElement { /** * 构建一个xml元素 - * @param {String} xml - xml内容 + * @param {String} data - xml内容 * @returns {KarinXmlElement} */ - constructor (xml) { + constructor (data) { super() this.type = 'xml' /** * @type {String} xml */ - this.xml = xml + this.data = data } /** - * @type {String} xml + * @type {String} data */ - xml + data } /** @@ -520,22 +520,22 @@ export class KarinXmlElement extends KarinElement { export class KarinJsonElement extends KarinElement { /** * 构建一个json元素 - * @param {String} json - json内容 + * @param {String} data - json内容 * @returns {KarinJsonElement} */ - constructor (json) { + constructor (data) { super() this.type = 'json' /** * @type {String} json */ - this.json = json + this.data = data } /** - * @type {String} json + * @type {String} data */ - json + data } /** diff --git a/lib/bot/KarinNotice.js b/lib/bot/KarinNotice.js index a211f941..2185ad5c 100644 --- a/lib/bot/KarinNotice.js +++ b/lib/bot/KarinNotice.js @@ -38,7 +38,7 @@ export class KarinNotice extends KarinEvent { * }, * content: any, * sub_event: 'friend_poke' | 'friend_recall' | 'friend_file_come' | 'group_poke' | 'group_card_changed' | 'group_member_unique_title_changed' | 'group_essence_changed' | 'group_recall' | 'group_member_increase' | 'group_member_decrease' | 'group_admin_change' | 'group_member_ban' | 'group_sign_in' | 'group_whole_ban' | 'group_file_uploaded' - * }} params + * }} */ constructor ({ self_id, sub_event, time, contact, sender, user_id, message_id, message_seq, raw_message = '', group_id = '' }) { super({ event: 'notice', self_id, user_id, group_id, time, contact, sender, sub_event }) @@ -89,7 +89,7 @@ export class KarinFriendPokeNotice extends KarinNotice { * action_image: String * }, * time: Number - * }} params + * }} */ constructor ({ self_id, content, time }) { const { operator_uid = '', operator_uin = '', target_uid = '', target_uin = '', message_id = '', message_seq = '', group_id = '', raw_message = '' } = content @@ -110,7 +110,7 @@ export class KarinFriendPokeNotice extends KarinNotice { message_id, message_seq, raw_message, - group_id + group_id, } super(data) this.content = content @@ -144,7 +144,7 @@ export class KarinFriendRecallNotice extends KarinNotice { * tip_text: String * }, * time: Number - * }} params + * }} */ constructor ({ self_id, content, time }) { const { operator_uid = '', operator_uin = '', target_uid = '', target_uin = '', message_id = '', message_seq = '', raw_message = '' } = content @@ -164,7 +164,7 @@ export class KarinFriendRecallNotice extends KarinNotice { user_id: operator_uid, message_id, message_seq, - raw_message + raw_message, } super(data) this.content = content @@ -201,7 +201,7 @@ export class KarinFriendFileUploadedNotice extends KarinNotice { * url: String * }, * time: Number - * }} params + * }} */ constructor ({ self_id, content, time }) { const { operator_uid = '', operator_uin = '', target_uid = '', target_uin = '', message_id = '', message_seq = '', raw_message = '' } = content @@ -221,7 +221,7 @@ export class KarinFriendFileUploadedNotice extends KarinNotice { user_id: operator_uid, message_id, message_seq, - raw_message + raw_message, } super(data) this.content = content @@ -262,7 +262,7 @@ export class KarinGroupPokeNotice extends KarinNotice { * action_image: string * }, * time: Number - * }} params + * }} */ constructor ({ self_id, content, time }) { const { operator_uid = '', operator_uin = '', target_uid = '', target_uin = '', message_id = '', message_seq = '', group_id = '', raw_message = '' } = content @@ -283,7 +283,7 @@ export class KarinGroupPokeNotice extends KarinNotice { message_id, message_seq, raw_message, - group_id + group_id, } super(data) this.content = content @@ -322,7 +322,7 @@ export class KarinGoupCardChangedNotice extends KarinNotice { * new_card: string * }, * time: Number - * }} params + * }} */ constructor ({ self_id, content, time }) { const { operator_uid = '', operator_uin = '', target_uid = '', target_uin = '', message_id = '', message_seq = '', group_id = '', raw_message = '' } = content @@ -343,7 +343,7 @@ export class KarinGoupCardChangedNotice extends KarinNotice { message_id, message_seq, raw_message, - group_id + group_id, } super(data) this.content = content @@ -377,7 +377,7 @@ export class KarinGroupUniqueTitleChangedNotice extends KarinNotice { * target: string * }, * time: Number - * }} params + * }} */ constructor ({ self_id, content, time }) { const { operator_uid = '', operator_uin = '', target_uid = '', target_uin = '', message_id = '', message_seq = '', group_id = '', raw_message = '' } = content @@ -398,7 +398,7 @@ export class KarinGroupUniqueTitleChangedNotice extends KarinNotice { message_id, message_seq, raw_message, - group_id + group_id, } super(data) this.content = content @@ -433,7 +433,7 @@ export class KarinGroupEssenceMessageNotice extends KarinNotice { * sub_event: Number * }, * time: Number - * }} params + * }} */ constructor ({ self_id, content, time }) { const { operator_uid = '', operator_uin = '', target_uid = '', target_uin = '', message_id = '', message_seq = '', group_id = '', raw_message = '' } = content @@ -454,7 +454,7 @@ export class KarinGroupEssenceMessageNotice extends KarinNotice { message_id, message_seq, raw_message, - group_id + group_id, } super(data) this.content = content @@ -494,7 +494,7 @@ export class KarinGroupRecallNotice extends KarinNotice { * message_seq: String * }, * time: Number - * }} params + * }} */ constructor ({ self_id, content, time }) { const { operator_uid = '', operator_uin = '', target_uid = '', target_uin = '', message_id = '', message_seq = '', group_id = '', raw_message = '' } = content @@ -515,7 +515,7 @@ export class KarinGroupRecallNotice extends KarinNotice { message_id, message_seq, raw_message, - group_id + group_id, } super(data) this.content = content @@ -554,7 +554,7 @@ export class KarinGroupMemberIncreasedNotice extends KarinNotice { * type: 0|1 * }, * time: Number - * }} params + * }} */ constructor ({ self_id, content, time }) { const { operator_uid = '', operator_uin = '', target_uid = '', target_uin = '', message_id = '', message_seq = '', group_id = '', raw_message = '' } = content @@ -575,7 +575,7 @@ export class KarinGroupMemberIncreasedNotice extends KarinNotice { message_id, message_seq, raw_message, - group_id + group_id, } super(data) this.content = content @@ -612,7 +612,7 @@ export class KarinGroupMemberDecreasedNotice extends KarinNotice { * type: 0|1|2 * }, * time: Number - * }} params + * }} */ constructor ({ self_id, content, time }) { const { operator_uid = '', operator_uin = '', target_uid = '', target_uin = '', message_id = '', message_seq = '', group_id = '', raw_message = '' } = content @@ -633,7 +633,7 @@ export class KarinGroupMemberDecreasedNotice extends KarinNotice { message_id, message_seq, raw_message, - group_id + group_id, } super(data) this.content = content @@ -668,7 +668,7 @@ export class KarinGroupAdminChangedNotice extends KarinNotice { * is_admin: boolean * }, * time: Number - * }} params + * }} */ constructor ({ self_id, content, time }) { const { target_uid = '', target_uin = '', message_id = '', message_seq = '', group_id = '', raw_message = '' } = content @@ -689,7 +689,7 @@ export class KarinGroupAdminChangedNotice extends KarinNotice { message_id, message_seq, raw_message, - group_id + group_id, } super(data) this.content = content @@ -725,7 +725,7 @@ export class KarinGroupMemberBanNotice extends KarinNotice { * type: 0|1 * }, * time: Number - * }} params + * }} */ constructor ({ self_id, content, time }) { const { operator_uid = '', operator_uin = '', target_uid = '', target_uin = '', message_id = '', message_seq = '', group_id = '', raw_message = '' } = content @@ -746,7 +746,7 @@ export class KarinGroupMemberBanNotice extends KarinNotice { message_id, message_seq, raw_message, - group_id + group_id, } super(data) this.content = content @@ -783,7 +783,7 @@ export class KarinGroupSignInNotice extends KarinNotice { * rank_image: string * }, * time: Number - * }} params + * }} */ constructor ({ self_id, content, time }) { const { operator_uid = '', operator_uin = '', target_uid = '', target_uin = '', message_id = '', message_seq = '', group_id = '', raw_message = '' } = content @@ -804,7 +804,7 @@ export class KarinGroupSignInNotice extends KarinNotice { message_id, message_seq, raw_message, - group_id + group_id, } super(data) this.content = content @@ -841,7 +841,7 @@ export class KarinGroupWholeBanNotice extends KarinNotice { * is_ban: boolean * }, * time: Number - * }} params + * }} */ constructor ({ self_id, content, time }) { const { operator_uid = '', operator_uin = '', target_uid = '', target_uin = '', message_id = '', message_seq = '', group_id = '', raw_message = '' } = content @@ -862,7 +862,7 @@ export class KarinGroupWholeBanNotice extends KarinNotice { message_id, message_seq, raw_message, - group_id + group_id, } super(data) this.content = content @@ -901,7 +901,7 @@ export class KarinGroupFileUploadedNotice extends KarinNotice { * url: string * }, * time: Number - * }} params + * }} */ constructor ({ self_id, content, time }) { const { operator_uid = '', operator_uin = '', target_uid = '', target_uin = '', message_id = '', message_seq = '', group_id = '', raw_message = '' } = content @@ -922,7 +922,7 @@ export class KarinGroupFileUploadedNotice extends KarinNotice { message_id, message_seq, raw_message, - group_id + group_id, } super(data) this.content = content @@ -949,3 +949,61 @@ export class KarinGroupFileUploadedNotice extends KarinNotice { */ content } + +/** + * 群消息被表情回应 + */ +export class KarinGroupMessagReactionNotice extends KarinNotice { + sub_event = 'group_message_reaction' + + /** + * @param {{ + * self_id: string, + * content: { + * group_id: string, + * operator_uid: string, + * operator_uin: string, + * message_id: string, + * face_id: number, + * is_set: boolean + * }, + * time: Number + * }} + */ + constructor ({ self_id, content, time }) { + const { operator_uid = '', operator_uin = '', target_uid = '', target_uin = '', message_id = '', message_seq = '', group_id = '', raw_message = '' } = content + /** 构建联系人 */ + const contact = Contacts('group', group_id) + /** 构建发送者信息 */ + const sender = SendersNotice(operator_uid, operator_uin, target_uid, target_uin) + /** 构建通知 */ + const data = { + self_id, + sub_event: 'group_message_reaction', + time, + contact, + sender, + content, + // user_id与peer统一使用uid + user_id: operator_uid, + message_id, + message_seq, + raw_message, + group_id, + } + super(data) + this.content = content + } + + /** + * @type {{ + * group_id: string, + * operator_uid: string, + * operator_uin: string, + * message_id: string, + * face_id: number, + * is_set: boolean + * }} + */ + content +} diff --git a/lib/bot/UserInfo.js b/lib/bot/UserInfo.js index e8871771..c09e5007 100644 --- a/lib/bot/UserInfo.js +++ b/lib/bot/UserInfo.js @@ -3,7 +3,11 @@ * @param {string} scene - 场景 * @param {string} peer - 群号或用户id * @param {string} sub_peer - 子群号或用户id - * @returns {Object} + * @returns {Contact} + * @typedef {Object} Contact + * @property {string} scene - 场景 + * @property {string} peer - 群号或用户id + * @property {string} sub_peer - 子群号或用户id */ export function Contacts (scene, peer, sub_peer = '') { return { scene, peer, sub_peer } diff --git a/lib/event/message.js b/lib/event/message.js index 45970e09..dfc92730 100644 --- a/lib/event/message.js +++ b/lib/event/message.js @@ -174,7 +174,7 @@ export default class Message extends Event { break case 'json': this.e.msg += val.data - logs.push(`[json:${val.data}]`) + logs.push(`[json:${JSON.stringify(val.data)}]`) break case 'markdown': { if (val.content) { diff --git a/lib/event/notice.js b/lib/event/notice.js index 544ac947..d5fc1718 100644 --- a/lib/event/notice.js +++ b/lib/event/notice.js @@ -67,7 +67,7 @@ export default class Notice extends Event { let res = App.accept && App.accept(this.e) /** 计算插件处理时间 */ - let start = Date.now() + const start = Date.now() if (util.types.isPromise(res)) res = await res @@ -197,6 +197,15 @@ export default class Notice extends Event { this.e.raw_message = `[群精华消息]: ${operator_uid || operator_uin} ${is_set ? `将${target_uid || target_uin}的消息${message_id}设置为精华消息` : `取消了${target_uid || target_uin}精华消息 ${message_id}`}` break } + /** 群表情回应 */ + case 'group_message_reaction': { + const { operator_uid, operator_uin, message_id, face_id } = this.e.content + this.e.raw_message = `[群表情回应]: ${operator_uid || operator_uin} 给消息 ${message_id} 回应了一个${face_id}的表情` + break + } + default: { + this.e.raw_message = `[未知事件]: ${JSON.stringify(this.e)}` + } } } } diff --git a/lib/index.js b/lib/index.js index 326adaa3..e3c7fe07 100644 --- a/lib/index.js +++ b/lib/index.js @@ -104,7 +104,7 @@ export const button = new Button() export const handler = new Handler() export const update = new Update() export const ffmpeg = await Ffmpeg(logger, config) -export { kritor, plugin, protobuf, YamlEditor, RenderBase, exec, App, KarinMessage, adapter, render, render as Renderer, update as Update, config as Cfg } +export { kritor, plugin, protobuf, YamlEditor, RenderBase, exec, App, KarinMessage, adapter, render, render as Renderer, update as Update, config as Cfg, plugin as Plugin } /** * 插件初始化