From 378194db66e9bbb7c1811726a3e622a490db75bf Mon Sep 17 00:00:00 2001 From: lanyi Date: Mon, 4 Jan 2021 04:59:17 +0100 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E5=8E=9F=E6=B6=88=E6=81=AF=E8=A2=AB?= =?UTF-8?q?=E6=92=A4=E5=9B=9E=E6=97=B6=E8=87=AA=E5=8A=A8=E6=92=A4=E5=9B=9E?= =?UTF-8?q?=E8=BD=AC=E5=8F=91=E7=9A=84=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.ts | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/index.ts b/index.ts index ed38548..46e1651 100644 --- a/index.ts +++ b/index.ts @@ -94,7 +94,7 @@ async function app() { // 对收到的消息进行处理 // message 本质相当于同时绑定了 FriendMessage GroupMessage TempMessage // 你也可以单独对某一类消息进行监听 - mirai.on('GroupMessage', async (msg) => { + mirai.on('GroupMessage', async msg => { const fromGroup = msg.sender.group.id if (!groups.find(({ group }) => group === fromGroup)) { return @@ -154,7 +154,7 @@ async function app() { // 因此,除非是为了回复的 @,否则一律转成纯文本 // 就算确实是为了回复的 @,假如转发的群里这个人不在,那也转成纯文本 // 此外,假如是回复的 @,但是这并不是回复对象的那个群,那么也转成纯文本 - if (x.target !== quote?.author || + if (x.target !== quote?.author || !members.has(x.target) || !quote.isOriginal) { // 把 @ 转换成纯文本的时候,优先使用哪个群里的群名片 @@ -204,25 +204,36 @@ async function app() { } } finally { - releaseMutex(); + releaseMutex() } }) - // 调用 mirai-ts 封装的 mirai-api-http 发送指令 - /*console.log("send command help"); - const data = await mirai.api.command.send("help", []); - console.log("帮助信息:" + data);*/ - // 处理各种事件类型 // 事件订阅说明(名称均与 mirai-api-http 中事件名一致) // https://github.com/RedBeanN/node-mirai/blob/master/event.md // console.log("on other event"); // https://github.com/project-mirai/mirai-api-http/blob/master/EventType.md#群消息撤回 - mirai.on("GroupRecallEvent", ({ operator }) => { - if (operator) { - const text = `${operator.memberName} 撤回了一条消息,并拜托你不要再发色图了。`; - console.log(text); - mirai.api.sendGroupMessage(text, operator.group.id); + mirai.on('GroupRecallEvent', async event => { + const releaseMutex = await mutex.acquire() + try { + for (const group of groups) { + if (group.group === event.group.id) { + continue + } + const matched = group.stored.translate(event.messageId) + if (!matched) { + continue + } + try { + await mirai.api.recall(matched.id) + } + catch (e) { + console.warn(e) + } + } + } + finally { + releaseMutex() } });