Add some modelines and fix indentation, I hope.

This commit is contained in:
kad 2010-07-27 23:11:58 -06:00
parent ec9acdd2ee
commit 0c17196b32
9 changed files with 26 additions and 7 deletions

View File

@ -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;

View File

@ -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;

View File

@ -73,3 +73,4 @@ class Countdown(Module):
connection.privmsg(replypath, relstr)
except NoOptionError: pass
# kate: indent-mode python;indent-width 4;replace-tabs on;

View File

@ -83,3 +83,4 @@ class Dice(Module):
else:
connection.privmsg(replypath, result)
# kate: indent-mode python;indent-width 4;replace-tabs on;

View File

@ -35,3 +35,4 @@ class FactFile(Module):
except NoOptionError: pass
# kate: indent-mode python;indent-width 4;replace-tabs on;

View File

@ -47,3 +47,4 @@ class GoogleTranslate(Module):
else:
connection.privmsg(replypath, translation)
# kate: indent-mode python;indent-width 4;replace-tabs on;

View File

@ -144,3 +144,4 @@ class IrcAdmin(Module):
else:
connection.privmsg(replypath, replystr)
# kate: indent-mode python;indent-width 4;replace-tabs on;

View File

@ -38,3 +38,4 @@ class Seen(Module):
connection.privmsg(replypath, replystr)
except NoOptionError: pass
# kate: indent-mode python;indent-width 4;replace-tabs on;

View File

@ -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;