Added commands to access player stats.

Loosely based on code from jcao219. New commands are "player", "p", "mystats", "me". The commands access existing stats stored in the game database (data.sqlite3).
This commit is contained in:
Yizhe Shen 2014-02-09 03:42:56 -05:00
parent 2b57abc1fb
commit 1994e7330f
2 changed files with 42 additions and 4 deletions

View File

@ -2868,13 +2868,45 @@ def flastgame(cli, nick, rest):
if rest.strip():
aftergame(cli, rawnick, rest)
@cmd("flastgame", admin_only=True, raw_nick=True)
def _flastgame(cli, nick, chan, rest):
flastgame(cli, nick, rest)
@cmd("player", "p")
def player_stats(cli, nick, chan, rest):
"""Gets the specified player's stats based on role"""
if var.PHASE not in ("none", "join"):
cli.notice(nick, "Wait until the game is over to view stats.")
return
params = rest.split()
if len(params) < 2:
cli.notice(nick, "Supply a nick and role name.")
return
player = params[0]
role = params[1]
msg = var.get_player_stats(player, role)
if msg == "":
cli.notice(nick, "No stats for {0} as {1}.".format(player, role))
else:
cli.notice(nick, msg)
@pmcmd("player", "p")
def player_stats_pm(cli, nick, rest):
player_stats(cli, nick, "", rest)
@pmcmd("mystats", "me")
def my_stats_pm(cli, nick, rest):
my_stats(cli, nick, "", rest)
@cmd("mystats", "me")
def my_stats(cli, nick, chan, rest):
player_stats(cli, nick, chan, "{0} {1}".format(nick, rest))
before_debug_mode_commands = list(COMMANDS.keys())
before_debug_mode_pmcommands = list(PM_COMMANDS.keys())

View File

@ -250,6 +250,7 @@ def add_simple_rolemsg(clk):
def remove_ping(clk):
with conn:
c.execute('DELETE from ping where cloak=?', (clk,))
def add_ping(clk):
with conn:
c.execute('INSERT into ping VALUES (?)', (clk,))
@ -277,5 +278,10 @@ def update_role_stats(acc, role, won, iwon):
c.execute("INSERT OR REPLACE INTO rolestats VALUES (?,?,?,?,?)",
(acc, role, wins, iwins, total))
def get_player_stats(player, role):
with conn:
for row in c.execute("SELECT * FROM rolestats WHERE player = '%s' AND role = '%s'" % (player, role)):
return "As {2}, {0} has {3} team wins, {4} individual wins, and {5} total games.".format(player, *row)
else:
return ""