From bb1088583095c3a389b21693a29e5eb360150f30 Mon Sep 17 00:00:00 2001 From: marksverdhei <> Date: Sat, 29 Apr 2023 10:25:59 +0200 Subject: [PATCH 1/4] Add optional database loading and configurable guild id --- src/run.py | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/run.py b/src/run.py index c8e2b0c..d7afc86 100644 --- a/src/run.py +++ b/src/run.py @@ -9,6 +9,14 @@ import yaml from logger import BotLogger +UIO_GAMING_GUILD_ID = 412646636771344395 +DATABASE_RELIANT_COGS = { + "birthday.py", + "gullkorn.py", + "mc_whitelist.py", + "word_cloud.py", +} + # Load config file with codecs.open('./src/config/config.yaml', 'r', encoding='utf8') as f: @@ -27,15 +35,26 @@ class Bot(commands.Bot): self.logger = BotLogger().logger # Initialize logger + self.guild_id = config.get("guild", UIO_GAMING_GUILD_ID) + # Connect to database - db = config.get('database', {}) - self.db_connection = psycopg2.connect( - host=db['host'], - dbname=db['dbname'], - user=db['username'], - password=db['password'], - ) - self.db_connection.autocommit = True + db = config.get('database') + + if db is not None: + self.db_connection = psycopg2.connect( + host=db['host'], + dbname=db['dbname'], + user=db['username'], + password=db['password'], + ) + self.db_connection.autocommit = True + else: + self.db_connection = None + self.logger.warning( + "No database credentials specified. " + "Disabling db reliant cogs:\n{DATABASE_RELIANT_COGS}" + ) + # Fetch misc config values self.mc_rcon_password = config['minecraft']['rcon_password'] @@ -46,8 +65,13 @@ class Bot(commands.Bot): self.config_mode = config.get('config_mode') async def setup_hook(self): + cog_files = listdir('./src/cogs') + + if self.db_connection is None: + cog_files = set(cog_files) - DATABASE_RELIANT_COGS + # Load cogs - for file in listdir('./src/cogs'): + for file in cog_files: if file.endswith('.py'): name = file[:-3] await bot.load_extension(f'cogs.{name}') @@ -56,8 +80,8 @@ class Bot(commands.Bot): if self.config_mode == 'prod': await self.tree.sync() else: - self.tree.copy_global_to(guild=discord.Object(id=412646636771344395)) - await self.tree.sync(guild=discord.Object(id=412646636771344395)) + self.tree.copy_global_to(guild=discord.Object(id=self.guild_id)) + await self.tree.sync(guild=discord.Object(id=self.guild_id)) # Create bot instance From f7b9f54203a29b6d52f9fcd79394f92ac575adaa Mon Sep 17 00:00:00 2001 From: LBlend Date: Sun, 30 Apr 2023 23:20:58 +0900 Subject: [PATCH 2/4] set actual uiog guild id as fallback dev guild --- src/run.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/run.py b/src/run.py index d7afc86..1fcd126 100644 --- a/src/run.py +++ b/src/run.py @@ -9,7 +9,8 @@ import yaml from logger import BotLogger -UIO_GAMING_GUILD_ID = 412646636771344395 + +UIO_GAMING_GUILD_ID = 747542543750660178 DATABASE_RELIANT_COGS = { "birthday.py", "gullkorn.py", From cbbf851c831414b6d4cdd06567edb11903a6d104 Mon Sep 17 00:00:00 2001 From: LBlend Date: Sun, 30 Apr 2023 23:22:21 +0900 Subject: [PATCH 3/4] rename guild id config parameter --- src/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/run.py b/src/run.py index 1fcd126..8c7ed7c 100644 --- a/src/run.py +++ b/src/run.py @@ -36,7 +36,7 @@ class Bot(commands.Bot): self.logger = BotLogger().logger # Initialize logger - self.guild_id = config.get("guild", UIO_GAMING_GUILD_ID) + self.guild_id = config.get("dev_guild", UIO_GAMING_GUILD_ID) # Connect to database db = config.get('database') From 35116cc6327c7dbc8d82e12d774c2ed232737fa2 Mon Sep 17 00:00:00 2001 From: LBlend Date: Sun, 30 Apr 2023 23:22:37 +0900 Subject: [PATCH 4/4] add dev guild id to example config --- src/config/config.yaml.example | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/config/config.yaml.example b/src/config/config.yaml.example index d2343c9..ffbd39b 100644 --- a/src/config/config.yaml.example +++ b/src/config/config.yaml.example @@ -1,5 +1,7 @@ config_mode: dev +dev_guild: 747542543750660178 + # Bot settings bot: token: