mirror of
https://github.com/LiteyukiStudio/nonebot-plugin-marshoai.git
synced 2025-02-24 20:29:25 +08:00
MegaKits插件移植 (#28)
* 新增了萌百插件(meowiki) * 更新萌百搜索 * 删除萌百插件, 结束开发 * 新建MegaKits插件 * 修复 * 摩尔斯电码加密/解码 * 猫语转换/翻译
This commit is contained in:
parent
b0d6f87134
commit
b331a209c3
45
nonebot_plugin_marshoai/plugins/twisuki_megakits/__init__.py
Normal file
45
nonebot_plugin_marshoai/plugins/twisuki_megakits/__init__.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
from nonebot_plugin_marshoai.plugin import (
|
||||||
|
Integer,
|
||||||
|
Parameter,
|
||||||
|
PluginMetadata,
|
||||||
|
String,
|
||||||
|
on_function_call,
|
||||||
|
)
|
||||||
|
|
||||||
|
from . import mk_morse_code, mk_nya_code
|
||||||
|
|
||||||
|
__marsho_meta__ = PluginMetadata(
|
||||||
|
name="MegaKits插件",
|
||||||
|
description="一个功能混杂的多文件插件",
|
||||||
|
author="Twisuki",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@on_function_call(description="摩尔斯电码加密").params(
|
||||||
|
msg=String(description="被加密语句")
|
||||||
|
)
|
||||||
|
async def morse_encrypt(msg: str) -> str:
|
||||||
|
"""摩尔斯电码加密"""
|
||||||
|
return str(await mk_morse_code.morse_encrypt(msg))
|
||||||
|
|
||||||
|
|
||||||
|
@on_function_call(description="摩尔斯电码解密").params(
|
||||||
|
msg=String(description="被解密语句")
|
||||||
|
)
|
||||||
|
async def morse_decrypt(msg: str) -> str:
|
||||||
|
"""摩尔斯电码解密"""
|
||||||
|
return str(await mk_morse_code.morse_decrypt(msg))
|
||||||
|
|
||||||
|
|
||||||
|
@on_function_call(description="转换为猫语").params(msg=String(description="被转换语句"))
|
||||||
|
async def nya_encrypt(msg: str) -> str:
|
||||||
|
"""转换为猫语"""
|
||||||
|
return str(await mk_nya_code.nya_encrypt(msg))
|
||||||
|
|
||||||
|
|
||||||
|
@on_function_call(description="将猫语翻译回人类语言").params(
|
||||||
|
msg=String(description="被翻译语句")
|
||||||
|
)
|
||||||
|
async def nya_decrypt(msg: str) -> str:
|
||||||
|
"""将猫语翻译回人类语言"""
|
||||||
|
return str(await mk_nya_code.nya_decrypt(msg))
|
@ -0,0 +1,82 @@
|
|||||||
|
# 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()}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
async def morse_decrypt(msg: str):
|
||||||
|
result = ""
|
||||||
|
msg = msg.replace("_", "-")
|
||||||
|
msg_arr = msg.split(" ")
|
||||||
|
for element in msg_arr:
|
||||||
|
if element in MorseDecode:
|
||||||
|
result += MorseDecode[element]
|
||||||
|
else:
|
||||||
|
result += "?"
|
||||||
|
return result
|
@ -0,0 +1,74 @@
|
|||||||
|
# NyaCode
|
||||||
|
|
||||||
|
import base64
|
||||||
|
import random
|
||||||
|
|
||||||
|
NyaCodeCharset = ["喵", "呜", "?", "~"]
|
||||||
|
NyaCodeSpecialCharset = ["唔", "!", "...", ".."]
|
||||||
|
NyaCodeEncode = {}
|
||||||
|
|
||||||
|
for i in range(64):
|
||||||
|
triplet = ""
|
||||||
|
for j in range(3):
|
||||||
|
index = (i // (4**j)) % 4
|
||||||
|
triplet += NyaCodeCharset[index]
|
||||||
|
|
||||||
|
if i < 26:
|
||||||
|
char = chr(65 + i) # 大写字母 A-Z
|
||||||
|
elif i < 52:
|
||||||
|
char = chr(97 + (i - 26)) # 小写字母 a-z
|
||||||
|
elif i < 62:
|
||||||
|
char = chr(48 + (i - 52)) # 数字 0-9
|
||||||
|
elif i == 62:
|
||||||
|
char = chr(43) # 特殊字符 +
|
||||||
|
else:
|
||||||
|
char = chr(47) # 特殊字符 /
|
||||||
|
NyaCodeEncode[char] = triplet
|
||||||
|
NyaCodeDecode = {value: key for key, value in NyaCodeEncode.items()}
|
||||||
|
|
||||||
|
|
||||||
|
async def nya_encrypt(msg: str):
|
||||||
|
result = ""
|
||||||
|
b64str = base64.b64encode(msg.encode()).decode().replace("=", "")
|
||||||
|
|
||||||
|
nyastr = ""
|
||||||
|
for b64char in b64str:
|
||||||
|
nyastr += NyaCodeEncode[b64char]
|
||||||
|
|
||||||
|
for char in nyastr:
|
||||||
|
if char == "呜" and random.random() < 0.5:
|
||||||
|
result += "!"
|
||||||
|
if random.random() < 0.25:
|
||||||
|
result += random.choice(NyaCodeSpecialCharset) + char
|
||||||
|
else:
|
||||||
|
result += char
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
async def nya_decrypt(msg: str):
|
||||||
|
msg = msg.replace("唔", "").replace("!", "").replace(".", "")
|
||||||
|
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):
|
||||||
|
nyastr.append(nyachar)
|
||||||
|
i += 3
|
||||||
|
except Exception:
|
||||||
|
return "这句话不是正确的猫语"
|
||||||
|
|
||||||
|
b64str = ""
|
||||||
|
for nyachar in nyastr:
|
||||||
|
b64str += NyaCodeDecode[nyachar]
|
||||||
|
b64str += "=" * (4 - len(b64str) % 4)
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = base64.b64decode(b64str.encode()).decode()
|
||||||
|
except Exception:
|
||||||
|
return "翻译失败"
|
||||||
|
return result
|
Loading…
x
Reference in New Issue
Block a user