Skip to content

Commit

Permalink
[reload] Minor code style improvements
Browse files Browse the repository at this point in the history
Also a nicer error message for the reload function
  • Loading branch information
Elad Alfassa committed May 2, 2014
1 parent 34d8190 commit a53cf73
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def f_reload(bot, trigger):
if name == bot.config.owner:
return bot.reply('What?')

if (not name) or (name == '*') or (name.upper() == 'ALL THE THINGS'):
if not name or name == '*' or name.upper() == 'ALL THE THINGS':
bot.callables = None
bot.commands = None
bot.setup()
return bot.reply('done')

if not name in sys.modules:
return bot.reply('%s: no such module!' % name)
if name not in sys.modules:
return bot.reply('%s: not loaded, try the `load` command' % name)

old_module = sys.modules[name]

Expand Down Expand Up @@ -77,23 +77,18 @@ def f_reload(bot, trigger):
bot.reply('%r (version: %s)' % (module, modified))


if sys.version_info >= (2, 7):
@willie.module.nickname_commands('update')
def f_update(bot, trigger):
if not trigger.admin:
return
@willie.module.nickname_commands('update')
def f_update(bot, trigger):
if not trigger.admin:
return

"""Pulls the latest versions of all modules from Git"""
proc = subprocess.Popen('/usr/bin/git pull',
stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
bot.reply(proc.communicate()[0])
"""Pulls the latest versions of all modules from Git"""
proc = subprocess.Popen('/usr/bin/git pull',
stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
bot.reply(proc.communicate()[0])

f_reload(bot, trigger)
else:
@willie.module.nickname_commands('update')
def f_update(bot, trigger):
bot.say('You need to run me on Python 2.7 to do that.')
f_reload(bot, trigger)


@willie.module.nickname_commands("load")
Expand Down

0 comments on commit a53cf73

Please sign in to comment.