@@ -274,32 +274,21 @@ async def on_submit(self, interaction: discord.Interaction):
274274 )
275275
276276
277- class PaginatedSelect (discord .ui .Select ):
278- def __init__ (self , channel : discord .VoiceChannel , options , page = 0 , per_page = 25 ):
277+ class MentionableSelect (discord .ui .MentionableSelect ):
278+ def __init__ (self , channel : discord .VoiceChannel , action : str ):
279279 self .channel = channel
280- self .page = page
281- self .per_page = per_page
282-
283- start = page * per_page
284- end = start + per_page
285- paginated_options = options [start :end ]
286-
287- super ().__init__ (
288- placeholder = f"Page { page + 1 } /{ (len (options ) - 1 ) // per_page + 1 } " ,
289- options = paginated_options ,
290- min_values = 1 ,
291- max_values = len (paginated_options ),
292- )
280+ self .action = action
281+ super ().__init__ (placeholder = "Select a user or role..." , min_values = 1 , max_values = 25 )
293282
294283 async def callback (self , interaction : discord .Interaction ):
295284 mentions = []
296- for value in self .values :
297- kind , identifier = value .split (":" )
285+ for selected in self .values :
298286 target = None
299- if kind == "user" :
300- target = self .channel .guild .get_member (int (identifier ))
301- else :
302- target = self .channel .guild .get_role (int (identifier ))
287+
288+ if isinstance (selected , discord .Member ):
289+ target = selected
290+ elif isinstance (selected , discord .Role ):
291+ target = selected
303292
304293 if target :
305294 if self .action == "permit" :
@@ -310,52 +299,21 @@ async def callback(self, interaction: discord.Interaction):
310299 mentions .append (target .mention )
311300
312301 if mentions :
302+ action_text = "permitted" if self .action == "permit" else "forbidden"
313303 await interaction .response .send_message (
314- f"✅ Updated permissions for: { ', ' .join (mentions )} " , ephemeral = True
304+ f"✅ Updated permissions for: { ', ' .join (mentions )} ({ action_text } )." ,
305+ ephemeral = True ,
315306 )
316307 else :
317308 await interaction .response .send_message (
318309 "❌ No valid users or roles were selected." , ephemeral = True
319310 )
320311
321312
322- class PaginationView (discord .ui .View ):
323- def __init__ (self , channel : discord .VoiceChannel , options , action : str , per_page : int = 25 ):
313+ class MentionableView (discord .ui .View ):
314+ def __init__ (self , channel : discord .VoiceChannel , action : str ):
324315 super ().__init__ ()
325- self .channel = channel
326- self .options = options
327- self .page = 0
328- self .action = action
329- self .per_page = per_page
330- self .update_select ()
331-
332- def update_select (self ):
333- for item in self .children [:]:
334- if isinstance (item , discord .ui .Select ):
335- self .remove_item (item )
336- self .add_item (
337- PaginatedSelect (self .channel , self .options , page = self .page , per_page = self .per_page )
338- )
339-
340- @discord .ui .button (label = "Previous" , style = discord .ButtonStyle .primary , row = 1 )
341- async def previous_page (self , interaction : discord .Interaction , button : discord .ui .Button ):
342- if self .page > 0 :
343- self .page -= 1
344- self .update_select ()
345- await interaction .response .edit_message (view = self )
346- else :
347- await interaction .response .send_message (
348- "❌ There is no previous page." , ephemeral = True
349- )
350-
351- @discord .ui .button (label = "Next" , style = discord .ButtonStyle .primary , row = 1 )
352- async def next_page (self , interaction : discord .Interaction , button : discord .ui .Button ):
353- if self .page * self .per_page + self .per_page < len (self .options ):
354- self .page += 1
355- self .update_select ()
356- await interaction .response .edit_message (view = self )
357- else :
358- await interaction .response .send_message ("❌ There is no next page." , ephemeral = True )
316+ self .add_item (MentionableSelect (channel , action ))
359317
360318
361319class RenameModal (discord .ui .Modal , title = "Rename Voice Channel" ):
@@ -517,65 +475,19 @@ async def permit(self, interaction: discord.Interaction, button: discord.ui.Butt
517475 if not await self ._check_permissions (interaction ):
518476 return
519477
520- options = []
521- for member in self .channel .guild .members :
522- perms = self .channel .overwrites_for (member )
523- if perms .connect is not True :
524- options .append (
525- discord .SelectOption (label = member .display_name , value = f"user:{ member .id } " )
526- )
527-
528- for role in self .channel .guild .roles :
529- if role .is_default () or role .managed :
530- continue
531- perms = self .channel .overwrites_for (role )
532- if perms .connect is not True :
533- options .append (
534- discord .SelectOption (label = f"@{ role .name } " , value = f"role:{ role .id } " )
535- )
536-
537- if not options :
538- await interaction .response .send_message (
539- "❌ No users or roles available to permit." , ephemeral = True
540- )
541- return
542-
543- view = PaginationView (self .channel , options , action = "permit" )
478+ view = MentionableView (self .channel , action = "permit" )
544479 await interaction .response .send_message (
545- "Select users or roles to permit:" , view = view , ephemeral = True
480+ "Select a user or role to permit:" , view = view , ephemeral = True
546481 )
547482
548483 @discord .ui .button (label = "➖ Forbid" , row = 1 , style = discord .ButtonStyle .danger )
549484 async def forbid (self , interaction : discord .Interaction , button : discord .ui .Button ):
550485 if not await self ._check_permissions (interaction ):
551486 return
552487
553- options = []
554- for member in self .channel .guild .members :
555- perms = self .channel .overwrites_for (member )
556- if perms .connect is not False :
557- options .append (
558- discord .SelectOption (label = member .display_name , value = f"user:{ member .id } " )
559- )
560-
561- for role in self .channel .guild .roles :
562- if role .is_default () or role .managed :
563- continue
564- perms = self .channel .overwrites_for (role )
565- if perms .connect is not False :
566- options .append (
567- discord .SelectOption (label = f"@{ role .name } " , value = f"role:{ role .id } " )
568- )
569-
570- if not options :
571- await interaction .response .send_message (
572- "❌ No users or roles available to forbid." , ephemeral = True
573- )
574- return
575-
576- view = PaginationView (self .channel , options , action = "forbid" )
488+ view = MentionableView (self .channel , action = "forbid" )
577489 await interaction .response .send_message (
578- "Select users or roles to forbid:" , view = view , ephemeral = True
490+ "Select a user or role to forbid:" , view = view , ephemeral = True
579491 )
580492
581493 @discord .ui .button (label = "✏️ Rename" , row = 0 , style = discord .ButtonStyle .primary )
@@ -622,7 +534,25 @@ async def reset_channel(self, interaction: discord.Interaction, button: discord.
622534 await interaction .response .edit_message (view = self )
623535 await interaction .followup .send ("🔄 Channel reset to default settings." , ephemeral = True )
624536
625- @discord .ui .button (label = "🎙 Claim Room" , row = 3 , style = discord .ButtonStyle .secondary )
537+ @discord .ui .button (label = "🧹 Clear Permissions" , row = 3 , style = discord .ButtonStyle .secondary )
538+ async def clear_permissions (self , interaction : discord .Interaction , button : discord .ui .Button ):
539+ if not await self ._check_permissions (interaction ):
540+ return
541+
542+ category = self .channel .category
543+ new_overwrites = category .overwrites if category else {}
544+
545+ try :
546+ await self .channel .edit (overwrites = new_overwrites )
547+ await interaction .response .send_message (
548+ "✅ All permission overwrites have been cleared." , ephemeral = True
549+ )
550+ except Exception as e :
551+ await interaction .response .send_message (
552+ f"❌ Failed to clear permissions: { e } " , ephemeral = True
553+ )
554+
555+ @discord .ui .button (label = "🎙 Claim Room" , row = 4 , style = discord .ButtonStyle .secondary )
626556 async def claim (self , interaction : discord .Interaction , button : discord .ui .Button ):
627557 try :
628558 cog = self .cog
0 commit comments