diff --git a/commandes/ticket/__init__.py b/commandes/ticket/__init__.py index eaa4c41..852db08 100644 --- a/commandes/ticket/__init__.py +++ b/commandes/ticket/__init__.py @@ -2899,18 +2899,27 @@ class PermissionConfigView(disnake.ui.View): # Determine which list to update if self.config_type == "staff": target_list = self.config.staff_roles - else: + elif self.config_type == "config": target_list = self.config.config_roles - + else: + # Category-specific staff roles (config_type = "cat_{cat_id}") + cat_id = self.config_type.replace("cat_", "") + category = self.config.get_category(cat_id) + if category: + target_list = category.staff_roles + else: + await interaction.response.send_message("Catégorie introuvable.", ephemeral=True) + return + # Get new selected IDs new_ids = interaction.data.get('values', []) added_count = 0 - + for new_id in new_ids: if new_id not in target_list: target_list.append(new_id) added_count += 1 - + self.storage.save_config(interaction.guild_id, self.config) @@ -2927,17 +2936,20 @@ class PermissionConfigView(disnake.ui.View): try: if self.config_type == "staff": target_list = self.config.staff_users - else: + elif self.config_type == "config": target_list = self.config.config_users - + else: + # Category-specific staff - users not separately managed per category, use global staff_users + target_list = self.config.staff_users + new_ids = [int(uid) for uid in interaction.data.get('values', [])] added_count = 0 - + for new_id in new_ids: if new_id not in target_list: target_list.append(new_id) added_count += 1 - + self.storage.save_config(interaction.guild_id, self.config) @@ -2958,9 +2970,20 @@ class PermissionConfigView(disnake.ui.View): await interaction.response.edit_message(components=self.get_components_v2()) def get_components_v2(self): - title = "🛡️ Permissions Staff" if self.config_type == "staff" else "⚙️ Permissions Config" - desc = "Configurez qui peut gérer les tickets." if self.config_type == "staff" else "Configurez qui peut modifier les paramètres." - + if self.config_type == "staff": + title = "🛡️ Permissions Staff" + desc = "Configurez qui peut gérer les tickets." + elif self.config_type == "config": + title = "⚙️ Permissions Config" + desc = "Configurez qui peut modifier les paramètres." + else: + # Category-specific staff roles + cat_id = self.config_type.replace("cat_", "") + category = self.config.get_category(cat_id) + cat_name = category.name if category else f"Catégorie {cat_id}" + title = f"🛡️ Permissions Staff - {cat_name}" + desc = f"Configurez les rôles staff ayant accès à la catégorie '{cat_name}'." + sections = [ disnake.ui.TextDisplay(content=f"# {title}\n{desc}"), disnake.ui.Separator(divider=True), @@ -2975,17 +2998,26 @@ class PermissionConfigView(disnake.ui.View): def _add_remove_select(self): # Build options from current config options = [] - + if self.config_type == "staff": roles = self.config.staff_roles users = self.config.staff_users - else: + elif self.config_type == "config": roles = self.config.config_roles users = self.config.config_users - + else: + # Category-specific staff roles + cat_id = self.config_type.replace("cat_", "") + category = self.config.get_category(cat_id) + if category: + roles = category.staff_roles + else: + roles = [] + users = self.config.staff_users # Category uses global staff_users + # Limit to 25 items for removal dropdown (API Limit) # If more, we might need pagination or just show first 25. - + count = 0 for r_id in roles: if count >= 25: break @@ -2998,7 +3030,7 @@ class PermissionConfigView(disnake.ui.View): description="Cliquez pour retirer" )) count += 1 - + for u_id in users: if count >= 25: break user = self.guild.get_member(u_id) @@ -3010,7 +3042,7 @@ class PermissionConfigView(disnake.ui.View): description="Cliquez pour retirer" )) count += 1 - + if options: select = disnake.ui.Select( placeholder="Sélectionnez pour RETIRER des permissions...", @@ -3026,23 +3058,40 @@ class PermissionConfigView(disnake.ui.View): async def _remove_callback(self, interaction: disnake.Interaction): try: values = interaction.data.get('values', []) - + removed_count = 0 for val in values: prefix, id_str = val.split('_') id_val = int(id_str) - - if prefix == 'r': # Role - target_list = self.config.staff_roles if self.config_type == "staff" else self.config.config_roles + + if prefix == 'r': # Role + if self.config_type == "staff": + target_list = self.config.staff_roles + elif self.config_type == "config": + target_list = self.config.config_roles + else: + # Category-specific staff roles + cat_id = self.config_type.replace("cat_", "") + category = self.config.get_category(cat_id) + if category: + target_list = category.staff_roles + else: + continue if str(id_val) in target_list: target_list.remove(str(id_val)) removed_count += 1 - elif prefix == 'u': # User - target_list = self.config.staff_users if self.config_type == "staff" else self.config.config_users + elif prefix == 'u': # User + if self.config_type == "staff": + target_list = self.config.staff_users + elif self.config_type == "config": + target_list = self.config.config_users + else: + # Category-specific staff uses global staff_users + target_list = self.config.staff_users if id_val in target_list: target_list.remove(id_val) removed_count += 1 - + self.storage.save_config(interaction.guild_id, self.config)