-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
72 lines (57 loc) · 2.11 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
# Python imports
from os import environ
import logging
# Third Party imports
from dotenv import load_dotenv
from interactions.api.events import Startup
from interactions import Activity, ActivityType, Client, Intents, listen, slash_command, InteractionContext
# Configuring logging cuz why not
logging.basicConfig(level=logging.ERROR)
# IMP: Intents is set to "ALL" for development phase only.
bot = Client(intents=Intents.ALL, send_command_tracebacks=False)
# Setting up bot's activity & status
@listen(Startup)
async def on_startup() -> None:
logging.debug("on_startup function is called. Setting up Ms. Haven's initial state.")
activity = Activity.create(
name="Cavetown",
type=ActivityType.LISTENING
)
await bot.change_presence(activity=activity)
# Loading environment variables (refer README.md)
load_dotenv()
bot_token = environ.get("BOT_TOKEN")
if not bot_token:
logging.error("Bot token is missing. Please set the BOT_TOKEN environment variable.")
exit(1)
# Checking if the bot is online
@slash_command(name='disaster', description="Check if I'm online!",dm_permission=False)
async def disaster(ctx: InteractionContext):
await ctx.send('> Response speed: {0} ms'.format(round(bot.latency * 100, 2)))
# Lists of Extensions(Modules essentially)
extensions = [
"Fun.Confessions",
"Fun.XPSystem",
"Moderation.AdvanceMod",
"Moderation.BasicMod",
"Moderation.ModLog",
"Utilities.ChannelUtils",
"Utilities.ServerUtils",
]
# Loading these extensions
for index, extension in enumerate(extensions, start=1):
try:
logging.info(f"Loading extension {index}: {extension}")
bot.load_extension(extension)
logging.info(f"Extension {index}: {extension} loaded successfully.\n")
except Exception as e:
logging.error(f"Extension {index}: {extension} failed to load. Error: {e}\n")
# Starting bot
try:
logging.debug("Ms. Haven is starting...")
bot.start(bot_token)
except KeyboardInterrupt:
bot.close()
logging.info("Bot terminated by user.")
except Exception as e:
logging.error(f"An error occurred during bot startup: {e}")