-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.py
81 lines (57 loc) · 1.84 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
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
import importlib
import json
import asyncio
import discord
client = discord.Client()
modules = []
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
@client.event
async def on_message(message):
# Handle help command
if message.content.startswith("!help"):
content = message.content.replace("!help", "").strip()
if len(content) == 0:
output = "```\n"
for module in modules:
output += module.handle_help()
output += "```"
await message.channel.send(output)
else:
content = content.split()
signal = content[0]
output = ""
for module in modules:
output += module.handle_help(command_name=signal)
await message.channel.send(output)
else:
for module in modules:
await module.handle_message(client, message)
if message.content.startswith('!sleep'):
await asyncio.sleep(5)
await message.channel.send("Done sleeping")
if __name__ == "__main__":
with open("config.json", "r") as f:
config = json.load(f)
print("Loading Modules...")
for module_name in config["handlers"]:
try:
module = importlib.import_module("handlers." + module_name)
modules.append(module.Module())
except:
print("Failed to load module: " + module_name)
print("Modules loaded.")
print("Initializing Modules...")
for module in modules:
try:
module.init_handlers()
except:
print("Failed to initialize module: " + str(module))
print("Modules initialized.")
with open("token.txt", "r") as f:
token = f.read().replace("\n", "")
client.run(token)