Skip to content

Commit

Permalink
fix: better way to handle elected?
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalk0 committed Apr 2, 2024
1 parent f64b24f commit d6092fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
3 changes: 2 additions & 1 deletion etuutt_bot/commands/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ async def add_ues(self, interaction: Interaction[EtuUTTBot], category: CategoryC
msg += "\n".join(f"- {r}" for r in missing)

if len(existing_roles) > 0:
elected = category.guild.get_role(self.bot.data.get("Elected").get(cat))
msg += "\n## Salons textuels créés :\n"
for role in existing_roles:
channel = await create_ue_channel(self.bot, category, role, cat)
channel = await create_ue_channel(category, role, elected)
msg += f"\n- {channel.name}"

for chunk in split_msg(msg):
Expand Down
12 changes: 3 additions & 9 deletions etuutt_bot/utils/channels.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
from __future__ import annotations

from os import getenv
from typing import TYPE_CHECKING

from discord import CategoryChannel, PermissionOverwrite, Role, TextChannel

if TYPE_CHECKING:
from etuutt_bot.bot import EtuUTTBot


async def create_ue_channel(
bot: EtuUTTBot, category: CategoryChannel, role: Role, cat: str
category: CategoryChannel, role: Role, elected: Role = None
) -> TextChannel:
guild = category.guild
overwrites = {
guild.default_role: PermissionOverwrite(read_messages=False),
role: PermissionOverwrite(read_messages=True),
guild.get_role(int(getenv("MODERATOR_ID"))): PermissionOverwrite(read_messages=True),
}
if elected := bot.data.get("Elected").get(cat):
overwrites.update({guild.get_role(elected): PermissionOverwrite(read_messages=True)})
if elected:
overwrites.update({elected: PermissionOverwrite(read_messages=True)})
new_channel = await category.create_text_channel(role.name.lower(), overwrites=overwrites)
await new_channel.send(f"Bonjour {role.mention}, votre salon textuel vient d'être créé !")
return new_channel

0 comments on commit d6092fa

Please sign in to comment.