fixes and improvements to recursion and alias support
This commit is contained in:
parent
516940630c
commit
4cac5f1a93
49
DrBotIRC.py
49
DrBotIRC.py
|
@ -103,7 +103,7 @@ class DrBotIRC(irclib.IRC):
|
|||
admin_unlocked = True
|
||||
except NoOptionError: pass
|
||||
|
||||
return self.try_recursion(connection, event, nick, userhost, replypath, what, admin_unlocked)
|
||||
return self.reply(connection, replypath, self.try_recursion(connection, event, nick, userhost, None, what, admin_unlocked))
|
||||
|
||||
def try_alias(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
|
||||
# first see if the aliases are being directly manipulated via add/remove
|
||||
|
@ -152,9 +152,9 @@ class DrBotIRC(irclib.IRC):
|
|||
# we found an alias for our given string, doing a replace
|
||||
command = re.sub(alias, self.config.get('Alias', alias), what)
|
||||
|
||||
# need to do another recursion scan
|
||||
ret = self.try_recursion(connection, event, nick, userhost, None, command, admin_unlocked)
|
||||
return self.reply(connection, replypath, ret)
|
||||
# i guess someone could have an alias of an alias... try again
|
||||
command = self.try_alias(connection, event, nick, userhost, replypath, command, admin_unlocked)
|
||||
return self.reply(connection, replypath, command)
|
||||
except NoOptionError: pass
|
||||
except NoSectionError: pass
|
||||
|
||||
|
@ -192,33 +192,40 @@ class DrBotIRC(irclib.IRC):
|
|||
"""
|
||||
|
||||
attempt = what
|
||||
|
||||
# check for aliases
|
||||
attempt = self.try_alias(connection, event, nick, userhost, replypath, attempt, admin_unlocked)
|
||||
|
||||
# begin recursion search
|
||||
|
||||
start_idx = attempt.find('[')
|
||||
subcmd = attempt[start_idx+1:]
|
||||
end_idx = subcmd.rfind(']')
|
||||
subcmd = subcmd[:end_idx]
|
||||
|
||||
if start_idx == -1 or end_idx == -1 or len(subcmd) == 0:
|
||||
# no recursion, now let's look for aliases
|
||||
command = self.try_alias(connection, event, nick, userhost, None, attempt, admin_unlocked)
|
||||
|
||||
# aliases resolved. run result against each module
|
||||
for module in self.modlist:
|
||||
ret = module.do(connection, event, nick, userhost, None, command, admin_unlocked)
|
||||
if ret is not None:
|
||||
# a module had a result for us, post-alias, so return it
|
||||
# TODO: scan all modules with compounding results
|
||||
return self.reply(connection, replypath, ret)
|
||||
|
||||
# if we got here, text isn't a command, so pass it back, but ONLY if the output
|
||||
# is different from the input
|
||||
if replypath is None or what != command:
|
||||
return self.reply(connection, replypath, command)
|
||||
# no recursion, so see if there's a module to handle this
|
||||
return self.reply(connection, replypath, self.scan_modules(connection, event, nick, userhost, replypath, attempt, admin_unlocked))
|
||||
else:
|
||||
# found recursion, search again
|
||||
ret = self.try_recursion(connection, event, nick, userhost, None, subcmd, admin_unlocked)
|
||||
if ret is not None:
|
||||
return self.try_alias(connection, event, nick, userhost, replypath, attempt.replace('['+subcmd+']', ret), admin_unlocked)
|
||||
# recursion search had a hit, replace [foo] with it and re-recurse
|
||||
return self.reply(connection, replypath, self.try_recursion(connection, event, nick, userhost, replypath, attempt.replace('['+subcmd+']', ret), admin_unlocked))
|
||||
else:
|
||||
return self.try_alias(connection, event, nick, userhost, replypath, attempt, admin_unlocked)
|
||||
# recursion search didn't have a hit, so see if there's a module to handle this
|
||||
return self.reply(connection, replypath, self.scan_modules(connection, event, nick, userhost, replypath, attempt, admin_unlocked))
|
||||
|
||||
def scan_modules(self, connection, event, nick, userhost, replypath, attempt, admin_unlocked):
|
||||
"""Walk the loaded modules, see if any reply to input text."""
|
||||
|
||||
# aliases resolved. run result against each module
|
||||
for module in self.modlist:
|
||||
ret = module.do(connection, event, nick, userhost, replypath, attempt, admin_unlocked)
|
||||
if ret is not None:
|
||||
# a module had a result for us, post-alias, so return it
|
||||
# TODO: scan all modules with compounding results
|
||||
return self.reply(connection, replypath, ret)
|
||||
|
||||
def quit_irc(self, connection, msg):
|
||||
for module in self.modlist:
|
||||
|
|
Loading…
Reference in New Issue