fix:添加表情回应功能

This commit is contained in:
Jerry 2025-10-06 18:10:51 +08:00
parent b6c230cfe1
commit 600325771a
3 changed files with 63 additions and 1 deletions

46
apps/face-reply.js Normal file
View File

@ -0,0 +1,46 @@
import ConfigControl from '../lib/config/configControl.js';
import Message from '../lib/yunzai/message.js';
export class FaceReply extends plugin {
constructor() {
super({
name: 'face-reply',
dsc: '给消息中的表情贴上回应',
event: 'message.group',
priority: -114,
});
}
async accept(e) {
if (!ConfigControl.get('config')?.faceReply) return;
if (!e.message_id || e.message.length === 0) return;
let face = [];
e.message.forEach((m) => {
if (m.type === 'face') {
face.push({ id: m.id });
} else if (m.type === 'text') {
let emojiList = exEmojis(m.text);
if (emojiList.length) {
for (const emoji of emojiList) {
const id = emoji.codePointAt(0);
face.push({ id: id });
}
}
}
});
if (face.length) {
for (const f of face) {
await Message.emojiLike(e, e.message_id, String(f.id));
}
}
}
}
//从消息中提取emoji
function exEmojis(text) {
//没错,爆红了
const emojiRegex =
/(?:\p{Extended_Pictographic}(?:\uFE0F|\uFE0E)?(?:\u200D\p{Extended_Pictographic}(?:\uFE0F|\uFE0E)?)*|\p{Emoji_Presentation}|\p{Emoji}\uFE0F)/gu;
const emojis = text.match(emojiRegex);
return emojis || [];
}

View File

@ -8,5 +8,6 @@
"zwa": true,
"rss": true,
"help": true,
"welcome": true
"welcome": true,
"faceReply": true
}

View File

@ -10,5 +10,20 @@ const Message = {
message_id: message_id,
});
},
/**
* 群表情回应
* @param e
* @param message_id 消息id
* @param emoji_id 表情id
* @returns {Promise<*>}
*/
async emojiLike(e, message_id, emoji_id) {
return await e.bot.sendApi('set_msg_emoji_like', {
message_id: message_id,
emoji_id: emoji_id,
set: true,
});
},
};
export default Message;