diff --git a/boots/admin_commands.py b/boots/admin_commands.py index 056b0e9..a3c869b 100644 --- a/boots/admin_commands.py +++ b/boots/admin_commands.py @@ -50,7 +50,7 @@ class AdminCmd: split_msg = message.split(" ") message = " ".join(split_msg[1:]) self.client.loop.create_task( - func(target, message, **kwargs)) + func(nick, target, message, **kwargs)) def on_command(self, command: str, diff --git a/boots/boots.py b/boots/boots.py index a2fd858..2292352 100644 --- a/boots/boots.py +++ b/boots/boots.py @@ -1,3 +1,4 @@ +import re import logging import asyncio import robot @@ -43,35 +44,101 @@ async def plugins(bot: robot.Bot): admin_cmd = admin_commands.AdminCmd(administrator) @admin_cmd.on_command("join") - async def join(target, message, **kwargs): + async def join(nick, target, message, **kwargs): await bot.join(channel=message) @admin_cmd.on_command("part") - async def part(target, message, **kwargs): + async def part(nick, target, message, **kwargs): _target = message.split(' ')[0] _message = " ".join(message.split(' ')[1:]) await bot.part(channel=_target, message=_message) @admin_cmd.on_command("msg") - async def msg(target, message, **kwargs): + async def msg(nick, target, message, **kwargs): _target = message.split(' ')[0] _message = " ".join(message.split(' ')[1:]) await bot.msg(target=_target, message=_message) @admin_cmd.on_command("action") - async def action(target, message, **kwargs): + async def action(nick, target, message, **kwargs): _target = message.split(' ')[0] _message = " ".join(message.split(' ')[1:]) await bot.action(target=_target, message=_message) @admin_cmd.on_command("notice") - async def msg(target, message, **kwargs): + async def msg(nick, arget, message, **kwargs): _target = message.split(' ')[0] _message = " ".join(message.split(' ')[1:]) await bot.notice(target=_target, message=_message) + @admin_cmd.on_command("mode") + async def chanmode(nick, target, message, **kwargs): + chanmode_pattern = r'^(?P(\#|\#\#|\&)[a-zA-Z0-9]+)?' \ + r'((^|\s+)(?P[\+\-][a-zA-Z]+))' \ + r'(\s+(?P.+)?)?' + compiled = re.compile(chanmode_pattern) + m = compiled.match(message) + + if m.group("channel"): + _channel = m.group("channel") + else: + _channel = target + + if m.group("modes"): + _modes = m.group("modes") + else: + await bot.msg(target=target, message="{}, you did not provide a mode".format(nick)) + return + + if m.group("params"): + _params = m.group("params") + else: + _params = None + + await bot.channelmode(channel=_channel, modes=_modes, params=_params) + + @admin_cmd.on_command("op") + async def op(nick, target, message, **kwargs): + _split_msg = message.split(' ') + nick_list = None + _channel = target + + if _split_msg[0]: + if _split_msg[0].startswith('#') or _split_msg[0].startswith('&'): + _channel = _split_msg[0] + if _split_msg.__len__() > 1: + nick_list = _split_msg[1:] + else: + nick_list = _split_msg + + if nick_list: + _modes = "+" + "o" * nick_list.__len__() + await bot.channelmode(channel=_channel, modes=_modes, params=" ".join(nick_list)) + else: + await bot.channelmode(channel=_channel, modes="+o", params=nick) + + @admin_cmd.on_command("deop") + async def op(nick, target, message, **kwargs): + _split_msg = message.split(' ') + nick_list = None + _channel = target + + if _split_msg[0]: + if _split_msg[0].startswith('#') or _split_msg[0].startswith('&'): + _channel = _split_msg[0] + if _split_msg.__len__() > 1: + nick_list = _split_msg[1:] + else: + nick_list = _split_msg + + if nick_list: + _modes = "-" + "o" * nick_list.__len__() + await bot.channelmode(channel=_channel, modes=_modes, params=" ".join(nick_list)) + else: + await bot.channelmode(channel=_channel, modes="-o", params=nick) + @admin_cmd.on_command("quit") - async def quit(target, message, **kwargs): + async def quit(nick, target, message, **kwargs): await bot.quit(message=message) await bot.disconnect() # Exit the event loop cleanly diff --git a/boots/robot.py b/boots/robot.py index 2a925c5..c2b7b66 100644 --- a/boots/robot.py +++ b/boots/robot.py @@ -260,6 +260,32 @@ class Bot(bottom.Client): """ await self.action_buffer("JOIN", channel=channel, **kwargs) + async def usermode(self, nick: str, modes: str, **kwargs): + """ + This method will send a usermode command to the server + + :param nick str: the nick to apply usermode action to + :param modes str: the mode to apply to the nick + :param kwargs: any other parameters that needs to be sent + :return None + """ + self.send("USERMODE", nick=nick, modes=modes) + + async def channelmode(self, channel: str, modes: str, params: str = None ,**kwargs): + """ + This method will send a channelmode command to the server + + :param channel str: the nick to apply usermode action to + :param modes str: the mode to apply to the channel + :param params str: the parameters to apply to the modes + :param kwargs: any other parameters that needs to be sent + :return None + """ + if params: + self.send("CHANNELMODE", channel=channel, modes=modes, params=params) + else: + self.send("CHANNELMODE", channel=channel, modes=modes) + async def part(self, channel: str, message: str = None, **kwargs) -> None: """ This method will send a part command to the action buffer