-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
68 lines (53 loc) · 1.87 KB
/
run.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
"""
The main module for mcstatus-discord bot
Should be run using "python3.11+ run.py"
mcstatus-discordbot is a Discord Bot which displays simple information
about a configured minecraft server
"""
import asyncio
import config
import cogs
from discord.ext import commands
from typing import List
from config import load_bot_id
COGS = [cogs.Standard, cogs.McStatus, cogs.LoopedTasks]
"""All cogs to add to the bot"""
def _start_background_tasks(cogs_to_start: List[commands.Cog]):
"""
If a cog has background tasks, start them
Cogs with background tasks need a "start_tasks" method
:param cogs_to_start: Cogs to check for start_tasks method
"""
for cog in cogs_to_start:
if hasattr(cog, 'start_tasks'):
cog.start_tasks()
def _define_on_ready(bot: commands.Bot, added_cogs: List[commands.Cog]):
"""
Defines the "on_ready" event for the bot
:param bot: commands.Bot object
:param added_cogs: A list of cogs added to the bot
"""
@bot.event
async def on_ready():
print('Ready!')
config.BOT_ID = load_bot_id(bot)
_start_background_tasks(added_cogs)
async def _add_cogs(bot: commands.Bot) -> List[commands.Cog]:
"""
Adds all cogs stored in COGS
:param bot: commands.Bot object
:return initialized_cogs: All cogs initialized (added to the bot)
"""
initialized_cogs = []
for cog in COGS:
initialized_cog = cog(bot)
initialized_cogs.append(initialized_cog)
await bot.add_cog(initialized_cog)
return initialized_cogs
if __name__ == "__main__":
mcstatus_bot = commands.Bot(command_prefix = config.PREFIX,
description = config.BOT_DESCRIPTION,
intents = config.INTENTS)
cogs = asyncio.run(_add_cogs(mcstatus_bot))
_define_on_ready(mcstatus_bot, cogs)
mcstatus_bot.run(config.TOKEN)