From 8114d74ec55c736c213643096a2ccca2ee5cf5d6 Mon Sep 17 00:00:00 2001 From: Twisuki Date: Thu, 5 Dec 2024 10:56:13 +0800 Subject: [PATCH 1/7] modified: pyproject.toml nonebot_plugin_marshoai/tools/marshoai-megakits/ --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 21cdc918..81bd7ee2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,7 @@ plugins = ["nonebot_plugin_marshoai"] # 测试用 adapters = [ { name = "OneBot V11", module_name = "nonebot.adapters.onebot.v11" }, + {name = "Console", module_name = "nonebot.adapters.console"}, ] [tool.pdm] From 5d1cdecfc0785e45bd47cefa63ebbcd5860c02c2 Mon Sep 17 00:00:00 2001 From: Twisuki Date: Thu, 5 Dec 2024 12:29:42 +0800 Subject: [PATCH 2/7] modified: nonebot_plugin_marshoai/models.py new file: nonebot_plugin_marshoai/tools/marshoai-megakits/a.py nonebot_plugin_marshoai/tools/marshoai-megakits/__init__.py nonebot_plugin_marshoai/tools/marshoai-megakits/tools.json --- nonebot_plugin_marshoai/models.py | 17 +++++++++++++---- .../tools/marshoai-megakits/a.py | 5 +++++ 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 nonebot_plugin_marshoai/tools/marshoai-megakits/a.py diff --git a/nonebot_plugin_marshoai/models.py b/nonebot_plugin_marshoai/models.py index 3447946a..0526b4c6 100644 --- a/nonebot_plugin_marshoai/models.py +++ b/nonebot_plugin_marshoai/models.py @@ -1,9 +1,12 @@ +from nonebot_plugin_alconna.uniseg.adapters import module + from .util import * from .config import config import os import re import json import importlib +import sys # import importlib.util import traceback @@ -74,6 +77,11 @@ class MarshoTools: for package_name in os.listdir(tools_dir): package_path = os.path.join(tools_dir, package_name) + + logger.info(f"尝试加载工具包 {package_name}") + + sys.path.append(package_path) + if os.path.isdir(package_path) and os.path.exists( os.path.join(package_path, "__init__.py") ): @@ -84,13 +92,14 @@ class MarshoTools: data = json.load(json_file) for i in data: self.tools_list.append(i) - # 导入包 + spec = importlib.util.spec_from_file_location( package_name, os.path.join(package_path, "__init__.py") ) - package = importlib.util.module_from_spec(spec) - spec.loader.exec_module(package) - self.imported_packages[package_name] = package + module = importlib.util.module_from_spec(spec) + sys.modules[spec.name] = module + spec.loader.exec_module(sys.modules[spec.name]) + logger.success(f"成功加载工具包 {package_name}") except json.JSONDecodeError as e: logger.error(f"解码 JSON {json_path} 时发生错误: {e}") diff --git a/nonebot_plugin_marshoai/tools/marshoai-megakits/a.py b/nonebot_plugin_marshoai/tools/marshoai-megakits/a.py new file mode 100644 index 00000000..930ad197 --- /dev/null +++ b/nonebot_plugin_marshoai/tools/marshoai-megakits/a.py @@ -0,0 +1,5 @@ +from nonebot import logger + + +def b () : + logger.success("测试成功") \ No newline at end of file From 4f92bdd6b60f06dc1b7878ca335b0dd985e0f9b7 Mon Sep 17 00:00:00 2001 From: Twisuki Date: Thu, 5 Dec 2024 13:13:01 +0800 Subject: [PATCH 3/7] modified: nonebot_plugin_marshoai/models.py nonebot_plugin_marshoai/tools/marshoai-megakits/__init__.py nonebot_plugin_marshoai/tools/marshoai-megakits/tools.json --- nonebot_plugin_marshoai/models.py | 11 ++++++----- nonebot_plugin_marshoai/util.py | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/nonebot_plugin_marshoai/models.py b/nonebot_plugin_marshoai/models.py index 0526b4c6..918bd015 100644 --- a/nonebot_plugin_marshoai/models.py +++ b/nonebot_plugin_marshoai/models.py @@ -1,4 +1,6 @@ from nonebot_plugin_alconna.uniseg.adapters import module +from requests.packages import package +from six import spec_from_loader from .util import * from .config import config @@ -80,8 +82,6 @@ class MarshoTools: logger.info(f"尝试加载工具包 {package_name}") - sys.path.append(package_path) - if os.path.isdir(package_path) and os.path.exists( os.path.join(package_path, "__init__.py") ): @@ -96,9 +96,10 @@ class MarshoTools: spec = importlib.util.spec_from_file_location( package_name, os.path.join(package_path, "__init__.py") ) - module = importlib.util.module_from_spec(spec) - sys.modules[spec.name] = module - spec.loader.exec_module(sys.modules[spec.name]) + package = importlib.util.module_from_spec(spec) + self.imported_packages[package_name] = package + sys.modules[package_name] = package + spec.loader.exec_module(package) logger.success(f"成功加载工具包 {package_name}") except json.JSONDecodeError as e: diff --git a/nonebot_plugin_marshoai/util.py b/nonebot_plugin_marshoai/util.py index 17f3c1e4..4ca295f7 100644 --- a/nonebot_plugin_marshoai/util.py +++ b/nonebot_plugin_marshoai/util.py @@ -96,6 +96,7 @@ async def make_chat( client: 用于与AI模型进行通信 msg: 消息内容 model_name: 指定AI模型名""" + return await client.complete( messages=msg, model=model_name, From 4f67d0c79461f232c1017c0c2cfaa0d3f8106707 Mon Sep 17 00:00:00 2001 From: Twisuki Date: Thu, 5 Dec 2024 13:45:54 +0800 Subject: [PATCH 4/7] deleted: nonebot_plugin_marshoai/tools/marshoai-megakits/a.py new file: nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Common.py new file: nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Info.py new file: nonebot_plugin_marshoai/tools/marshoai-megakits/mk_MorseCode.py new file: nonebot_plugin_marshoai/tools/marshoai-megakits/mk_NyaCode.py nonebot_plugin_marshoai/tools/marshoai-megakits/__init__.py nonebot_plugin_marshoai/tools/marshoai-megakits/tools.json --- .../tools/marshoai-megakits/a.py | 5 -- .../tools/marshoai-megakits/mk_Common.py | 24 +++++++++ .../tools/marshoai-megakits/mk_Info.py | 7 +++ .../tools/marshoai-megakits/mk_MorseCode.py | 44 ++++++++++++++++ .../tools/marshoai-megakits/mk_NyaCode.py | 52 +++++++++++++++++++ 5 files changed, 127 insertions(+), 5 deletions(-) delete mode 100644 nonebot_plugin_marshoai/tools/marshoai-megakits/a.py create mode 100644 nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Common.py create mode 100644 nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Info.py create mode 100644 nonebot_plugin_marshoai/tools/marshoai-megakits/mk_MorseCode.py create mode 100644 nonebot_plugin_marshoai/tools/marshoai-megakits/mk_NyaCode.py diff --git a/nonebot_plugin_marshoai/tools/marshoai-megakits/a.py b/nonebot_plugin_marshoai/tools/marshoai-megakits/a.py deleted file mode 100644 index 930ad197..00000000 --- a/nonebot_plugin_marshoai/tools/marshoai-megakits/a.py +++ /dev/null @@ -1,5 +0,0 @@ -from nonebot import logger - - -def b () : - logger.success("测试成功") \ No newline at end of file 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..5d96525d --- /dev/null +++ b/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Common.py @@ -0,0 +1,24 @@ +import random + +# Random Turntable +async def random_turntable(upper: int, lower: int = "0"): + return random.randint(lower, upper) + +# Number Calc +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 "未知运算符" \ 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 new file mode 100644 index 00000000..c9611e95 --- /dev/null +++ b/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Info.py @@ -0,0 +1,7 @@ +# Twisuki +def twisuki(): + return "Twiuski(苏阳)是megakits插件作者, Github : 'https://github.com/Twisuki'" + +# MegaKits +def megakits(): + return "MegaKits插件是一个功能混杂的MarshoAI插件, 由Twisuki(Github : 'https://github.com/Twisuki')开发, 插件仓库 : 'https://github.com/Twisuki/marsho-toolsets/tree/main/Twisuki/marshoai-megakits'" diff --git a/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_MorseCode.py b/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_MorseCode.py new file mode 100644 index 00000000..e81e0cad --- /dev/null +++ b/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_MorseCode.py @@ -0,0 +1,44 @@ +# MorseCode +MorseEncode = { + 'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.', + 'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..', + 'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.', + 'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-', + 'Y': '-.--', 'Z': '--..', + '1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....', + '6': '-....', '7': '--...', '8': '---..', '9': '----.', '0': '-----', + '.': '.-.-.-', ':': '---...', ',': '--..--', ';': '-.-.-.', + '?': '..--..', '=': '-...-', '\'': '.----.', '/': '-..-.', + '!': '-.-.--', '-': '-....-', '_': '..--.-', '\"': '.-..-.', + '(': '-.--.', ')': '-.--.-', '$': '...-..-', '&': '....', + '@': '.--.-.', ' ': ' ' +} +MorseDecode = {value: key for key, value in MorseEncode.items()} + + +# MorseCode Encrypt +def morse_encrypt(msg: str): + result = "" + msg = msg.upper() + for char in msg: + if char in MorseEncode: + result += MorseEncode[char] + else: + result += '..--..' + result += ' ' + + return result + + +# MorseCode Decrypt +def morse_decrypt(msg: str): + result = "" + + msg_arr = msg.split() + for char in msg_arr: + if char in MorseDecode: + result += MorseDecode[char] + else: + result += '?' + + return result diff --git a/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_NyaCode.py b/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_NyaCode.py new file mode 100644 index 00000000..299394b6 --- /dev/null +++ b/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_NyaCode.py @@ -0,0 +1,52 @@ +import random +import base64 + +# NyaCode +NyaCodeCharset = [ + '喵', '呜', '?', '~' +] +NyaCodeSpecialCharset = [ + '唔', '!', '...', '....' +] +NyaCodeEncode = {} +for i in range(64): + triplet = ''.join(NyaCodeCharset[(i // (4 ** j)) % 4] for j in range(3)) + NyaCodeEncode[chr(65 + i if i < 26 else 97 + (i - 26) if i < 52 else 48 + (i - 52) if i < 62 else ( + 43 if i == 62 else 47))] = triplet +NyaCodeDecode = {value: key for key, value in NyaCodeEncode.items()} + + +# NyaCode Encrypt +def nya_encode(msg: str): + msg_b64str = base64.b64encode(msg.encode()).decode().replace('=', '') + msg_nyastr = ''.join(NyaCodeEncode[base64_char] for base64_char in msg_b64str) + result = "" + for char in msg_nyastr: + if random.random() < 0.2: + result += random.choice(NyaCodeSpecialCharset) + char + else: + result += char + return result + + +# NyaCode Decrypt +def nya_decode(msg: str): + msg = msg.replace('唔', '').replace('.', '').replace('!', '') + msg_nyastr = [] + i = 0 + if len(msg) % 3 != 0 : + return "这句话不是正确的猫语" + while i < len(msg): + nyachar = msg[i : i + 3] + try: + if all(char in NyaCodeCharset for char in nyachar): + msg_nyastr.append(nyachar) + i += 3 + except Exception: + return "这句话不是正确的猫语" + msg_b64str = ''.join(NyaCodeDecode[nya_char] for nya_char in msg_nyastr) + try: + result = base64.b64decode(msg_b64str.encode()).decode() + except Exception: + return "翻译失败" + return result From 5a73bf6761133d6468c045a1b9972a0fe6ccf845 Mon Sep 17 00:00:00 2001 From: Twisuki Date: Thu, 5 Dec 2024 18:39:52 +0800 Subject: [PATCH 5/7] modified: nonebot_plugin_marshoai/models.py modified: nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Info.py modified: nonebot_plugin_marshoai/util.py modified: pyproject.toml nonebot_plugin_marshoai/tools/marshoai-megakits/__init__.py nonebot_plugin_marshoai/tools/marshoai-megakits/tools.json --- nonebot_plugin_marshoai/models.py | 5 ----- nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Info.py | 2 +- nonebot_plugin_marshoai/util.py | 1 - pyproject.toml | 1 - 4 files changed, 1 insertion(+), 8 deletions(-) diff --git a/nonebot_plugin_marshoai/models.py b/nonebot_plugin_marshoai/models.py index 918bd015..0b81b27f 100644 --- a/nonebot_plugin_marshoai/models.py +++ b/nonebot_plugin_marshoai/models.py @@ -1,11 +1,6 @@ -from nonebot_plugin_alconna.uniseg.adapters import module -from requests.packages import package -from six import spec_from_loader - from .util import * from .config import config import os -import re import json import importlib import sys diff --git a/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Info.py b/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Info.py index c9611e95..f89bc32c 100644 --- a/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Info.py +++ b/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Info.py @@ -4,4 +4,4 @@ def twisuki(): # MegaKits def megakits(): - return "MegaKits插件是一个功能混杂的MarshoAI插件, 由Twisuki(Github : 'https://github.com/Twisuki')开发, 插件仓库 : 'https://github.com/Twisuki/marsho-toolsets/tree/main/Twisuki/marshoai-megakits'" + return "MegaKits插件是一个功能混杂的MarshoAI插件, 由Twisuki(Github : 'https://github.com/Twisuki')开发, 插件仓库 : 'https://github.com/LiteyukiStudio/marsho-toolsets/tree/main/Twisuki/marshoai-megakits'" diff --git a/nonebot_plugin_marshoai/util.py b/nonebot_plugin_marshoai/util.py index 4ca295f7..17f3c1e4 100644 --- a/nonebot_plugin_marshoai/util.py +++ b/nonebot_plugin_marshoai/util.py @@ -96,7 +96,6 @@ async def make_chat( client: 用于与AI模型进行通信 msg: 消息内容 model_name: 指定AI模型名""" - return await client.complete( messages=msg, model=model_name, diff --git a/pyproject.toml b/pyproject.toml index 4f877a06..acb9b864 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,6 @@ plugins = ["nonebot_plugin_marshoai"] # 测试用 adapters = [ { name = "OneBot V11", module_name = "nonebot.adapters.onebot.v11" }, - {name = "Console", module_name = "nonebot.adapters.console"}, ] [tool.pdm] From a13d49a06ea2420baae25b4b2b051c6df9b41c21 Mon Sep 17 00:00:00 2001 From: Twisuki Date: Thu, 5 Dec 2024 18:39:52 +0800 Subject: [PATCH 6/7] modified: nonebot_plugin_marshoai/models.py modified: nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Info.py modified: nonebot_plugin_marshoai/util.py modified: pyproject.toml nonebot_plugin_marshoai/tools/marshoai-megakits/__init__.py nonebot_plugin_marshoai/tools/marshoai-megakits/tools.json --- nonebot_plugin_marshoai/models.py | 5 - .../tools/marshoai-megakits/__init__.py | 37 +++++ .../tools/marshoai-megakits/mk_Info.py | 2 +- .../tools/marshoai-megakits/tools.json | 142 ++++++++++++++++++ nonebot_plugin_marshoai/util.py | 1 - pyproject.toml | 1 - 6 files changed, 180 insertions(+), 8 deletions(-) create mode 100644 nonebot_plugin_marshoai/tools/marshoai-megakits/__init__.py create mode 100644 nonebot_plugin_marshoai/tools/marshoai-megakits/tools.json diff --git a/nonebot_plugin_marshoai/models.py b/nonebot_plugin_marshoai/models.py index 918bd015..0b81b27f 100644 --- a/nonebot_plugin_marshoai/models.py +++ b/nonebot_plugin_marshoai/models.py @@ -1,11 +1,6 @@ -from nonebot_plugin_alconna.uniseg.adapters import module -from requests.packages import package -from six import spec_from_loader - from .util import * from .config import config import os -import re import json import importlib import sys 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..c590b032 --- /dev/null +++ b/nonebot_plugin_marshoai/tools/marshoai-megakits/__init__.py @@ -0,0 +1,37 @@ + +from . import mk_Info +from . import mk_Common +from . import mk_MorseCode +from . import mk_NyaCode + +# Twisuki +async def twisuki(): + return str(mk_Info.twisuki()) + +# MegaKits +async def megakits(): + return str(mk_Info.megakits()) + +# Random Turntable +async def random_turntable(upper: int, lower: int = "0"): + return str(mk_Common.random_turntable(upper, lower)) + +# Number Calc +async def number_calc(a: str, b: str, op: str): + return str(mk_Common.number_calc(a, b, op)) + +# MorseCode Encrypt +async def morse_encrypt(msg: str): + return str(mk_MorseCode.morse_encrypt(msg)) + +# MorseCode Decrypt +async def morse_decrypt(msg: str): + return str(mk_MorseCode.morse_decrypt(msg)) + +# NyaCode Encrypt +async def nya_encode(msg: str): + return str(mk_NyaCode.nya_encode(msg)) + +# NyaCode Decrypt +async def nya_decode(msg: str): + return str(mk_NyaCode.nya_decode(msg)) diff --git a/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Info.py b/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Info.py index c9611e95..f89bc32c 100644 --- a/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Info.py +++ b/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_Info.py @@ -4,4 +4,4 @@ def twisuki(): # MegaKits def megakits(): - return "MegaKits插件是一个功能混杂的MarshoAI插件, 由Twisuki(Github : 'https://github.com/Twisuki')开发, 插件仓库 : 'https://github.com/Twisuki/marsho-toolsets/tree/main/Twisuki/marshoai-megakits'" + return "MegaKits插件是一个功能混杂的MarshoAI插件, 由Twisuki(Github : 'https://github.com/Twisuki')开发, 插件仓库 : 'https://github.com/LiteyukiStudio/marsho-toolsets/tree/main/Twisuki/marshoai-megakits'" diff --git a/nonebot_plugin_marshoai/tools/marshoai-megakits/tools.json b/nonebot_plugin_marshoai/tools/marshoai-megakits/tools.json new file mode 100644 index 00000000..397494f0 --- /dev/null +++ b/nonebot_plugin_marshoai/tools/marshoai-megakits/tools.json @@ -0,0 +1,142 @@ +[ + { + "type" : "function", + "function" : { + "name" : "marshoai-megakits__twisuki", + "description" : "介绍插件作者Twisuki(苏阳)" + } + }, + { + "type" : "function", + "function" : { + "name" : "marshoai-megakits__megakits", + "description" : "介绍本插件MegaKits" + } + }, + { + "type" : "function", + "function" : { + "name" : "marshoai-megakits__random_turntable", + "description" : "随机转盘, 玩家输入上下限(均为整数), 返回一个随机整数", + "parameters" : { + "type" : "object", + "properties" : { + "upper" : { + "type" : "integer", + "description" : "随机数上限" + }, + "lower" : { + "type" : "integer", + "description" : "随机数下限" + } + } + }, + "require" : [ + "upper" + ] + } + }, + { + "type" : "function", + "function" : { + "name" : "marshoai-megakits__number_calc", + "description" : "数字计算器, 可对整数 小数做加减乘除, 乘方 取余运算", + "parameters" : { + "type" : "object", + "properties" : { + "a" : { + "type" : "string", + "description" : "第一个运算数" + }, + "b" : { + "type" : "string", + "description" : "第二个运算数" + }, + "op" : { + "type" : "string", + "description" : "运算符, 目前仅支持 + - * / %(取余) **(乘方)" + } + } + }, + "require" : [ + "a", "b", "op" + ] + } + }, + { + "type" : "function", + "function" : { + "name" : "marshoai-megakits__morse_encrypt", + "description" : "摩尔斯电码加密, 输入一个字符串, 返回由.- 组成的摩尔斯电码", + "parameters" : { + "type" : "object", + "properties" : { + "msg" : { + "type" : "string", + "description" : "录入的字符串(包含字母, 数字, 部分标点符号(.:,;?='/!-_\"()$&@))" + } + }, + "require" : [ + "msg" + ] + } + } + }, + { + "type" : "function", + "function" : { + "name" : "marshoai-megakits__morse_decrypt", + "description" : "摩尔斯电码解码, 输入一个字符串(由.- 组成), 返回由解码", + "parameters" : { + "type" : "object", + "properties" : { + "msg" : { + "type" : "string", + "description" : "录入的字符串(.- )" + } + }, + "require" : [ + "msg" + ] + } + } + }, + { + "type" : "function", + "function" : { + "name" : "marshoai-megakits__nya_encode", + "description" : "转换为猫猫语", + "parameters" : { + "type" : "object", + "properties" : { + "msg" : { + "type" : "string", + "description" : "待转换的字符串" + } + }, + "require" : [ + "msg" + ] + } + } + }, + { + "type": "function", + "function": { + "name": "marshoai-megakits__nya_decode", + "description": "翻译猫语", + "parameters": { + "type": "object", + "properties": { + "msg": { + "type": "string", + "description": "录入的猫语" + } + }, + "require": [ + "msg" + ] + } + } + } +] \ No newline at end of file diff --git a/nonebot_plugin_marshoai/util.py b/nonebot_plugin_marshoai/util.py index 4ca295f7..17f3c1e4 100644 --- a/nonebot_plugin_marshoai/util.py +++ b/nonebot_plugin_marshoai/util.py @@ -96,7 +96,6 @@ async def make_chat( client: 用于与AI模型进行通信 msg: 消息内容 model_name: 指定AI模型名""" - return await client.complete( messages=msg, model=model_name, diff --git a/pyproject.toml b/pyproject.toml index 4f877a06..acb9b864 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,6 @@ plugins = ["nonebot_plugin_marshoai"] # 测试用 adapters = [ { name = "OneBot V11", module_name = "nonebot.adapters.onebot.v11" }, - {name = "Console", module_name = "nonebot.adapters.console"}, ] [tool.pdm] From 580f01d844796d60bf0483b0d71b420a380a318b Mon Sep 17 00:00:00 2001 From: Twisuki Date: Sat, 7 Dec 2024 14:15:40 +0800 Subject: [PATCH 7/7] modified: nonebot_plugin_marshoai/tools/marshoai-megakits/mk_NyaCode.py --- .../tools/marshoai-megakits/mk_NyaCode.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_NyaCode.py b/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_NyaCode.py index 299394b6..3ba1dbdc 100644 --- a/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_NyaCode.py +++ b/nonebot_plugin_marshoai/tools/marshoai-megakits/mk_NyaCode.py @@ -6,7 +6,7 @@ NyaCodeCharset = [ '喵', '呜', '?', '~' ] NyaCodeSpecialCharset = [ - '唔', '!', '...', '....' + '唔', '!', '...', '..' ] NyaCodeEncode = {} for i in range(64): @@ -22,7 +22,10 @@ def nya_encode(msg: str): msg_nyastr = ''.join(NyaCodeEncode[base64_char] for base64_char in msg_b64str) result = "" for char in msg_nyastr: - if random.random() < 0.2: + if char == '呜' and random.random() < 0.5: + result += "!" + + if random.random() < 0.25: result += random.choice(NyaCodeSpecialCharset) + char else: result += char @@ -31,7 +34,7 @@ def nya_encode(msg: str): # NyaCode Decrypt def nya_decode(msg: str): - msg = msg.replace('唔', '').replace('.', '').replace('!', '') + msg = msg.replace('唔', '').replace('!', '').replace('.', '') msg_nyastr = [] i = 0 if len(msg) % 3 != 0 : @@ -45,6 +48,7 @@ def nya_decode(msg: str): except Exception: return "这句话不是正确的猫语" msg_b64str = ''.join(NyaCodeDecode[nya_char] for nya_char in msg_nyastr) + msg_b64str += "=" * (4 - len(msg_b64str) % 4) try: result = base64.b64decode(msg_b64str.encode()).decode() except Exception: