diff --git a/Module.py b/Module.py index b0eaf78..492fea6 100644 --- a/Module.py +++ b/Module.py @@ -17,11 +17,12 @@ class Module(object): self.config = config self.modlist = modlist self.register_handlers(server) + # Should do some error handling here. self.botserver = config.get('IRC', 'server') self.botport = config.getint('IRC', 'port') self.botnick = config.get('IRC', 'nick') self.botircname = config.get('IRC', 'name') - self.rehash = rehash + self.rehash = rehash # Is there another way to call the rehash function in dr.botzo? def register_handlers(self, server): # This is called by __init__ and sets up server.add_global_handlers. Classes @@ -136,3 +137,5 @@ class Module(object): # IRC functionality. This is called by the default on_pubmsg and on_privmsg print "looks like someone forgot to implement do!" + +# kate: indent-mode python;indent-width 4;replace-tabs on; diff --git a/dr.botzo.py b/dr.botzo.py index 63bb137..051a9cd 100644 --- a/dr.botzo.py +++ b/dr.botzo.py @@ -32,7 +32,7 @@ from modules import * modlist = [] -moduleList = [ "Countdown", "Dice", "IrcAdmin", "GoogleTranslate", "Seen" ] +moduleList = [ "Countdown", "Dice", "IrcAdmin", "GoogleTranslate", "Seen", "FactFile" ] modObjs = [] class DrBotServerConnection(irclib.ServerConnection): @@ -47,6 +47,9 @@ class DrBotIRC(irclib.IRC): self.connections.append(c) return c +# This finds all the currently loaded modules that start with "modules" (as all +# the bot modules are currently in a subfolder called modules) and calls +# reload() on them. This will only work if the folder name doesn't change. def rehash(): myre = re.compile('modules') for i in sys.modules: @@ -54,15 +57,23 @@ def rehash(): if currMod is not None and myre.search(i): reload(currMod) + # Remove the pubmsg and privmsg handlers from the irclib object. + # If we don't do this we will see phantom messages for obj in modObjs: server.remove_global_handler('pubmsg', obj.on_pubmsg) server.remove_global_handler('privmsg', obj.on_privmsg) reload_modules(moduleList) +# Create the actual module objects, which will readd the handlers we removed +# earlier, and add them to the modObjs list, which we can use during the next +# rehash to remove the handlers. def reload_modules(moduleList): for mod in moduleList: cls = globals()[mod] + # Importing the names imports a module since the file name and class + # name are the same. Look for the class definition in each module with + # the same name and create that object. if inspect.ismodule(cls): for name, obj in inspect.getmembers(cls): if inspect.isclass(obj) and re.search(mod, obj.__name__): @@ -70,8 +81,6 @@ def reload_modules(moduleList): break else: modObjs.append(cls(config, server, modlist, rehash)) - print "-------MODOBJS: " - print modObjs # read config file @@ -111,7 +120,5 @@ reload_modules(moduleList) # loop forever irc.process_forever() - - - # vi:tabstop=4:expandtab:autoindent +# kate: indent-mode python;indent-width 4;replace-tabs on; diff --git a/modules/Countdown.py b/modules/Countdown.py index f3c72b7..10a8f88 100644 --- a/modules/Countdown.py +++ b/modules/Countdown.py @@ -73,3 +73,4 @@ class Countdown(Module): connection.privmsg(replypath, relstr) except NoOptionError: pass +# kate: indent-mode python;indent-width 4;replace-tabs on; diff --git a/modules/Dice.py b/modules/Dice.py index d8c8a90..3dbcb57 100644 --- a/modules/Dice.py +++ b/modules/Dice.py @@ -83,3 +83,4 @@ class Dice(Module): else: connection.privmsg(replypath, result) +# kate: indent-mode python;indent-width 4;replace-tabs on; diff --git a/modules/FactFile.py b/modules/FactFile.py index ed5a0a6..69a66f7 100644 --- a/modules/FactFile.py +++ b/modules/FactFile.py @@ -35,3 +35,4 @@ class FactFile(Module): except NoOptionError: pass +# kate: indent-mode python;indent-width 4;replace-tabs on; diff --git a/modules/GoogleTranslate.py b/modules/GoogleTranslate.py index fd76caa..b553ea2 100644 --- a/modules/GoogleTranslate.py +++ b/modules/GoogleTranslate.py @@ -47,3 +47,4 @@ class GoogleTranslate(Module): else: connection.privmsg(replypath, translation) +# kate: indent-mode python;indent-width 4;replace-tabs on; diff --git a/modules/IrcAdmin.py b/modules/IrcAdmin.py index 61adb72..07689d6 100644 --- a/modules/IrcAdmin.py +++ b/modules/IrcAdmin.py @@ -144,3 +144,4 @@ class IrcAdmin(Module): else: connection.privmsg(replypath, replystr) +# kate: indent-mode python;indent-width 4;replace-tabs on; diff --git a/modules/Seen.py b/modules/Seen.py index f3e2e88..18229b6 100644 --- a/modules/Seen.py +++ b/modules/Seen.py @@ -38,3 +38,4 @@ class Seen(Module): connection.privmsg(replypath, replystr) except NoOptionError: pass +# kate: indent-mode python;indent-width 4;replace-tabs on; diff --git a/modules/__init__.py b/modules/__init__.py index 8471b91..c0eaaa0 100644 --- a/modules/__init__.py +++ b/modules/__init__.py @@ -16,6 +16,9 @@ for i in files: lastDot = i.rfind(".") i = i[0:lastDot] __all__.append(i) + # This line is essentially: from i import * __import__(i, locals(), globals(), ["*"]) __all__ = list(set(__all__)) + +# kate: indent-mode python;indent-width 4;replace-tabs on;