This commit is contained in:
远野千束 2024-03-19 20:38:25 +08:00
parent 9585910623
commit 15c751b1c8
10 changed files with 109 additions and 15 deletions

View File

@ -10,7 +10,7 @@ driver = nonebot.get_driver()
for adapter in adapters: for adapter in adapters:
driver.register_adapter(adapter) driver.register_adapter(adapter)
nonebot.load_plugin("src.plugins.liteyuki_plugin_main") nonebot.load_plugin("src.liteyuki_main")
if __name__ == "__main__": if __name__ == "__main__":
nonebot.run() nonebot.run()

0
src/__init__.py Normal file
View File

View File

@ -9,8 +9,5 @@ THIS_PLUGIN_NAME = os.path.basename(os.path.dirname(__file__))
RESOURCE_PATH = "src/resources" RESOURCE_PATH = "src/resources"
load_resource_from_dir(RESOURCE_PATH) load_resource_from_dir(RESOURCE_PATH)
for plugin_dir in os.listdir("src/plugins"): nonebot.plugin.load_plugins("src/plugins")
if plugin_dir != THIS_PLUGIN_NAME:
nonebot.plugin.load_plugin(f"src.plugins.{plugin_dir}")
nonebot.plugin.load_plugins("plugins") nonebot.plugin.load_plugins("plugins")

View File

@ -0,0 +1,97 @@
import nonebot
from nonebot import on_command
from nonebot.adapters.onebot.v11 import MessageSegment
from nonebot.params import CommandArg
from nonebot.permission import SUPERUSER
from src.utils.adapter import T_Message, T_Bot, v11, T_MessageEvent
md_test = on_command("mdts", aliases={"会话md"}, permission=SUPERUSER)
md_group = on_command("mdg", aliases={"群md"}, permission=SUPERUSER)
placeholder = {
"[": "[",
"]": "]",
"&": "&",
",": ",",
"\n" : r"\n",
"\"" : r'\\\"'
}
@md_test.handle()
async def _(bot: T_Bot, event: T_MessageEvent, arg: v11.Message = CommandArg()):
arg = str(arg).replace("\\", "\\\\").replace("\n", "\\n")
print(arg)
for k, v in placeholder.items():
arg = arg.replace(k, v)
sfm = await bot.call_api(
api="send_private_forward_msg",
user_id=bot.self_id,
messages=[
{
"type": "node",
"data": {
"name": "Liteyuki",
"uin": bot.self_id,
"content": [
{
"type": "markdown",
"data": {
"content": '{"content":"%s"}' % arg
}
}
]
},
},
]
)
await md_test.finish(
message=v11.Message(
MessageSegment(
type="longmsg",
data={
"id": sfm["forward_id"]
}
)
)
)
@md_group.handle()
async def _(bot: T_Bot, event: T_MessageEvent, arg: v11.Message = CommandArg()):
group_id, arg = str(arg).split(" ", 1)
print(arg)
for k, v in placeholder.items():
arg = arg.replace(k, v)
nonebot.logger.info("Markdown 测试")
sfm = await bot.call_api(
api="send_private_forward_msg",
user_id=bot.self_id,
messages=[
{
"type": "node",
"data": {
"name": "Liteyuki",
"uin": bot.self_id,
"content": [
{
"type": "markdown",
"data": {
"content": '{"content":"%s"}' % arg
}
}
]
},
},
]
)
await bot.send_group_msg(
message=v11.Message(
MessageSegment(
type="longmsg",
data={
"id": sfm["forward_id"]
}
)
),
group_id=group_id
)

View File

@ -2,7 +2,7 @@ import nonebot.plugin
from nonebot import on_command from nonebot import on_command
from nonebot.permission import SUPERUSER from nonebot.permission import SUPERUSER
from src.utils.adapter import MessageEvent from src.utils.adapter import T_MessageEvent
from src.utils.language import get_user_lang from src.utils.language import get_user_lang
list_plugins = on_command("list-plugin", aliases={"列出插件"}, priority=0) list_plugins = on_command("list-plugin", aliases={"列出插件"}, priority=0)
@ -10,7 +10,7 @@ toggle_plugin = on_command("enable-plugin", aliases={"启用插件", "禁用插
@list_plugins.handle() @list_plugins.handle()
async def _(event: MessageEvent): async def _(event: T_MessageEvent):
lang = get_user_lang(str(event.user_id)) lang = get_user_lang(str(event.user_id))
reply = lang.get("npm.loaded_plugins") reply = lang.get("npm.loaded_plugins")
for plugin in nonebot.get_loaded_plugins(): for plugin in nonebot.get_loaded_plugins():

View File

@ -1,7 +1,7 @@
from nonebot import on_command from nonebot import on_command
from nonebot.params import CommandArg from nonebot.params import CommandArg
from src.utils.adapter import Bot, Message, MessageEvent from src.utils.adapter import T_Bot, T_Message, T_MessageEvent
from src.utils.data_manager import User, user_db from src.utils.data_manager import User, user_db
from src.utils.language import get_user_lang from src.utils.language import get_user_lang
@ -16,7 +16,7 @@ attr_cmd = on_command("profile", aliases={"个人设置"}, priority=0)
@attr_cmd.handle() @attr_cmd.handle()
async def _(bot: Bot, event: MessageEvent, args: Message = CommandArg()): async def _(bot: T_Bot, event: T_MessageEvent, args: T_Message = CommandArg()):
user = user_db.first(User, "user_id = ?", str(event.user_id), default=User(user_id=str(event.user_id))) user = user_db.first(User, "user_id = ?", str(event.user_id), default=User(user_id=str(event.user_id)))
ulang = get_user_lang(str(event.user_id)) ulang = get_user_lang(str(event.user_id))

View File

@ -1,9 +1,9 @@
from nonebot.adapters.onebot import v11, v12 from nonebot.adapters.onebot import v11, v12
Bot = v11.Bot | v12.Bot T_Bot = v11.Bot | v12.Bot
GroupMessageEvent = v11.GroupMessageEvent | v12.GroupMessageEvent T_GroupMessageEvent = v11.GroupMessageEvent | v12.GroupMessageEvent
PrivateMessageEvent = v11.PrivateMessageEvent | v12.PrivateMessageEvent T_PrivateMessageEvent = v11.PrivateMessageEvent | v12.PrivateMessageEvent
MessageEvent = v11.MessageEvent | v12.MessageEvent T_MessageEvent = v11.MessageEvent | v12.MessageEvent
Message = v11.Message | v12.Message T_Message = v11.Message | v12.Message

View File

@ -12,7 +12,7 @@ class BasicConfig(BaseModel):
port: int = 20216 port: int = 20216
superusers: list[str] = [] superusers: list[str] = []
command_start: list[str] = ["/", ""] command_start: list[str] = ["/", ""]
nickname: set[str] = {"Liteyuki"} nickname: list[str] = ["liteyuki"]
def load_from_yaml(file: str) -> dict: def load_from_yaml(file: str) -> dict: