creates channels with lacking functionality
crispy-caesus 114518720+crispy-caesus@users.noreply.github
Fri, 18 Oct 2024 23:55:41 +0200
M
bot.py
→
bot.py
@@ -104,11 +104,12 @@ return
member = await member_converter.convert(ctx, member) - response = await db.select_club_by_owner(ctx.author.id) + response = await db.select_role_id_by_owner(ctx.author.id) if response == None: await ctx.respond("Du hast keinen Club") return - role = await role_converter.convert(ctx, str(response)) + print(f"{type(response)}: {response}") + role = discord.utils.get(ctx.guild.roles, id=response) await member.add_roles(role)@@ -121,17 +122,37 @@ await ctx.respond(f"Pong! Latency is {bot.latency}")
# ==================== distributor vc ======================= # -@bot.slash_command(description="Setzt join to create VC") -@discord.ext.commands.has_role(1170646611332956208) -async def verteiler_setzen(kanal_id): - pass +@bot.event +async def on_voice_state_update(user, before, after): + if before.channel != after.channel: + if after.channel and after.channel.id == 1052988388250226691: + print(f"{user.name} Joined The {after.channel.name} VC") + print(after.channel.members) + + db = database.Database(f"{after.channel.guild.id}.db") + category = discord.utils.get(after.channel.guild.categories, id=await db.get_discord_id("new_channel_category_id")) + if category is None: + print("Kategorie nicht gefunden") + + role = discord.utils.get(after.channel.guild.roles, id=await db.get_discord_id("booster_role_id")) + if role is None: + print("Rolle nicht gefunden") + -#@bot.listen() -async def on_voice_state_update(user, before, after): - if after.channel.id == 1: - print(f"{user.name} Joined The {after.channel.name} VC") - print(after.channel.members) + overwrites = { + after.channel.guild.default_role: discord.PermissionOverwrite(view_channel=False), # @everyone can't view + role: discord.PermissionOverwrite(view_channel=True, connect=True) # Role can view and connect + } + response = await db.get_channel_name_role_name_by_member(user.id) + channel_name = response[0][0] + print(f"{type(channel_name)}: {channel_name}") + + voice_channel = await category.create_voice_channel( + name = channel_name, + overwrites=overwrites + ) + print(f"Voice channel '{channel_name}' created under the category '{category}' and restricted to the role '{role}'.") bot.run(bot_token.token)
M
db.py
→
db.py
@@ -33,7 +33,7 @@ roles TEXT NOT NULL UNIQUE);""")
await db.commit() await db.execute("""CREATE TABLE IF NOT EXISTS ids ( id INTEGER PRIMARY KEY, - id_type INTEGER UNIQUE NOT NULL, + id_type TEXT UNIQUE NOT NULL, discord_id INTEGER NOT NULL);""") await db.commit()@@ -63,11 +63,11 @@ async with aiosqlite.connect(self.db_name) as db:
async with db.execute("SELECT discord_id FROM ids WHERE id_type = 'booster_role_id';") as cursor: return((await cursor.fetchone())[0]) - async def select_club_by_owner(self, owner_id): + async def select_role_id_by_owner(self, owner_id): async with aiosqlite.connect(self.db_name) as db: try: - async with db.execute("SELECT * FROM clubs WHERE owner_id = ?;", (owner_id,)) as cursor: - return(await cursor.fetchone()) + async with db.execute("SELECT role_id FROM clubs WHERE owner_id = ?;", (owner_id,)) as cursor: + return(await cursor.fetchone()[3]) except Error as e: print(e) return("❌ Error! Du besitzt keinen Club")@@ -170,3 +170,24 @@ clubs.append(row)
return clubs + + + async def get_channel_name_role_name_by_member(self, user_id)->list: + clubs = [] + async with aiosqlite.connect(self.db_name) as db: + async with db.execute("SELECT club_id FROM members WHERE user_id = ?;", (user_id,)) as cursor: + async for club_id in cursor: + print(f"{type(club_id[0])}: {club_id[0]}") + async with db.execute("SELECT channel_name, role_name FROM clubs WHERE id = ?;", (club_id[0], )) as cursor2: + async for club in cursor2: + clubs.append(club) + print(clubs) + + return clubs + + + + + + +
M
logic.py
→
logic.py
@@ -70,7 +70,7 @@ case 1: # check if booster
return(await db.get_booster_role_id()) case 2: # check for ability to create given club - existing_club_of_owner = await db.select_club_by_owner(owner_id) + existing_club_of_owner = await db.select_role_id_by_owner(owner_id) if existing_club_of_owner != None: return("❌ Error! Du hast bereits einen Club")@@ -86,7 +86,7 @@ if emoji.emoji_count(channel_name_without_emoji) > 0:
return("❌ Error! Der Kanalname darf keine Emojis enthalten") - combined_channel_name = f"「{emoji}」{channel_name_without_emoji}" + combined_channel_name = f"「{emoji_}」{channel_name_without_emoji}" existing_club = await db.select_club_by_channel_name(combined_channel_name) if existing_club != None: return("❌ Error! Es gibt bereits einen Club mit diesem Kanalnamen")@@ -106,11 +106,11 @@ return(role_name, color)
case 3: - error = await db.create_club(f"「{emoji}」{channel_name_without_emoji}", owner_id, int(color), role_name) + error = await db.create_club(f"「{emoji_}」{channel_name_without_emoji}", owner_id, int(color), role_name) if error != None: return(error) else: - return(f"✅ Club `「{emoji}」{channel_name_without_emoji}` erstellt!") + return(f"✅ Club `「{emoji_}」{channel_name_without_emoji}` erstellt!") # ==================================== EDIT CLUB ============================= #