index — Deutsche-Haus-Bot @ 938b6f9946a582a8af2e0e595a07a0790ebba6c3

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

can change colors and adjusted channel overwrite permissions
crispy-caesus 114518720+crispy-caesus@users.noreply.github.com
Wed, 23 Oct 2024 11:09:52 +0200
commit

938b6f9946a582a8af2e0e595a07a0790ebba6c3

parent

318bec16b15594c758fe24234895ad94d946c5fd

3 files changed, 41 insertions(+), 8 deletions(-)

jump to
M bot.pybot.py

@@ -94,6 +94,11 @@

await ctx.author.add_roles(role) await ctx.respond(await logic.add_club(ctx.guild.id, kanalname, emoji, rollenname, role.id, ctx.author.id, 3)) + + db = database.Database(f"{ctx.guild.id}.db") + await db.add_member(ctx.author.id, ctx.author.id) + + # ==================== EDIT CLUBS ====================== #

@@ -185,9 +190,36 @@ role = discord.utils.get(after.channel.guild.roles, id=db_response[int(response.content)-1][1])

if role is None: print("Rolle nicht gefunden") + bot_member = after.channel.guild.me + club_owner = discord.utils.get(after.channel.guild.members, id=await db.get_owner_by_club_id(db_response[int(response.content)-1][2])) + + + bot_overwrites = discord.PermissionOverwrite ( + move_members = True, + view_channel = True, + manage_channels = True + ) + + club_member_overwrites = discord.PermissionOverwrite ( + view_channel = True + ) + + club_owner_overwrites = discord.PermissionOverwrite ( + manage_channels = True, + mute_members = True, + deafen_members = True, + move_members = True + ) + + default_overwrites = discord.PermissionOverwrite ( + view_channel = False + ) + 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 + after.channel.guild.default_role: default_overwrites, + bot_member: bot_overwrites, + club_owner: club_owner_overwrites, + role: club_member_overwrites }
M db.pydb.py

@@ -178,16 +178,17 @@ 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_id FROM clubs WHERE id = ?;", (club_id[0], )) as cursor2: + async with db.execute("SELECT channel_name, role_id, id FROM clubs WHERE id = ?;", (club_id[0], )) as cursor2: async for club in cursor2: clubs.append(club) print(clubs) return clubs - - - - + async def get_owner_by_club_id(self, club_id): + async with aiosqlite.connect(self.db_name) as db: + async with db.execute("SELECT owner_id FROM clubs WHERE id = ?;", (club_id, )) as cursor: + result = await cursor.fetchone() + return (result[0])
M logic.pylogic.py

@@ -98,7 +98,7 @@

if color[0] == '#': color = color[1:] try: - color = int("0x"+color, 16)+0x200 + color = int("0x"+color, 16) except: return("❌ Error! Farbformat falsch angegeben")