2018-03-16 03:13:43 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""
|
|
|
|
Loads, reloads and unloads modules on the fly.
|
|
|
|
"""
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import loader
|
|
|
|
import module
|
|
|
|
|
|
|
|
|
|
|
|
@module.require_admin
|
|
|
|
@module.commands("reload")
|
|
|
|
@module.thread(False)
|
|
|
|
def f_reload(bot, trigger):
|
|
|
|
"""Reloads a module, for use by admins only."""
|
2020-01-07 18:58:19 -05:00
|
|
|
if len(trigger.args) < 2:
|
|
|
|
return boy.reply("Reload what?")
|
|
|
|
name = trigger.args[1]
|
2018-03-16 03:13:43 -04:00
|
|
|
|
2020-01-07 18:58:19 -05:00
|
|
|
if name == "*" or name.upper() == "ALL THE THINGS":
|
2018-03-16 03:13:43 -04:00
|
|
|
bot.load_modules()
|
|
|
|
return bot.msg("done")
|
|
|
|
|
|
|
|
if name not in sys.modules:
|
|
|
|
name = "modules." + name
|
|
|
|
|
|
|
|
if name not in sys.modules:
|
|
|
|
return bot.msg(f"Module '{name}' not loaded, try the 'load' command.")
|
|
|
|
|
|
|
|
loader.unload_module(bot, name)
|
|
|
|
loader.load_module(bot, name)
|
|
|
|
bot.msg(f"Module '{name}' reloaded.")
|
|
|
|
|
|
|
|
|
|
|
|
@module.require_admin
|
|
|
|
@module.commands("load")
|
|
|
|
@module.thread(False)
|
|
|
|
def f_load(bot, trigger):
|
|
|
|
"""Loads a module, for use by admins only."""
|
2020-01-07 18:58:19 -05:00
|
|
|
if len(trigger.args) < 2:
|
2018-03-16 03:13:43 -04:00
|
|
|
return bot.msg('Load what?')
|
2020-01-07 18:58:19 -05:00
|
|
|
name = trigger.args[1]
|
2018-03-16 03:13:43 -04:00
|
|
|
|
|
|
|
if name in sys.modules:
|
|
|
|
return bot.msg('Module already loaded, use reload.')
|
|
|
|
|
|
|
|
try:
|
|
|
|
loader.load_module(bot, name)
|
|
|
|
except ModuleNotFoundError:
|
|
|
|
if name.startswith("modules."):
|
|
|
|
return bot.msg(f"Module not found: '{name}'")
|
|
|
|
|
|
|
|
name = "modules." + name
|
|
|
|
try:
|
|
|
|
loader.load_module(bot, name)
|
|
|
|
except ModuleNotFoundError:
|
|
|
|
return bot.msg(f"Module not found: '{name}'")
|
|
|
|
bot.msg(f"Module '{name}' loaded.")
|
|
|
|
|
|
|
|
|
|
|
|
@module.require_admin
|
|
|
|
@module.commands("unload")
|
|
|
|
@module.thread(False)
|
|
|
|
def f_unload(bot, trigger):
|
|
|
|
"""Unloads a module, for use by admins only."""
|
2020-01-07 18:58:19 -05:00
|
|
|
if len(trigger.args) < 2:
|
2018-03-16 03:13:43 -04:00
|
|
|
return bot.msg('Unload what?')
|
2020-01-07 18:58:19 -05:00
|
|
|
name = trigger.args[1]
|
2018-03-16 03:13:43 -04:00
|
|
|
|
|
|
|
if name not in sys.modules:
|
|
|
|
name = "modules." + name
|
|
|
|
|
|
|
|
if name not in sys.modules:
|
|
|
|
return bot.msg(f"Module '{name}' not loaded, try the 'load' command.")
|
|
|
|
|
|
|
|
loader.unload_module(bot, name)
|
2019-10-08 07:52:37 -04:00
|
|
|
bot.msg(f"Module '{name}' unloaded.")
|