!update: Don't restart the bot if already up-to-date
This commit is contained in:
parent
abd2dd149d
commit
82d6760c5a
@ -768,6 +768,7 @@
|
|||||||
"no_such_role": "No such role: {0}",
|
"no_such_role": "No such role: {0}",
|
||||||
"available_modes": "Available game modes: \u0002",
|
"available_modes": "Available game modes: \u0002",
|
||||||
"process_exited": "Process {0} exited with {1} {2}",
|
"process_exited": "Process {0} exited with {1} {2}",
|
||||||
|
"already_up_to_date": "Already up-to-date.",
|
||||||
"admin_fleave_deadchat": "You have forced {0} to leave the deadchat.",
|
"admin_fleave_deadchat": "You have forced {0} to leave the deadchat.",
|
||||||
"available_mode_setters_help": "Votes to make a specific game mode more likely. Available game mode setters: ",
|
"available_mode_setters_help": "Votes to make a specific game mode more likely. Available game mode setters: ",
|
||||||
"fspectate_help": "Usage: fspectate <wolfchat|deadchat> [on|off]",
|
"fspectate_help": "Usage: fspectate <wolfchat|deadchat> [on|off]",
|
||||||
|
@ -7207,20 +7207,21 @@ def vote(cli, nick, chan, rest):
|
|||||||
else:
|
else:
|
||||||
return show_votes.caller(cli, nick, chan, rest)
|
return show_votes.caller(cli, nick, chan, rest)
|
||||||
|
|
||||||
@cmd("pull", "fpull", flag="D", pm=True)
|
def _call_command(cli, nick, chan, command, no_out=False):
|
||||||
def fpull(cli, nick, chan, rest):
|
"""
|
||||||
"""Pulls from the repository to update the bot."""
|
Executes a system command.
|
||||||
|
|
||||||
commands = ["git fetch",
|
If `no_out` is True, the command's output will not be sent to IRC,
|
||||||
"git rebase --stat --preserve-merges"]
|
unless the exit code is non-zero.
|
||||||
|
"""
|
||||||
|
|
||||||
for command in commands:
|
|
||||||
child = subprocess.Popen(command.split(),
|
child = subprocess.Popen(command.split(),
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
(out, err) = child.communicate()
|
(out, err) = child.communicate()
|
||||||
ret = child.returncode
|
ret = child.returncode
|
||||||
|
|
||||||
|
if not (no_out and ret == 0):
|
||||||
for line in (out + err).splitlines():
|
for line in (out + err).splitlines():
|
||||||
reply(cli, nick, chan, line.decode("utf-8"), private=True)
|
reply(cli, nick, chan, line.decode("utf-8"), private=True)
|
||||||
|
|
||||||
@ -7233,6 +7234,28 @@ def fpull(cli, nick, chan, rest):
|
|||||||
|
|
||||||
reply(cli, nick, chan, messages["process_exited"].format(command, cause, ret), private=True)
|
reply(cli, nick, chan, messages["process_exited"].format(command, cause, ret), private=True)
|
||||||
|
|
||||||
|
return (ret, out)
|
||||||
|
|
||||||
|
@cmd("pull", "fpull", flag="D", pm=True)
|
||||||
|
def fpull(cli, nick, chan, rest):
|
||||||
|
"""Pulls from the repository to update the bot."""
|
||||||
|
|
||||||
|
(ret, _) = _call_command(cli, nick, chan, "git fetch")
|
||||||
|
|
||||||
|
if ret != 0:
|
||||||
|
return False
|
||||||
|
|
||||||
|
(_, out) = _call_command(cli, nick, chan, "git status -b --porcelain", no_out=True)
|
||||||
|
|
||||||
|
if not re.search(rb"behind \d+", out.splitlines()[0]):
|
||||||
|
# Already up-to-date
|
||||||
|
reply(cli, nick, chan, messages["already_up_to_date"], private=True)
|
||||||
|
return False
|
||||||
|
|
||||||
|
(ret, _) = _call_command(cli, nick, chan, "git rebase --stat --preserve-merges")
|
||||||
|
|
||||||
|
return (ret == 0)
|
||||||
|
|
||||||
@cmd("update", flag="D", pm=True)
|
@cmd("update", flag="D", pm=True)
|
||||||
def update(cli, nick, chan, rest):
|
def update(cli, nick, chan, rest):
|
||||||
"""Pulls from the repository and restarts the bot to update it."""
|
"""Pulls from the repository and restarts the bot to update it."""
|
||||||
@ -7251,7 +7274,9 @@ def update(cli, nick, chan, rest):
|
|||||||
# Display "Scheduled restart" instead of "Forced restart" when called with !faftergame
|
# Display "Scheduled restart" instead of "Forced restart" when called with !faftergame
|
||||||
restart_program.aftergame = True
|
restart_program.aftergame = True
|
||||||
|
|
||||||
fpull.caller(cli, nick, chan, "")
|
ret = fpull.caller(cli, nick, chan, "")
|
||||||
|
|
||||||
|
if ret:
|
||||||
restart_program.caller(cli, nick, chan, "Updating bot")
|
restart_program.caller(cli, nick, chan, "Updating bot")
|
||||||
|
|
||||||
@cmd("send", "fsend", flag="F", pm=True)
|
@cmd("send", "fsend", flag="F", pm=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user