diff --git a/earwigbot/bot.py b/earwigbot/bot.py index 6f98690..e6c0be6 100644 --- a/earwigbot/bot.py +++ b/earwigbot/bot.py @@ -137,7 +137,10 @@ class Bot(object): If given, 'msg' will be used as our quit message. """ - self.logger.info("Restarting bot per request from owner") + if msg: + self.logger.info('Restarting bot ("{0}")'.format(msg)) + else: + self.logger.info("Restarting bot") with self.component_lock: self._stop_irc_components(msg) self.config.load() @@ -150,7 +153,10 @@ class Bot(object): If given, 'msg' will be used as our quit message. """ - self.logger.info("Stopping bot") + if msg: + self.logger.info('Stopping bot ("{0}")'.format(msg)) + else: + self.logger.info("Stopping bot") with self.component_lock: self._stop_irc_components(msg) self._keep_looping = False diff --git a/earwigbot/commands/__init__.py b/earwigbot/commands/__init__.py index 4b4049f..1dd745d 100644 --- a/earwigbot/commands/__init__.py +++ b/earwigbot/commands/__init__.py @@ -63,7 +63,7 @@ class BaseCommand(object): self.action = lambda target, msg: self.bot.frontend.action(target, msg) self.notice = lambda target, msg: self.bot.frontend.notice(target, msg) self.join = lambda chan: self.bot.frontend.join(chan) - self.part = lambda chan: self.bot.frontend.part(chan) + self.part = lambda chan, msg=None: self.bot.frontend.part(chan, msg) self.mode = lambda t, level, msg: self.bot.frontend.mode(t, level, msg) self.pong = lambda target: self.bot.frontend.pong(target) diff --git a/earwigbot/commands/chanops.py b/earwigbot/commands/chanops.py index f429a95..9783411 100644 --- a/earwigbot/commands/chanops.py +++ b/earwigbot/commands/chanops.py @@ -28,8 +28,8 @@ class Command(BaseCommand): name = "chanops" def check(self, data): - commands = ["chanops", "voice", "devoice", "op", "deop", "join", "part"] - if data.is_command and data.command in commands: + cmnds = ["chanops", "voice", "devoice", "op", "deop", "join", "part"] + if data.is_command and data.command in cmnds: return True return False @@ -42,26 +42,52 @@ class Command(BaseCommand): self.reply(data, "you must be a bot admin to use this command.") return - if data.command in ["voice", "devoice", "op", "deop"]: - # If it is just !op/!devoice/whatever without arguments, assume they - # want to do this to themselves: + if data.command == "join": + self.do_join(data) + elif data.command == "part": + self.do_part(data) + else: + # If it is just !op/!devoice/whatever without arguments, assume + # they want to do this to themselves: if not data.args: target = data.nick else: target = data.args[0] + command = data.command.upper() + self.say("ChanServ", " ".join((command, data.chan, target))) + log = "{0} requested {1} on {2} in {3}" + self.logger.info(log.format(data.nick, command, target, data.chan)) - msg = " ".join((data.command, data.chan, target)) - self.say("ChanServ", msg) - - else: - if not data.args: - msg = "you must specify a channel to join or part from." - self.reply(data, msg) - return + def do_join(self, data): + if data.args: channel = data.args[0] if not channel.startswith("#"): channel = "#" + channel - if data.command == "join": - self.join(channel) - else: - self.part(channel) + else: + msg = "you must specify a channel to join or part from." + self.reply(data, msg) + return + + self.join(channel) + log = "{0} requested JOIN to {1}".format(data.nick, channel) + self.logger.info(log) + + def do_part(self, data): + channel = data.chan + reason = None + if data.args: + if data.args[0].startswith("#"): + # !part #channel reason for parting + channel = data.args[0] + if data.args[1:]: + reason = " ".join(data.args[1:]) + else: # !part reason for parting; assume current channel + reason = " ".join(data.args) + + msg = "Requested by {0}".format(data.nick) + log = "{0} requested PART from {1}".format(data.nick, channel) + if reason: + msg += ": {0}".format(reason) + log += ' ("{0}")'.format(reason) + self.part(channel, msg) + self.logger.info(log) diff --git a/earwigbot/commands/quit.py b/earwigbot/commands/quit.py index db3f168..9ca1f38 100644 --- a/earwigbot/commands/quit.py +++ b/earwigbot/commands/quit.py @@ -54,7 +54,6 @@ class Command(BaseCommand): self.bot.stop("Stopped by {0}".format(data.nick)) def do_restart(self, data): - self.logger.info("Restarting bot per owner request") if data.args: msg = " ".join(data.args) self.bot.restart("Restarted by {0}: {1}".format(data.nick, msg)) @@ -62,7 +61,7 @@ class Command(BaseCommand): self.bot.restart("Restarted by {0}".format(data.nick)) def do_reload(self, data): - self.logger.info("Reloading IRC commands and bot tasks") + self.logger.info("{0} requested command/task reload".format(data.nick)) self.bot.commands.load() self.bot.tasks.load() self.reply(data, "IRC commands and bot tasks reloaded.") diff --git a/earwigbot/irc/connection.py b/earwigbot/irc/connection.py index 9ede2e9..3a00383 100644 --- a/earwigbot/irc/connection.py +++ b/earwigbot/irc/connection.py @@ -113,10 +113,12 @@ class IRCConnection(object): msg = "JOIN {0}".format(chan) self._send(msg) - def part(self, chan): - """Part from a channel on the server.""" - msg = "PART {0}".format(chan) - self._send(msg) + def part(self, chan, msg=None): + """Part from a channel on the server, optionally using an message.""" + if msg: + self._send("PART {0} :{1}".format(chan, msg)) + else: + self._send("PART {0}".format(chan)) def mode(self, target, level, msg): """Send a mode message to the server."""