diff --git a/dr_botzo/ircbot/bot.py b/dr_botzo/ircbot/bot.py index ede7890..ede76e9 100644 --- a/dr_botzo/ircbot/bot.py +++ b/dr_botzo/ircbot/bot.py @@ -377,10 +377,7 @@ class IRCBot(irc.client.SimpleIRCClient): dest = None if feedback: - if irc.client.is_channel(event.target): - dest = event.target - else: - dest = irc.client.NickMask(event.source).nick + dest = ircbotlib.reply_destination_for_event(event) for path, plugin in self.plugins: if plugin_path == path: @@ -421,10 +418,7 @@ class IRCBot(irc.client.SimpleIRCClient): log.debug(u"trying to unload %s", plugin_path) - if irc.client.is_channel(event.target): - dest = event.target - else: - dest = irc.client.NickMask(event.source).nick + dest = ircbotlib.reply_destination_for_event(event) for path, plugin in self.plugins: if plugin_path == path: diff --git a/dr_botzo/ircbot/lib.py b/dr_botzo/ircbot/lib.py index c8f4f2a..baea459 100644 --- a/dr_botzo/ircbot/lib.py +++ b/dr_botzo/ircbot/lib.py @@ -2,6 +2,8 @@ import logging +import irc.client + from ircbot.models import BotAdmin @@ -40,3 +42,17 @@ def is_admin(source): return True log.debug(u"in is_admin; False") return False + + +def reply_destination_for_event(event): + """Get the "natural" reply destination for an event. + + If the event appears to be from a person within a channel, the channel + is the reply destination. Otherwise, the source (assumed to be the speaker + in a privmsg)'s nick is the reply destination. + """ + + if irc.client.is_channel(event.target): + return event.target + else: + return irc.client.NickMask(event.source).nick