fix administration plugin

This commit is contained in:
Zodiac 2025-02-12 23:43:25 -08:00
parent 55e35fb20b
commit 8c5d17e202

View File

@ -92,33 +92,39 @@ class VoicePlugin:
async def give_voice_all(self, target): 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: Args:
target (str): The IRC channel. target (str): The IRC channel.
""" """
self.bot.log.info("Granting voice to all non-voiced users in channel %s", target) self.bot.log.info("Granting voice to all non-voiced users in channel %s", target)
names = await self.bot.async_cmds.names(target) result = await self.bot.async_cmds.names(target)
for user in names['names']: for user in result['names']:
if not user.startswith(("+", "@")): # Ignore voiced/opped users nick = user.get('nick')
self.bot.log.info("Granting voice to user %s", user) modes = user.get('modes', '')
self.bot.send(f'MODE {target} +v {user}') # 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 await asyncio.sleep(0.07) # Prevent server flooding
async def remove_voice_all(self, target): 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: Args:
target (str): The IRC channel. target (str): The IRC channel.
""" """
self.bot.log.info("Removing voice from all voiced users in channel %s", target) self.bot.log.info("Removing voice from all voiced users in channel %s", target)
names = await self.bot.async_cmds.names(target) result = await self.bot.async_cmds.names(target)
for user in names['names']: for user in result['names']:
if user.startswith("+"): # Only devoice voiced users nick = user.get('nick')
actual_user = user.lstrip("+") modes = user.get('modes', '')
self.bot.log.info("Removing voice from user %s", actual_user) # Remove voice only if the user has a voice prefix (and not op)
self.bot.send(f'MODE {target} -v {actual_user}') 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 await asyncio.sleep(0.07) # Prevent server flooding