use add_global_handler on pubmsg/privmsg to learn from IRC.
this rather than inside do(), which could internal commands and stuff that probably counts as noise
This commit is contained in:
parent
c23b59d705
commit
bed3f7ec23
|
@ -37,6 +37,9 @@ class MegaHAL(Module):
|
|||
|
||||
Module.__init__(self, irc, config, server)
|
||||
|
||||
self.server.add_global_handler('pubmsg', self.learn_from_irc_event)
|
||||
self.server.add_global_handler('privmsg', self.learn_from_irc_event)
|
||||
|
||||
mh_python.initbrain()
|
||||
|
||||
def save(self):
|
||||
|
@ -47,8 +50,13 @@ class MegaHAL(Module):
|
|||
"""Sync the megahal brain."""
|
||||
mh_python.cleanup()
|
||||
|
||||
def learn_from_irc_event(self, connection, event):
|
||||
"""Learn text when an irc event happens."""
|
||||
what = event.arguments()[0]
|
||||
mh_python.learn(what)
|
||||
|
||||
def do(self, connection, event, nick, userhost, what, admin_unlocked):
|
||||
"""Say something on IRC if the bot is being addressed, or at least learn what was said."""
|
||||
"""Say something on IRC if the bot is being addressed."""
|
||||
|
||||
# i think this megahal module is corrupting the object while walking it,
|
||||
# so give it a stupid copy of the string. stupid stupid stupid.
|
||||
|
@ -66,8 +74,6 @@ class MegaHAL(Module):
|
|||
reply = mh_python.doreply(line)
|
||||
elif re.search('^!megahal$', line, re.IGNORECASE) is not None:
|
||||
reply = mh_python.doreply('')
|
||||
else:
|
||||
mh_python.learn(line)
|
||||
|
||||
if reply is not "":
|
||||
if append_nick:
|
||||
|
|
Loading…
Reference in New Issue