📝 更新README

This commit is contained in:
CMHopeSunshine 2023-02-05 21:31:30 +08:00
parent 7cef262937
commit 8ef012c733
5 changed files with 231 additions and 200 deletions

View File

@ -26,43 +26,49 @@ responseAdaptor(api, payload, query, request, response) {
},
'''
icon_path = 'http://static.cherishmoon.fun/LittlePaimon/readme/logo.png'
icon_path = 'https://s1.ax1x.com/2023/02/05/pS62DJK.png'
@DRIVER.on_startup
def init_web():
app: FastAPI = nonebot.get_app()
app.include_router(BaseApiRouter)
logger.info('Web UI', f'<g>启用成功</g>,默认地址为<m>http://127.0.0.1:{DRIVER.config.port}/LittlePaimon/login</m>')
logger.info(
'Web UI',
f'<g>启用成功</g>,默认地址为<m>http://127.0.0.1:{DRIVER.config.port}/LittlePaimon/login</m>',
)
@app.get('/LittlePaimon/admin', response_class=HTMLResponse)
async def admin():
if config.admin_enable:
return admin_app.render(site_title='LittlePaimon 后台管理',
site_icon=icon_path,
theme=config.admin_theme,
requestAdaptor=requestAdaptor,
responseAdaptor=responseAdaptor)
return admin_app.render(
site_title='LittlePaimon 后台管理',
site_icon=icon_path,
theme=config.admin_theme,
requestAdaptor=requestAdaptor,
responseAdaptor=responseAdaptor,
)
else:
return blank_page.render(site_title='LittlePaimon',
site_icon=icon_path)
return blank_page.render(site_title='LittlePaimon', site_icon=icon_path)
@app.get('/LittlePaimon/login', response_class=HTMLResponse)
async def login():
if config.admin_enable:
return login_page.render(site_title='登录 | LittlePaimon 后台管理',
site_icon=icon_path,
theme=config.admin_theme)
return login_page.render(
site_title='登录 | LittlePaimon 后台管理',
site_icon=icon_path,
theme=config.admin_theme,
)
else:
return blank_page.render(site_title='LittlePaimon',
site_icon=icon_path)
return blank_page.render(site_title='LittlePaimon', site_icon=icon_path)
@app.get('/LittlePaimon/cookie', response_class=HTMLResponse)
async def bind_cookie():
if config.CookieWeb_enable:
return bind_cookie_page.render(site_title='绑定Cookie | LittlePaimon',
site_icon=icon_path,
theme=config.admin_theme)
return bind_cookie_page.render(
site_title='绑定Cookie | LittlePaimon',
site_icon=icon_path,
theme=config.admin_theme,
)
else:
return blank_page.render(site_title='LittlePaimon',
site_icon=icon_path)
return blank_page.render(site_title='LittlePaimon', site_icon=icon_path)

View File

@ -1,12 +1,32 @@
from LittlePaimon.utils import __version__
from LittlePaimon.config import config
from amis import Page, PageSchema, Html, Property, Service, Flex, ActionType, LevelEnum, Divider, ButtonGroupSelect, \
Log, Alert, Form, Dialog, Select, Group, InputText, DisplayModeEnum, Horizontal
from amis import (
Page,
PageSchema,
Html,
Property,
Service,
Flex,
ActionType,
LevelEnum,
Divider,
ButtonGroupSelect,
Log,
Alert,
Form,
Dialog,
Select,
Group,
InputText,
DisplayModeEnum,
Horizontal,
)
logo = Html(html=f'''
logo = Html(
html=f'''
<p align="center">
<a href="https://github.com/CMHopeSunshine/LittlePaimon/">
<img src="http://static.cherishmoon.fun/LittlePaimon/readme/logo.png"
<img src="https://s1.ax1x.com/2023/02/05/pS62DJK.png"
width="256" height="256" alt="LittlePaimon">
</a>
</p>
@ -18,33 +38,19 @@ logo = Html(html=f'''
target="_blank">文档</a>
</div>
<br>
''')
'''
)
select_log_num = Select(
label='日志数量',
name='log_num',
value=100,
options=[
{
'label': 100,
'value': 100
},
{
'label': 200,
'value': 200
},
{
'label': 300,
'value': 300
},
{
'label': 400,
'value': 400
},
{
'label': 500,
'value': 500
}
]
{'label': 100, 'value': 100},
{'label': 200, 'value': 200},
{'label': 300, 'value': 300},
{'label': 400, 'value': 400},
{'label': 500, 'value': 500},
],
)
select_log_level = ButtonGroupSelect(
@ -53,16 +59,7 @@ select_log_level = ButtonGroupSelect(
btnLevel=LevelEnum.light,
btnActiveLevel=LevelEnum.info,
value='info',
options=[
{
'label': 'INFO',
'value': 'info'
},
{
'label': 'DEBUG',
'value': 'debug'
}
]
options=[{'label': 'INFO', 'value': 'info'}, {'label': 'DEBUG', 'value': 'debug'}],
)
log_page = Log(
@ -72,10 +69,8 @@ log_page = Log(
source={
'method': 'get',
'url': '/LittlePaimon/api/log?level=${log_level | raw}&num=${log_num | raw}',
'headers': {
'token': config.secret_key[:16]
}
}
'headers': {'token': config.secret_key[:16]},
},
)
cmd_input = Form(
@ -83,66 +78,75 @@ cmd_input = Form(
horizontal=Horizontal(left=0),
wrapWithPanel=False,
body=[
InputText(name='command', required=True, clearable=True, addOn=ActionType.Dialog(
label='执行',
level=LevelEnum.primary,
dialog=Dialog(
title='命令执行结果',
size='xl',
body=Log(
autoScroll=True,
placeholder='执行命令中,请稍候...',
operation=['stop', 'showLineNumber', 'filter'],
source={
'method': 'get',
'url': '/LittlePaimon/api/run_cmd?cmd=${command | raw}',
'headers': {
'token': config.secret_key[:16]
}
}),
)
))
]
InputText(
name='command',
required=True,
clearable=True,
addOn=ActionType.Dialog(
label='执行',
level=LevelEnum.primary,
dialog=Dialog(
title='命令执行结果',
size='xl',
body=Log(
autoScroll=True,
placeholder='执行命令中,请稍候...',
operation=['stop', 'showLineNumber', 'filter'],
source={
'method': 'get',
'url': '/LittlePaimon/api/run_cmd?cmd=${command | raw}',
'headers': {'token': config.secret_key[:16]},
},
),
),
),
)
],
)
operation_button = Flex(justify='center', items=[
ActionType.Ajax(
label='更新',
api='/LittlePaimon/api/bot_update',
confirmText='该操作将会对Bot进行检查并尝试更新请在更新完成后重启Bot使更新生效',
level=LevelEnum.info
),
ActionType.Ajax(
label='重启',
className='m-l',
api='/LittlePaimon/api/bot_restart',
confirmText='该操作将会使Bot重启在完成重启之前该页面也将无法访问也可能会弹出报错可无视请耐心等待重启',
level=LevelEnum.danger
),
ActionType.Dialog(
label='日志',
className='m-l',
level=LevelEnum.primary,
dialog=Dialog(title='查看日志',
size='xl',
actions=[],
body=[
Alert(level=LevelEnum.info,
body='查看最近最多500条日志不会自动刷新需要手动点击两次"暂停键"来进行刷新DEBUG日志需要Nonebot日志模式为DEBUG才能查看。'),
Form(
body=[Group(body=[select_log_num, select_log_level]), log_page]
)])
),
ActionType.Dialog(
label='执行命令',
className='m-l',
level=LevelEnum.warning,
dialog=Dialog(title='执行命令',
size='lg',
actions=[],
body=[cmd_input])
)
])
operation_button = Flex(
justify='center',
items=[
ActionType.Ajax(
label='更新',
api='/LittlePaimon/api/bot_update',
confirmText='该操作将会对Bot进行检查并尝试更新请在更新完成后重启Bot使更新生效',
level=LevelEnum.info,
),
ActionType.Ajax(
label='重启',
className='m-l',
api='/LittlePaimon/api/bot_restart',
confirmText='该操作将会使Bot重启在完成重启之前该页面也将无法访问也可能会弹出报错可无视请耐心等待重启',
level=LevelEnum.danger,
),
ActionType.Dialog(
label='日志',
className='m-l',
level=LevelEnum.primary,
dialog=Dialog(
title='查看日志',
size='xl',
actions=[],
body=[
Alert(
level=LevelEnum.info,
body='查看最近最多500条日志不会自动刷新需要手动点击两次"暂停键"来进行刷新DEBUG日志需要Nonebot日志模式为DEBUG才能查看。',
),
Form(
body=[Group(body=[select_log_num, select_log_level]), log_page]
),
],
),
),
ActionType.Dialog(
label='执行命令',
className='m-l',
level=LevelEnum.warning,
dialog=Dialog(title='执行命令', size='lg', actions=[], body=[cmd_input]),
),
],
)
status = Service(
api='/LittlePaimon/api/status',
@ -150,46 +154,20 @@ status = Service(
title='机器人信息',
column=2,
items=[
Property.Item(
label='Bot昵称',
content='${nickname}'
),
Property.Item(
label='Bot qq号',
content='${bot_id}'
),
Property.Item(
label='Bot启动时间',
content='${start_time}'
),
Property.Item(
label='系统启动时间',
content='${system_start_time}'
),
Property.Item(
label='已接收信息',
content='${msg_received}'
),
Property.Item(
label='已发送信息',
content='${msg_sent}'
),
Property.Item(
label='CPU占用率',
content='${cpu_percent}'
),
Property.Item(
label='RAM占用率',
content='${ram_percent}'
),
Property.Item(
label='SWAP占用率',
content='${swap_percent}',
span=2
),
]
)
Property.Item(label='Bot昵称', content='${nickname}'),
Property.Item(label='Bot qq号', content='${bot_id}'),
Property.Item(label='Bot启动时间', content='${start_time}'),
Property.Item(label='系统启动时间', content='${system_start_time}'),
Property.Item(label='已接收信息', content='${msg_received}'),
Property.Item(label='已发送信息', content='${msg_sent}'),
Property.Item(label='CPU占用率', content='${cpu_percent}'),
Property.Item(label='RAM占用率', content='${ram_percent}'),
Property.Item(label='SWAP占用率', content='${swap_percent}', span=2),
],
),
)
page_detail = Page(title='', body=[logo, operation_button, Divider(), status])
page = PageSchema(url='/home', label='首页', icon='fa fa-home', isDefaultPage=True, schema=page_detail)
page = PageSchema(
url='/home', label='首页', icon='fa fa-home', isDefaultPage=True, schema=page_detail
)

