Changed behaviour of "gamestats" command.

"gamestats" without a parameter will list game totals for all game
sizes. The role parameter for player stats commands is now case
insensitive.
This commit is contained in:
Yizhe Shen 2014-02-09 22:31:29 -05:00
parent a12128b486
commit 829fd260e2
2 changed files with 18 additions and 4 deletions

View File

@ -2880,13 +2880,13 @@ def _flastgame(cli, nick, chan, rest):
@cmd("gamestats", "gstats")
def game_stats(cli, nick, chan, rest):
"""Gets the game stats for a given game size"""
"""Gets the game stats for a given game size or lists game totals for all game sizes if no game size is given."""
if var.PHASE not in ("none", "join"):
cli.notice(nick, "Wait until the game is over to view stats.")
return
if rest == "":
cli.notice(nick, "Supply a game size")
cli.msg(chan, var.get_game_totals())
return
if not rest.isdigit():
@ -2913,7 +2913,7 @@ def player_stats(cli, nick, chan, rest):
return
player = params[0]
role = " ".join(params[1:])
role = " ".join(params[1:]).lower()
msg = var.get_player_stats(player, role)
if msg == "":

View File

@ -313,4 +313,18 @@ def get_game_stats(size):
for row in c.execute("SELECT * FROM gamestats WHERE size = %d" % (size)):
return "{0} player games: {1} village wins, {2} wolf wins, and {3} total games.".format(*row)
else:
return ""
return ""
def get_game_totals():
sizeList = []
with conn:
for size in range(4, MAX_PLAYERS):
c.execute("SELECT size, totalgames FROM gamestats WHERE size = %d" % size)
row = c.fetchone()
if row:
sizeList.append("{0}p({1})".format(*row))
if len(sizeList) == 0:
return "No games have been played."
else:
return "Game totals: %s" % ", ".join(sizeList)