index — Deutsche-Haus-Bot @ 9933058c10457e9e283e19030297be4b09d0dea6

Discord bot to dynamically create voice chats for clubs that boosters can create

bot+db: fix setup (updated dependencies?)
crispy-caesus crispy@crispy-caesus.eu
Tue, 18 Nov 2025 09:40:04 +0100
commit

9933058c10457e9e283e19030297be4b09d0dea6

parent

29ce5c3411710451c9388091383625f89664e348

2 files changed, 22 insertions(+), 12 deletions(-)

jump to
M bot.pybot.py

@@ -28,16 +28,19 @@

@bot.listen() async def on_guild_join(guild): - db = await init_db(guild) - await db.create_tables() + db = await init_db(guild, guild=guild) print(f"LOG: guild {guild} joined") # ====================== DB INIT ========================= # async def init_db(ctx, guild=None) -> database.Database: if guild: - return database.Database(f"{guild.id}.db") - return database.Database(f"{ctx.guild.id}.db") + db = database.Database(f"{guild.id}.db") + else: + db = database.Database(f"{ctx.guild.id}.db") + await db.initial_setup() + + return db # ======================== ERROR HANDLING ============================= #

@@ -93,7 +96,10 @@ if await is_admin(ctx) is False:

return db = await init_db(ctx) + await db.initial_setup() ids = await db.get_discord_ids() + + print(ids) checks = [] for id in ids:

@@ -104,13 +110,13 @@ checks.append("✅")

await ctx.respond( f"{checks[0] - } Setze die Booster Rolle mit `/{nameof(setze_booster_rolle)}`\n" + } Setze die Booster Rolle mit `/{nameof(setze_booster_rolle)[0]}`\n" f"{checks[1]} Setze den Verteiler Channel mit `/{ - nameof(setze_verteiler_channel)}`\n" + nameof(setze_verteiler_channel)[0]}`\n" f"{checks[2]} Setze die Kategorie, in der die Clubs erstellt werden sollen mit `/{ - nameof(setze_club_kategorie)}`\n" + nameof(setze_club_kategorie)[0]}`\n" f"{checks[3]} Setze die Rolle, welche als Clubrollenheader dient mit `/{ - nameof(setze_clubrollenheader_rolle)}`" + nameof(setze_clubrollenheader_rolle)[0]}`" ) return

@@ -302,7 +308,7 @@ member = await member_converter.convert(ctx, member)

response = await db.select_role_id_by_owner(ctx.author.id) if response is None: - await ctx.respond("Du hast keinen Club") + await ctx.respond(":x: Du hast keinen Club") return role = discord.utils.get(ctx.guild.roles, id=response)
M db.pydb.py

@@ -2,11 +2,15 @@ import aiosqlite

from aiosqlite import Error class Database(): - def __init__(self, db_name: str): self.db_name = db_name + print(db_name) # ====================== INITIALIZATION ======================== # + async def initial_setup(self): + await self.create_tables() + await self.create_id_rows() + # could be done more flexibly somehow probably, receiving the schema from the logic.py, but ehhhhhhhhhhh (also not databse independent then) async def create_tables(self): async with aiosqlite.connect(self.db_name) as db:

@@ -16,7 +20,7 @@ channel_name TEXT NOT NULL UNIQUE,

owner_id INTEGER NOT NULL UNIQUE, role_id INTEGER NOT NULL UNIQUE, role_name TEXT NOT NULL UNIQUE);""") - await db.commit() + await db.commit() await db.execute("""CREATE TABLE IF NOT EXISTS members ( id INTEGER PRIMARY KEY, user_id INTEGER NOT NULL,

@@ -41,7 +45,7 @@ async def create_id_rows(self):

id_types = ["booster_role_id", "distributor_channel_id", "new_channel_category_id", "club_role_header_role_id"] for id_type in id_types: async with aiosqlite.connect(self.db_name) as db: - await db.execute("""INSERT INTO ids (id_type) VALUES(?);""", (id_type,)) + await db.execute("""INSERT OR IGNORE INTO ids (id_type) VALUES(?);""", (id_type,)) await db.commit() # ========================= SETUP ============================ #