Make !gstats show totals for all game modes by default

This commit is contained in:
nyuszika7h 2016-09-24 12:27:45 +02:00
parent 810433b656
commit e0bf47c182
2 changed files with 29 additions and 11 deletions

View File

@ -394,10 +394,24 @@ def get_game_stats(mode, size):
def get_game_totals(mode): def get_game_totals(mode):
conn = _conn() conn = _conn()
c = conn.cursor() c = conn.cursor()
if mode == "all":
c.execute("SELECT COUNT(1) FROM game")
else:
c.execute("SELECT COUNT(1) FROM game WHERE gamemode = ?", (mode,)) c.execute("SELECT COUNT(1) FROM game WHERE gamemode = ?", (mode,))
total_games = c.fetchone()[0] total_games = c.fetchone()[0]
if not total_games: if not total_games:
return "No games have been played in the {0} game mode.".format(mode) return "No games have been played in the {0} game mode.".format(mode)
if mode == "all":
c.execute("""SELECT
gamesize,
COUNT(1) AS games
FROM game
GROUP BY gamesize
ORDER BY gamesize ASC""")
else:
c.execute("""SELECT c.execute("""SELECT
gamesize, gamesize,
COUNT(1) AS games COUNT(1) AS games
@ -408,6 +422,10 @@ def get_game_totals(mode):
totals = [] totals = []
for row in c: for row in c:
totals.append("\u0002{0}p\u0002: {1}".format(*row)) totals.append("\u0002{0}p\u0002: {1}".format(*row))
if mode == "all":
return "Total games: {0} | {1}".format(total_games, ", ".join(totals))
else:
return "Total games (\u0002{0}\u0002): {1} | {2}".format(mode, total_games, ", ".join(totals)) return "Total games (\u0002{0}\u0002): {1} | {2}".format(mode, total_games, ", ".join(totals))
def get_warning_points(acc, hostmask): def get_warning_points(acc, hostmask):

View File

@ -7087,13 +7087,13 @@ def game_stats(cli, nick, chan, rest):
cli.notice(nick, messages["stats_wait_for_game_end"]) cli.notice(nick, messages["stats_wait_for_game_end"])
return return
gamemode = var.CURRENT_GAMEMODE.name gamemode = "all"
gamesize = None gamesize = None
rest = rest.split() rest = rest.split()
# Check for gamemode # Check for gamemode
if len(rest) and not rest[0].isdigit(): if len(rest) and not rest[0].isdigit():
gamemode = rest[0] gamemode = rest[0]
if gamemode not in var.GAME_MODES.keys(): if gamemode != "all" and gamemode not in var.GAME_MODES.keys():
gamemode, _ = complete_match(gamemode, var.GAME_MODES.keys()) gamemode, _ = complete_match(gamemode, var.GAME_MODES.keys())
if not gamemode: if not gamemode:
cli.notice(nick, messages["invalid_mode_no_list"].format(rest[0])) cli.notice(nick, messages["invalid_mode_no_list"].format(rest[0]))