-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain.py
73 lines (53 loc) · 1.86 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
"""Main file, intended to be launched."""
__version__ = "under developpement"
import json
from discord import Intents
from discord.ext import commands
from cogs.omega import Omega
from cogs.moderation import Moderation
from cogs.fun import Fun, Confession
from logs.logger import logger
# Configuration.
with open("config.json", encoding="utf-8") as file:
config = json.load(file)
class Bot(commands.Bot):
"""Encapsulate a discord bot."""
extensions = (
Fun,
Moderation,
Omega
)
optionals = {
Confession: config["CONFESSION"]["ENABLED"]
}
def __init__(self):
intents = Intents.default()
intents.message_content = True
super().__init__(config["PREFIX"], intents=intents)
self.description = "A bot for two Omega Discord servers."
self.token = config["TOKEN"]
async def on_ready(self):
"""Log information about bot launching."""
logger.info("Bot %s connected on %s servers",
self.user.name,
len(self.guilds))
async def on_command(self, msg):
"""Log each command submitted. Log message provides information
about name, author and arguments of the command.
"""
args = msg.args[2:]
args_info = ', '.join(repr(arg) for arg in args) if args else ""
log_msg = (f"{msg.command.name} called by {msg.author} with "
f"args {args_info}.")
logger.info(log_msg)
def run(self):
"""Start the bot and load one by one available cogs."""
for cog in self.extensions:
self.add_cog(cog(self, config))
for cog, requirement in self.optionals.items():
if requirement:
self.add_cog(cog(self, config))
super().run(self.token)
if __name__ == "__main__":
omega_robot = Bot()
omega_robot.run()