diff --git a/ModuleManager.py b/ModuleManager.py index 3f6fa9fc..7103b7d3 100644 --- a/ModuleManager.py +++ b/ModuleManager.py @@ -1,4 +1,4 @@ -import glob, imp, inspect, os +import glob, imp, inspect, os, sys class ModuleManager(object): def __init__(self, bot, directory="modules"): @@ -12,11 +12,17 @@ class ModuleManager(object): with open(filename) as module_file: while True: line = module_file.readline().strip() + line_split = line.split(" ") if line and line.startswith("#--"): # this is a hashflag if line == "#--ignore": # nope, ignore this module. return None + elif line_split[0] == "#--require-config" and len( + line_split) > 1: + if not line_split[1].lower() in self.bot.config: + # nope, required config option not present. + return None else: break module = imp.load_source("bitbot_%s" % name, filename) @@ -35,3 +41,5 @@ class ModuleManager(object): assert not module._name in self.modules, ( "module name '%s' attempted to be used twice.") self.modules[module._name] = module + else: + sys.stderr.write("module '%s' not loaded.\n" % filename) diff --git a/modules/bitly.py b/modules/bitly.py index cc73c200..b0aa5d7b 100644 --- a/modules/bitly.py +++ b/modules/bitly.py @@ -1,3 +1,5 @@ +#--require-config bitly-api-key + import re import Utils diff --git a/modules/commands.py b/modules/commands.py index 07fbbaed..de941f77 100644 --- a/modules/commands.py +++ b/modules/commands.py @@ -1,3 +1,5 @@ +import Utils + STR_MORE = " (more...)" STR_CONTINUED = "(...continued) " @@ -30,10 +32,12 @@ class Out(object): class StdOut(Out): def prefix(self): - return self.module_name + return "%s%s%s" % (Utils.color(Utils.COLOR_GREEN), + self.module_name, Utils.FONT_RESET) class StdErr(Out): def prefix(self): - return "!%s" % self.module_name + return "%s!%s%s" % (Utils.color(Utils.COLOR_RED), + self.module_name, Utils.FONT_RESET) class Module(object): def __init__(self, bot): diff --git a/modules/define.py b/modules/define.py index f6b36e3e..19a590fb 100644 --- a/modules/define.py +++ b/modules/define.py @@ -1,3 +1,5 @@ +#--require-config wordnik-api-key + import Utils URL_WORDNIK = "http://api.wordnik.com:80/v4/word.json/%s/definitions" diff --git a/modules/google.py b/modules/google.py index 8d00945f..d391de7f 100644 --- a/modules/google.py +++ b/modules/google.py @@ -1,3 +1,6 @@ +#--require-config google-api-key +#--require-config google-search-id + import Utils URL_GOOGLESEARCH = "https://www.googleapis.com/customsearch/v1" diff --git a/modules/lastfm.py b/modules/lastfm.py index cb985f11..3b3e8bdf 100644 --- a/modules/lastfm.py +++ b/modules/lastfm.py @@ -1,3 +1,5 @@ +#--require-config lastfm-api-key + import Utils URL_SCROBBLER = "http://ws.audioscrobbler.com/2.0/" diff --git a/modules/thesaurus.py b/modules/thesaurus.py index 923b1901..b0b54aa3 100644 --- a/modules/thesaurus.py +++ b/modules/thesaurus.py @@ -1,3 +1,5 @@ +#--require-config bighugethesaurus-api-key + import Utils URL_THESAURUS = "http://words.bighugelabs.com/api/2/%s/%s/json" diff --git a/modules/trakt.py b/modules/trakt.py index bec38768..94538b8f 100644 --- a/modules/trakt.py +++ b/modules/trakt.py @@ -1,3 +1,5 @@ +#--require-config trakt-api-key + import Utils URL_TRAKT = "https://api-v2launch.trakt.tv/users/%s/watching" diff --git a/modules/twitter.py b/modules/twitter.py index 35b35123..921d1ad9 100644 --- a/modules/twitter.py +++ b/modules/twitter.py @@ -1,3 +1,8 @@ +#--require-config twitter-api-key +#--require-config twitter-api-secret +#--require-config twitter-access-token +#--require-config twitter-access-secret + import datetime, re, time, traceback import twitter import Utils diff --git a/modules/weather.py b/modules/weather.py index 868f9fca..e3350de3 100644 --- a/modules/weather.py +++ b/modules/weather.py @@ -1,3 +1,5 @@ +#--require-config openweathermap-api-key + import Utils URL_WEATHER = "http://api.openweathermap.org/data/2.5/weather" diff --git a/modules/wolframalpha.py b/modules/wolframalpha.py index 534187dc..3ab5d670 100644 --- a/modules/wolframalpha.py +++ b/modules/wolframalpha.py @@ -1,3 +1,5 @@ +#--require-config wolframalpha-api-key + import re import Utils @@ -21,6 +23,7 @@ class Module(object): if int(soup.find("queryresult").get("numpods")) > 0: input = soup.find(id="Input").find("subpod").find("plaintext" ).text + answered = False for pod in soup.find_all("pod"): if pod.get("primary") == "true": answer = pod.find("subpod").find("plaintext") @@ -34,8 +37,11 @@ class Module(object): match.group(1), 16)), text) else: break + answered = True event["stdout"].write(text) break + if not answered: + event["stderr"].write("No results found") else: event["stderr"].write("No results found") else: diff --git a/modules/youtube.py b/modules/youtube.py index b5066e6f..350e7863 100644 --- a/modules/youtube.py +++ b/modules/youtube.py @@ -1,3 +1,5 @@ +#--require-config google-api-key + import re import Utils diff --git a/start.py b/start.py index 8a74f331..bb919dfe 100755 --- a/start.py +++ b/start.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -import argparse +import argparse, time import IRCBot, Config, Database def bool_input(s): @@ -19,6 +19,7 @@ for server in servers: if len(bot.servers): bot.modules.load_modules() bot.events.on("boot").on("done").call() + time.sleep(5) bot.connect_all() bot.run() else: