# HG changeset patch # User Teemu Piippo # Date 1440556763 -10800 # Node ID aaa5618e8dc256ba618e22f251d0de35107b1578 # Parent 5747c959c29359069840fa00102b3693e4944ac6 Make cobalt not forget its pages the moment someone days something Added .strftime diff -r 5747c959c293 -r aaa5618e8dc2 mod_util.py --- a/mod_util.py Tue Aug 18 14:38:54 2015 +0300 +++ b/mod_util.py Wed Aug 26 05:39:23 2015 +0300 @@ -34,6 +34,7 @@ import utility import calc import urllib.parse +import datetime @modulecore.irc_command (args=' as ') def convert (bot, args, reply, error, **rest): @@ -165,4 +166,8 @@ reply ('\x0f' + result[-1]) else: for line in result: - reply ('\x0f' + line) \ No newline at end of file + reply ('\x0f' + line) + +@modulecore.irc_command (args='') +def strftime (reply, args, **rest): + reply ('\x0f' + datetime.datetime.utcnow().strftime (args['format'])) diff -r 5747c959c293 -r aaa5618e8dc2 modulecore.py --- a/modulecore.py Tue Aug 18 14:38:54 2015 +0300 +++ b/modulecore.py Wed Aug 26 05:39:23 2015 +0300 @@ -173,8 +173,7 @@ # 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 '')) + bot.privmsg (replyto, "%d more page%s, use .more to continue output" % (num, 's' if num != 1 else '')) # # check_same_caller (comm1, comm2) @@ -214,12 +213,8 @@ except Exception as e: command_error (str (e)) -# -# call_command (bot, message, cmdname, **kvargs) -# -# Calls a cobalt command -# -def call_command (bot, message, cmdname, **kvargs): +def call_command (bot, message, cmdname, **kwargs): + '''Calls a cobalt command''' global g_responsePages global g_responsePageNum @@ -229,7 +224,7 @@ print ('''No such command %s''' % cmdname) return - if not is_available (cmd=cmd, ident=kvargs['ident'], host=kvargs['host']): + if not is_available (cmd=cmd, ident=kwargs['ident'], host=kwargs['host']): command_error ('''you may not use %s''' % cmdname) match = re.compile (cmd['regex']).match (message) @@ -238,21 +233,18 @@ # didn't match command_error ('''usage: %s %s''' % (cmd['name'], cmd['args'])) - # .more is special as it is an interface to the page system. - # Anything else resets it. + # The more command needs the pages intact so that it can access them. Any other command resets the pages. if cmdname != 'more': g_responsePages = [[]] g_responsePageNum = 0 - i = 1 args = {} - for argname in cmd['argnames']: + for i, argname in enumerate (cmd['argnames'], start=1): args[argname] = match.group (i) - i += 1 - print ('''%s was called by %s''' % (cmdname, kvargs['sender'])) - commandObject = kvargs + print ('''%s was called by %s''' % (cmdname, kwargs['sender'])) + commandObject = kwargs commandObject['bot'] = bot commandObject['cmdname'] = cmdname commandObject['args'] = args @@ -269,13 +261,11 @@ if cmdname != 'more': print_responses (commandObject) -def call_hook (bot, hookname, **kvargs): +def call_hook (bot, hookname, **kwargs): global g_responsePages global g_responsePageNum - hookObject = kvargs + hookObject = kwargs hookObject['bot'] = bot - g_responsePages = [[]] - g_responsePageNum = 0 if 'replyto' in hookObject: hookObject['reply'] = response_function @@ -284,7 +274,7 @@ for hook in Hooks[hookname]: hook['func'] (**hookObject) - print_responses (hookObject) + # print_responses (hookObject) def confirm (cmd, yes): global g_confirmCommand @@ -407,4 +397,4 @@ install_command (command, sys.modules[fn.__module__]) return fn - return result \ No newline at end of file + return result