Try to dynamically create modules

This commit is contained in:
kad 2010-07-26 21:46:48 -06:00
parent 0fc413f2e3
commit 1c728b14bd
1 changed files with 10 additions and 16 deletions

View File

@ -91,6 +91,9 @@ class Module(object):
admin_unlocked = True
except NoOptionError: pass
if replypath is not None:
what = self.try_recursion(connection, event, nick, userhost, replypath, what, admin_unlocked)
self.do(connection, event, nick, userhost, replypath, what, admin_unlocked)
def try_recursion(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
@ -161,10 +164,6 @@ class GoogleTranslate(Module):
def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
whats = what.split(' ')
if whats[0] == 'translate' and len(whats) >= 4:
if replypath is not None:
what = self.try_recursion(connection, event, nick, userhost, replypath, what, admin_unlocked)
whats = what.split(' ')
fromlang = whats[1]
tolang = whats[2]
text = ' '.join(whats[3:])
@ -208,10 +207,6 @@ class Countdown(Module):
def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
whats = what.split(' ')
if whats[0] == 'countdown' and len(whats) >= 2:
if replypath is not None:
what = self.try_recursion(connection, event, nick, userhost, replypath, what, admin_unlocked)
whats = what.split(' ')
if whats[1] == 'add' and len(whats) >= 4:
item = whats[2]
target = parse(' '.join(whats[3:]), default=datetime.now().replace(tzinfo=tzlocal()))
@ -373,10 +368,6 @@ class Seen(Module):
# also see if it's a query
whats = what.split(' ')
if whats[0] == 'seen' and len(whats) >= 2:
if replypath is not None:
what = self.try_recursion(connection, event, nick, userhost, replypath, what, admin_unlocked)
whats = what.split(' ')
query = whats[1]
if query != 'debug':
try:
@ -535,11 +526,8 @@ class FactFile(Module):
whats = what.split(' ')
try:
filename = self.config.get('fact', whats[0])
if replypath is not None:
what = self.try_recursion(connection, event, nick, userhost, replypath, what, admin_unlocked)
whats = what.split(' ')
# open file
# open file
if os.path.isfile(filename):
# http://www.regexprn.com/2008/11/read-random-line-in-large-file-in.html
with open(filename, 'r') as file:
@ -600,6 +588,12 @@ server = irc.server().connect(botserver, botport, botnick, botircname)
modlist = []
moduleList = [ "Countdown", "Dice", "FactFile", "IrcAdmin", "GoogleTranslate", "Seen" ]
modObjs = []
for mod in moduleList:
modObjs.append(mod(config, server modlist))
count = Countdown(config, server, modlist)
dice = Dice(config, server, modlist)
fact = FactFile(config, server, modlist)