index — Deutsche-Haus-Bot @ 2813526592488834341398c22710c73a9e608a0e

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

some database structure
crispy-caesus 114518720+crispy-caesus@users.noreply.github.com
Fri, 09 Aug 2024 00:30:04 +0200
commit

2813526592488834341398c22710c73a9e608a0e

parent

97216eb443942ca3a720b3ebbfe5faab65613025

3 files changed, 72 insertions(+), 0 deletions(-)

jump to
M .gitignore.gitignore

@@ -1,2 +1,3 @@

bot_token.py __pycache__/* +*.db
M bot.pybot.py

@@ -1,7 +1,15 @@

import discord import bot_token +import aiosqlite bot = discord.Bot() + +@bot.on_guild_join() +def joined(guild) + + + + @bot.slash_command() async def hello(ctx, name: str = None):
A db.py

@@ -0,0 +1,63 @@

+import aiosqlite +from aiosqlite import Error +import asyncio + +class Database(): + + def __init__(self, db_name: str): + self.db_name = db_name + + async def list_tables(self): + async with aiosqlite.connect(self.db_name) as db: + async with db.execute("SELECT name FROM sqlite_master WHERE type = 'table';") as cursor: + async for row in cursor: + print(row) + + async def create_table(self): + async with aiosqlite.connect(self.db_name) as db: + await db.execute("""CREATE TABLE IF NOT EXISTS clubs ( + id INTEGER PRIMARY KEY, + channel_name TEXT NOT NULL UNIQUE, + owner INTEGER NOT NULL UNIQUE, + role_id INTEGER NOT NULL UNIQUE);""") + await db.commit() + + async def create_club(self, channel_name: str, owner: int, role_id: int): + args = (channel_name, owner, role_id) + sql = """INSERT INTO clubs (channel_name,owner,role_id) + VALUES(?,?,?);""" + try: + async with aiosqlite.connect(self.db_name) as db: + await db.execute(sql, args) + await db.commit() + except Error as e: + print(e) + return("Club existiert schon") + + + + async def select_clubs(self): + clubs = [] + async with aiosqlite.connect(self.db_name) as db: + async with db.execute("SELECT * FROM clubs;") as cursor: + async for row in cursor: + clubs.append(row) + +""" + async def select_clubs_of_member(self, member: int): + clubs = [] + async with aiosqlite.connect(self.db_name) as db: + async with db.execute("SELECT * FROM clubs WHERE ;") as cursor: + async for row in cursor: + clubs.append(row) +""" +# seperate users table with user and foreign key club id +# select * where user=... and translate to club + + + +my_db = Database("test.db") +asyncio.run(my_db.create_table()) +asyncio.run(my_db.list_tables()) +print(asyncio.run(my_db.create_club("test channel", 123123, 12312))) +print(asyncio.run(my_db.select_clubs()))