From 5d48dd8ca7a317daf772d0627f0843d315c49876 Mon Sep 17 00:00:00 2001 From: "Sean B. Palmer" Date: Thu, 18 Jun 2009 14:20:12 +0100 Subject: [PATCH] Run setup when reloading a module. --- modules/clock.py | 8 +++++++- modules/oblique.py | 2 +- modules/reload.py | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/clock.py b/modules/clock.py index 80d1c73..e648f41 100755 --- a/modules/clock.py +++ b/modules/clock.py @@ -7,7 +7,7 @@ Licensed under the Eiffel Forum License 2. http://inamidst.com/phenny/ """ -import math, time, urllib +import re, math, time, urllib, locale from tools import deprecated TimeZones = {'KST': 9, 'CADT': 10.5, 'EETDST': 3, 'MESZ': 2, 'WADT': 9, @@ -190,6 +190,8 @@ TZ3 = { TimeZones.update(TZ1) TimeZones.update(TZ3) +r_local = re.compile(r'\([a-z]+_[A-Z]+\)') + @deprecated def f_time(self, origin, match, args): """Returns the current time.""" @@ -211,6 +213,10 @@ def f_time(self, origin, match, args): if (TZ == 'UTC') or (TZ == 'Z'): msg = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()) self.msg(origin.sender, msg) + elif r_local.match(tz): # thanks to Mark Shoulsdon (clsn) + locale.setlocale(locale.LC_TIME, (tz[1:-1], 'UTF-8')) + msg = time.strftime("%A, %d %B %Y %H:%M:%SZ", time.gmtime()) + self.msg(origin.sender, msg) elif TimeZones.has_key(TZ): offset = TimeZones[TZ] * 3600 timenow = time.gmtime(time.time() + offset) diff --git a/modules/oblique.py b/modules/oblique.py index 49e7d8c..b4efa77 100755 --- a/modules/oblique.py +++ b/modules/oblique.py @@ -23,7 +23,7 @@ def mappings(uri): if not ' ' in item: continue command, template = item.split(' ', 1) - if not command.isalpha(): continue + if not command.isalnum(): continue if not template.startswith('http://'): continue result[command] = template.replace('&', '&') return result diff --git a/modules/reload.py b/modules/reload.py index a48b625..fc508a6 100755 --- a/modules/reload.py +++ b/modules/reload.py @@ -25,6 +25,8 @@ def f_reload(phenny, input): except ImportError: module = getattr(__import__('opt.' + name), name) reload(module) + if hasattr(module, 'setup'): + module.setup(phenny) if hasattr(module, '__file__'): import os.path, time