Browse Source

More helpful logging; support for !parts with messages

tags/v0.1^2
Ben Kurtovic 12 years ago
parent
commit
a97670262b
5 changed files with 59 additions and 26 deletions
  1. +8
    -2
      earwigbot/bot.py
  2. +1
    -1
      earwigbot/commands/__init__.py
  3. +43
    -17
      earwigbot/commands/chanops.py
  4. +1
    -2
      earwigbot/commands/quit.py
  5. +6
    -4
      earwigbot/irc/connection.py

+ 8
- 2
earwigbot/bot.py View File

@@ -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

+ 1
- 1
earwigbot/commands/__init__.py View File

@@ -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)



+ 43
- 17
earwigbot/commands/chanops.py View File

@@ -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)

+ 1
- 2
earwigbot/commands/quit.py View File

@@ -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.")

+ 6
- 4
earwigbot/irc/connection.py View File

@@ -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."""


Loading…
Cancel
Save