🔥 Cookie Web

This commit is contained in:
CMHopeSunshine 2022-08-25 14:44:03 +08:00
parent b5a4865493
commit 45dd4f07aa
6 changed files with 16 additions and 12 deletions

View File

@ -33,6 +33,7 @@ logo = """<g>
async def startup():
logger.opt(colors=True).info(logo)
await database.connect()
from LittlePaimon import admin
await migrate_database()
await check_resource()

View File

@ -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)))
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'<g>启用CookieWeb成功</g>{plugin_manager.get_config("CookieWeb地址")}')
app.mount('/LittlePaimon/cookie', FastAPI(routes=webio_routes(bind_cookie_page)))

View File

@ -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后**刷新**本页面再次绑定'

View File

@ -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('插件管理器', '<r>无法读取配置文件</r>,请检查是否已将<m>config/paimon_config_default.yml</m>复制为<m>config/paimon_config.yml</m>')
for file in self.plugin_config_path.iterdir():
if file.is_file() and file.name.endswith('.yml'):
data = load_yaml(file)

View File

@ -64,8 +64,8 @@ async def check_resource():
except Exception as e:
logger.warning('资源检查', f'下载<m>{resource.split("/")[-1]}</m>时<r>出错: {e}</r>')
if flag:
logger.info('资源检查', '资源<g>下载完成</g>')
logger.info('资源检查', '<g>资源下载完成</g>')
else:
logger.info('资源检查', '资源完好,无需下载')
logger.info('资源检查', '<g>资源完好,无需下载</g>')

View File

@ -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进行配置