diff --git a/modules/wolfgame.py b/modules/wolfgame.py index 9819219..84caf78 100644 --- a/modules/wolfgame.py +++ b/modules/wolfgame.py @@ -2926,24 +2926,19 @@ def game_stats(cli, nick, chan, rest): return # Attempt to find game stats for the given game size. - size = int(rest) - msg = var.get_game_stats(size) - if msg == "": - cli.msg(chan, "No stats for \u0002{0}\u0002 player games.".format(size)) - else: - cli.msg(chan, msg) + cli.msg(chan, var.get_game_stats(int(rest))) @cmd("player", "p") def player_stats(cli, nick, chan, rest): - """Gets the stats for the given player and role.""" + """Gets the stats for the given player and role or a list of role totals if no role is given.""" if var.PHASE not in ("none", "join"): cli.notice(nick, "Wait until the game is over to view stats.") return # Check if we have enough parameters. params = rest.split() - if len(params) < 2: - cli.notice(nick, "Supply a nick and role name.") + if len(params) < 1: + cli.notice(nick, "Supply at least a nick.") return # Find the player's account if possible. @@ -2951,14 +2946,14 @@ def player_stats(cli, nick, chan, rest): acc = var.USERS[params[0]]["account"] else: acc = params[0] - role = " ".join(params[1:]).lower() - # Attempt to find the player's stats. - msg = var.get_player_stats(acc, role) - if msg == "": - cli.notice(nick, "No stats for {0} as {1}.".format(acc, role)) + # List the player's total games for all roles if no role is given + if len(params) == 1: + cli.notice(nick, var.get_player_totals(acc)) else: - cli.notice(nick, msg) + role = " ".join(params[1:]).lower() + # Attempt to find the player's stats. + cli.notice(nick, var.get_player_stats(acc, role)) @pmcmd("player", "p") def player_stats_pm(cli, nick, rest): @@ -2970,12 +2965,7 @@ def my_stats_pm(cli, nick, rest): @cmd("mystats", "me") def my_stats(cli, nick, chan, rest): - """Gets your own stats for the given role.""" - # Check if role has been given - if rest == "": - cli.notice(nick, "Supply a role.") - return - + """Gets your own stats for the given role or a list of role totals if no role is given.""" # Check if player is identified acc = var.USERS[nick]["account"] if acc == "*": diff --git a/settings/wolfgame.py b/settings/wolfgame.py index 5f218da..3b7197c 100644 --- a/settings/wolfgame.py +++ b/settings/wolfgame.py @@ -305,15 +305,29 @@ def get_player_stats(acc, role): msg = "\u0002{0}\u0002 as \u0002{1}\u0002 | Team wins: {2} (%d%%), Individual wins: {3} (%d%%), Total games: {4}".format(*row) return msg % (round(row[2]/row[4] * 100), round(row[3]/row[4] * 100)) else: - return "" + return "No stats for {0} as {1}.".format(acc, role) +def get_player_totals(acc): + roleTotals = [] + with conn: + for role in ["villager"] + [v for k, v in ROLE_INDICES.items()]: + c.execute("SELECT totalgames FROM rolestats WHERE player=? AND role=?", (acc, role)) + row = c.fetchone() + if row: + roleTotals.append("\u0002{0}\u0002: {1}".format(role, *row)) + + if len(roleTotals) == 0: + return "{0} has not played any games.".format(acc) + else: + return "\u0002{0}\u0002's totals | {1}".format(acc, ", ".join(roleTotals)) + def get_game_stats(size): with conn: for row in c.execute("SELECT * FROM gamestats WHERE size=?", (size,)): msg = "\u0002{0}\u0002 player games | Village wins: {1} (%d%%), Wolf wins: {2} (%d%%), Total games: {3}".format(*row) return msg % (round(row[1]/row[3] * 100), round(row[2]/row[3] * 100)) else: - return "" + return "No stats for \u0002{0}\u0002 player games.".format(size) def get_game_totals(): sizeList = [] @@ -322,9 +336,9 @@ def get_game_totals(): c.execute("SELECT size, totalgames FROM gamestats WHERE size=?", (size,)) row = c.fetchone() if row: - sizeList.append("\02{0}p\02: {1}".format(*row)) + sizeList.append("\u0002{0}p\u0002: {1}".format(*row)) if len(sizeList) == 0: return "No games have been played." else: - return "Game totals: %s" % ", ".join(sizeList) + return "Game totals | %s" % ", ".join(sizeList)