import irc3 from irc3.plugins.command import command import asyncio @irc3.plugin class VoicePlugin: def __init__(self, bot): self.bot = bot @command(permission='admin') async def voice(self, mask, target, args): """Give voice to all users or a specific user %%voice [] """ nick = args.get('') if nick: await self.give_voice(target, nick) else: await self.give_voice_all(target) @command(permission='admin') async def devoice(self, mask, target, args): """Remove voice from all users or a specific user %%devoice [] """ nick = args.get('') if nick: await self.remove_voice(target, nick) else: await self.remove_voice_all(target) async def give_voice(self, target, nick): """Give voice to a specific user""" self.bot.send(f'MODE {target} +v {nick}') async def remove_voice(self, target, nick): """Remove voice from a specific user""" self.bot.send(f'MODE {target} -v {nick}') async def give_voice_all(self, target): """Give voice to all users in the channel who currently don't have it""" names = await self.bot.async_cmds.names(target) for user in names['names']: if not user.startswith("+") and not user.startswith("@"): self.bot.send(f'MODE {target} +v {user}') await asyncio.sleep(0.07) # To avoid flooding the server with commands async def remove_voice_all(self, target): """Remove voice from all users in the channel""" names = await self.bot.async_cmds.names(target) for user in names['names']: if user.startswith("+"): self.bot.send(f'MODE {target} -v {user.lstrip("+")}') await asyncio.sleep(0.07) # To avoid flooding the server with commands @irc3.plugin class KickPlugin: def __init__(self, bot): self.bot = bot @command(permission='admin') async def kick(self, mask, target, args): """Kick a specific user from the channel %%kick [] """ nick = args.get('') reason = args.get('') or 'Kicked by admin' if nick: await self.kick_user(target, nick, reason) async def kick_user(self, target, nick, reason): """Kick a specific user from the channel using ChanServ""" self.bot.send(f'PRIVMSG ChanServ :KICK {target} {nick} {reason}') @irc3.plugin class BanPlugin: def __init__(self, bot): self.bot = bot @command(permission='admin') async def ban(self, mask, target, args): """Ban a specific user from the channel %%ban """ nick = args.get('') if nick: await self.ban_user(target, nick) @command(permission='admin') async def unban(self, mask, target, args): """Unban a specific user from the channel %%unban """ nick = args.get('') if nick: await self.unban_user(target, nick) async def ban_user(self, target, nick): """Ban a specific user from the channel""" self.bot.send(f'MODE {target} +b {nick}') async def unban_user(self, target, nick): """Unban a specific user from the channel""" self.bot.send(f'MODE {target} -b {nick}')