2008-02-21 07:06:33 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""
|
|
|
|
reload.py - Phenny Module Reloader Module
|
|
|
|
Copyright 2008, Sean B. Palmer, inamidst.com
|
|
|
|
Licensed under the Eiffel Forum License 2.
|
|
|
|
|
|
|
|
http://inamidst.com/phenny/
|
|
|
|
"""
|
|
|
|
|
|
|
|
import irc
|
|
|
|
|
|
|
|
def f_reload(phenny, input):
|
|
|
|
"""Reloads a module, for use by admins only."""
|
|
|
|
if not input.admin: return
|
|
|
|
|
2008-02-23 07:16:43 -05:00
|
|
|
name = input.group(2)
|
2008-08-09 11:01:20 -04:00
|
|
|
if name == phenny.config.owner:
|
|
|
|
return phenny.reply('What?')
|
|
|
|
|
2008-03-01 16:07:23 -05:00
|
|
|
if (not name) or (name == '*'):
|
2008-02-29 10:36:18 -05:00
|
|
|
phenny.setup()
|
|
|
|
return phenny.reply('done')
|
|
|
|
|
2008-02-23 07:16:43 -05:00
|
|
|
try: module = getattr(__import__('modules.' + name), name)
|
|
|
|
except ImportError:
|
|
|
|
module = getattr(__import__('opt.' + name), name)
|
2008-02-21 07:06:33 -05:00
|
|
|
reload(module)
|
|
|
|
|
|
|
|
if hasattr(module, '__file__'):
|
|
|
|
import os.path, time
|
|
|
|
mtime = os.path.getmtime(module.__file__)
|
|
|
|
modified = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(mtime))
|
|
|
|
else: modified = 'unknown'
|
|
|
|
|
2008-02-23 07:16:43 -05:00
|
|
|
phenny.register(vars(module))
|
|
|
|
phenny.bind_commands()
|
2008-02-21 07:06:33 -05:00
|
|
|
|
|
|
|
phenny.reply('%r (version: %s)' % (module, modified))
|
|
|
|
f_reload.name = 'reload'
|
2008-02-29 10:36:18 -05:00
|
|
|
f_reload.rule = ('$nick', ['reload'], r'(\S+)?')
|
|
|
|
f_reload.priority = 'low'
|
2008-02-21 07:06:33 -05:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
print __doc__.strip()
|