feat: 热评包含发送热评的人的昵称换成自己的昵称 (#239)

This commit is contained in:
shanmite 2023-02-12 12:42:30 +08:00
parent 5ae7801086
commit 7b9d251e80
3 changed files with 10 additions and 6 deletions

View File

@ -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(

View File

@ -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<Array<string>>}
* @returns {Promise<Array<[string,string]>>} [[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 []
}

View File

@ -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 () => {