From 847e6806c6edad999e4750a8d48430c6ca266042 Mon Sep 17 00:00:00 2001 From: shanmite Date: Mon, 7 Nov 2022 15:14:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=B0=E5=AF=8C=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E5=86=85=E5=AE=B9(#135)(#194)(#211)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed #135 Fixed #194 Fixed #211 --- lib/core/monitor.js | 4 ++-- lib/lottery.js | 12 +++++------- lib/utils.js | 48 ++++++++++++++++++++++++++++++++++++--------- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/lib/core/monitor.js b/lib/core/monitor.js index 418121c..103d8e1 100644 --- a/lib/core/monitor.js +++ b/lib/core/monitor.js @@ -66,7 +66,7 @@ class Monitor extends Searcher { case 2004: log.warn('账号异常', `UID(${global_var.get('myUID')})异常号只会对部分UP出现关注异常`) if (!config.is_exception) { - await sendNotify('[动态抽奖]账号异常通知', `UID: ${global_var.get('myUID')}\n\n异常号只会对部分UP出现关注异常\n\n可在设置中令is_exception为true关闭此推送`) + await sendNotify('[动态抽奖]账号异常通知', `UID: ${global_var.get('myUID')}\n异常号只会对部分UP出现关注异常\n可在设置中令is_exception为true关闭此推送\n${log._cache.filter(it => /Error|\[抽奖信息\]/.test(it)).join('\n')}`) } config.is_exception = true; event_bus.emit('Turn_on_the_Monitor') @@ -74,7 +74,7 @@ class Monitor extends Searcher { case 2005: log.warn('关注已达上限', `UID(${global_var.get('myUID')})关注已达上限,已临时进入只转已关注模式`) if (!config.is_outof_maxfollow) { - await sendNotify('[动态抽奖]关注已达上限', `UID: ${global_var.get('myUID')}\n\n关注已达上限,已临时进入只转已关注模式\n\n可在设置中令is_outof_maxfollow为true关闭此推送`) + await sendNotify('[动态抽奖]关注已达上限', `UID: ${global_var.get('myUID')}\n关注已达上限,已临时进入只转已关注模式\n可在设置中令is_outof_maxfollow为true关闭此推送\n${log._cache.filter(it => /Error|\[抽奖信息\]/.test(it)).join('\n')}`) } config.is_outof_maxfollow = true; config.only_followed = true; diff --git a/lib/lottery.js b/lib/lottery.js index e739c86..559633f 100644 --- a/lib/lottery.js +++ b/lib/lottery.js @@ -34,9 +34,6 @@ async function createRandomDynamic(num) { function start(num) { return new Promise(resolve => { let times = utils.counter(); - if (config.notice_running_state) { - sendNotify(`动态抽奖-帐号${num}开始抽奖`, "运行正常") - } /* 注册事件 */ event_bus.on('Turn_on_the_Monitor', async () => { const lotterys = global_var.get("Lottery"); @@ -56,11 +53,12 @@ function start(num) { await (new Monitor(lottery)).init(); }); event_bus.on('Turn_off_the_Monitor', async (msg) => { - if (config.notice_running_state) { - sendNotify(`动态抽奖-帐号${num}结束抽奖`, msg) - } - await createRandomDynamic(config.create_dy_num); log.info('结束抽奖', '原因: ' + msg); + if (config.notice_running_state) { + sendNotify(`动态抽奖-帐号${num}结束抽奖`, `${log._cache.filter(it => /抽奖\]|Error|\[抽奖信息\]/.test(it)).join('\n')}`); + } + log._cache.length = 0; + await createRandomDynamic(config.create_dy_num); event_bus.flush(); resolve(); }) diff --git a/lib/utils.js b/lib/utils.js index fcaec1e..ba09a05 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -189,8 +189,8 @@ const utils = { chalk.hex('#64B3FF'), chalk.grey, chalk.hex('#FFA500'), chalk.hex('#0070BB'), chalk.hex('#48BB31'), chalk.hex('#BBBB23'), chalk.hex('#FF0006') ], - _iso_time: () => new Date(Date.now() + 288e5).toISOString().slice(0, -1) + '+08' - , + _iso_time: () => new Date(Date.now() + 288e5).toISOString().slice(0, -1) + '+08', + _cache: [], /** * 初始化默认level为3 */ @@ -229,20 +229,50 @@ const utils = { debug(context, msg) { if (this._level > 3) { if (msg instanceof Object) msg = JSON.stringify(msg, null, 4); - this.proPrint([this._colors[0](`[${this._iso_time()}]`), this._colors[1]("[Debug]"), this._colors[2](`[帐号${process.env["NUMBER"]} ${context}]`), this._colors[3](`[\n${msg}\n]`)]) + let color_text_pair = [ + [this._colors[0], `[${this._iso_time()}]`], + [this._colors[1], "[Debug]"], + [this._colors[2], `[帐号${process.env["NUMBER"]} ${context}]`], + [this._colors[3], `[\n${msg}\n]`], + ]; + this.proPrint(color_text_pair.map(([color, text]) => color(text))) } }, info(context, msg) { - if (this._level > 2) - this.proPrint([this._colors[0](`[${this._iso_time()}]`), this._colors[1]("[Info]"), this._colors[2](`[帐号${process.env["NUMBER"]} ${context}]`), this._colors[4](`[${msg}]`)]) + if (this._level > 2) { + let color_text_pair = [ + [this._colors[0], `[${this._iso_time()}]`], + [this._colors[1], "[Info]"], + [this._colors[2], `[帐号${process.env["NUMBER"]} ${context}]`], + [this._colors[4], `[${msg}]`], + ]; + this._cache.push(color_text_pair.map(it => it[1]).join(' ')); + this.proPrint(color_text_pair.map(([color, text]) => color(text))) + } }, warn(context, msg) { - if (this._level > 1) - this.proPrint([this._colors[0](`[${this._iso_time()}]`), this._colors[1]("[Warn]"), this._colors[2](`[帐号${process.env["NUMBER"]} ${context}]`), this._colors[5](`[\n${msg}\n]`)]) + if (this._level > 1) { + let color_text_pair = [ + [this._colors[0], `[${this._iso_time()}]`], + [this._colors[1], "[Warn]"], + [this._colors[2], `[帐号${process.env["NUMBER"]} ${context}]`], + [this._colors[5], `[\n${msg}\n]`], + ]; + this._cache.push(color_text_pair.map(it => it[1]).join(' ')); + this.proPrint(color_text_pair.map(([color, text]) => color(text))) + } }, error(context, msg) { - if (this._level > 0) - this.proPrint([this._colors[0](`[${this._iso_time()}]`), this._colors[1]("[Error]"), this._colors[2](`[帐号${process.env["NUMBER"]} ${context}]`), this._colors[6](`[\n${msg}\n]`)]) + if (this._level > 0) { + let color_text_pair = [ + [this._colors[0], `[${this._iso_time()}]`], + [this._colors[1], "[Error]"], + [this._colors[2], `[帐号${process.env["NUMBER"]} ${context}]`], + [this._colors[6], `[\n${msg}\n]`], + ]; + this._cache.push(color_text_pair.map(it => it[1]).join(' ')); + this.proPrint(color_text_pair.map(([color, text]) => color(text))) + } } }, /**