In some modules, raise ImportError to avoid module loading on errors

This commit is contained in:
nemunaire 2015-06-03 22:07:06 +02:00
commit d95de8c195
10 changed files with 109 additions and 114 deletions

View file

@ -24,7 +24,10 @@ def load(context):
mod.send_response = context.send_response
page.load(context.config, context.add_hook)
watchWebsite.load(context.data)
whois.load(context.config, context.add_hook)
try:
whois.load(context.config, context.add_hook)
except ImportError:
logger.exception("Unable to load netwhois module")
def help_full():

View file

@ -12,15 +12,16 @@ def load(CONF, add_hook):
global URL_WHOIS
if not CONF or not CONF.hasNode("whoisxmlapi") or not CONF.getNode("whoisxmlapi").hasAttribute("username") or not CONF.getNode("whoisxmlapi").hasAttribute("password"):
print ("You need a WhoisXML API account in order to use the "
"!netwhois feature. Add it to the module configuration file:\n"
"<whoisxmlapi username=\"XX\" password=\"XXX\" />\nRegister at "
"http://www.whoisxmlapi.com/newaccount.php")
else:
URL_WHOIS = URL_WHOIS % (urllib.parse.quote(CONF.getNode("whoisxmlapi")["username"]), urllib.parse.quote(CONF.getNode("whoisxmlapi")["password"]))
raise ImportError("You need a WhoisXML API account in order to use "
"the !netwhois feature. Add it to the module "
"configuration file:\n<whoisxmlapi username=\"XX\" "
"password=\"XXX\" />\nRegister at "
"http://www.whoisxmlapi.com/newaccount.php")
import nemubot.hooks
add_hook("cmd_hook", nemubot.hooks.Message(cmd_whois, "netwhois"))
URL_WHOIS = URL_WHOIS % (urllib.parse.quote(CONF.getNode("whoisxmlapi")["username"]), urllib.parse.quote(CONF.getNode("whoisxmlapi")["password"]))
import nemubot.hooks
add_hook("cmd_hook", nemubot.hooks.Message(cmd_whois, "netwhois"))
def extractdate(str):