!p is case insensetive, and tells you when a player / role doesn't exist

At the request of / using some code from brrr
This commit is contained in:
jacob1 2014-05-31 23:37:04 -04:00
parent 08855dba9a
commit d56e1731b2
2 changed files with 23 additions and 16 deletions

View File

@ -3128,7 +3128,7 @@ def player_stats(cli, nick, chan, rest):
else: else:
cli.msg(chan, var.get_player_totals(acc)) cli.msg(chan, var.get_player_totals(acc))
else: else:
role = " ".join(params[1:]).lower() role = " ".join(params[1:])
# Attempt to find the player's stats. # Attempt to find the player's stats.
if chan == nick: if chan == nick:
pm(cli, nick, var.get_player_stats(acc, role)) pm(cli, nick, var.get_player_stats(acc, role))

View File

@ -304,26 +304,33 @@ def update_game_stats(size, winner):
(size, vwins, wwins, total)) (size, vwins, wwins, total))
def get_player_stats(acc, role): def get_player_stats(acc, role):
if role.lower() not in ["villager"] + [v.lower() for k, v in ROLE_INDICES.items()]:
return "No such role: {0}".format(role)
with conn: with conn:
for row in c.execute("SELECT * FROM rolestats WHERE player=? AND role=?", (acc, role)): c.execute("SELECT player FROM rolestats WHERE player=? COLLATE NOCASE", (acc,))
msg = "\u0002{0}\u0002 as \u0002{1}\u0002 | Team wins: {2} (%d%%), Individual wins: {3} (%d%%), Total games: {4}".format(*row) player = c.fetchone()
return msg % (round(row[2]/row[4] * 100), round(row[3]/row[4] * 100)) if player:
else: for row in c.execute("SELECT * FROM rolestats WHERE player=? COLLATE NOCASE AND role=? COLLATE NOCASE", (acc, role)):
return "No stats for {0} as {1}.".format(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 "No stats for {0} as {1}.".format(player[0], role)
return "{0} has not played any games.".format(acc)
def get_player_totals(acc): def get_player_totals(acc):
role_totals = [] role_totals = []
with conn: with conn:
for role in ["villager"] + [v for k, v in ROLE_INDICES.items()]: c.execute("SELECT player FROM rolestats WHERE player=? COLLATE NOCASE", (acc,))
c.execute("SELECT totalgames FROM rolestats WHERE player=? AND role=?", (acc, role)) player = c.fetchone()
row = c.fetchone() if player:
if row: for role in ["villager"] + [v for k, v in ROLE_INDICES.items()]:
role_totals.append("\u0002{0}\u0002: {1}".format(role, *row)) c.execute("SELECT totalgames FROM rolestats WHERE player=? COLLATE NOCASE AND role=? COLLATE NOCASE", (acc, role))
row = c.fetchone()
if len(role_totals) == 0: if row:
return "{0} has not played any games.".format(acc) role_totals.append("\u0002{0}\u0002: {1}".format(role, *row))
else: return "\u0002{0}\u0002's totals | {1}".format(player[0], ", ".join(role_totals))
return "\u0002{0}\u0002's totals | {1}".format(acc, ", ".join(role_totals)) else:
return "{0} has not played any games.".format(acc)
def get_game_stats(size): def get_game_stats(size):
with conn: with conn: