diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4d3c8a95..713d912a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,10 +11,10 @@ repos: # - id: black # args: [--config=./pyproject.toml] - # - repo: https://github.com/pre-commit/mirrors-mypy - # rev: v0.910 - # hooks: - # - id: mypy + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.13.0 + hooks: + - id: mypy # - repo: https://github.com/pre-commit/pre-commit-hooks # rev: v4.0.1 diff --git a/nonebot_plugin_marshoai/azure.py b/nonebot_plugin_marshoai/azure.py index 895679e1..b21744c3 100644 --- a/nonebot_plugin_marshoai/azure.py +++ b/nonebot_plugin_marshoai/azure.py @@ -220,7 +220,7 @@ async def marsho(target: MsgTarget, event: Event, text: Optional[UniMsg] = None) ) is_reasoning_model = model_name.lower() in REASONING_MODELS usermsg = [] if is_support_image_model else "" - for i in text: + for i in text: # type: ignore if i.type == "text": if is_support_image_model: usermsg += [TextContentItem(text=i.data["text"] + nickname_prompt)] # type: ignore @@ -230,11 +230,11 @@ async def marsho(target: MsgTarget, event: Event, text: Optional[UniMsg] = None) if is_support_image_model: usermsg.append( # type: ignore ImageContentItem( - image_url=ImageUrl( - url=str(await get_image_b64(i.data["url"])) - ) - ) - ) + image_url=ImageUrl( # type: ignore + url=str(await get_image_b64(i.data["url"])) # type: ignore + ) # type: ignore + ) # type: ignore + ) # type: ignore elif config.marshoai_enable_support_image_tip: await UniMessage("*此模型不支持图片处理。").send() backup_context = await get_backup_context(target.id, target.private) diff --git a/nonebot_plugin_marshoai/config.py b/nonebot_plugin_marshoai/config.py index 53cb7ef9..db4743c7 100644 --- a/nonebot_plugin_marshoai/config.py +++ b/nonebot_plugin_marshoai/config.py @@ -1,7 +1,7 @@ import shutil from pathlib import Path -import yaml as yaml_ +import yaml as yaml_ # type: ignore from nonebot import get_plugin_config, logger from pydantic import BaseModel from ruamel.yaml import YAML diff --git a/nonebot_plugin_marshoai/tools/marshoai-megakits/__init__.py b/nonebot_plugin_marshoai/tools/marshoai-megakits/__init__.py deleted file mode 100644 index 16abf7d1..00000000 --- a/nonebot_plugin_marshoai/tools/marshoai-megakits/__init__.py +++ /dev/null @@ -1,41 +0,0 @@ -from . import mk_Common, mk_Info, mk_MorseCode, mk_NyaCode - - -# Twisuki -async def twisuki(): - return str(await mk_Info.twisuki()) - - -# MegaKits -async def megakits(): - return str(await mk_Info.megakits()) - - -# Random Turntable -async def random_turntable(upper: int, lower: int = 0): - return str(await mk_Common.random_turntable(upper, lower)) - - -# Number Calc -async def number_calc(a: str, b: str, op: str): - return str(await mk_Common.number_calc(a, b, op)) - - -# MorseCode Encrypt -async def morse_encrypt(msg: str): - return str(await mk_MorseCode.morse_encrypt(msg)) - - -# MorseCode Decrypt -async def morse_decrypt(msg: str): - return str(await mk_MorseCode.morse_decrypt(msg)) - - -# NyaCode Encrypt -async def nya_encode(msg: str): - return str(await mk_NyaCode.nya_encode(msg)) - - -# NyaCode Decrypt -async def nya_decode(msg: str): - return str(await mk_NyaCode.nya_decode(msg)) diff --git a/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Common.py b/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Common.py deleted file mode 100644 index d2c914c7..00000000 --- a/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Common.py +++ /dev/null @@ -1,26 +0,0 @@ -import random - - -# Random Turntable -async def random_turntable(upper: int, lower: int): - return random.randint(lower, upper) - - -# Number Calc -async def number_calc(a: str, b: str, op: str): - a, b = float(a), float(b) - match op: - case "+": - return str(a + b) - case "-": - return str(a - b) - case "*": - return str(a * b) - case "/": - return str(a / b) - case "**": - return str(a**b) - case "%": - return str(a % b) - case _: - return "未知运算符" diff --git a/nonebot_plugin_marshoai/tools/marshoai-bangumi/__init__.py b/nonebot_plugin_marshoai/tools/marshoai_bangumi/__init__.py similarity index 100% rename from nonebot_plugin_marshoai/tools/marshoai-bangumi/__init__.py rename to nonebot_plugin_marshoai/tools/marshoai_bangumi/__init__.py diff --git a/nonebot_plugin_marshoai/tools/marshoai-bangumi/tools.json b/nonebot_plugin_marshoai/tools/marshoai_bangumi/tools.json similarity index 100% rename from nonebot_plugin_marshoai/tools/marshoai-bangumi/tools.json rename to nonebot_plugin_marshoai/tools/marshoai_bangumi/tools.json diff --git a/nonebot_plugin_marshoai/tools/marshoai-basic/__init__.py b/nonebot_plugin_marshoai/tools/marshoai_basic/__init__.py similarity index 100% rename from nonebot_plugin_marshoai/tools/marshoai-basic/__init__.py rename to nonebot_plugin_marshoai/tools/marshoai_basic/__init__.py diff --git a/nonebot_plugin_marshoai/tools/marshoai-basic/tools.json b/nonebot_plugin_marshoai/tools/marshoai_basic/tools.json similarity index 100% rename from nonebot_plugin_marshoai/tools/marshoai-basic/tools.json rename to nonebot_plugin_marshoai/tools/marshoai_basic/tools.json diff --git a/nonebot_plugin_marshoai/tools/marshoai-basic/tools_test.json b/nonebot_plugin_marshoai/tools/marshoai_basic/tools_test.json similarity index 100% rename from nonebot_plugin_marshoai/tools/marshoai-basic/tools_test.json rename to nonebot_plugin_marshoai/tools/marshoai_basic/tools_test.json diff --git a/nonebot_plugin_marshoai/tools/marshoai_megakits/__init__.py b/nonebot_plugin_marshoai/tools/marshoai_megakits/__init__.py new file mode 100644 index 00000000..f16a340b --- /dev/null +++ b/nonebot_plugin_marshoai/tools/marshoai_megakits/__init__.py @@ -0,0 +1,41 @@ +from . import mk_common, mk_info, mk_morse_code, mk_nya_code + + +# Twisuki +async def twisuki(): + return str(await mk_info.twisuki()) + + +# MegaKits +async def megakits(): + return str(await mk_info.megakits()) + + +# Random Turntable +async def random_turntable(upper: int, lower: int = 0): + return str(await mk_common.random_turntable(upper, lower)) + + +# Number Calc +async def number_calc(a: str, b: str, op: str): + return str(await mk_common.number_calc(a, b, op)) + + +# MorseCode Encrypt +async def morse_encrypt(msg: str): + return str(await mk_morse_code.morse_encrypt(msg)) + + +# MorseCode Decrypt +async def morse_decrypt(msg: str): + return str(await mk_morse_code.morse_decrypt(msg)) + + +# NyaCode Encrypt +async def nya_encode(msg: str): + return str(await mk_nya_code.nya_encode(msg)) + + +# NyaCode Decrypt +async def nya_decode(msg: str): + return str(await mk_nya_code.nya_decode(msg)) diff --git a/nonebot_plugin_marshoai/tools/marshoai_megakits/mk_Common.py b/nonebot_plugin_marshoai/tools/marshoai_megakits/mk_Common.py new file mode 100644 index 00000000..c049703a --- /dev/null +++ b/nonebot_plugin_marshoai/tools/marshoai_megakits/mk_Common.py @@ -0,0 +1,45 @@ +import random + + +async def random_turntable(upper: int, lower: int): + """Random Turntable + + Args: + upper (int): _description_ + lower (int): _description_ + + Returns: + _type_: _description_ + """ + return random.randint(lower, upper) + + + +async def number_calc(a: str, b: str, op: str) -> str: + """Number Calc + + Args: + a (str): _description_ + b (str): _description_ + op (str): _description_ + + Returns: + str: _description_ + """ + a, b = float(a), float(b) # type: ignore + match op: + case "+": + return str(a + b) # type: ignore + case "-": + return str(a - b) # type: ignore + case "*": + return str(a * b) # type: ignore + case "/": + return str(a / b) # type: ignore + case "**": + return str(a**b) # type: ignore + case "%": + return str(a % b) + case _: + return "未知运算符" + \ No newline at end of file diff --git a/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Info.py b/nonebot_plugin_marshoai/tools/marshoai_megakits/mk_Info.py similarity index 100% rename from nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Info.py rename to nonebot_plugin_marshoai/tools/marshoai_megakits/mk_Info.py diff --git a/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_MorseCode.py b/nonebot_plugin_marshoai/tools/marshoai_megakits/mk_morse_code.py similarity index 100% rename from nonebot_plugin_marshoai/tools/marshoai-megakits/mk_MorseCode.py rename to nonebot_plugin_marshoai/tools/marshoai_megakits/mk_morse_code.py diff --git a/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_NyaCode.py b/nonebot_plugin_marshoai/tools/marshoai_megakits/mk_nya_code.py similarity index 100% rename from nonebot_plugin_marshoai/tools/marshoai-megakits/mk_NyaCode.py rename to nonebot_plugin_marshoai/tools/marshoai_megakits/mk_nya_code.py diff --git a/nonebot_plugin_marshoai/tools/marshoai-megakits/tools.json b/nonebot_plugin_marshoai/tools/marshoai_megakits/tools.json similarity index 100% rename from nonebot_plugin_marshoai/tools/marshoai-megakits/tools.json rename to nonebot_plugin_marshoai/tools/marshoai_megakits/tools.json diff --git a/nonebot_plugin_marshoai/tools/marshoai-meogirl/__init__.py b/nonebot_plugin_marshoai/tools/marshoai_meogirl/__init__.py similarity index 100% rename from nonebot_plugin_marshoai/tools/marshoai-meogirl/__init__.py rename to nonebot_plugin_marshoai/tools/marshoai_meogirl/__init__.py diff --git a/nonebot_plugin_marshoai/tools/marshoai-meogirl/mg_Info.py b/nonebot_plugin_marshoai/tools/marshoai_meogirl/mg_Info.py similarity index 100% rename from nonebot_plugin_marshoai/tools/marshoai-meogirl/mg_Info.py rename to nonebot_plugin_marshoai/tools/marshoai_meogirl/mg_Info.py diff --git a/nonebot_plugin_marshoai/tools/marshoai-meogirl/mg_Introduce.py b/nonebot_plugin_marshoai/tools/marshoai_meogirl/mg_Introduce.py similarity index 98% rename from nonebot_plugin_marshoai/tools/marshoai-meogirl/mg_Introduce.py rename to nonebot_plugin_marshoai/tools/marshoai_meogirl/mg_Introduce.py index 98e0026a..af0c49b9 100644 --- a/nonebot_plugin_marshoai/tools/marshoai-meogirl/mg_Introduce.py +++ b/nonebot_plugin_marshoai/tools/marshoai_meogirl/mg_Introduce.py @@ -67,7 +67,7 @@ async def introduce(msg: str): from . import mg_Search context = await mg_Search.search(msg, 1) - keyword = re.search(r".*?\n", context, flags=re.DOTALL).group()[:-1] + keyword = re.search(r".*?\n", context, flags=re.DOTALL).group()[:-1] # type: ignore logger.success(f'搜索完成, 打开"{keyword}"') return await introduce(keyword) diff --git a/nonebot_plugin_marshoai/tools/marshoai-meogirl/mg_Search.py b/nonebot_plugin_marshoai/tools/marshoai_meogirl/mg_Search.py similarity index 100% rename from nonebot_plugin_marshoai/tools/marshoai-meogirl/mg_Search.py rename to nonebot_plugin_marshoai/tools/marshoai_meogirl/mg_Search.py diff --git a/nonebot_plugin_marshoai/tools/marshoai-meogirl/tools.json b/nonebot_plugin_marshoai/tools/marshoai_meogirl/tools.json similarity index 100% rename from nonebot_plugin_marshoai/tools/marshoai-meogirl/tools.json rename to nonebot_plugin_marshoai/tools/marshoai_meogirl/tools.json diff --git a/nonebot_plugin_marshoai/tools_wip/marshoai-memory/__init__.py b/nonebot_plugin_marshoai/tools_wip/marshoai_memory/__init__.py similarity index 100% rename from nonebot_plugin_marshoai/tools_wip/marshoai-memory/__init__.py rename to nonebot_plugin_marshoai/tools_wip/marshoai_memory/__init__.py diff --git a/nonebot_plugin_marshoai/tools_wip/marshoai-memory/tools.json b/nonebot_plugin_marshoai/tools_wip/marshoai_memory/tools.json similarity index 100% rename from nonebot_plugin_marshoai/tools_wip/marshoai-memory/tools.json rename to nonebot_plugin_marshoai/tools_wip/marshoai_memory/tools.json diff --git a/nonebot_plugin_marshoai/util_hunyuan.py b/nonebot_plugin_marshoai/util_hunyuan.py index 42d24efd..43e1b86a 100644 --- a/nonebot_plugin_marshoai/util_hunyuan.py +++ b/nonebot_plugin_marshoai/util_hunyuan.py @@ -9,7 +9,7 @@ from tencentcloud.common.profile.client_profile import \ from tencentcloud.common.profile.http_profile import \ HttpProfile # type: ignore from tencentcloud.hunyuan.v20230901 import hunyuan_client # type: ignore -from tencentcloud.hunyuan.v20230901 import models +from tencentcloud.hunyuan.v20230901 import models # type: ignore from .config import config diff --git a/pyproject.toml b/pyproject.toml index 6025b644..023f358f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,4 +56,6 @@ dev = [ "pytest>=8.3.4", "pre-commit>=4.0.1", "nonebot-adapter-onebot>=2.4.6", + "mypy>=1.13.0", + "black>=24.10.0", ] \ No newline at end of file