From 9f7dbc0d4563db225c1ce1426c2e255ed0b82f80 Mon Sep 17 00:00:00 2001 From: Gabriella Date: Fri, 21 Nov 2025 12:27:28 -0700 Subject: [PATCH] update bot_core.py for base reaction functionality, create db_helper.py --- src/bot_core.py | 26 +++++++++++++++++++++++- src/helper/db_helper.py | 44 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 src/helper/db_helper.py diff --git a/src/bot_core.py b/src/bot_core.py index 7ea2c5a..15cf700 100644 --- a/src/bot_core.py +++ b/src/bot_core.py @@ -6,25 +6,49 @@ from discord.ext import commands CONTRASTELLAR = 181187505448681472 +# instance variables +larboard = 0 +active_guild = 0 +# end instance variables + +# discord.py init intents = discord.Intents.default() intents.message_content = True intents.guild_messages = True intents.presences = False client = commands.Bot(command_prefix='!', intents=intents) +# end discord.py init - +# parser init parser: argparse.ArgumentParser = argparse.ArgumentParser(prog='very bad core', description='very bad bot core') parser.add_argument('token') +parser.add_argument('guild_id') +parser.add_argument('channel_id') +# end parser init # --- commands below here @client.event async def on_ready(): + await client.tree.sync() print(f'{client.user} has connected.') + print(f'we are using the guild {args.guild_id} and channel {args.channel_id}') + +@client.tree.command() +async def ping(interaction: discord.Interaction): + await interaction.response.send_message('go fuck yourself (bot is running)') + return + +@client.event +async def on_reaction_add(react: discord.Reaction, user: discord.User): + print("reaction was added!") + return + # --- end commands +# runtime lines args: argparse.Namespace = parser.parse_args() TOKEN: str = open(args.token, encoding='utf-8').read() diff --git a/src/helper/db_helper.py b/src/helper/db_helper.py new file mode 100644 index 0000000..a6b0666 --- /dev/null +++ b/src/helper/db_helper.py @@ -0,0 +1,44 @@ +""" +database interaction module of the very-bad bot + +@author: Gabriella 'contrastellar' Agathon +""" + +import psycopg2 +import psycopg2.extensions +from configparser import ConfigParser +import datetime + + +def load_config(filename='database.ini', section='postgresql'): + + parser = ConfigParser() + parser.read(filename) + + # get section, default is postgresql + config = {} + if parser.has_section(section): + params = parser.items(section) + for param in params: + config[param[0]] = param[1] + + else: + raise Exception('Section {0} not found in the {1} file'.format(section, filename)) + + return config + + +def connect_config(config) -> psycopg2.extensions.connection: + try: + with psycopg2.connect(**config) as conn: + print('connected to the server') + return conn + + except (psycopg2.DatabaseError, Exception) as error: + print(error) + + finally: + if conn is None: + raise psycopg2.DatabaseError("Failed to connect!") + +