Browse Source

convert commands to use the actions.reply() format

tags/v0.1
Ben Kurtovic 13 years ago
parent
commit
a7afc6c803
2 changed files with 22 additions and 22 deletions
  1. +18
    -18
      irc/commands/git.py
  2. +4
    -4
      irc/commands/help.py

+ 18
- 18
irc/commands/git.py View File

@@ -12,11 +12,11 @@ def call(a, d):
actions, data = a, d actions, data = a, d


if data.host not in ADMINS: if data.host not in ADMINS:
actions.say(data.chan, "\x02%s\x0F: you must be a bot admin to use this command." % data.nick)
actions.reply(data.chan, data.nick, "you must be a bot admin to use this command.")
return return
if not data.args: if not data.args:
actions.say(data.chan, "\x02%s\x0F: no arguments provided." % data.nick)
actions.reply(data.chan, data.nick, "no arguments provided.")
return return


if data.args[0] == "help": if data.args[0] == "help":
@@ -41,7 +41,7 @@ def call(a, d):
do_status() do_status()


else: # they asked us to do something we don't know else: # they asked us to do something we don't know
actions.say(data.chan, "\x02%s\x0F: unknown argument: \x0303%s\x0301." % (data.nick, data.args[0]))
actions.reply(data.chan, data.nick, "unknown argument: \x0303%s\x0301." % data.args[0])


def exec_shell(command): def exec_shell(command):
"""execute a shell command and get the output""" """execute a shell command and get the output"""
@@ -64,14 +64,14 @@ def do_help():
help += "\x0303%s\x0301: (%s)," % (key, help_dict[key]) help += "\x0303%s\x0301: (%s)," % (key, help_dict[key])
help = help[:-1] # trim last comma help = help[:-1] # trim last comma


actions.say(data.chan, "\x02%s\x0F: sub-commands are: %s." % (data.nick, help))
actions.reply(data.chan, data.nick, "sub-commands are: %s." % help)


def do_branch(): def do_branch():
"""get our current branch""" """get our current branch"""
branch = exec_shell("git name-rev --name-only HEAD") branch = exec_shell("git name-rev --name-only HEAD")
branch = branch[:-1] # strip newline branch = branch[:-1] # strip newline


actions.say(data.chan, "\x02%s\x0F: currently on branch \x0302%s\x0301." % (data.nick, branch))
actions.reply(data.chan, data.nick, "currently on branch \x0302%s\x0301." % branch)


def do_branches(): def do_branches():
"""get list of branches""" """get list of branches"""
@@ -83,62 +83,62 @@ def do_branches():
branches = branches.replace('\n ', ', ') branches = branches.replace('\n ', ', ')
branches = branches.strip() branches = branches.strip()


actions.say(data.chan, "\x02%s\x0F: branches: \x0302%s\x0301." % (data.nick, branches))
actions.reply(data.chan, data.nick, "branches: \x0302%s\x0301." % branches)


def do_checkout(): def do_checkout():
"""switch branches""" """switch branches"""
try: try:
branch = data.args[1] branch = data.args[1]
except IndexError: # no branch name provided except IndexError: # no branch name provided
actions.say(data.chan, "\x02%s\x0F: switch to which branch?" % data.nick)
actions.reply(data.chan, data.nick, "switch to which branch?")
return return


try: try:
result = exec_shell("git checkout %s" % branch) result = exec_shell("git checkout %s" % branch)
if "Already on" in result: if "Already on" in result:
actions.say(data.chan, "\x02%s\x0F: already on \x0302%s\x0301!" % (data.nick, branch))
actions.reply(data.chan, data.nick, "already on \x0302%s\x0301!" % branch)
else: else:
actions.say(data.chan, "\x02%s\x0F: switched to branch \x0302%s\x0301." % (data.nick, branch))
actions.reply(data.chan, data.nick, "switched to branch \x0302%s\x0301." % branch)


except subprocess.CalledProcessError: # git couldn't switch branches except subprocess.CalledProcessError: # git couldn't switch branches
actions.say(data.chan, "\x02%s\x0F: branch \x0302%s\x0301 does not exist!" % (data.nick, branch))
actions.reply(data.chan, data.nick, "branch \x0302%s\x0301 does not exist!" % branch)


