1
0
forked from bot/app
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

@ -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

@ -1,19 +0,0 @@
import nonebot
from nonebot.plugin import PluginMetadata
from src.utils.language import get_system_lang
from .loader import *
from .webdash import *
__author__ = "snowykami"
__plugin_meta__ = PluginMetadata(
name="轻雪主程序",
description="轻雪主程序插件,包含了许多初始化的功能",
usage="",
homepage="https://github.com/snowykami/LiteyukiBot",
)
from src.utils.config import config
sys_lang = get_system_lang()
nonebot.logger.info(sys_lang.get("main.current_language", LANG=sys_lang.get("language.name")))
nonebot.logger.info(sys_lang.get("main.enable_webdash", URL=f"http://127.0.0.1:{config.get('port', 8080)}"))

View File

@ -1,16 +0,0 @@
import os
import nonebot.plugin
from src.utils.language import load_from_dir
from src.utils.resource import load_resource_from_dir
THIS_PLUGIN_NAME = os.path.basename(os.path.dirname(__file__))
RESOURCE_PATH = "src/resources"
load_resource_from_dir(RESOURCE_PATH)
for plugin_dir in os.listdir("src/plugins"):
if plugin_dir != THIS_PLUGIN_NAME:
nonebot.plugin.load_plugin(f"src.plugins.{plugin_dir}")
nonebot.plugin.load_plugins("plugins")

View File

@ -1,91 +0,0 @@
import nonebot
import psutil
from dash import Dash, Input, Output, dcc, html
from starlette.middleware.wsgi import WSGIMiddleware
from src.utils.language import Language
from src.utils.tools import convert_size
app = nonebot.get_app()
def get_system_info():
cpu_percent = psutil.cpu_percent()
memory_info = psutil.virtual_memory()
memory_percent = memory_info.percent
return {
"cpu_percent" : cpu_percent,
"memory_percent": memory_percent
}
@app.get("/system_info")
async def system_info():
return get_system_info()
lang = Language()
dash_app = Dash(__name__)
dash_app.layout = dash_app.layout = html.Div(children=[
html.H1(children=lang.get("main.monitor.title"), style={
'textAlign': 'center'
}),
dcc.Graph(id='live-update-graph'),
dcc.Interval(
id='interval-component',
interval=1 * 1000, # in milliseconds
n_intervals=0
)
])
@dash_app.callback(Output('live-update-graph', 'figure'),
[Input('interval-component', 'n_intervals')])
def update_graph_live(n):
lang = Language()
system_inf = get_system_info()
dash_app.layout = html.Div(children=[
html.H1(children=lang.get("main.monitor.title"), style={
'textAlign': 'center'
}),
dcc.Graph(id='live-update-graph'),
dcc.Interval(
id='interval-component',
interval=2 * 1000, # in milliseconds
n_intervals=0
)
])
mem = psutil.virtual_memory()
cpu_f = psutil.cpu_freq()
figure = {
'data' : [
{
'x' : [f"{cpu_f.current / 1000:.2f}GHz {psutil.cpu_count(logical=False)}c{psutil.cpu_count()}t"],
'y' : [system_inf['cpu_percent']],
'type': 'bar',
'name': f"{lang.get('main.monitor.cpu')} {lang.get('main.monitor.usage')}"
},
{
'x' : [f"{convert_size(mem.used, add_unit=False)}/{convert_size(mem.total)}({mem.used / mem.total * 100:.2f}%)"],
'y' : [system_inf['memory_percent']],
'type': 'bar',
'name': f"{lang.get('main.monitor.memory')} {lang.get('main.monitor.usage')}"
},
],
'layout': {
'title': lang.get('main.monitor.description'),
# 'xaxis': {
# 'range': [0, 10]
# }, # 设置x轴的范围
'yaxis': {
'range': [0, 100]
}, # 设置y轴的范围
}
}
return figure
app.mount("/", WSGIMiddleware(dash_app.server))

View File

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

View File

@ -1,7 +1,7 @@
from nonebot import on_command
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.language import get_user_lang
@ -16,7 +16,7 @@ attr_cmd = on_command("profile", aliases={"个人设置"}, priority=0)
@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)))
ulang = get_user_lang(str(event.user_id))