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."""
|
|
|
|
name = trigger.group(2)
|
|
|
|
|
|
|
|
if not name or name == "*" or name.upper() == "ALL THE THINGS":
|
|
|
|
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."""
|
|
|
|
name = trigger.group(2)
|
|
|
|
if not name:
|
|
|
|
return bot.msg('Load what?')
|
|
|
|
|
|
|
|
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."""
|
|
|
|
name = trigger.group(2)
|
|
|
|
if not name:
|
|
|
|
return bot.msg('Unload what?')
|
|
|
|
|
|
|
|
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.")
|