📝 更新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 @DRIVER.on_startup
def init_web(): def init_web():
app: FastAPI = nonebot.get_app() app: FastAPI = nonebot.get_app()
app.include_router(BaseApiRouter) 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) @app.get('/LittlePaimon/admin', response_class=HTMLResponse)
async def admin(): async def admin():
if config.admin_enable: if config.admin_enable:
return admin_app.render(site_title='LittlePaimon 后台管理', return admin_app.render(
site_icon=icon_path, site_title='LittlePaimon 后台管理',
theme=config.admin_theme, site_icon=icon_path,
requestAdaptor=requestAdaptor, theme=config.admin_theme,
responseAdaptor=responseAdaptor) requestAdaptor=requestAdaptor,
responseAdaptor=responseAdaptor,
)
else: else:
return blank_page.render(site_title='LittlePaimon', return blank_page.render(site_title='LittlePaimon', site_icon=icon_path)
site_icon=icon_path)
@app.get('/LittlePaimon/login', response_class=HTMLResponse) @app.get('/LittlePaimon/login', response_class=HTMLResponse)
async def login(): async def login():
if config.admin_enable: if config.admin_enable:
return login_page.render(site_title='登录 | LittlePaimon 后台管理', return login_page.render(
site_icon=icon_path, site_title='登录 | LittlePaimon 后台管理',
theme=config.admin_theme) site_icon=icon_path,
theme=config.admin_theme,
)
else: else:
return blank_page.render(site_title='LittlePaimon', return blank_page.render(site_title='LittlePaimon', site_icon=icon_path)
site_icon=icon_path)
@app.get('/LittlePaimon/cookie', response_class=HTMLResponse) @app.get('/LittlePaimon/cookie', response_class=HTMLResponse)
async def bind_cookie(): async def bind_cookie():
if config.CookieWeb_enable: if config.CookieWeb_enable:
return bind_cookie_page.render(site_title='绑定Cookie | LittlePaimon', return bind_cookie_page.render(
site_icon=icon_path, site_title='绑定Cookie | LittlePaimon',
theme=config.admin_theme) site_icon=icon_path,
theme=config.admin_theme,
)
else: else:
return blank_page.render(site_title='LittlePaimon', return blank_page.render(site_title='LittlePaimon', site_icon=icon_path)
site_icon=icon_path)

View File

