diff -r cdafc1a0544e -r 08e9b1c1b324 modulecore.py --- a/modulecore.py Wed Dec 31 10:27:57 2014 -0500 +++ b/modulecore.py Wed Dec 31 11:40:46 2014 -0500 @@ -49,14 +49,10 @@ continue cmd['argnames'].append (argname) - #done - #done print "Loaded module %s" % fn - #done print 'Loaded %d commands in %d modules' % (len (Commands), len (Modules)) -#enddef # # command_error (message) @@ -79,11 +75,50 @@ return True # +# response_function +# +g_responsePages = [[]] +g_responsePageNum = 0 + +def response_function (message): + global g_responsePages + + if len (g_responsePages[-1]) > 4: + g_responsePages.append ([message]) + else: + g_responsePages[-1].append (message) + +def print_responses (bot, replyto): + global g_responsePages + global g_responsePageNum + + # Check bounds + if g_responsePageNum >= len (g_responsePages): + bot.privmsg (replyto, "No more messages.") + return + + # Print this page + for line in g_responsePages[g_responsePageNum]: + bot.privmsg (replyto, line) + + # Advance page cursor + g_responsePageNum += 1 + + # If this was not the last page, tell the user there's more + if g_responsePageNum != len (g_responsePages): + num = (len (g_responsePages) - g_responsePageNum) + bot.privmsg (replyto, "%d more page%s, use .more to continue output" \ + % (num, 's' if num != 1 else '')) + +# # call_command (bot, message, cmdname, **kvargs) # # Calls a cobalt command # def call_command (bot, message, cmdname, **kvargs): + global g_responsePages + global g_responsePageNum + try: cmd = Commands[cmdname] except KeyError: @@ -98,7 +133,13 @@ # didn't match print "regex: %s" % cmd['regex'] command_error ('invalid arguments\nusage: %s %s' % (cmd['name'], cmd['args'])) - + + # .more is special as it is an interface to the page system. + # Anything else resets it. + if cmdname != 'more': + g_responsePages = [[]] + g_responsePageNum = 0 + i = 1 args = {} @@ -106,7 +147,12 @@ args[argname] = match.group (i) i += 1 - getattr (cmd['module'], "cmd_%s" % cmdname) (bot=bot, cmdname=cmdname, args=args, **kvargs) + getattr (cmd['module'], "cmd_%s" % cmdname) (bot=bot, cmdname=cmdname, args=args, reply=response_function, **kvargs) + + # Print the first page of responses. + if cmdname != 'more': + print_responses (bot, kvargs['replyto']) + return True #