-
Notifications
You must be signed in to change notification settings - Fork 0
/
josix.py
93 lines (74 loc) · 2.49 KB
/
josix.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
from os import getenv
import discord
from discord.ext import commands
from dotenv import load_dotenv
from psycopg2 import Error
import pkg.logwrite as log
from database.database import DatabaseHandler
EXIT = True
class Josix(commands.Bot):
"""
The main class that represents Josix bot
Attributes
----------
db : DatabaseHandler
A handler for the connection with the database to perform requests
Methods
-------
run()
Run the bot
"""
load_dotenv(".env.dev")
_TOKEN = getenv("DISCORD")
def __init__(self, bot_intents: discord.Intents) -> None:
super().__init__(
description="Josix !",
activity=discord.Game("/help and stats"), # The activity
intents=bot_intents,
help_command=None
)
try:
self.db = DatabaseHandler()
except Error as error:
log.writeError(log.formatError(error))
if EXIT:
exit(1)
self._extensions()
def _extensions(self) -> None:
"""
Load all the extensions of the bot.
Goes recursively in the cogs file and load every python
file that does not starts with an underscore
Once done, check the results for each extension, and log it
"""
try:
res = self.load_extension("cogs", recursive=True, store=True)
if res is None or isinstance(res, list):
return
for cogName, cogRes in res.items():
if isinstance(cogRes, Exception):
log.writeError(log.formatError(cogRes))
elif isinstance(cogRes, bool) and cogRes:
log.writeLog(f"Extension {cogName} succesfully loaded")
except Exception as error:
log.writeError(log.formatError(error))
def get_handler(self) -> DatabaseHandler:
return self.db
def run(self) -> None:
super().run(Josix._TOKEN)
if __name__ == "__main__":
# The informations available for the bot
intents = discord.Intents.none()
intents.members = True
intents.guilds = True
intents.guild_messages = True
intents.bans = True
intents.emojis_and_stickers = True
intents.webhooks = True
intents.messages = True
intents.message_content = True
intents.reactions = True
intents.auto_moderation_configuration = True
intents.auto_moderation_execution = True
josix = Josix(intents)
josix.run()