@ -1,12 +1,32 @@
from LittlePaimon.utils import __version__ from LittlePaimon.utils import __version__
from LittlePaimon.config import config from LittlePaimon.config import config
from amis import Page, PageSchema, Html, Property, Service, Flex, ActionType, LevelEnum, Divider, ButtonGroupSelect, \ from amis import (
Log, Alert, Form, Dialog, Select, Group, InputText, DisplayModeEnum, Horizontal 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"> <p align="center">
<a href="https://github.com/CMHopeSunshine/LittlePaimon/"> <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"> width="256" height="256" alt="LittlePaimon">
</a> </a>
</p> </p>
@ -18,33 +38,19 @@ logo = Html(html=f'''
target="_blank">文档</a> target="_blank">文档</a>
</div> </div>
<br> <br>
''') '''
)
select_log_num = Select( select_log_num = Select(
label='日志数量', label='日志数量',
name='log_num', name='log_num',
value=100, value=100,
options=[ options=[
{ {'label': 100, 'value': 100},
'label': 100, {'label': 200, 'value': 200},
'value': 100 {'label': 300, 'value': 300},
}, {'label': 400, 'value': 400},
{ {'label': 500, 'value': 500},
'label': 200, ],
'value': 200
},
{
'label': 300,
'value': 300
},
{
'label': 400,
'value': 400
},
{
'label': 500,
'value': 500
}
]
) )
select_log_level = ButtonGroupSelect( select_log_level = ButtonGroupSelect(
@ -53,16 +59,7 @@ select_log_level = ButtonGroupSelect(
btnLevel=LevelEnum.light, btnLevel=LevelEnum.light,
btnActiveLevel=LevelEnum.info, btnActiveLevel=LevelEnum.info,
value='info', value='info',
options=[ options=[{'label': 'INFO', 'value': 'info'}, {'label': 'DEBUG', 'value': 'debug'}],
{
'label': 'INFO',
'value': 'info'
},
{
'label': 'DEBUG',
'value': 'debug'
}
]
) )
log_page = Log( log_page = Log(
@ -72,10 +69,8 @@ log_page = Log(
source={ source={
'method': 'get', 'method': 'get',
'url': '/LittlePaimon/api/log?level=${log_level | raw}&num=${log_num | raw}', 'url': '/LittlePaimon/api/log?level=${log_level | raw}&num=${log_num | raw}',
'headers': { 'headers': {'token': config.secret_key[:16]},
'token': config.secret_key[:16] },
}
}
) )
cmd_input = Form( cmd_input = Form(
@ -83,66 +78,75 @@ cmd_input = Form(
horizontal=Horizontal(left=0), horizontal=Horizontal(left=0),
wrapWithPanel=False, wrapWithPanel=False,
body=[ body=[
InputText(name='command', required=True, clearable=True, addOn=ActionType.Dialog( InputText(
label='执行', name='command',
level=LevelEnum.primary, required=True,
dialog=Dialog( clearable=True,
title='命令执行结果', addOn=ActionType.Dialog(
size='xl', label='执行',
body=Log( level=LevelEnum.primary,
autoScroll=True, dialog=Dialog(
placeholder='执行命令中,请稍候...', title='命令执行结果',
operation=['stop', 'showLineNumber', 'filter'], size='xl',
source={ body=Log(
'method': 'get', autoScroll=True,
'url': '/LittlePaimon/api/run_cmd?cmd=${command | raw}', placeholder='执行命令中,请稍候...',
'headers': { operation=['stop', 'showLineNumber', 'filter'],
'token': config.secret_key[:16] source={
} 'method': 'get',
}), 'url': '/LittlePaimon/api/run_cmd?cmd=${command | raw}',
) 'headers': {'token': config.secret_key[:16]},
)) },
] ),
),
),
)
],
) )
operation_button = Flex(justify='center', items=[ operation_button = Flex(
ActionType.Ajax( justify='center',
label='更新', items=[
api='/LittlePaimon/api/bot_update', ActionType.Ajax(
confirmText='该操作将会对Bot进行检查并尝试更新请在更新完成后重启Bot使更新生效', label='更新',
level=LevelEnum.info api='/LittlePaimon/api/bot_update',
), confirmText='该操作将会对Bot进行检查并尝试更新请在更新完成后重启Bot使更新生效',
ActionType.Ajax( level=LevelEnum.info,
label='重启', ),
className='m-l', ActionType.Ajax(
api='/LittlePaimon/api/bot_restart', label='重启',
confirmText='该操作将会使Bot重启在完成重启之前该页面也将无法访问也可能会弹出报错可无视请耐心等待重启', className='m-l',
level=LevelEnum.danger api='/LittlePaimon/api/bot_restart',
), confirmText='该操作将会使Bot重启在完成重启之前该页面也将无法访问也可能会弹出报错可无视请耐心等待重启',
ActionType.Dialog( level=LevelEnum.danger,
label='日志', ),
className='m-l', ActionType.Dialog(
level=LevelEnum.primary, label='日志',
dialog=Dialog(title='查看日志', className='m-l',
size='xl', level=LevelEnum.primary,
actions=[], dialog=Dialog(
body=[ title='查看日志',
Alert(level=LevelEnum.info, size='xl',
body='查看最近最多500条日志不会自动刷新需要手动点击两次"暂停键"来进行刷新DEBUG日志需要Nonebot日志模式为DEBUG才能查看。'), actions=[],
Form( body=[
body=[Group(body=[select_log_num, select_log_level]), log_page] Alert(
)]) level=LevelEnum.info,
), body='查看最近最多500条日志不会自动刷新需要手动点击两次"暂停键"来进行刷新DEBUG日志需要Nonebot日志模式为DEBUG才能查看。',
ActionType.Dialog( ),
label='执行命令', Form(
className='m-l', body=[Group(body=[select_log_num, select_log_level]), log_page]
level=LevelEnum.warning, ),
dialog=Dialog(title='执行命令', ],
size='lg', ),
actions=[], ),
body=[cmd_input]) ActionType.Dialog(
) label='执行命令',
]) className='m-l',
level=LevelEnum.warning,
dialog=Dialog(title='执行命令', size='lg', actions=[], body=[cmd_input]),
),
],
)
status = Service( status = Service(
api='/LittlePaimon/api/status', api='/LittlePaimon/api/status',
@ -150,46 +154,20 @@ status = Service(
title='机器人信息', title='机器人信息',
column=2, column=2,
items=[ items=[
Property.Item( Property.Item(label='Bot昵称', content='${nickname}'),
label='Bot昵称', Property.Item(label='Bot qq号', content='${bot_id}'),
content='${nickname}' Property.Item(label='Bot启动时间', content='${start_time}'),
), Property.Item(label='系统启动时间', content='${system_start_time}'),
Property.Item( Property.Item(label='已接收信息', content='${msg_received}'),
label='Bot qq号', Property.Item(label='已发送信息', content='${msg_sent}'),
content='${bot_id}' Property.Item(label='CPU占用率', content='${cpu_percent}'),
), Property.Item(label='RAM占用率', content='${ram_percent}'),
Property.Item( Property.Item(label='SWAP占用率', content='${swap_percent}', span=2),
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_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 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"> <p align="center">
<a href="https://github.com/CMHopeSunshine/LittlePaimon/"> <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"> width="256" height="256" alt="LittlePaimon">
</a> </a>
</p> </p>
@ -17,7 +29,8 @@ logo = Html(html=f'''
</div> </div>
<br> <br>
<br> <br>
''') '''
)
login_api = AmisAPI( login_api = AmisAPI(
url='/LittlePaimon/api/login', url='/LittlePaimon/api/login',
method='post', method='post',
@ -26,13 +39,30 @@ login_api = AmisAPI(
localStorage.setItem("token", payload.data.token); localStorage.setItem("token", payload.data.token);
} }
return payload; return payload;
''' ''',
) )
login_form = Form(api=login_api, title='', body=[ login_form = Form(
InputText(name='user_id', label='用户ID', labelRemark=Remark(shape='circle', content='超级用户的QQ号在.env.prod文件中配置')), api=login_api,
InputPassword(name='password', label='密码', labelRemark=Remark(shape='circle', content='默认为admin可以在paimon_config.json中修改')), title='',
# Switch(name='is_admin', label='身份组', onText='管理员', offText='用户', labelRemark=Remark(shape='circle', content='是否以管理员身份登录')) body=[
], mode=DisplayModeEnum.horizontal, horizontal=Horizontal(left=3, right=9, offset=5), redirect='/LittlePaimon/admin') 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) body = Wrapper(className='w-2/5 mx-auto my-0 m:w-full', body=login_form)
login_page = Page(title='', body=[logo, body]) 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 from .command_alias import page as command_alias_page
github_logo = Tpl(className='w-full', github_logo = Tpl(
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>') className='w-full',
header = Flex(className='w-full', justify='flex-end', alignItems='flex-end', items=[github_logo]) 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', admin_app = App(
logo='http://static.cherishmoon.fun/LittlePaimon/readme/logo.png', brandName='LittlePaimon',
header=header, logo='https://s1.ax1x.com/2023/02/05/pS62DJK.png',
pages=[{ header=header,
'children': [ pages=[
home_page, {
PageSchema(label='Cookie管理', icon='fa fa-key', 'children': [
children=[public_cookie_page, private_cookie_page]), home_page,
PageSchema(label='机器人配置', icon='fa fa-wrench', PageSchema(
children=[plugin_manage_page, config_page, command_alias_page]) label='Cookie管理',
]}], icon='fa fa-key',
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>') 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='该页面未开启或不存在') blank_page = Page(title='LittlePaimon 404', body='该页面未开启或不存在')

View File

@ -1,69 +1,71 @@
<p align="center" > <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> </p>
<h1 align="center">小派蒙|LittlePaimon</h1> <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"> <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> <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/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> <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> </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> <details>
<summary>帮助列表</summary> <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>
<details> <details>
<summary>玩家卡片</summary> <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>
<details> <details>
<summary>角色背包</summary> <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>
<details> <details>
<summary>角色面板</summary> <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>
<details> <details>
<summary>角色卡片</summary> <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>
<details> <details>
<summary>深渊战报</summary> <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>
<details> <details>
<summary>实时便签</summary> <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>
<details> <details>
<summary>每月札记</summary> <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> </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)。 详见[常见问题](https://docs.paimon.cherishmoon.fun/question.html)和[致谢](https://docs.paimon.cherishmoon.fun/thanks.html)。