From 7b9d251e802e34e15798f74090eced8bf66250b8 Mon Sep 17 00:00:00 2001 From: shanmite Date: Sun, 12 Feb 2023 12:42:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=83=AD=E8=AF=84=E5=8C=85=E5=90=AB?= =?UTF-8?q?=E5=8F=91=E9=80=81=E7=83=AD=E8=AF=84=E7=9A=84=E4=BA=BA=E7=9A=84?= =?UTF-8?q?=E6=98=B5=E7=A7=B0=E6=8D=A2=E6=88=90=E8=87=AA=E5=B7=B1=E7=9A=84?= =?UTF-8?q?=E6=98=B5=E7=A7=B0=20(#239)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/core/monitor.js | 7 ++++++- lib/net/bili.js | 5 +++-- test/dynamic_card.test.js | 4 +--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/core/monitor.js b/lib/core/monitor.js index d7e62e1..3be1b34 100644 --- a/lib/core/monitor.js +++ b/lib/core/monitor.js @@ -598,7 +598,12 @@ class Monitor extends Searcher { /* 评论 */ if (rid && chat_type) { if (is_copy_chat) { - chat = getRandomOne(await bili.getChat(rid, chat_type)) || "!!!" + const copy_chat = getRandomOne(await bili.getChat(rid, chat_type)); + chat = copy_chat[1] + .replace( + new RegExp(copy_chat[0], 'g'), + global_var.get("myUNAME") || '') + || "!!!" } status = await retryfn( diff --git a/lib/net/bili.js b/lib/net/bili.js index 7209922..23ae9fb 100644 --- a/lib/net/bili.js +++ b/lib/net/bili.js @@ -143,6 +143,7 @@ const bili_client = { }), res = strToJson(responseText); if (res.code === 0) { + GlobalVar.set("myUNAME", res.data.name) return true; } else { return false; @@ -1056,7 +1057,7 @@ const bili_client = { * 查询评论 * @param {*} rid * @param {*} type - * @returns {Promise>} + * @returns {Promise>} [[uname,chat],] */ async getChat(rid, type) { const @@ -1072,7 +1073,7 @@ const bili_client = { case 0: log.info('查询评论', `成功`); try { - return res.data.replies.map(it => it.content.message); + return res.data.replies.map(it => [it.member.uname, it.content.message]); } catch (_) { return [] } diff --git a/test/dynamic_card.test.js b/test/dynamic_card.test.js index 9e52439..ff21354 100644 --- a/test/dynamic_card.test.js +++ b/test/dynamic_card.test.js @@ -4,8 +4,6 @@ const searcher = require("../lib/core/searcher"); const util = require('./util'); (async () => { - assert(await bili_client.getMyinfo()); - await util.par_run([0, 1, 2, 3], [ // 0 async () => { @@ -21,7 +19,7 @@ const util = require('./util'); async () => { let card = searcher.parseDynamicCard(await bili_client.getOneDynamicByDyid("746824225190314008")); let chats = await bili_client.getChat(card.rid_str, card.chat_type) - assert(chats.length > 0 && typeof chats[0] == "string") + assert(chats.length > 0 && typeof chats[0][0] == "string") }, // 3 async () => {