def do_delete(): def do_delete():
"""delete a branch, while making sure that we are not on it""" """delete a branch, while making sure that we are not on it"""
try: try:
delete_branch = data.args[1] delete_branch = data.args[1]
except IndexError: # no branch name provided except IndexError: # no branch name provided
actions.say(data.chan, "\x02%s\x0F: delete which branch?" % data.nick)
actions.reply(data.chan, data.nick, "delete which branch?")
return return


current_branch = exec_shell("git name-rev --name-only HEAD") current_branch = exec_shell("git name-rev --name-only HEAD")
current_branch = current_branch[:-1] # strip newline current_branch = current_branch[:-1] # strip newline


if current_branch == delete_branch: if current_branch == delete_branch:
actions.say(data.chan, "\x02%s\x0F: you're currently on this branch; please checkout to a different branch before deleting." % data.nick)
actions.reply(data.chan, data.nick, "you're currently on this branch; please checkout to a different branch before deleting.")
return return


exec_shell("git branch -d %s" % delete_branch) exec_shell("git branch -d %s" % delete_branch)


actions.say(data.chan, "\x02%s\x0F: branch \x0302%s\x0301 has been deleted locally." % (data.nick, delete_branch))
actions.reply(data.chan, data.nick, "branch \x0302%s\x0301 has been deleted locally." % delete_branch)


def do_pull(): def do_pull():
"""pull from remote repository""" """pull from remote repository"""
branch = exec_shell("git name-rev --name-only HEAD") branch = exec_shell("git name-rev --name-only HEAD")
branch = branch[:-1] # strip newline branch = branch[:-1] # strip newline
actions.say(data.chan, "\x02%s\x0F: pulling from remote (currently on \x0302%s\x0301)..." % (data.nick, branch))
actions.reply(data.chan, data.nick, "pulling from remote (currently on \x0302%s\x0301)..." % branch)


result = exec_shell("git pull") result = exec_shell("git pull")


if "Already up-to-date." in result: if "Already up-to-date." in result:
actions.say(data.chan, "\x02%s\x0F: done; no new changes." % data.nick)
actions.reply(data.chan, data.nick, "done; no new changes.")
else: else:
actions.say(data.chan, "\x02%s\x0F: done; new changes merged." % data.nick)
actions.reply(data.chan, data.nick, "done; new changes merged.")


def do_status(): def do_status():
"""check whether we have anything to pull""" """check whether we have anything to pull"""
result = exec_shell("git fetch --dry-run") result = exec_shell("git fetch --dry-run")
if not result: if not result:
actions.say(data.chan, "\x02%s\x0F: local copy is up-to-date with remote." % data.nick)
actions.reply(data.chan, data.nick, "local copy is up-to-date with remote.")
else: else:
actions.say(data.chan, "\x02%s\x0F: remote is ahead of local copy." % (data.nick))
actions.reply(data.chan, data.nick, "remote is ahead of local copy.")

+ 4
- 4
irc/commands/help.py View File

@@ -15,7 +15,7 @@ def call(a, d):
do_command_help() do_command_help()


def do_general_help(): def do_general_help():
actions.say(data.chan, "\x02%s\x0F: I am a bot! You can get help for any command by typing '!help <command>'." % (data.nick))
actions.reply(data.chan, data.nick, "I am a bot! You can get help for any command by typing '!help <command>'.")


def do_command_help(): def do_command_help():
command = data.args[0] command = data.args[0]
@@ -23,12 +23,12 @@ def do_command_help():
try: try:
exec "from irc.commands import %s as this_command" % command exec "from irc.commands import %s as this_command" % command
except ImportError: except ImportError:
actions.say(data.chan, "\x02%s\x0F: command \x0303%s\x0301 not found!" % (data.nick, command))
actions.reply(data.chan, data.nick, "command \x0303%s\x0301 not found!" % command)
return return


info = this_command.__doc__ info = this_command.__doc__


if info: if info:
actions.say(data.chan, "\x02%s\x0F: Info for command \"\x0303%s\x0301: %s\"" % (data.nick, command, info))
actions.reply(data.chan, data.nick, "info for command \"\x0303%s\x0301: %s\"" % (command, info))
else: else:
actions.say(data.chan, "\x02%s\x0F: Sorry, no information for \x0303%s\x0301." % (data.nick, command))
actions.reply(data.chan, data.nick, "sorry, no information for \x0303%s\x0301." % command)

Loading…
Cancel
Save