diff --git a/plugins/services/administration.py b/plugins/services/administration.py index 7013a7d..9dfc116 100644 --- a/plugins/services/administration.py +++ b/plugins/services/administration.py @@ -92,33 +92,39 @@ class VoicePlugin: async def give_voice_all(self, target): """ - Grant voice to all users in the channel who do not have it. + Grant voice to all users in the channel who do not already have voice or op privileges. Args: target (str): The IRC channel. """ self.bot.log.info("Granting voice to all non-voiced users in channel %s", target) - names = await self.bot.async_cmds.names(target) - for user in names['names']: - if not user.startswith(("+", "@")): # Ignore voiced/opped users - self.bot.log.info("Granting voice to user %s", user) - self.bot.send(f'MODE {target} +v {user}') - await asyncio.sleep(0.07) # Prevent server flooding + result = await self.bot.async_cmds.names(target) + for user in result['names']: + nick = user.get('nick') + modes = user.get('modes', '') + # Check if the user already has op or voice based on the modes field. + if modes.endswith('@') or modes.endswith('+'): + continue + self.bot.log.info("Granting voice to user %s", nick) + self.bot.send(f'MODE {target} +v {nick}') + await asyncio.sleep(0.07) # Prevent server flooding async def remove_voice_all(self, target): """ - Remove voice from all users in the channel. + Remove voice from all users in the channel who currently have voice privileges. Args: target (str): The IRC channel. """ self.bot.log.info("Removing voice from all voiced users in channel %s", target) - names = await self.bot.async_cmds.names(target) - for user in names['names']: - if user.startswith("+"): # Only devoice voiced users - actual_user = user.lstrip("+") - self.bot.log.info("Removing voice from user %s", actual_user) - self.bot.send(f'MODE {target} -v {actual_user}') + result = await self.bot.async_cmds.names(target) + for user in result['names']: + nick = user.get('nick') + modes = user.get('modes', '') + # Remove voice only if the user has a voice prefix (and not op) + if modes.endswith('+'): + self.bot.log.info("Removing voice from user %s", nick) + self.bot.send(f'MODE {target} -v {nick}') await asyncio.sleep(0.07) # Prevent server flooding