mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-12 06:55:49 +08:00
✨ 新增on_core_start
装饰器和拆分exec_list
This commit is contained in:
parent
59b5d4648e
commit
919a296988
@ -19,7 +19,9 @@ from gsuid_core.config import core_config # noqa: E402
|
||||
from gsuid_core.data_store import image_res # noqa: E402
|
||||
from gsuid_core.handler import handle_event # noqa: E402
|
||||
from gsuid_core.models import MessageReceive # noqa: E402
|
||||
from gsuid_core.server import core_start_def # noqa: E402
|
||||
from gsuid_core.webconsole.mount_app import site # noqa: E402
|
||||
from gsuid_core.utils.database.startup import exec_list # noqa: E402
|
||||
from gsuid_core.aps import start_scheduler, shutdown_scheduler # noqa: E402
|
||||
from gsuid_core.utils.plugins_config.models import ( # noqa: E402
|
||||
GsListStrConfig,
|
||||
@ -40,6 +42,21 @@ app = FastAPI()
|
||||
HOST = core_config.get_config('HOST')
|
||||
PORT = int(core_config.get_config('PORT'))
|
||||
|
||||
exec_list.extend(
|
||||
[
|
||||
'ALTER TABLE GsBind ADD COLUMN group_id TEXT',
|
||||
'ALTER TABLE GsBind ADD COLUMN sr_uid TEXT',
|
||||
'ALTER TABLE GsUser ADD COLUMN sr_uid TEXT',
|
||||
'ALTER TABLE GsUser ADD COLUMN sr_region TEXT',
|
||||
'ALTER TABLE GsUser ADD COLUMN fp TEXT',
|
||||
'ALTER TABLE GsUser ADD COLUMN device_id TEXT',
|
||||
'ALTER TABLE GsUser ADD COLUMN sr_sign_switch TEXT DEFAULT "off"',
|
||||
'ALTER TABLE GsUser ADD COLUMN sr_push_switch TEXT DEFAULT "off"',
|
||||
'ALTER TABLE GsUser ADD COLUMN draw_switch TEXT DEFAULT "off"',
|
||||
'ALTER TABLE GsCache ADD COLUMN sr_uid TEXT',
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@app.websocket('/ws/{bot_id}')
|
||||
async def websocket_endpoint(websocket: WebSocket, bot_id: str):
|
||||
@ -66,6 +83,12 @@ async def startup_event():
|
||||
from gsuid_core.webconsole.__init__ import start_check
|
||||
|
||||
await start_check()
|
||||
try:
|
||||
_task = [_def() for _def in core_start_def]
|
||||
asyncio.gather(*_task)
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
|
||||
except ImportError:
|
||||
logger.warning('未加载GenshinUID...网页控制台启动失败...')
|
||||
await start_scheduler()
|
||||
|
@ -9,6 +9,14 @@ from fastapi import WebSocket
|
||||
from gsuid_core.bot import _Bot
|
||||
from gsuid_core.logger import logger
|
||||
|
||||
core_start_def = set()
|
||||
|
||||
|
||||
def on_core_start(func: Callable):
|
||||
if func not in core_start_def:
|
||||
core_start_def.add(func)
|
||||
return func
|
||||
|
||||
|
||||
class GsServer:
|
||||
_instance = None
|
||||
|
@ -523,7 +523,7 @@ class User(BaseModel):
|
||||
) -> List[T_User]:
|
||||
sql = select(cls).where(cls.cookie is not None, cls.cookie != '')
|
||||
result = await session.execute(sql)
|
||||
data: List[T_User] = result.scalars().all()
|
||||
data = result.scalars().all()
|
||||
return data
|
||||
|
||||
@classmethod
|
||||
|
18
gsuid_core/utils/database/startup.py
Normal file
18
gsuid_core/utils/database/startup.py
Normal file
@ -0,0 +1,18 @@
|
||||
from sqlalchemy.sql import text
|
||||
|
||||
from gsuid_core.server import on_core_start
|
||||
|
||||
from .base_models import async_maker
|
||||
|
||||
exec_list = []
|
||||
|
||||
|
||||
@on_core_start
|
||||
async def sr_adapter():
|
||||
async with async_maker() as session:
|
||||
for _t in exec_list:
|
||||
try:
|
||||
await session.execute(text(_t))
|
||||
await session.commit()
|
||||
except: # noqa: E722
|
||||
pass
|
Loading…
x
Reference in New Issue
Block a user