-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathqq_bot_core.py
112 lines (80 loc) · 3.14 KB
/
qq_bot_core.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from json import dump
from logging import getLogger, ERROR
from os import path, getcwd, mkdir, environ
from time import sleep
import nonebot
from loguru import logger
from nonebot.adapters.onebot.v11 import Adapter as OneBotdapter
# 如果下面这行报错,请暂时注释掉这行然后运行下面的main()
from awesome.adminControl import group_control
config_file = \
"""
HOST = '127.0.0.1' # 必填
PORT = 5700 # 必填
SUPER_USER = 0 # 必填
NICKNAME = {}
PIXIV_REFRESH_TOKEN = '' # 选填,用于搜图功能
OPEN_API_KEY = '' # 选填,用于chatgpt功能
DANMAKU_PROCESS = f'' # 选填,如果需要b站开播追踪功能
PATH_TO_ONEDRIVE = '' # 选填,如果需要twitch下载功能
PATH_TEMP_DOWNLOAD = '' # 选填,如果需要YouTube下载功能
FFMPEG_PATH = '' # 选填,如果需要twitch或YouTube下载功能
SHARE_LINK = '' # 选填,如果需要twitch或YouTube下载功能
SAUCE_API_KEY = '' # 选填,如果需要sauceNAO逆向图片搜索
DISCORD_AUTH = '' # 选填,如果需要discord跟踪功能
COMMAND_START = {'/', '!', '/', '!', '#'}
CLOUD_STORAGE_SIZE_LIMIT_GB = 90
BILI_SESS_DATA = "" # 选填,如果需要b站开播追踪功能
"""
nonebot.init()
driver = nonebot.get_driver()
driver.register_adapter(OneBotdapter)
nonebot.load_plugins("awesome/plugins")
def _remove_unused_files_from_db():
group_control.group_quote_startup_sanity_check()
def _init_bot_resources():
try:
_create_necessary_folders()
_remove_unused_files_from_db()
except IOError:
raise IOError(
'Error occurred while creating directory for biaoqing, and bilibiliPic.'
)
def _create_necessary_folders():
_create_dir(f'{getcwd()}/logs/')
_create_dir(f'{getcwd()}/config/')
_create_dir(f'{getcwd()}/data/')
_create_dir(f'{getcwd()}/data/biaoqing')
_create_dir(f'{getcwd()}/data/bilibiliPic')
_create_dir(f'{getcwd()}/data/bot')
_create_dir(f'{getcwd()}/data/db')
_create_dir(f'{getcwd()}/data/live')
_create_dir(f'{getcwd()}/data/pixivPic')
_create_dir(f'{getcwd()}/data/lol')
_create_dir(f'{getcwd()}/data/temp')
_create_dir(f'{getcwd()}/data/bot/stock')
def _create_dir(path_to_check: str):
if not path.exists(path_to_check):
mkdir(path_to_check)
def _create_file(path_to_check: str, dump_data=None):
if dump_data is None:
dump_data = {}
if not path.exists(path_to_check):
with open(path_to_check, 'w+', encoding='utf-8') as f:
dump(dump_data, f, indent=4, ensure_ascii=False)
def main():
logger.warning('Plugins successfully installed.')
getLogger('asyncio').setLevel(ERROR)
nonebot.run()
if __name__ == '__main__':
logger.warning(f'Working directory: {getcwd()}')
environ['PYTHONUTF8'] = '1'
if not path.exists(f'{getcwd()}/config.py'):
logger.warning('未检测到配置文件,尝试生成模板中……')
with open('config.py', 'w+', encoding='utf-8') as file:
file.write(config_file)
logger.warning('模板生成完毕!请修改config.py中的参数!')
sleep(10)
exit(1)
_init_bot_resources()
main()