querynick = arg.lower()
else:
querynick = sender.lower()
- # Select user and user above this user in scoring list.
- querystring = "SELECT x.nick, x.position, x.points, x.channel FROM (SELECT t.nick, t.points, t.channel, @rownum := @rownum + 1 AS position FROM trivia_scores AS t JOIN (SELECT @rownum := 0) r ON t.channel = %s ORDER BY t.points DESC) x WHERE x.nick >= %s ORDER BY x.position DESC LIMIT 2;"
-
- self.dbp.execute(querystring, (self.get_cid(channel), querynick))
+ self.dbp.execute("SELECT nick, points FROM trivia_scores WHERE channel = %s ORDER BY points DESC;", (self.get_cid(channel),))
rows = self.dbp.fetchall()
- if len(rows) >= 1 and rows[0][0].lower() == querynick:
- userdata = rows[0]
- out = "%s is currently ranked #%d with %d %s" % (userdata[0], userdata[1], userdata[2], "point" if userdata[2] == 1 else "points")
- if len(rows) == 2:
- otherdata = rows[1]
- diff = otherdata[2] - userdata[2]
- out += ", %d %s behind %s" % (diff, "point" if diff == 1 else "points", otherdata[0])
- out += "."
- self.notice(sender, out)
+ for i in range(len(rows)):
+ userdata = rows[i]
+ if userdata[0].lower() == querynick.lower():
+ out = "%s is currently ranked #%d with %d %s" % (userdata[0], i + 1, userdata[1], "point" if userdata[1] == 1 else "points")
+ if i > 0:
+ otherdata = rows[i - 1]
+ diff = otherdata[1] - userdata[1]
+ out += ", %d %s behind %s" % (diff, "point" if diff == 1 else "points", otherdata[0])
+ out += "."
+ self.notice(sender, out)
+ break
else:
self.notice(sender, "Nickname not found.")
#elif command == 'next': # Defunct in orig trivia