1
# gozerbot/plugs/reload.py
5
__copyright__ = 'this file is in the public domain'
8
from gozerbot.config import config
9
from gozerbot.plugins import plugins
10
from gozerbot.commands import cmnds
11
from gozerbot.examples import examples
12
from gozerbot.plughelp import plughelp
13
from gozerbot.aliases import aliases
14
from gozerbot.gozerimport import gozer_import
15
from gozerbot.tests import tests
20
plughelp.add('reload', 'reload a plugin')
22
def handle_reload(bot, ievent):
24
""" reload a plugin. """
29
ievent.missing('<list plugins>')
40
ievent.reply('config reloaded')
43
p = gozer_import('gozerbot.plugs.__init__')
45
if plug in p.__plugs__:
46
reloaded.extend(plugins.reload('gozerbot.plugs', plug))
50
reloaded.extend(plugins.reload('myplugs', plug))
51
except ImportError, ex:
53
reloaded.extend(plugins.reload('gozerplugs', plug))
54
except ImportError, ex:
55
errors.append(str(ex))
57
ievent.reply('reloaded: ', reloaded, dot=True)
60
cantreload = list(sets.Set(plugs) - sets.Set(reloaded))
62
ievent.reply("can't reload: " , cantreload, dot=True)
64
ievent.reply('errors: ', errors)
65
except AttributeError: # in case of !reload reload
68
cmnds.add('reload', handle_reload, 'OPER')
69
examples.add('reload', 'reload <plugin>', 'reload core')
70
aliases.data['load'] = 'reload'
71
tests.add('reload country', 'country').add('unload country')
73
def handle_unload(bot, ievent):
75
""" unload a plugin. """
78
what = ievent.args[0].lower()
80
ievent.missing('<plugin>')
83
if not plugins.exist(what):
84
ievent.reply('there is no %s module' % what)
87
got = plugins.unload(what)
92
ievent.reply("unloaded and disabled: ", got, dot=True)
94
cmnds.add('unload', handle_unload, 'OPER')
95
examples.add('unload', 'unload <plugin>', 'unload relay')
96
tests.add('reload country').add('unload country', 'country')