forked from Ailitonia/omega-miya
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
66 lines (52 loc) · 2.38 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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()