From 45dd4f07aa8f1dac19f91efa80b0fb17d118405a Mon Sep 17 00:00:00 2001 From: CMHopeSunshine <277073121@qq.com> Date: Thu, 25 Aug 2022 14:44:03 +0800 Subject: [PATCH] :fire: Cookie Web --- LittlePaimon/__init__.py | 1 + LittlePaimon/admin/__init__.py | 10 +++++++--- LittlePaimon/admin/bind_cookie.py | 4 ++-- LittlePaimon/manager/plugin_manager/manager.py | 4 ++-- LittlePaimon/utils/tool.py | 4 ++-- config/paimon_config_default.yml | 5 ++--- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/LittlePaimon/__init__.py b/LittlePaimon/__init__.py index 9408110..8c7cfd2 100644 --- a/LittlePaimon/__init__.py +++ b/LittlePaimon/__init__.py @@ -33,6 +33,7 @@ logo = """ async def startup(): logger.opt(colors=True).info(logo) await database.connect() + from LittlePaimon import admin await migrate_database() await check_resource() diff --git a/LittlePaimon/admin/__init__.py b/LittlePaimon/admin/__init__.py index 1a0104a..56ab047 100644 --- a/LittlePaimon/admin/__init__.py +++ b/LittlePaimon/admin/__init__.py @@ -1,8 +1,12 @@ import nonebot from fastapi import FastAPI -from pywebio.platform.fastapi import webio_routes -from .bind_cookie import bind_cookie_page +from LittlePaimon.utils import logger +from LittlePaimon.manager.plugin_manager import plugin_manager app: FastAPI = nonebot.get_app() -app.mount('/LittlePaimon/cookie', FastAPI(routes=webio_routes(bind_cookie_page))) \ No newline at end of file +if plugin_manager.get_config('启用CookieWeb', False): + from pywebio.platform.fastapi import webio_routes + from .bind_cookie import bind_cookie_page + logger.info('原神Cookie', f'启用CookieWeb成功,{plugin_manager.get_config("CookieWeb地址")}') + app.mount('/LittlePaimon/cookie', FastAPI(routes=webio_routes(bind_cookie_page))) diff --git a/LittlePaimon/admin/bind_cookie.py b/LittlePaimon/admin/bind_cookie.py index 72138bc..153e0bc 100644 --- a/LittlePaimon/admin/bind_cookie.py +++ b/LittlePaimon/admin/bind_cookie.py @@ -53,10 +53,10 @@ async def bind_cookie(data: dict): await PrivateCookie.update_or_create(user_id=str(data['qq']), uid=game_uid, mys_id=mys_id, defaults={'cookie': data['cookie'], 'stoken': f'stuid={mys_id};stoken={stoken};'}) - return f'QQ`{data["qq"]}`成功绑定原神玩家`{game_name}`-UID`{game_uid}`\n但cookie中没有`login_ticket`或`login_ticket`无效,`米游币相关功能`无法使用哦' + return f'QQ`{data["qq"]}`成功绑定原神玩家`{game_name}`-UID`{game_uid}`' else: await PrivateCookie.update_or_create(user_id=str(data['qq']), uid=game_uid, mys_id=mys_id, defaults={'cookie': data['cookie']}) - return f'QQ`{data["qq"]}`成功绑定原神玩家`{game_name}`-UID`{game_uid}`' + return f'QQ`{data["qq"]}`成功绑定原神玩家`{game_name}`-UID`{game_uid}`\n但cookie中没有`login_ticket`或`login_ticket`无效,`米游币相关功能`无法使用哦' else: return '这个cookie**无效**,请确认是否正确\n请重新获取cookie后**刷新**本页面再次绑定' diff --git a/LittlePaimon/manager/plugin_manager/manager.py b/LittlePaimon/manager/plugin_manager/manager.py index a4f9af5..ed35405 100644 --- a/LittlePaimon/manager/plugin_manager/manager.py +++ b/LittlePaimon/manager/plugin_manager/manager.py @@ -40,8 +40,8 @@ class PluginManager: """ if self.config_path.exists(): self.config = load_yaml(self.config_path) - # else: - # logger.warning('插件管理器', '无法读取LittlePaimon配置文件,请检查目录') + else: + logger.warning('插件管理器', '无法读取配置文件,请检查是否已将config/paimon_config_default.yml复制为config/paimon_config.yml') for file in self.plugin_config_path.iterdir(): if file.is_file() and file.name.endswith('.yml'): data = load_yaml(file) diff --git a/LittlePaimon/utils/tool.py b/LittlePaimon/utils/tool.py index 642f629..882974b 100644 --- a/LittlePaimon/utils/tool.py +++ b/LittlePaimon/utils/tool.py @@ -64,8 +64,8 @@ async def check_resource(): except Exception as e: logger.warning('资源检查', f'下载{resource.split("/")[-1]}出错: {e}') if flag: - logger.info('资源检查', '资源下载完成') + logger.info('资源检查', '资源下载完成') else: - logger.info('资源检查', '资源完好,无需下载') + logger.info('资源检查', '资源完好,无需下载') diff --git a/config/paimon_config_default.yml b/config/paimon_config_default.yml index 82e027d..abcb1a4 100644 --- a/config/paimon_config_default.yml +++ b/config/paimon_config_default.yml @@ -1,5 +1,4 @@ -全局入群欢迎: true -新群默认关闭所有插件: false - 启用CookieWeb: false +# 是否启用绑定Cookie的网页UI CookieWeb地址: http://127.0.0.1:13579/LittlePaimon/cookie +# CookieWeb的地址,如要公网访问,请修改公网ip,如需使用nginx等反代,请参考https://pywebio.readthedocs.io/zh_CN/latest/misc.html?highlight=nginx#nginx-websocket-config-example进行配置