Cleanup code
This commit is contained in:
commit
02df2ca783
@ -3,7 +3,7 @@ import re
|
||||
|
||||
class Module(object):
|
||||
# Base class used for creating classes that have real functionality.
|
||||
|
||||
|
||||
def __init__(self, config, server, modlist, rehash):
|
||||
# Constructor for a feature module. Inheritors should not do anything special
|
||||
# here, instead they should implement register_handlers and do, or else this will
|
||||
@ -17,7 +17,7 @@ class Module(object):
|
||||
self.config = config
|
||||
self.modlist = modlist
|
||||
self.register_handlers(server)
|
||||
# Should do some error handling here.
|
||||
# Should do some error handling here.
|
||||
self.botserver = config.get('IRC', 'server')
|
||||
self.botport = config.getint('IRC', 'port')
|
||||
self.botnick = config.get('IRC', 'nick')
|
||||
@ -61,7 +61,7 @@ class Module(object):
|
||||
return
|
||||
else:
|
||||
what = addressed_re.sub('', what)
|
||||
|
||||
|
||||
if replypath is not None:
|
||||
what = self.try_recursion(connection, event, nick, userhost, replypath, what, admin_unlocked)
|
||||
|
||||
|
17
dr.botzo.py
17
dr.botzo.py
@ -31,7 +31,6 @@ from irclib import irclib
|
||||
from modules import *
|
||||
|
||||
modlist = []
|
||||
|
||||
moduleList = [ "Countdown", "Dice", "IrcAdmin", "GoogleTranslate", "Seen", "FactFile" ]
|
||||
modObjs = []
|
||||
|
||||
@ -46,7 +45,7 @@ class DrBotIRC(irclib.IRC):
|
||||
c = DrBotServerConnection(self)
|
||||
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.
|
||||
@ -56,24 +55,24 @@ def rehash():
|
||||
currMod = sys.modules[i]
|
||||
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.
|
||||
# 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.
|
||||
# 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__):
|
||||
|
@ -44,7 +44,7 @@ class IrcAdmin(Module):
|
||||
self.sub_save_config(connection, event, nick, userhost, replypath, what, admin_unlocked)
|
||||
self.sub_change_nick(connection, event, nick, userhost, replypath, what, admin_unlocked)
|
||||
self.sub_rehash(connection, event, nick, userhost, replypath, what, admin_unlocked)
|
||||
|
||||
|
||||
def sub_rehash(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
|
||||
whats = what.split(' ')
|
||||
if whats[0] == 'rehash' and admin_unlocked:
|
||||
|
@ -11,7 +11,7 @@ initre = re.compile('__init__')
|
||||
for i in files:
|
||||
if initre.search(i):
|
||||
continue
|
||||
|
||||
|
||||
i = os.path.basename(i)
|
||||
lastDot = i.rfind(".")
|
||||
i = i[0:lastDot]
|
||||
|
Loading…
Reference in New Issue
Block a user