Cleanup code
This commit is contained in:
		
						commit
						02df2ca783
					
				| @ -3,7 +3,7 @@ import re | |||||||
| 
 | 
 | ||||||
| class Module(object): | class Module(object): | ||||||
|     # Base class used for creating classes that have real functionality. |     # Base class used for creating classes that have real functionality. | ||||||
|      | 
 | ||||||
|     def __init__(self, config, server, modlist, rehash): |     def __init__(self, config, server, modlist, rehash): | ||||||
|         # Constructor for a feature module. Inheritors should not do anything special |         # Constructor for a feature module. Inheritors should not do anything special | ||||||
|         # here, instead they should implement register_handlers and do, or else this will |         # here, instead they should implement register_handlers and do, or else this will | ||||||
| @ -17,7 +17,7 @@ class Module(object): | |||||||
|         self.config = config |         self.config = config | ||||||
|         self.modlist = modlist |         self.modlist = modlist | ||||||
|         self.register_handlers(server) |         self.register_handlers(server) | ||||||
|         # Should do some error handling here.  |         # Should do some error handling here. | ||||||
|         self.botserver   = config.get('IRC', 'server') |         self.botserver   = config.get('IRC', 'server') | ||||||
|         self.botport     = config.getint('IRC', 'port') |         self.botport     = config.getint('IRC', 'port') | ||||||
|         self.botnick     = config.get('IRC', 'nick') |         self.botnick     = config.get('IRC', 'nick') | ||||||
| @ -61,7 +61,7 @@ class Module(object): | |||||||
|             return |             return | ||||||
|         else: |         else: | ||||||
|             what = addressed_re.sub('', what) |             what = addressed_re.sub('', what) | ||||||
|              | 
 | ||||||
|         if replypath is not None: |         if replypath is not None: | ||||||
|             what = self.try_recursion(connection, event, nick, userhost, replypath, what, admin_unlocked) |             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 * | from modules import * | ||||||
| 
 | 
 | ||||||
| modlist = [] | modlist = [] | ||||||
| 
 |  | ||||||
| moduleList = [ "Countdown", "Dice", "IrcAdmin", "GoogleTranslate", "Seen", "FactFile" ] | moduleList = [ "Countdown", "Dice", "IrcAdmin", "GoogleTranslate", "Seen", "FactFile" ] | ||||||
| modObjs = [] | modObjs = [] | ||||||
| 
 | 
 | ||||||
| @ -46,7 +45,7 @@ class DrBotIRC(irclib.IRC): | |||||||
|          c = DrBotServerConnection(self) |          c = DrBotServerConnection(self) | ||||||
|          self.connections.append(c) |          self.connections.append(c) | ||||||
|          return c |          return c | ||||||
|           | 
 | ||||||
| # This finds all the currently loaded modules that start with "modules" (as all | # 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 | # 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. | # reload() on them. This will only work if the folder name doesn't change. | ||||||
| @ -56,24 +55,24 @@ def rehash(): | |||||||
|         currMod = sys.modules[i] |         currMod = sys.modules[i] | ||||||
|         if currMod is not None and myre.search(i): |         if currMod is not None and myre.search(i): | ||||||
|             reload(currMod) |             reload(currMod) | ||||||
|      | 
 | ||||||
|     # Remove the pubmsg and privmsg handlers from the irclib object. |     # Remove the pubmsg and privmsg handlers from the irclib object. | ||||||
|     # If we don't do this we will see phantom messages |     # If we don't do this we will see phantom messages | ||||||
|     for obj in modObjs: |     for obj in modObjs: | ||||||
|         server.remove_global_handler('pubmsg', obj.on_pubmsg) |         server.remove_global_handler('pubmsg', obj.on_pubmsg) | ||||||
|         server.remove_global_handler('privmsg', obj.on_privmsg) |         server.remove_global_handler('privmsg', obj.on_privmsg) | ||||||
|          | 
 | ||||||
|     reload_modules(moduleList) |     reload_modules(moduleList) | ||||||
| 
 | 
 | ||||||
| # Create the actual module objects, which will readd the handlers we removed | # 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 | # earlier, and add them to the modObjs list, which we can use during the | ||||||
| # rehash to remove the handlers. | # next rehash to remove the handlers. | ||||||
| def reload_modules(moduleList): | def reload_modules(moduleList): | ||||||
|     for mod in moduleList: |     for mod in moduleList: | ||||||
|         cls = globals()[mod] |         cls = globals()[mod] | ||||||
|         # Importing the names imports a module since the file name and class  |         # 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 |         # name are the same. Look for the class definition in each module | ||||||
|         # the same name and create that object. |         # with the same name and create that object. | ||||||
|         if inspect.ismodule(cls): |         if inspect.ismodule(cls): | ||||||
|             for name, obj in inspect.getmembers(cls): |             for name, obj in inspect.getmembers(cls): | ||||||
|                 if inspect.isclass(obj) and re.search(mod, obj.__name__): |                 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_save_config(connection, event, nick, userhost, replypath, what, admin_unlocked) | ||||||
|         self.sub_change_nick(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) |         self.sub_rehash(connection, event, nick, userhost, replypath, what, admin_unlocked) | ||||||
|          | 
 | ||||||
|     def sub_rehash(self, connection, event, nick, userhost, replypath, what, admin_unlocked): |     def sub_rehash(self, connection, event, nick, userhost, replypath, what, admin_unlocked): | ||||||
|         whats = what.split(' ') |         whats = what.split(' ') | ||||||
|         if whats[0] == 'rehash' and admin_unlocked: |         if whats[0] == 'rehash' and admin_unlocked: | ||||||
|  | |||||||
| @ -11,7 +11,7 @@ initre = re.compile('__init__') | |||||||
| for i in files: | for i in files: | ||||||
|     if initre.search(i): |     if initre.search(i): | ||||||
|         continue |         continue | ||||||
|          | 
 | ||||||
|     i = os.path.basename(i) |     i = os.path.basename(i) | ||||||
|     lastDot = i.rfind(".") |     lastDot = i.rfind(".") | ||||||
|     i = i[0:lastDot] |     i = i[0:lastDot] | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user