From 26960be27efc5203d8a33c5ea534012223099621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sat, 27 Jan 2024 18:39:05 +0800 Subject: [PATCH] add wa safecheck --- modules/dice/locales/en_us.json | 16 ++++++++-------- modules/dice/locales/zh_cn.json | 14 +++++++------- modules/dice/locales/zh_tw.json | 14 +++++++------- modules/ip/__init__.py | 2 +- modules/wolframalpha/__init__.py | 7 ++++--- modules/wolframalpha/check.py | 11 +++++++++++ 6 files changed, 38 insertions(+), 26 deletions(-) create mode 100644 modules/wolframalpha/check.py diff --git a/modules/dice/locales/en_us.json b/modules/dice/locales/en_us.json index cb37475d..81caa14a 100644 --- a/modules/dice/locales/en_us.json +++ b/modules/dice/locales/en_us.json @@ -1,17 +1,17 @@ { "dice.help": "Roll the specified dice. You can specify the number of dice rolls and DC check.", "dice.help.desc": "Random dice.", - "dice.help.rule": "Modify the check rule of DC.", "dice.help.option.dc": "Check when the result of each roll. If the result meets the DC, the check is a success, otherwise is a failure.", "dice.help.option.klx": "The output of the smallest sum of x dice points.", "dice.help.option.kx": "The output of the biggest sum of x dice points.", "dice.help.option.m": "The number of dice, output The sum of all its points, default 1.", - "dice.help.option.N": "Repeat the polynomial operation N times (roll N times) and then output N results.", "dice.help.option.n": "The number of sides of the dice.", + "dice.help.option.N": "Repeat the polynomial operation N times (roll N times) and then output N results.", "dice.help.option.polynomial": "Format \"[x][]d[k(l)][±]...\", e.g., \"10d4-2d20\" will output the sum of the points of 10 4-sided dice minus the sum of the points of 2 20-sided dice.", "dice.help.option.polynomial.title": "Polynomial", "dice.help.option.y": "The polynomial can be an integer (adjustment value). e.g., \"d20+5\" will output the result of adding 5 to the number of a 20-sided die.", "dice.help.regex.desc": "(扔|投|掷|丢)个[面]骰子 Roll the specified dice.", + "dice.help.rule": "Modify the check rule of DC.", "dice.message.dc.check": "▷ Check Success: ${success} Check Failure: ${failed}", "dice.message.dc.failed": " Failed!", "dice.message.dc.success": " Success!", @@ -29,15 +29,15 @@ "dice.message.error.value.m.invalid": "Invalid number of dice.", "dice.message.error.value.n.d1": "D...D1?", "dice.message.error.value.n.invalid": "Invalid number of sides of the die.", - "dice.message.error.value.n.out_of_range": "The number of dice cannot be less than 1 or greater than ${max}.", + "dice.message.error.value.n.less_2": "The number of sides of the die cannot be less than 2.", "dice.message.error.value.N.out_of_range": "The number of die rolls cannot be less than 1 or greater than ${max}.", + "dice.message.error.value.n.out_of_range": "The number of dice cannot be less than 1 or greater than ${max}.", "dice.message.error.value.too_long": "The number of items in the dice polynomial exceeds the limit.", + "dice.message.error.value.y.invalid": "Invalid adjustment value", + "dice.message.error.value.y.out_of_range": "The adjustment value cannot be less than ${min} or greater than ${max}.", "dice.message.output": "Your result: ", "dice.message.output.too_long": "${length} items have been omitted", "dice.message.rule.disable": "The check rule has been changed to forward.", "dice.message.rule.enable": "The check rule has been changed to reverse.", - "dice.message.too_long": "Output is too long...", - "dice.message.error.value.y.invalid": "Invalid adjustment value", - "dice.message.error.value.y.out_of_range": "The adjustment value cannot be less than ${min} or greater than ${max}.", - "dice.message.error.value.n.less_2": "The number of sides of the die cannot be less than 2." -} + "dice.message.too_long": "Output is too long..." +} \ No newline at end of file diff --git a/modules/dice/locales/zh_cn.json b/modules/dice/locales/zh_cn.json index 8dc05b33..650a3288 100644 --- a/modules/dice/locales/zh_cn.json +++ b/modules/dice/locales/zh_cn.json @@ -1,17 +1,17 @@ { "dice.help": "投掷指定骰子,可指定投骰次数与 DC 判断判定。", "dice.help.desc": "随机骰子。", - "dice.help.rule": "修改 DC 的判定规则。", "dice.help.option.dc": "在每一次投掷输出结果时进行判定,若结果符合 DC 则判定为成功,否则判定失败。", "dice.help.option.klx": "表示输出其最小的 x 个骰子点数之和。", "dice.help.option.kx": "表示输出其最大的 x 个骰子点数之和。", "dice.help.option.m": "表示骰子数量,输出其所有点数之和,省略则默认 1。", - "dice.help.option.N": "将多项式的操作重复 N 次(投骰 N 次),之后输出 N 个结果。", "dice.help.option.n": "表示骰子面数。", + "dice.help.option.N": "将多项式的操作重复 N 次(投骰 N 次),之后输出 N 个结果。", "dice.help.option.polynomial": "格式为“[x][]d[k(l)][±]...”,如“10d4-2d20”会输出 10 个 4 面骰所有点数之和减去 2 个 20 面骰点数之和。", "dice.help.option.polynomial.title": "多项式", "dice.help.option.y": "多项式中可以是整数(即调节值),如“d20+5”会输出 1 个 20 面骰的点数加上 5 的结果。", "dice.help.regex.desc": "(扔|投|掷|丢)个[面]骰子[次] 投掷指定骰子。", + "dice.help.rule": "修改 DC 的判定规则。", "dice.message.dc.check": "▷ 判定成功数量:${success} 判定失败数量:${failed}", "dice.message.dc.failed": " 判定失败!", "dice.message.dc.success": " 判定成功!", @@ -29,15 +29,15 @@ "dice.message.error.value.m.invalid": "无效的骰子数量。", "dice.message.error.value.n.d1": "1……1 面的骰子?", "dice.message.error.value.n.invalid": "无效的骰子面数。", - "dice.message.error.value.n.out_of_range": "骰子数量不得小于 1 或大于 ${max}。", + "dice.message.error.value.n.less_2": "骰子面数不得小于 2。", "dice.message.error.value.N.out_of_range": "投骰次数不得小于 1 或大于 ${max}。", + "dice.message.error.value.n.out_of_range": "骰子数量不得小于 1 或大于 ${max}。", "dice.message.error.value.too_long": "骰子多项式项数超过限制。", + "dice.message.error.value.y.invalid": "无效的调节值项。", + "dice.message.error.value.y.out_of_range": "调节值不得小于 ${min} 或大于 ${max}。", "dice.message.output": "你掷得的结果是:", "dice.message.output.too_long": "数量过大,已省略 ${length} 条数据", "dice.message.rule.disable": "判定规则已更改为正向。", "dice.message.rule.enable": "判定规则已更改为反向。", - "dice.message.too_long": "输出过长……", - "dice.message.error.value.y.invalid": "无效的调节值项。", - "dice.message.error.value.y.out_of_range": "调节值不得小于 ${min} 或大于 ${max}。", - "dice.message.error.value.n.less_2": "骰子面数不得小于 2。" + "dice.message.too_long": "输出过长……" } \ No newline at end of file diff --git a/modules/dice/locales/zh_tw.json b/modules/dice/locales/zh_tw.json index 418346ef..567dc448 100644 --- a/modules/dice/locales/zh_tw.json +++ b/modules/dice/locales/zh_tw.json @@ -1,17 +1,17 @@ { "dice.help": "投擲指定骰子,可指定投骰次數與 dc 判斷判定。", "dice.help.desc": "隨機骰子。", - "dice.help.rule": "修改 DC 的判定規則。", "dice.help.option.dc": "在每一次投擲輸出結果時進行判定,若結果符合 DC 則判定成功,否則判定失敗。", "dice.help.option.klx": "表示輸出其最小之 x 個骰子點數之和。", "dice.help.option.kx": "表示輸出其最大之 x 個骰子點數之和。", "dice.help.option.m": "表示骰子數量,輸出其所有點數之和,省略則預設 1。", - "dice.help.option.N": "將多項式的行為重複 N 次(投骰 N 次),之後輸出 N 個結果。", "dice.help.option.n": "表示骰子面數。", + "dice.help.option.N": "將多項式的行為重複 N 次(投骰 N 次),之後輸出 N 個結果。", "dice.help.option.polynomial": "格式為「[#][]d[k(l)][±]...」,如「10d4-2d20」會輸出 10 個 4 面骰所有點數之和減去 2 個 20 面骰點數之和。", "dice.help.option.polynomial.title": "多項式", "dice.help.option.y": "多項式中可以是整數(即調整值),如「d20+5」會輸出 1 個 20 面骰的點數加上 5 的結果。", "dice.help.regex.desc": "(扔|投|擲|丟)個[面]骰子[次] 投擲指定骰子。", + "dice.help.rule": "修改 DC 的判定規則。", "dice.message.dc.check": "▷ 判定成功數量:${success} 判定失敗數量:${failed}", "dice.message.dc.failed": " 判定失敗!", "dice.message.dc.success": " 判定成功!", @@ -29,15 +29,15 @@ "dice.message.error.value.m.invalid": "無效的骰子數量。", "dice.message.error.value.n.d1": "1……1 面的骰子?", "dice.message.error.value.n.invalid": "無效的骰子面數。", - "dice.message.error.value.n.out_of_range": "骰子數量不得小於 1 或大於 ${max}。", + "dice.message.error.value.n.less_2": "骰子面數不得小於 2。", "dice.message.error.value.N.out_of_range": "投骰次數不得小於 1 或大於 ${max}。", + "dice.message.error.value.n.out_of_range": "骰子數量不得小於 1 或大於 ${max}。", "dice.message.error.value.too_long": "骰子多項式項數超過限制。", + "dice.message.error.value.y.invalid": "無效的調整值項。", + "dice.message.error.value.y.out_of_range": "調整值不得小於 ${min} 或大於 ${max}。", "dice.message.output": "你掷得的結果是:", "dice.message.output.too_long": "數量過大,已省略 ${length} 條資訊", "dice.message.rule.disable": "判定規則已更改為正向。", "dice.message.rule.enable": "判定規則已更改為反向。", - "dice.message.too_long": "輸出過長……", - "dice.message.error.value.y.invalid": "無效的調整值項。", - "dice.message.error.value.y.out_of_range": "調整值不得小於 ${min} 或大於 ${max}。", - "dice.message.error.value.n.less_2": "骰子面數不得小於 2。" + "dice.message.too_long": "輸出過長……" } \ No newline at end of file diff --git a/modules/ip/__init__.py b/modules/ip/__init__.py index 3a0c5de7..0355113b 100644 --- a/modules/ip/__init__.py +++ b/modules/ip/__init__.py @@ -18,7 +18,7 @@ async def _(msg: Bot.MessageSession, ip_address: str): except BaseException: await msg.finish(msg.locale.t('ip.message.error.unknown')) res = await check_ip(ip_address) - await msg.finish(await format_ip(msg, res)) + await msg.finish(await format_ip(msg, res), disable_secret_check=True) async def check_ip(ip: str): diff --git a/modules/wolframalpha/__init__.py b/modules/wolframalpha/__init__.py index 5a4b7c7e..420cd863 100644 --- a/modules/wolframalpha/__init__.py +++ b/modules/wolframalpha/__init__.py @@ -5,9 +5,10 @@ from PIL import Image from config import Config from core.builtins import Bot, Image as BImage from core.component import module -from core.dirty_check import check_bool, rickroll +from core.dirty_check import rickroll from core.exceptions import ConfigValueError from core.utils.http import download_to_cache, get_url +from .check import safe_check appid = Config('wolfram_alpha_appid') @@ -22,7 +23,7 @@ w = module( @w.handle(' {{wolframalpha.help}}') async def _(msg: Bot.MessageSession, query: str): - if await check_bool(query): + if await safe_check(query): await msg.finish(rickroll(msg)) url_query = urllib.parse.quote(query) if not appid: @@ -44,7 +45,7 @@ async def _(msg: Bot.MessageSession, query: str): @w.handle('ask {{wolframalpha.help.ask}}') async def _(msg: Bot.MessageSession, question: str): - if await check_bool(question): + if await safe_check(question): await msg.finish(rickroll(msg)) url_query = urllib.parse.quote(question) if not appid: diff --git a/modules/wolframalpha/check.py b/modules/wolframalpha/check.py new file mode 100644 index 00000000..508d646d --- /dev/null +++ b/modules/wolframalpha/check.py @@ -0,0 +1,11 @@ +unsafe_word_list = [ + "ip", + "where am i", + "where i am", + ] + +async def safe_check(msg, query): + for word in unsafe_word_list: + if word in query.lower(): + return False + return True \ No newline at end of file