added a "hashflag" to modules to stop modules being loaded that rely on a not-present config option.
This commit is contained in:
parent
e7dc2d566c
commit
87af05d4b6
13 changed files with 45 additions and 4 deletions
|
@ -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)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#--require-config bitly-api-key
|
||||
|
||||
import re
|
||||
import Utils
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#--require-config wordnik-api-key
|
||||
|
||||
import Utils
|
||||
|
||||
URL_WORDNIK = "http://api.wordnik.com:80/v4/word.json/%s/definitions"
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
#--require-config google-api-key
|
||||
#--require-config google-search-id
|
||||
|
||||
import Utils
|
||||
|
||||
URL_GOOGLESEARCH = "https://www.googleapis.com/customsearch/v1"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#--require-config lastfm-api-key
|
||||
|
||||
import Utils
|
||||
|
||||
URL_SCROBBLER = "http://ws.audioscrobbler.com/2.0/"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#--require-config bighugethesaurus-api-key
|
||||
|
||||
import Utils
|
||||
|
||||
URL_THESAURUS = "http://words.bighugelabs.com/api/2/%s/%s/json"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#--require-config trakt-api-key
|
||||
|
||||
import Utils
|
||||
|
||||
URL_TRAKT = "https://api-v2launch.trakt.tv/users/%s/watching"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#--require-config openweathermap-api-key
|
||||
|
||||
import Utils
|
||||
|
||||
URL_WEATHER = "http://api.openweathermap.org/data/2.5/weather"
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#--require-config google-api-key
|
||||
|
||||
import re
|
||||
import Utils
|
||||
|
||||
|
|
3
start.py
3
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:
|
||||
|
|
Loading…
Reference in a new issue