!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:
cli.msg(chan, var.get_player_totals(acc))
else:
role = " ".join(params[1:]).lower()
role = " ".join(params[1:])
# Attempt to find the player's stats.
if chan == nick:
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))
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:
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,))
player = c.fetchone()
if player:
for row in c.execute("SELECT * FROM rolestats WHERE player=? COLLATE NOCASE AND role=? COLLATE NOCASE", (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(acc, role)
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):
role_totals = []
with conn:
c.execute("SELECT player FROM rolestats WHERE player=? COLLATE NOCASE", (acc,))
player = c.fetchone()
if player:
for role in ["villager"] + [v for k, v in ROLE_INDICES.items()]:
c.execute("SELECT totalgames FROM rolestats WHERE player=? AND role=?", (acc, role))
c.execute("SELECT totalgames FROM rolestats WHERE player=? COLLATE NOCASE AND role=? COLLATE NOCASE", (acc, role))
row = c.fetchone()
if row:
role_totals.append("\u0002{0}\u0002: {1}".format(role, *row))
if len(role_totals) == 0:
return "{0} has not played any games.".format(acc)
return "\u0002{0}\u0002's totals | {1}".format(player[0], ", ".join(role_totals))
else:
return "\u0002{0}\u0002's totals | {1}".format(acc, ", ".join(role_totals))
return "{0} has not played any games.".format(acc)
def get_game_stats(size):
with conn: