mirror of
https://github.com/LiteyukiStudio/nonebot-plugin-marshoai.git
synced 2025-08-02 08:29:51 +00:00
✨ 更新 mypy 版本至 1.13.0,重构 marshoai-megakits 模块并添加随机数和计算功能
This commit is contained in:
41
nonebot_plugin_marshoai/tools/marshoai_megakits/__init__.py
Normal file
41
nonebot_plugin_marshoai/tools/marshoai_megakits/__init__.py
Normal file
@ -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))
|
45
nonebot_plugin_marshoai/tools/marshoai_megakits/mk_Common.py
Normal file
45
nonebot_plugin_marshoai/tools/marshoai_megakits/mk_Common.py
Normal file
@ -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 "未知运算符"
|
||||
|
@ -0,0 +1,8 @@
|
||||
# Twisuki
|
||||
async def twisuki():
|
||||
return 'Twiuski(苏阳)是megakits插件作者, Github : "https://github.com/Twisuki"'
|
||||
|
||||
|
||||
# MegaKits
|
||||
async def megakits():
|
||||
return 'MegaKits插件是一个功能混杂的MarshoAI插件, 由Twisuki(Github : "https://github.com/Twisuki")开发, 插件仓库 : "https://github.com/LiteyukiStudio/marsho-toolsets/tree/main/Twisuki/marshoai-megakits"'
|
@ -0,0 +1,86 @@
|
||||
# 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
|
||||
async 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
|
||||
async 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
|
@ -0,0 +1,61 @@
|
||||
import base64
|
||||
import random
|
||||
|
||||
# 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
|
||||
async 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 char == "呜" and random.random() < 0.5:
|
||||
result += "!"
|
||||
|
||||
if random.random() < 0.25:
|
||||
result += random.choice(NyaCodeSpecialCharset) + char
|
||||
else:
|
||||
result += char
|
||||
return result
|
||||
|
||||
|
||||
# NyaCode Decrypt
|
||||
async 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)
|
||||
msg_b64str += "=" * (4 - len(msg_b64str) % 4)
|
||||
try:
|
||||
result = base64.b64decode(msg_b64str.encode()).decode()
|
||||
except Exception:
|
||||
return "翻译失败"
|
||||
return result
|
142
nonebot_plugin_marshoai/tools/marshoai_megakits/tools.json
Normal file
142
nonebot_plugin_marshoai/tools/marshoai_megakits/tools.json
Normal file
@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
Reference in New Issue
Block a user