DrBotIRC: use format() rather than string concat
a couple other generic ' vs. " show up here too
This commit is contained in:
parent
bf8a7e6453
commit
ebfeafe87b
30
DrBotIRC.py
30
DrBotIRC.py
|
@ -94,14 +94,16 @@ class DrBotzoMethods:
|
||||||
try:
|
try:
|
||||||
func = getattr(module, method)
|
func = getattr(module, method)
|
||||||
except AttributeError:
|
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__'):
|
if hasattr(func, '__call__'):
|
||||||
return func(*args)
|
return func(*args)
|
||||||
else:
|
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):
|
class DrBotServerConnection(irclib.ServerConnection):
|
||||||
|
|
||||||
|
@ -172,7 +174,7 @@ class DrBotServerConnection(irclib.ServerConnection):
|
||||||
splitpos = text.rfind(' ', 0, splitspace)
|
splitpos = text.rfind(' ', 0, splitspace)
|
||||||
splittext = text[0:splitpos] + ' ' + splitter
|
splittext = text[0:splitpos] + ' ' + splitter
|
||||||
text = splitter + ' ' + text[splitpos+1:]
|
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
|
times = times + 1
|
||||||
if times >= 4:
|
if times >= 4:
|
||||||
|
@ -180,9 +182,9 @@ class DrBotServerConnection(irclib.ServerConnection):
|
||||||
return
|
return
|
||||||
|
|
||||||
# done splitting
|
# done splitting
|
||||||
self.send_raw("PRIVMSG %s :%s" % (target, text))
|
self.send_raw("PRIVMSG {0:s} :{1:s}".format(target, text))
|
||||||
else:
|
else:
|
||||||
self.send_raw("PRIVMSG %s :%s" % (target, text))
|
self.send_raw("PRIVMSG {0:s} :{1:s}".format(target, text))
|
||||||
|
|
||||||
class DrBotIRC(irclib.IRC):
|
class DrBotIRC(irclib.IRC):
|
||||||
|
|
||||||
|
@ -367,14 +369,14 @@ class DrBotIRC(irclib.IRC):
|
||||||
self.config.add_section('Alias')
|
self.config.add_section('Alias')
|
||||||
|
|
||||||
self.config.set('Alias', whats[2], ' '.join(whats[3:]))
|
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)
|
return self.reply(connection, event, replystr)
|
||||||
if whats[0] == '!alias' and whats[1] == 'remove' and len(whats) >= 3:
|
if whats[0] == '!alias' and whats[1] == 'remove' and len(whats) >= 3:
|
||||||
if not self.config.has_section('Alias'):
|
if not self.config.has_section('Alias'):
|
||||||
self.config.add_section('Alias')
|
self.config.add_section('Alias')
|
||||||
|
|
||||||
if self.config.remove_option('Alias', whats[2]):
|
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)
|
return self.reply(connection, event, replystr)
|
||||||
elif whats[0] == '!alias' and whats[1] == 'list':
|
elif whats[0] == '!alias' and whats[1] == 'list':
|
||||||
try:
|
try:
|
||||||
|
@ -557,7 +559,7 @@ class DrBotIRC(irclib.IRC):
|
||||||
with open('dr.botzo.cfg', 'w') as cfg:
|
with open('dr.botzo.cfg', 'w') as cfg:
|
||||||
self.config.write(cfg)
|
self.config.write(cfg)
|
||||||
|
|
||||||
return 'Saved config.'
|
return "Saved config."
|
||||||
|
|
||||||
def load_module(self, modname):
|
def load_module(self, modname):
|
||||||
"""Load a module (in both the python and dr.botzo sense) if not
|
"""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:
|
for module in self.modlist:
|
||||||
if modname == module.__class__.__name__:
|
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
|
# not loaded, let's get to work
|
||||||
try:
|
try:
|
||||||
|
@ -589,11 +591,11 @@ class DrBotIRC(irclib.IRC):
|
||||||
modset.add(modname)
|
modset.add(modname)
|
||||||
self.config.set('dr.botzo', 'module_list', ','.join(modset))
|
self.config.set('dr.botzo', 'module_list', ','.join(modset))
|
||||||
|
|
||||||
return 'Module ' + modname + ' loaded.'
|
return "Module '{0:s}' loaded.".format(modname)
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
log.error("Error loading '{0:s}'".format(modname))
|
log.error("Error loading '{0:s}'".format(modname))
|
||||||
log.exception(e)
|
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):
|
def unload_module(self, modname):
|
||||||
"""Attempt to unload and del a module if it's loaded.
|
"""Attempt to unload and del a module if it's loaded.
|
||||||
|
@ -626,10 +628,10 @@ class DrBotIRC(irclib.IRC):
|
||||||
modset.remove(modname)
|
modset.remove(modname)
|
||||||
self.config.set('dr.botzo', 'module_list', ','.join(modset))
|
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
|
# guess it was never loaded
|
||||||
return 'Module ' + modname + ' is not loaded.'
|
return "Module '{0:s}' is not loaded.".format(modname)
|
||||||
|
|
||||||
def list_modules(self):
|
def list_modules(self):
|
||||||
"""List loaded modules.
|
"""List loaded modules.
|
||||||
|
|
Loading…
Reference in New Issue