forked from lllbbbyyy/GCbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
55 lines (45 loc) · 1.56 KB
/
main.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
import asyncio
import os
import json
from graia.saya import Saya
from graia.saya.builtins.broadcast import BroadcastBehaviour
from graia.broadcast import Broadcast
from graia.application.entry import GraiaMiraiApplication, Session
loop = asyncio.get_event_loop()
bcc = Broadcast(loop=loop)
saya = Saya(bcc)
saya.install_behaviours(BroadcastBehaviour(bcc))
configs = {}
# 配置文件名一定是config.json
# 配置文件格式为:
# {
# "host":str形式的主机,例:"http://localhost:8080",
# "auth-key":str形式的认证串,
# "bot-qq":num形式的qq号
# }
current_path = os.path.dirname(__file__)
with open(current_path + '/config.json', 'r', encoding='utf-8') as f:
configs = json.load(f)
app = GraiaMiraiApplication(broadcast=bcc,
connect_info=Session(host=configs["host"],
authKey=configs["auth-key"],
account=configs["bot-qq"],
websocket=True))
ignore = ["__init__.py", "__pycache__"]
with saya.module_context():
for module in os.listdir("modules"):
if module in ignore:
continue
try:
if os.path.isdir(module):
saya.require(f"modules.{module}")
else:
saya.require(f"modules.{module.split('.')[0]}")
except ModuleNotFoundError:
print(f"ERROR: {module}模块出现异常")
pass
app.launch_blocking()
try:
loop.run_forever()
except KeyboardInterrupt:
exit()