Run setup when reloading a module.

master
Sean B. Palmer 2009-06-18 14:20:12 +01:00
parent b35681c759
commit 5d48dd8ca7
3 changed files with 10 additions and 2 deletions

View File

@ -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)

View File

@ -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

View File

@ -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