From b6c230cfe1bd6adbc77977c2621ccd67b7656ffc Mon Sep 17 00:00:00 2001 From: Jerryplusy Date: Mon, 6 Oct 2025 15:40:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=B7=BB=E5=8A=A0=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/auth.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/apps/auth.js b/apps/auth.js index 36c339e..1ba1bb0 100644 --- a/apps/auth.js +++ b/apps/auth.js @@ -170,7 +170,7 @@ Bot.on?.('notice.group.increase', async (e) => { async function auth(e, group_id, user_id) { const cfg = await configControl.get('auth'); if (!cfg) return; - const groupCfg = cfg.groups[group_id] || cfg.default; + let groupCfg = cfg.groups[group_id] || cfg.default; if (!groupCfg.enable) return; const key = `${group_id}_${user_id}`; if (groupCfg.carbon.enable) { @@ -190,15 +190,12 @@ async function auth(e, group_id, user_id) { ]); } catch (err) { logger.error('[crystelf-plugin] 请求手性碳验证API失败..', err); + e.reply('手性碳api出现异常,已暂时切换至数字验证模式..'); + await numberAuth(e); } } else { await tools.sleep(500); - const a = Math.floor(Math.random() * 100); - const b = Math.floor(Math.random() * 100); - const op = Math.random() > 0.5 ? '+' : '-'; - const ans = op === '+' ? a + b : a - b; - pending.set(key, { type: 'math', answer: ans, tries: 0, cfg: groupCfg }); - e.reply([segment.at(user_id), `请在${groupCfg.timeout}秒内发送${a} ${op} ${b}的计算结果..`]); + await numberAuth(e); } if (groupCfg.timeout > 60) { @@ -220,3 +217,17 @@ async function auth(e, group_id, user_id) { } }, groupCfg.timeout * 1000); } + +/** + * 数字验证逻辑 + * @param e + * @returns {Promise} + */ +async function numberAuth(e) { + const a = Math.floor(Math.random() * 100); + const b = Math.floor(Math.random() * 100); + const op = Math.random() > 0.5 ? '+' : '-'; + const ans = op === '+' ? a + b : a - b; + pending.set(key, { type: 'math', answer: ans, tries: 0, cfg: groupCfg }); + e.reply([segment.at(user_id), `请在${groupCfg.timeout}秒内发送${a} ${op} ${b}的计算结果..`]); +}