Make !votes work in PM

This commit is contained in:
nyuszika7h 2014-08-01 11:53:56 +02:00
parent 3915be7aa9
commit d2b96752c7

View File

@ -760,41 +760,43 @@ def chk_decision(cli):
transition_night(cli) transition_night(cli)
@cmd('votes')
@cmd("votes")
def show_votes(cli, nick, chan, rest): def show_votes(cli, nick, chan, rest):
"""Displays the voting statistics.""" """Displays the voting statistics."""
if var.PHASE in ("none", "join"): if var.PHASE in ('none', 'join'):
cli.notice(nick, "No game is currently running.") cli.notice(nick, "No game is currently running.")
return return
if var.PHASE != "day":
if var.PHASE != 'day':
cli.notice(nick, "Voting is only during the day.") cli.notice(nick, "Voting is only during the day.")
return return
if (var.LAST_VOTES and if (chan != nick and var.LAST_VOTES and var.VOTES_RATE_LIMIT and
var.LAST_VOTES + timedelta(seconds=var.VOTES_RATE_LIMIT) > datetime.now()): var.LAST_VOTES + timedelta(seconds=var.VOTES_RATE_LIMIT) >
cli.notice(nick, ("This command is rate-limited." + datetime.now()):
"Please wait a while before using it again.")) cli.notice(nick, ('This command is rate-limited. Please wait a while '
return 'before using it again.'))
return
pl = var.list_players() pl = var.list_players()
if nick in pl: if nick in pl:
var.LAST_VOTES = datetime.now() var.LAST_VOTES = datetime.now()
if not var.VOTES.values(): if not var.VOTES.values():
msg = nick+": No votes yet." msg = nick+ ': No votes yet.'
if nick in pl: if nick in pl:
var.LAST_VOTES = None # reset var.LAST_VOTES = None # reset
else: else:
votelist = ["{0}: {1} ({2})".format(votee, votelist = ['{}: {} ({})'.format(votee,
len(var.VOTES[votee]), len(var.VOTES[votee]),
" ".join(var.VOTES[votee])) ' '.join(var.VOTES[votee]))
for votee in var.VOTES.keys()] for votee in var.VOTES.keys()]
msg = "{0}: {1}".format(nick, ", ".join(votelist)) msg = '{}: {}'.format(nick, ', '.join(votelist))
if nick in pl: if chan == nick or nick in pl:
cli.msg(chan, msg) cli.msg(chan, msg)
else: else:
cli.notice(nick, msg) cli.notice(nick, msg)
@ -802,15 +804,20 @@ def show_votes(cli, nick, chan, rest):
pl = var.list_players() pl = var.list_players()
avail = len(pl) - len(var.WOUNDED) avail = len(pl) - len(var.WOUNDED)
votesneeded = avail // 2 + 1 votesneeded = avail // 2 + 1
the_message = ("{0}: \u0002{1}\u0002 players, \u0002{2}\u0002 votes "+ the_message = ('{}: \u0002{}\u0002 players, \u0002{}\u0002 votes '
"required to lynch, \u0002{3}\u0002 players available " + 'required to lynch, \u0002{3}\u0002 players available to '
"to vote.").format(nick, len(pl), votesneeded, avail) 'vote.').format(nick, len(pl), votesneeded, avail)
if nick in pl:
if chan == nick or nick in pl:
cli.msg(chan, the_message) cli.msg(chan, the_message)
else: else:
cli.notice(nick, the_message) cli.notice(nick, the_message)
@pmcmd('votes')
def show_votes_pm(cli, nick, rest):
show_votes(cli, nick, nick, rest)
def chk_traitor(cli): def chk_traitor(cli):
for tt in var.ROLES["traitor"]: for tt in var.ROLES["traitor"]: