1 Star 1 Fork 3

邓晓楠/omega-miya

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
bot.py 2.38 KB
一键复制 编辑 原始数据 按行查看 历史
Ailitonia 提交于 2021-08-25 21:34 . Change: 调整公共资源文件位置
import os
import nonebot
from datetime import datetime
from nonebot.adapters.cqhttp import Bot as CQHTTPBot
from nonebot.log import logger, default_format
# win环境下proxy配置
import sys
import asyncio
if sys.version_info[0] == 3 and sys.version_info[1] >= 8 and sys.platform.startswith('win'):
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
# File path
bot_root_path = os.path.abspath(os.path.dirname(__file__))
bot_tmp_path = os.path.abspath(os.path.join(bot_root_path, 'tmp'))
if not os.path.exists(bot_tmp_path):
os.makedirs(bot_tmp_path)
bot_log_path = os.path.abspath(os.path.join(bot_root_path, 'log'))
if not os.path.exists(bot_log_path):
os.makedirs(bot_log_path)
# Static resources path
bot_resources_path = os.path.abspath(os.path.join(bot_root_path, 'omega_miya', 'resources'))
if not os.path.exists(bot_resources_path):
os.makedirs(bot_resources_path)
# Custom logger
log_info_name = f"{datetime.today().strftime('%Y%m%d-%H%M%S')}-INFO.log"
log_error_name = f"{datetime.today().strftime('%Y%m%d-%H%M%S')}-ERROR.log"
log_info_path = os.path.join(bot_log_path, log_info_name)
log_error_path = os.path.join(bot_log_path, log_error_name)
logger.add(log_info_path, rotation="00:00", diagnose=False, level="INFO", format=default_format, encoding='utf-8')
logger.add(log_error_path, rotation="00:00", diagnose=False, level="ERROR", format=default_format, encoding='utf-8')
# Add extra debug log file
# log_debug_name = f"{datetime.today().strftime('%Y%m%d-%H%M%S')}-DEBUG.log"
# log_debug_path = os.path.join(bot_log_path, log_debug_name)
# logger.add(log_debug_path, rotation="00:00", diagnose=False, level="DEBUG", format=default_format, encoding='utf-8')
# You can pass some keyword args config to init function
nonebot.init()
# 初始化一些系统变量配置
config = nonebot.get_driver().config
config.root_path_ = bot_root_path
config.tmp_path_ = bot_tmp_path
config.resources_path_ = bot_resources_path
# 注册 cqhttp adapter
driver = nonebot.get_driver()
driver.register_adapter("cqhttp", CQHTTPBot)
nonebot.load_plugins("omega_miya/utils")
nonebot.load_plugins("omega_miya/plugins")
# Modify some config / config depends on loaded configs
# config = nonebot.get_driver().config
# do something...
# nonebot.load_plugin("nonebot_plugin_test")
# nonebot.require("nonebot_plugin_apscheduler").scheduler.print_jobs()
if __name__ == "__main__":
nonebot.run()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/dengtianlang/omega-miya.git
git@gitee.com:dengtianlang/omega-miya.git
dengtianlang
omega-miya
omega-miya
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385