34 lines
903 B
Python
34 lines
903 B
Python
import nonebot
|
|||
|
|
from nonebot.adapters.onebot.v11 import Adapter as ONEBOTV11Adapter
|
||
|
|
from nonebot.log import logger
|
||
|
|
from sqlalchemy import StaticPool
|
||
|
|
from starlette.middleware.cors import CORSMiddleware
|
||
|
|
|
||
|
|
# 初始化 NoneBot 以及 数据库
|
||
|
|
nonebot.init(datastore_engine_options={"poolclass": StaticPool})
|
||
|
|
|
||
|
|
# 获取应用和驱动实例
|
||
|
|
app = nonebot.get_app()
|
||
|
|
app.add_middleware(
|
||
|
|
CORSMiddleware,
|
||
|
|
allow_origins=[
|
||
|
|
"http://localhost:5173",
|
||
|
|
"http://192.168.2.186:5173",
|
||
|
|
"http://127.0.0.1:5173"
|
||
|
|
],
|
||
|
|
allow_credentials=True,
|
||
|
|
allow_methods=["*"],
|
||
|
|
allow_headers=["*"],
|
||
|
|
)
|
||
|
|
driver = nonebot.get_driver()
|
||
|
|
|
||
|
|
# 注册适配器
|
||
|
|
driver.register_adapter(ONEBOTV11Adapter)
|
||
|
|
|
||
|
|
# 加载插件
|
||
|
|
nonebot.load_plugins("hexi")
|
||
|
|
nonebot.load_from_toml("pyproject.toml")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
logger.warning("hexi?启动!")
|
||
|
|
nonebot.run() # 直接运行,不需要传参
|