diff --git a/assets/config_store/en_us/config.toml b/assets/config_store/en_us/config.toml index d9644260ef..659abad4fd 100644 --- a/assets/config_store/en_us/config.toml +++ b/assets/config_store/en_us/config.toml @@ -36,10 +36,6 @@ gained_petal_limit = 0 # The maximum number of petals users can get per day. lost_petal_limit = 0 # The maximum number of petals users can lose per day. use_secrets_random = false # Whether to use the random number generator based on the secrets library. web_render_local = "" # The local WebRender service address. -enable_langsmith = "" -langsmith_endpoint = "" -langsmith_project = "" -langsmith_api_key = "" coin_limit = 10000 # The maximum number of coins tossed of coin module. coin_faceup_weight = 4997 # The weight of heads of the coins tossed of coin module. coin_facedown_weight = 4997 # The weight of tails of the coins tossed of coin module. diff --git a/assets/config_store/zh_cn/config.toml b/assets/config_store/zh_cn/config.toml index d1292b7c86..be8a1fb4ca 100644 --- a/assets/config_store/zh_cn/config.toml +++ b/assets/config_store/zh_cn/config.toml @@ -36,10 +36,6 @@ gained_petal_limit = 0 # 单日获取花瓣上限。 lost_petal_limit = 0 # 单日失去花瓣上限。 use_secrets_random = false # 是否使用基于 secrets 库的随机数生成器。 web_render_local = "" # 本地 WebRender 服务地址。 -enable_langsmith = "" -langsmith_endpoint = "" -langsmith_project = "" -langsmith_api_key = "" coin_limit = 10000 # coin 模块可抛硬币的上限。 coin_faceup_weight = 4997 # coin 模块抛硬币时正面的权重。 coin_facedown_weight = 4997 # coin 模块抛硬币时反面的权重。 diff --git a/assets/config_store/zh_tw/config.toml b/assets/config_store/zh_tw/config.toml index 685898be1b..f8535f2171 100644 --- a/assets/config_store/zh_tw/config.toml +++ b/assets/config_store/zh_tw/config.toml @@ -36,10 +36,6 @@ gained_petal_limit = 0 # 單日取得花瓣上限。 lost_petal_limit = 0 # 單日失去花瓣上限。 use_secrets_random = false # 是否使用基於 secrets 庫的隨機數產生器。 web_render_local = "" # 本地 WebRender 服務位址。 -enable_langsmith = "" -langsmith_endpoint = "" -langsmith_project = "" -langsmith_api_key = "" coin_limit = 10000 # coin 模組可拋硬幣的上限。 coin_faceup_weight = 4997 # coin 模組拋硬幣時正面的權重。 coin_facedown_weight = 4997 # coin 模組拋硬幣時反面的權重。 diff --git a/assets/config_store_packed/en_us.zip b/assets/config_store_packed/en_us.zip index 3ad9c3db05..9a35874ddf 100644 Binary files a/assets/config_store_packed/en_us.zip and b/assets/config_store_packed/en_us.zip differ diff --git a/assets/config_store_packed/zh_cn.zip b/assets/config_store_packed/zh_cn.zip index 3298b7e361..658b420f42 100644 Binary files a/assets/config_store_packed/zh_cn.zip and b/assets/config_store_packed/zh_cn.zip differ diff --git a/assets/config_store_packed/zh_tw.zip b/assets/config_store_packed/zh_tw.zip index 06c530f135..dcd006a8d6 100644 Binary files a/assets/config_store_packed/zh_tw.zip and b/assets/config_store_packed/zh_tw.zip differ diff --git a/modules/ask/__old_init__.py b/modules/ask/__old_init__.py deleted file mode 100644 index dd6092282c..0000000000 --- a/modules/ask/__old_init__.py +++ /dev/null @@ -1,126 +0,0 @@ -import io -import os -import re - -from PIL import Image as PILImage - -from core.builtins import Bot, I18NContext, Image, Plain -from core.component import module -from core.config import Config -from core.constants.exceptions import ConfigValueError -from core.dirty_check import check_bool, rickroll -from core.utils.cooldown import CoolDown -from .petal import count_token_petal - -os.environ["LANGCHAIN_TRACING_V2"] = str(Config("enable_langsmith")) -if Config("enable_langsmith"): - os.environ["LANGCHAIN_ENDPOINT"] = Config("langsmith_endpoint") - os.environ["LANGCHAIN_PROJECT"] = Config("langsmith_project") - os.environ["LANGCHAIN_API_KEY"] = Config("langsmith_api_key") - - from langchain.callbacks import get_openai_callback # noqa: E402 - from .agent import agent_executor # noqa: E402 - from .formatting import generate_latex, generate_code_snippet # noqa: E402 - - a = module("ask", developers=["Dianliang233"], desc="{ask.help.desc}", doc=True) - - @a.command("[--verbose] {{ask.help}}") - @a.regex( - r"^(?:question||问|問)[\::]\s?(.+?)[??]$", flags=re.I, desc="{ask.help.regex}" - ) - async def _(msg: Bot.MessageSession): - is_superuser = msg.check_super_user() - if not Config("openai_api_key", secret=True): - raise ConfigValueError(msg.locale.t("error.config.secret.not_found")) - if not is_superuser and msg.petal <= 0: # refuse - await msg.finish(msg.locale.t("petal.message.cost.not_enough")) - - qc = CoolDown("call_openai", msg) - c = qc.check(60) - if c == 0 or msg.target.client_name == "TEST" or is_superuser: - if hasattr(msg, "parsed_msg"): - question = msg.parsed_msg[""] - else: - question = msg.matched_msg[0] - if await check_bool(question): - await msg.finish(rickroll(msg)) - with get_openai_callback() as cb: - res = await agent_executor.arun(question) - tokens = cb.total_tokens - if not is_superuser: - petal = await count_token_petal(msg, tokens) - else: - petal = 0 - - blocks = parse_markdown(res) - - chain = [] - for block in blocks: - if block["type"] == "text": - chain.append(Plain(block["content"])) - elif block["type"] == "latex": - content = await generate_latex(block["content"]) - try: - img = PILImage.open(io.BytesIO(content)) - chain.append(Image(img)) - except Exception: - chain.append( - I18NContext("ask.message.text2img.error", text=content) - ) - elif block["type"] == "code": - content = block["content"]["code"] - try: - chain.append( - Image( - PILImage.open( - io.BytesIO( - await generate_code_snippet( - content, block["content"]["language"] - ) - ) - ) - ) - ) - except Exception: - chain.append( - I18NContext("ask.message.text2img.error", text=content) - ) - - if await check_bool(res): - await msg.finish( - f"{rickroll(msg)}\n{msg.locale.t('petal.message.cost', amount=petal)}" - ) - if petal != 0: - chain.append(I18NContext("petal.message.cost", amount=petal)) - - if msg.target.client_name != "TEST" and not is_superuser: - qc.reset() - - await msg.finish(chain) - else: - await msg.finish(msg.locale.t("message.cooldown", time=int(60 - c))) - - def parse_markdown(md: str): - regex = r"(```[\s\S]*?\n```|\$[\s\S]*?\$|[^\n]+)" - - blocks = [] - for match in re.finditer(regex, md): - content = match.group(1) - print(content) - if content.startswith("```"): - block = "code" - try: - language, code = re.match( - r"```(.*)\n([\s\S]*?)\n```", content - ).groups() - except AttributeError: - raise ValueError("Code block is missing language or code") - content = {"language": language, "code": code} - elif content.startswith("$"): - block = "latex" - content = content[1:-1].strip() - else: - block = "text" - blocks.append({"type": block, "content": content}) - - return blocks diff --git a/modules/calc/__init__.py b/modules/calc/__init__.py deleted file mode 100644 index ed70057730..0000000000 --- a/modules/calc/__init__.py +++ /dev/null @@ -1,76 +0,0 @@ -import asyncio -import os -import subprocess -import sys - -from core.builtins import Bot -from core.component import module -from core.constants.exceptions import NoReportException -from core.logger import Logger -from core.utils.info import Info - -calc_dir = os.path.dirname(os.path.abspath(__file__)) - -c = module("calc", developers=["Dianliang233"], doc=True) - -if Info.binary_mode: - - @c.command() - async def _(msg: Bot.MessageSession): - await msg.finish(msg.locale.t("calc.message.binary_mode")) - -else: - - @c.command(" {{calc.help}}") - async def _(msg: Bot.MessageSession, math_expression: str): - expr = math_expression.replace("\\", "") - res = await spawn_subprocess("/calc.py", expr, msg) - if res[:6] == "Result": - if msg.Feature.markdown: - expr = expr.replace("*", "\\*") - m = f"{expr} = {res[7:]}" - await msg.finish(m) - else: - await msg.finish(msg.locale.t("calc.message.invalid", expr=res[7:])) - - async def spawn_subprocess(file: str, arg: str, msg: Bot.MessageSession) -> str: - envs = os.environ.copy() - if sys.platform == "win32" and sys.version_info.minor < 10: - try: - return subprocess.check_output( - [sys.executable, calc_dir + file, arg], - timeout=10, - shell=False, - cwd=os.path.abspath("."), - env=envs, - ).decode("utf-8") - except subprocess.TimeoutExpired as e: - raise NoReportException(msg.locale.t("calc.message.time_out")) from e - else: - try: - p = await asyncio.create_subprocess_exec( - sys.executable, - calc_dir + file, - arg, - stdout=asyncio.subprocess.PIPE, - stderr=asyncio.subprocess.PIPE, - cwd=os.path.abspath("."), - env=envs, - ) - try: - await asyncio.wait_for(p.wait(), timeout=10) - except asyncio.TimeoutError as e: - p.kill() - raise NoReportException( - msg.locale.t("calc.message.time_out") - ) from e - stdout_data, stderr_data = await p.communicate() - if p.returncode != 0: - Logger.error(f"{file} exited with code {p.returncode}") - try: - Logger.error(f'{file} stderr: {stderr_data.decode("utf-8")}') - except UnicodeDecodeError: - Logger.error(f'{file} stderr: {stderr_data.decode("gbk")}') - return stdout_data.decode("utf-8") - except Exception as e: - raise NoReportException(e) from e diff --git a/modules/calc/calc.py b/modules/calc/calc.py deleted file mode 100644 index 234fd468a3..0000000000 --- a/modules/calc/calc.py +++ /dev/null @@ -1,96 +0,0 @@ -import ast -import cmath -import decimal -import fractions -import math -import operator as op -import statistics -import sys - -from simpleeval import ( - EvalWithCompoundTypes, - DEFAULT_FUNCTIONS, - DEFAULT_NAMES, - DEFAULT_OPERATORS, -) - -from constant import consts -from utils import invoke - -funcs = {} -named_funcs = {} - -invoke() - - -def add_func(module): - for name in dir(module): - item = getattr(module, name) - if not name.startswith("_") and callable(item): - funcs[name] = item - - -def add_named_func(module): - named_funcs[module.__name__] = {} - for name in dir(module): - item = getattr(module, name) - if not name.startswith("_") and callable(item): - named_funcs[module.__name__][name] = item - - -add_func(math) -add_func(statistics) -add_named_func(cmath) -add_named_func(decimal) -add_named_func(fractions) - -s_eval = EvalWithCompoundTypes( - operators={ - **DEFAULT_OPERATORS, - ast.BitOr: op.or_, - ast.BitAnd: op.and_, - ast.BitXor: op.xor, - ast.Invert: op.invert, - }, - functions={ - **funcs, - **DEFAULT_FUNCTIONS, - "bin": bin, - "bool": bool, - "complex": complex, - "divmod": divmod, - "hex": hex, - "len": len, - "oct": oct, - "round": round, - }, - names={ - **DEFAULT_NAMES, - **consts, - **named_funcs, - "pi": math.pi, - "e": math.e, - "tau": math.tau, - "inf": math.inf, - "nan": math.nan, - "cmath": { - "pi": cmath.pi, - "e": cmath.e, - "tau": cmath.tau, - "inf": cmath.inf, - "infj": cmath.infj, - "nan": cmath.nan, - "nanj": cmath.nanj, - **named_funcs["cmath"], - }, - }, -) - -try: # rina's rina lazy solution :rina: - res = s_eval.eval(" ".join(sys.argv[1:])) - if abs(res) >= 10**9 or abs(res) <= 10**-9: - res = "{:.10e}".format(res) - sys.stdout.write(f"Result {str(res)}") -except Exception as e: - sys.stdout.write(f"Failed {str(e)}") -sys.exit() diff --git a/modules/calc/constant.py b/modules/calc/constant.py deleted file mode 100644 index 56b7fc85f5..0000000000 --- a/modules/calc/constant.py +++ /dev/null @@ -1,17 +0,0 @@ -consts = { - "pi": "3.1415926535897932384626433832795028841971693993751", - "tansec": "4.8481368111333441675396429478852851658848753880815e-6", - "ln10": "2.3025850929940456840179914546843642076011014886288", - "wien_x": "4.9651142317442763036987591313228939440555849867973", - "wien_u": "2.8214393721220788934031913302944851953458817440731", - "eulers_number": "2.71828182845904523536028747135266249775724709369995", - "speed_of_light": "299792458", - "planck_constant": "6.62607015e-34", - "elementary_charge": "1.602176634e-19", - "avogadro_number": "6.02214076e23", - "boltzmann_constant": "1.380649e-23", - "standard_gravity": "9.80665 ** 2", - "standard_atmosphere": "1.01325e5", - "conventional_josephson_constant": "4.835979e14", - "conventional_von_klitzing_constant": "2.5812807e4", -} diff --git a/modules/calc/locales/en_us.json b/modules/calc/locales/en_us.json deleted file mode 100644 index abbd708557..0000000000 --- a/modules/calc/locales/en_us.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "calc.help": "Safely evaluate Python ast expressions.", - "calc.message.invalid": "Invalid expression: ${expr}", - "calc.message.time_out": "Calculation timeout.", - "calc.message.binary_mode": "The bot is deployed through the binary executable and therefore this module is disabled. To use the module, deploy the bot right through the source code." -} diff --git a/modules/calc/locales/zh_cn.json b/modules/calc/locales/zh_cn.json deleted file mode 100644 index a84c411a73..0000000000 --- a/modules/calc/locales/zh_cn.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "calc.help": "安全地计算 Python ast 表达式。", - "calc.message.invalid": "表达式无效:${expr}", - "calc.message.time_out": "计算超时。", - "calc.message.binary_mode": "机器人正在使用二进制部署,此模块已被禁用。如需使用此模块,请使用源代码部署机器人。" -} diff --git a/modules/calc/locales/zh_tw.json b/modules/calc/locales/zh_tw.json deleted file mode 100644 index 861a22eb77..0000000000 --- a/modules/calc/locales/zh_tw.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "calc.help": "安全地計算 Python ast 運算式。", - "calc.message.invalid": "運算式無效:${expr}", - "calc.message.time_out": "計算逾時。", - "calc.message.binary_mode": "機器人正在使用二進位部署,此模組已停用。如需使用此模組,請使用原始碼部署機器人。" -} diff --git a/modules/calc/utils.py b/modules/calc/utils.py deleted file mode 100644 index be9e917b1a..0000000000 --- a/modules/calc/utils.py +++ /dev/null @@ -1,23 +0,0 @@ -import os -import sys - - -def invoke(): - if sys.version_info.minor > 8 or ( - sys.version_info.minor == 8 and sys.version_info.micro >= 14 - ): # Added in 3.8.14, 3.7 and below not supported so - sys.set_int_max_str_digits(0) - if os.name == "posix" and os.uname().sysname != "Darwin": - os.nice(15) - import resource - - resource.setrlimit(resource.RLIMIT_AS, (16 * 1024 * 1024, 16 * 1024 * 1024)) - resource.setrlimit(resource.RLIMIT_DATA, (16 * 1024 * 1024, 16 * 1024 * 1024)) - resource.setrlimit(resource.RLIMIT_STACK, (16 * 1024 * 1024, 16 * 1024 * 1024)) - elif os.name == "nt": - import win32process - - win32process.SetPriorityClass(win32process.GetCurrentProcess(), 16384) - win32process.SetProcessWorkingSetSize( - win32process.GetCurrentProcess(), 1, 16 * 1024 * 1024 - )