View File

@ -1,10 +1,22 @@
from LittlePaimon.utils import __version__
from amis import Form, InputText, InputPassword, DisplayModeEnum, Horizontal, Remark, Html, Page, AmisAPI, Wrapper
from amis import (
Form,
InputText,
InputPassword,
DisplayModeEnum,
Horizontal,
Remark,
Html,
Page,
AmisAPI,
Wrapper,
)
logo = Html(html=f'''
logo = Html(
html=f'''
<p align="center">
<a href="https://github.com/CMHopeSunshine/LittlePaimon/">
<img src="http://static.cherishmoon.fun/LittlePaimon/readme/logo.png"
<img src="https://s1.ax1x.com/2023/02/05/pS62DJK.png"
width="256" height="256" alt="LittlePaimon">
</a>
</p>
@ -17,7 +29,8 @@ logo = Html(html=f'''
</div>
<br>
<br>
''')
'''
)
login_api = AmisAPI(
url='/LittlePaimon/api/login',
method='post',
@ -26,13 +39,30 @@ login_api = AmisAPI(
localStorage.setItem("token", payload.data.token);
}
return payload;
'''
''',
)
login_form = Form(api=login_api, title='', body=[
InputText(name='user_id', label='用户ID', labelRemark=Remark(shape='circle', content='超级用户的QQ号在.env.prod文件中配置')),
InputPassword(name='password', label='密码', labelRemark=Remark(shape='circle', content='默认为admin可以在paimon_config.json中修改')),
# Switch(name='is_admin', label='身份组', onText='管理员', offText='用户', labelRemark=Remark(shape='circle', content='是否以管理员身份登录'))
], mode=DisplayModeEnum.horizontal, horizontal=Horizontal(left=3, right=9, offset=5), redirect='/LittlePaimon/admin')
login_form = Form(
api=login_api,
title='',
body=[
InputText(
name='user_id',
label='用户ID',
labelRemark=Remark(shape='circle', content='超级用户的QQ号在.env.prod文件中配置'),
),
InputPassword(
name='password',
label='密码',
labelRemark=Remark(
shape='circle', content='默认为admin可以在paimon_config.json中修改'
),
),
# Switch(name='is_admin', label='身份组', onText='管理员', offText='用户', labelRemark=Remark(shape='circle', content='是否以管理员身份登录'))
],
mode=DisplayModeEnum.horizontal,
horizontal=Horizontal(left=3, right=9, offset=5),
redirect='/LittlePaimon/admin',
)
body = Wrapper(className='w-2/5 mx-auto my-0 m:w-full', body=login_form)
login_page = Page(title='', body=[logo, body])

View File

@ -8,22 +8,37 @@ from .public_cookie import page as public_cookie_page
from .command_alias import page as command_alias_page
github_logo = Tpl(className='w-full',
tpl='<div class="flex justify-between"><div></div><div><a href="https://github.com/CMHopeSunshine/LittlePaimon" target="_blank" title="Copyright"><i class="fa fa-github fa-2x"></i></a></div></div>')
header = Flex(className='w-full', justify='flex-end', alignItems='flex-end', items=[github_logo])
github_logo = Tpl(
className='w-full',
tpl='<div class="flex justify-between"><div></div><div><a href="https://github.com/CMHopeSunshine/LittlePaimon" target="_blank" title="Copyright"><i class="fa fa-github fa-2x"></i></a></div></div>',
)
header = Flex(
className='w-full', justify='flex-end', alignItems='flex-end', items=[github_logo]
)
admin_app = App(brandName='LittlePaimon',
logo='http://static.cherishmoon.fun/LittlePaimon/readme/logo.png',
header=header,
pages=[{
'children': [
home_page,
PageSchema(label='Cookie管理', icon='fa fa-key',
children=[public_cookie_page, private_cookie_page]),
PageSchema(label='机器人配置', icon='fa fa-wrench',
children=[plugin_manage_page, config_page, command_alias_page])
]}],
footer=f'<div class="p-2 text-center bg-blue-100">Copyright © 2021 - 2022 <a href="https://github.com/CMHopeSunshine/LittlePaimon" target="_blank" class="link-secondary">LittlePaimon v{__version__}</a> X<a target="_blank" href="https://github.com/baidu/amis" class="link-secondary" rel="noopener"> amis v2.2.0</a></div>')
admin_app = App(
brandName='LittlePaimon',
logo='https://s1.ax1x.com/2023/02/05/pS62DJK.png',
header=header,
pages=[
{
'children': [
home_page,
PageSchema(
label='Cookie管理',
icon='fa fa-key',
children=[public_cookie_page, private_cookie_page],
),
PageSchema(
label='机器人配置',
icon='fa fa-wrench',
children=[plugin_manage_page, config_page, command_alias_page],
),
]
}
],
footer=f'<div class="p-2 text-center bg-blue-100">Copyright © 2021 - 2022 <a href="https://github.com/CMHopeSunshine/LittlePaimon" target="_blank" class="link-secondary">LittlePaimon v{__version__}</a> X<a target="_blank" href="https://github.com/baidu/amis" class="link-secondary" rel="noopener"> amis v2.2.0</a></div>',
)
blank_page = Page(title='LittlePaimon 404', body='该页面未开启或不存在')

View File

@ -1,69 +1,71 @@
<p align="center" >
<a href="https://github.com/CMHopeSunshine/LittlePaimon/tree/nonebot2"><img src="http://static.cherishmoon.fun/LittlePaimon/readme/logo.png" width="256" height="256" alt="LittlePaimon"></a>
<a href="https://github.com/CMHopeSunshine/LittlePaimon/tree/nonebot2"><img src="https://s1.ax1x.com/2023/02/05/pS62DJK.png" width="256" height="256" alt="LittlePaimon"></a>
</p>
<h1 align="center">小派蒙|LittlePaimon</h1>
<h4 align="center">✨基于<a href="https://github.com/nonebot/nonebot2" target="_blank">NoneBot2</a><a href="https://github.com/Mrs4s/go-cqhttp" target="_blank">go-cqhttp</a>的原神Q群机器人✨</h4>
<h4 align="center">✨基于<a href="https://github.com/nonebot/nonebot2" target="_blank">NoneBot2</a>的原神Q群机器人✨</h4>
<p align="center">
<a href="https://cdn.jsdelivr.net/gh/CMHopeSunshine/LittlePaimon@master/LICENSE"><img src="https://img.shields.io/github/license/CMHopeSunshine/LittlePaimon" alt="license"></a>
<img src="https://img.shields.io/badge/Python-3.8+-yellow" alt="python">
<img src="https://img.shields.io/badge/Version-3.0.0rc3-green" alt="version">
<a href="https://qun.qq.com/qqweb/qunpro/share?_wv=3&_wwv=128&inviteCode=MmWrI&from=246610&biz=ka"><img src="https://img.shields.io/badge/QQ频道交流-尘世闲游-blue?style=flat-square" alt="QQ guild"></a>
</p>
## 丨简介
原神多功能机器人,查询游戏信息、图鉴攻略、树脂提醒等等,以及各种各样的好玩的功能,不仅仅是原神。
## 丨快速部署
使用[小派蒙脚手架插件](https://github.com/CMHopeSunshine/nb-cli-plugin-littlepaimon)快速部署安装小派蒙。
## 丨文档
详细部署教程、使用和配置等请看[小派蒙文档](https://docs.paimon.cherishmoon.fun/)。
[![asciicast](https://asciinema.org/a/kMBRbuX5lCEnk5lmXcU53ys5b.svg)](https://asciinema.org/a/kMBRbuX5lCEnk5lmXcU53ys5b)
## | 功能示例
> 更多功能及其详细用法请看文档。
<details>
<summary>帮助列表</summary>
<img src="https://static.cherishmoon.fun/LittlePaimon/readme/new/help.jpg" alt="help">
<img src="https://s1.ax1x.com/2023/02/05/pS6gWCT.jpg" alt="help">
</details>
<details>
<summary>玩家卡片</summary>
<img src="https://static.cherishmoon.fun/LittlePaimon/readme/new/ys.jpg" alt="ys">
<img src="https://s1.ax1x.com/2023/02/05/pS6g25V.jpg" alt="ys">
</details>
<details>
<summary>角色背包</summary>
<img src="https://static.cherishmoon.fun/LittlePaimon/readme/new/ysa.jpg" alt="ysa">
<img src="https://s1.ax1x.com/2023/02/05/pS6ggU0.jpg" alt="ysa">
</details>
<details>
<summary>角色面板</summary>
<img src="https://static.cherishmoon.fun/LittlePaimon/readme/new/ysd.jpg" alt="ysd">
<img src="https://s1.ax1x.com/2023/02/05/pS6gh2F.jpg" alt="ysd">
</details>
<details>
<summary>角色卡片</summary>
<img src="https://static.cherishmoon.fun/LittlePaimon/readme/new/ysc.jpg" alt="ysc">
<img src="https://s1.ax1x.com/2023/02/05/pS6gf8U.jpg" alt="ysc">
</details>
<details>
<summary>深渊战报</summary>
<img src="https://static.cherishmoon.fun/LittlePaimon/readme/new/sy.jpg" alt="sy">
<img src="https://s1.ax1x.com/2023/02/05/pS6gcEq.jpg" alt="sy">
</details>
<details>
<summary>实时便签</summary>
<img src="https://static.cherishmoon.fun/LittlePaimon/readme/ssbq.jpg" alt="ssbq">
<img src="https://s1.ax1x.com/2023/02/05/pS6gybn.jpg" alt="ssbq">
</details>
<details>
<summary>每月札记</summary>
<img src="https://static.cherishmoon.fun/LittlePaimon/readme/myzj.jpg" alt="myzj">
<img src="https://s1.ax1x.com/2023/02/05/pS624FP.jpg" alt="myzj">
</details>
## 丨文档
部署教程、使用和配置等请看[文档](https://docs.paimon.cherishmoon.fun/),文档仍在编写中,部分尚未完善。
文档地址https://docs.paimon.cherishmoon.fun/
## | 常见问题&致谢
详见[常见问题](https://docs.paimon.cherishmoon.fun/question.html)和[致谢](https://docs.paimon.cherishmoon.fun/thanks.html)。