Skip to content

Commit

Permalink
fix: add_category creating channels for all categories
Browse files Browse the repository at this point in the history
and clean admin.py
  • Loading branch information
Zalk0 committed Jul 10, 2024
1 parent 82f78f2 commit ba0681c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
5 changes: 3 additions & 2 deletions etuutt_bot/commands/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@


class AdminCog(commands.Cog):
"""Commandes pour les administrateurs du bot."""

def __init__(self, bot: EtuUTTBot) -> None:
self.bot = bot

# Add command to sync slash commands for team members and owner of the bot
@commands.is_owner()
@commands.command(name="sync")
async def sync_tree(self, ctx: commands.Context[EtuUTTBot]):
"""Synchronise les commandes slash."""
try:
await self.bot.tree.sync()
for guild in self.bot.guilds:
Expand All @@ -27,7 +29,6 @@ async def sync_tree(self, ctx: commands.Context[EtuUTTBot]):
await ctx.reply(
f"Il y a eu une erreur lors de la synchronisation des commandes slash\n{e}"
)
return

@commands.Cog.listener()
async def on_command_error(
Expand Down
2 changes: 1 addition & 1 deletion etuutt_bot/commands/ue.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def add_category(self, interaction: Interaction[EtuUTTBot], category: Cate
msg = ""

# Ensure that channels don't exist yet in order not to overwrite them
to_create = self.ue_service.get_missing_channels()
to_create = self.ue_service.get_missing_channels(category)
if len(to_create) < len(settings_cat.ues):
msg += "\n## \N{SLEEPING SYMBOL} Les salons suivants existent déjà :\n"
msg += "\n".join(f"- {c}" for c in ues_names - to_create)
Expand Down
20 changes: 14 additions & 6 deletions etuutt_bot/services/ue.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,21 @@ async def create_channel(self, name: str) -> (TextChannel, Role):
name.lower(), overwrites=overwrites, reason=f"Création d'un salon pour l'UE {name}"
), role

def get_missing_channels(self) -> set[LowerStr]:
def get_missing_channels(self, category: CategoryChannel = None) -> set[LowerStr]:
"""Renvoie le nom de tous les salons d'UEs manquant sur le serveur."""
ues = {
LowerStr(ue.lower())
for category in self._bot.settings.categories
for ue in category.ues
}
if category:
ues = {
LowerStr(ue.lower())
for ue in next(
(cat for cat in self._bot.settings.categories if cat.id == category.id), None
).ues
}
existing = {
LowerStr(channel.name) # les noms des salons Discord sont en minuscule par défaut
for channel in category.text_channels
}
return ues - existing
ues = {LowerStr(ue.lower()) for cat in self._bot.settings.categories for ue in cat.ues}
existing = {
LowerStr(channel.name) # les noms des salons Discord sont en minuscule par défaut
for channel in self._bot.watched_guild.text_channels
Expand Down

0 comments on commit ba0681c

Please sign in to comment.