-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
rubbergod.py
106 lines (85 loc) · 3.56 KB
/
rubbergod.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
94
95
96
97
98
99
100
101
102
103
104
105
106
from __future__ import annotations
import logging
from datetime import datetime, timezone
from typing import TYPE_CHECKING
import aiohttp
import disnake
from disnake import AllowedMentions, Intents, TextChannel
from disnake.ext import commands
import database.db_migrations as migrations
from config.app_config import config
from config.messages import Messages
from features.git import Git
if TYPE_CHECKING:
from features.error import ErrorLogger
class Rubbergod(commands.Bot):
is_initialized = False
logger: logging.Logger
err_logger: ErrorLogger
def __init__(self):
self.logger = logging.getLogger("rubbergod")
intents = Intents.none()
intents.guilds = True
intents.members = True
intents.emojis = True
intents.messages = True
intents.message_content = True
intents.reactions = True
intents.presences = True
intents.moderation = True
intents.automod_execution = True
super().__init__(
command_prefix=commands.when_mentioned_or(*config.command_prefix),
help_command=None,
case_insensitive=True,
allowed_mentions=AllowedMentions(roles=False, everyone=False, users=True),
intents=intents,
command_sync_flags=commands.CommandSyncFlags(sync_commands=True, sync_commands_debug=False),
)
# Create missing tables at start
migrations.init_db()
async def on_ready(self) -> None:
"""If RubberGod is ready"""
# Inspired from https://github.com/sinus-x/rubbergoddess/blob/master/rubbergoddess.py
if self.is_initialized:
return
self.is_initialized = True
await self.create_sessions()
bot_room: TextChannel = self.get_channel(config.bot_room)
if bot_room is not None:
await bot_room.send(Messages.on_ready_message)
await self.application_info()
await self.set_presence()
self.logger.info("Ready")
async def on_button_click(self, inter: disnake.MessageInteraction):
if inter.component.custom_id in [Messages.trash_delete_id, "bookmark:delete"]:
try:
await inter.message.delete()
except disnake.NotFound:
pass
async def on_error(self, event, *args, **kwargs):
return await self.err_logger.handle_event_error(event, args)
def init_cogs(self) -> None:
self.load_extension("cogs.system")
self.logger.info("SYSTEM loaded")
for extension in config.extensions:
self.load_extension(f"cogs.{extension}")
self.logger.info(f"{extension.upper()} loaded")
async def create_sessions(self):
owner_id = str(self.owner_id)
rubbergod_headers = {"Author": owner_id}
grillbot_headers = {"ApiKey": config.grillbot_api_key, "Author": owner_id}
vut_api_headers = {"Authorization": f"Bearer {config.vut_api_key}", "Author": owner_id}
self.rubbergod_session = aiohttp.ClientSession(
timeout=aiohttp.ClientTimeout(total=10), headers=rubbergod_headers
)
self.grillbot_session = aiohttp.ClientSession(
timeout=aiohttp.ClientTimeout(total=10), headers=grillbot_headers
)
self.vutapi_session = aiohttp.ClientSession(
timeout=aiohttp.ClientTimeout(total=10), headers=vut_api_headers
)
async def set_presence(self):
git = Git()
activity = disnake.Game(name=f"hash {git.short_hash()}", start=datetime.now(timezone.utc))
await self.change_presence(activity=activity)