allow using !votes in join phase to see gamemode votes
This commit is contained in:
parent
51c0cb9188
commit
4b07779bc3
@ -1749,14 +1749,35 @@ def chk_decision(cli, force = ""):
|
||||
transition_night(cli)
|
||||
break
|
||||
|
||||
@cmd("votes", pm=True, game=True)
|
||||
@cmd("votes", pm=True, game=True, join=True)
|
||||
def show_votes(cli, nick, chan, rest):
|
||||
"""Displays the voting statistics."""
|
||||
|
||||
if var.PHASE != 'day':
|
||||
pl = var.list_players()
|
||||
if var.PHASE == "join":
|
||||
#get gamemode votes in a dict (key = mode, value = number of votes)
|
||||
gamemode_votes = {}
|
||||
for vote in var.GAMEMODE_VOTES.values():
|
||||
gamemode_votes[vote] = gamemode_votes.get(vote, 0) + 1
|
||||
|
||||
votelist = []
|
||||
majority = False
|
||||
for gamemode,num_votes in sorted(gamemode_votes.items(), key=lambda x: x[1], reverse=True):
|
||||
#bold the game mode if: we have the right number of players, another game mode doesn't already have the majority, and this gamemode can be picked randomly or has the majority
|
||||
if (len(pl) >= var.GAME_MODES[gamemode][1] and len(pl) <= var.GAME_MODES[gamemode][2] and
|
||||
(not majority or num_votes >= len(pl)/2) and (var.GAME_MODES[gamemode][3] > 0 or num_votes >= len(pl)/2)):
|
||||
votelist.append("\u0002{0}\u0002: {1}".format(gamemode, num_votes))
|
||||
if num_votes >= len(pl)/2:
|
||||
majority = True
|
||||
else:
|
||||
votelist.append("{0}: {1}".format(gamemode, num_votes))
|
||||
the_message = ", ".join(votelist)
|
||||
if len(pl) >= var.MIN_PLAYERS:
|
||||
the_message += "{0}Votes needed for a majority: {1}".format("; " if votelist else "", int(math.ceil(len(pl)/2)))
|
||||
elif var.PHASE == "night":
|
||||
cli.notice(nick, "Voting is only during the day.")
|
||||
return
|
||||
|
||||
else:
|
||||
if (chan != nick and var.LAST_VOTES and var.VOTES_RATE_LIMIT and
|
||||
var.LAST_VOTES + timedelta(seconds=var.VOTES_RATE_LIMIT) >
|
||||
datetime.now()):
|
||||
@ -1764,8 +1785,6 @@ def show_votes(cli, nick, chan, rest):
|
||||
'before using it again.'))
|
||||
return
|
||||
|
||||
pl = var.list_players()
|
||||
|
||||
_nick = nick + ": "
|
||||
if chan == nick:
|
||||
_nick = ""
|
||||
@ -1808,7 +1827,7 @@ def show_votes(cli, nick, chan, rest):
|
||||
|
||||
if chan == nick:
|
||||
pm(cli, nick, the_message)
|
||||
elif nick not in pl and var.PHASE not in ("none", "join"):
|
||||
elif nick not in pl and var.PHASE != "join":
|
||||
cli.notice(nick, the_message)
|
||||
else:
|
||||
cli.msg(chan, the_message)
|
||||
|
Loading…
x
Reference in New Issue
Block a user