DrBotIRC: use format() rather than string concat

a couple other generic ' vs. " show up here too
This commit is contained in:
Brian S. Stephan 2012-12-18 22:32:11 -06:00
parent bf8a7e6453
commit ebfeafe87b
1 changed files with 16 additions and 14 deletions

View File

@ -94,14 +94,16 @@ class DrBotzoMethods:
try:
func = getattr(module, method)
except AttributeError:
return "couldn't find " + method + " in found module " + modname
return ("couldn't find '{0:s}' in found module "
"'{1:s}'".format(method, modname))
if hasattr(func, '__call__'):
return func(*args)
else:
return method + " in found module " + modname + " is not callable"
return ("'{0:s}' in found module '{1:s}' is not "
"callable".format(method, modname))
return "couldn't find " + modname
return "couldn't find module '{0:s}'".format(modname)
class DrBotServerConnection(irclib.ServerConnection):
@ -172,7 +174,7 @@ class DrBotServerConnection(irclib.ServerConnection):
splitpos = text.rfind(' ', 0, splitspace)
splittext = text[0:splitpos] + ' ' + splitter
text = splitter + ' ' + text[splitpos+1:]
self.send_raw("PRIVMSG %s :%s" % (target, splittext))
self.send_raw("PRIVMSG {0:s} :{1:s}".format(target, splittext))
times = times + 1
if times >= 4:
@ -180,9 +182,9 @@ class DrBotServerConnection(irclib.ServerConnection):
return
# done splitting
self.send_raw("PRIVMSG %s :%s" % (target, text))
self.send_raw("PRIVMSG {0:s} :{1:s}".format(target, text))
else:
self.send_raw("PRIVMSG %s :%s" % (target, text))
self.send_raw("PRIVMSG {0:s} :{1:s}".format(target, text))
class DrBotIRC(irclib.IRC):
@ -367,14 +369,14 @@ class DrBotIRC(irclib.IRC):
self.config.add_section('Alias')
self.config.set('Alias', whats[2], ' '.join(whats[3:]))
replystr = 'Added alias ' + whats[2] + '.'
replystr = "Added alias '{0:s}'.".format(whats[2])
return self.reply(connection, event, replystr)
if whats[0] == '!alias' and whats[1] == 'remove' and len(whats) >= 3:
if not self.config.has_section('Alias'):
self.config.add_section('Alias')
if self.config.remove_option('Alias', whats[2]):
replystr = 'Removed alias ' + whats[2] + '.'
replystr = "Removed alias '{0:s}'.".format(whats[2])
return self.reply(connection, event, replystr)
elif whats[0] == '!alias' and whats[1] == 'list':
try:
@ -557,7 +559,7 @@ class DrBotIRC(irclib.IRC):
with open('dr.botzo.cfg', 'w') as cfg:
self.config.write(cfg)
return 'Saved config.'
return "Saved config."
def load_module(self, modname):
"""Load a module (in both the python and dr.botzo sense) if not
@ -573,7 +575,7 @@ class DrBotIRC(irclib.IRC):
for module in self.modlist:
if modname == module.__class__.__name__:
return 'Module ' + modname + ' is already loaded.'
return "Module '{0:s}' is already loaded.".format(modname)
# not loaded, let's get to work
try:
@ -589,11 +591,11 @@ class DrBotIRC(irclib.IRC):
modset.add(modname)
self.config.set('dr.botzo', 'module_list', ','.join(modset))
return 'Module ' + modname + ' loaded.'
return "Module '{0:s}' loaded.".format(modname)
except ImportError as e:
log.error("Error loading '{0:s}'".format(modname))
log.exception(e)
return "Module '" + modname + "' could not be loaded."
return "Module '{0:s}' could not be loaded.".format(modname)
def unload_module(self, modname):
"""Attempt to unload and del a module if it's loaded.
@ -626,10 +628,10 @@ class DrBotIRC(irclib.IRC):
modset.remove(modname)
self.config.set('dr.botzo', 'module_list', ','.join(modset))
return 'Module ' + modname + ' unloaded.'
return "Module '{0:s}' unloaded.".format(modname)
# guess it was never loaded
return 'Module ' + modname + ' is not loaded.'
return "Module '{0:s}' is not loaded.".format(modname)
def list_modules(self):
"""List loaded modules.