From 1c728b14bd0ab88615650e9e0b3a1b605ed396c3 Mon Sep 17 00:00:00 2001 From: kad Date: Mon, 26 Jul 2010 21:46:48 -0600 Subject: [PATCH] Try to dynamically create modules --- dr.botzo.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/dr.botzo.py b/dr.botzo.py index 59f46b0..730fdd4 100644 --- a/dr.botzo.py +++ b/dr.botzo.py @@ -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)