ircbotlib.reply_destination_for_event
common idiom that'll only get used more and more, so might as well make a library method of it
This commit is contained in:
parent
8c39b017d3
commit
14e5fb4d6f
@ -377,10 +377,7 @@ class IRCBot(irc.client.SimpleIRCClient):
|
|||||||
|
|
||||||
dest = None
|
dest = None
|
||||||
if feedback:
|
if feedback:
|
||||||
if irc.client.is_channel(event.target):
|
dest = ircbotlib.reply_destination_for_event(event)
|
||||||
dest = event.target
|
|
||||||
else:
|
|
||||||
dest = irc.client.NickMask(event.source).nick
|
|
||||||
|
|
||||||
for path, plugin in self.plugins:
|
for path, plugin in self.plugins:
|
||||||
if plugin_path == path:
|
if plugin_path == path:
|
||||||
@ -421,10 +418,7 @@ class IRCBot(irc.client.SimpleIRCClient):
|
|||||||
|
|
||||||
log.debug(u"trying to unload %s", plugin_path)
|
log.debug(u"trying to unload %s", plugin_path)
|
||||||
|
|
||||||
if irc.client.is_channel(event.target):
|
dest = ircbotlib.reply_destination_for_event(event)
|
||||||
dest = event.target
|
|
||||||
else:
|
|
||||||
dest = irc.client.NickMask(event.source).nick
|
|
||||||
|
|
||||||
for path, plugin in self.plugins:
|
for path, plugin in self.plugins:
|
||||||
if plugin_path == path:
|
if plugin_path == path:
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import irc.client
|
||||||
|
|
||||||
from ircbot.models import BotAdmin
|
from ircbot.models import BotAdmin
|
||||||
|
|
||||||
|
|
||||||
@ -40,3 +42,17 @@ def is_admin(source):
|
|||||||
return True
|
return True
|
||||||
log.debug(u"in is_admin; False")
|
log.debug(u"in is_admin; False")
|
||||||
return 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
|
||||||
|
Loading…
Reference in New Issue
Block a user