update bot_core.py for base reaction functionality, create db_helper.py

This commit is contained in:
2025-11-21 12:27:28 -07:00
parent a3c6a080e4
commit 9f7dbc0d45
2 changed files with 69 additions and 1 deletions

View File

@@ -6,25 +6,49 @@ from discord.ext import commands
CONTRASTELLAR = 181187505448681472 CONTRASTELLAR = 181187505448681472
# instance variables
larboard = 0
active_guild = 0
# end instance variables
# discord.py init
intents = discord.Intents.default() intents = discord.Intents.default()
intents.message_content = True intents.message_content = True
intents.guild_messages = True intents.guild_messages = True
intents.presences = False intents.presences = False
client = commands.Bot(command_prefix='!', intents=intents) client = commands.Bot(command_prefix='!', intents=intents)
# end discord.py init
# parser init
parser: argparse.ArgumentParser = argparse.ArgumentParser(prog='very bad core', parser: argparse.ArgumentParser = argparse.ArgumentParser(prog='very bad core',
description='very bad bot core') description='very bad bot core')
parser.add_argument('token') parser.add_argument('token')
parser.add_argument('guild_id')
parser.add_argument('channel_id')
# end parser init
# --- commands below here # --- commands below here
@client.event @client.event
async def on_ready(): async def on_ready():
await client.tree.sync()
print(f'{client.user} has connected.') 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 # --- end commands
# runtime lines
args: argparse.Namespace = parser.parse_args() args: argparse.Namespace = parser.parse_args()
TOKEN: str = open(args.token, encoding='utf-8').read() TOKEN: str = open(args.token, encoding='utf-8').read()

44
src/helper/db_helper.py Normal file
View File

@@ -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!")