-
Notifications
You must be signed in to change notification settings - Fork 1
/
pandehelper.py
70 lines (62 loc) · 2.29 KB
/
pandehelper.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
import os
import discord
import logging
from datetime import datetime
import bot.db.connection
import bot.utils.bloonsdata
from bot import __version__
from discord.ext import commands
from config import TOKEN, APP_ID, DATA_PATH
from bot.utils.colors import purple
class PandeHelper(commands.Bot):
def __init__(self):
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
super().__init__(
command_prefix=commands.when_mentioned_or(",,,"),
intents=intents,
application_id=APP_ID,
activity=discord.CustomActivity(name="pandehelper.sarto.dev"),
)
self.remove_command("help")
self.version = __version__
self.last_restart = datetime.now()
self.synced_tree = None
async def setup_hook(self):
await bot.utils.bloonsdata.init_bloonspy_client()
await bot.db.connection.start()
cogs = [
"OwnerCog",
"TrackerCog",
"LeaderboardCog",
"TilestratCog",
"UtilsCog",
"PlannerCog",
"WelcomeCog",
"TilesCog",
]
for cog in cogs:
await self.load_extension(f"bot.cogs.{cog}")
print(f"{purple('[PandeHelper]')} Loaded all cogs")
async def get_app_command(self, cmd_name: str) -> discord.app_commands.AppCommand or None:
if self.synced_tree is None:
self.synced_tree = await self.tree.fetch_commands()
return discord.utils.get(self.synced_tree, name=cmd_name)
def reload_version(self):
with open("bot/__init__.py") as fin:
for ln in fin:
ln = ln.strip()
if ln.startswith("__version__ = \""):
self.version = ln[len("__version__ = \""):-1]
return
async def signal(self, event: str, *args, **kwargs) -> None:
for cog_name in self.cogs:
cog = self.cogs[cog_name]
if hasattr(cog, event):
handler = getattr(cog, event)
await handler(*args, **kwargs)
if __name__ == '__main__':
os.chdir(os.path.abspath(os.path.dirname(__file__)))
os.makedirs(os.path.join(DATA_PATH, "tmp"), exist_ok=True)
PandeHelper().run(TOKEN, log_level=logging.ERROR)