-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit_bot.py
91 lines (80 loc) · 2.8 KB
/
init_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
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
'''下面是bot的初始化'''
import asyncio
import json
from graia.application import GraiaMiraiApplication, Session
from graia.broadcast import Broadcast
from MsgObj import Msg
from config import *
GroupQA = {}
LoveTalkList = []
temp_talk = dict() # 简易的会话管理器
WelcomeScence = {}
BlackUser = []
# 黑名单
Manager = []
# 超级管理员
FuckUser = []
# 诈骗黑名单
start_baiDu_group = []
mast_manager_group = []
quick_find_question_list = {}
shutdown_all_group = []
loop = asyncio.get_event_loop() # 获取bot运行的协程
bcc = Broadcast(loop=loop)
app = GraiaMiraiApplication(
broadcast=bcc,
connect_info=Session(
host=API_ROOT, # httpapi 服务运行的地址
authKey=AuthKey, # authKey
account=BOTQQ, # 机器人的 qq 号
websocket=True # Graia 已经可以根据所配置的消息接收的方式来保证消息接收部分的正常运作.
)
)
async def ReadQA():
try:
with open('QAindex.json', 'r') as f:
tempDict = json.loads(f.read())
for i in tempDict.keys():
GroupQA[int(i)] = tempDict[i]
for key in GroupQA[int(i)].keys():
t = tempDict[i][key]
GroupQA[int(i)][key] = Msg()
GroupQA[int(i)][key].set_dict_from_json(t)
quick_find_question_list[int(i)] = sorted(GroupQA[int(i)].keys(), key=lambda i: len(i), reverse=False)
f.close()
print("读取结束")
except:
with open('QAIndex.json', 'w+') as f:
f.close()
async def saveQA(): # 对已有问答数据进行保存
AllData = dict()
with open('QAindex.json', 'w+') as f:
for key in GroupQA:
t_dict = GroupQA[key]
indexDict = dict()
for i in t_dict:
data = json.dumps(t_dict[i].getMsgDict())
indexDict[i] = data
AllData[key] = indexDict.copy()
indexDict.clear()
f.write(json.dumps(AllData))
f.close()
print("已保存")
async def Compatible_old_index(): # 对旧有数据的转化
with open('QAindex.json', 'r') as f:
tempDick = json.loads(f.read())
for i in tempDick.keys():
tempDick[i] = json.loads(tempDick[i])
GroupQA[int(i)] = tempDick[i].copy()
for key in tempDick[i]:
txt = tempDick[i][key]
GroupQA[int(i)][key] = Msg()
TransformDict = {
'user_id': None,
'at': None,
'msg_txt': txt,
'img_url': None
}
GroupQA[int(i)][key].set_dict(TransformDict)
f.close()
await saveQA()