]> jfr.im git - irc/rizon/acid.git/commitdiff
Fixed rank command
authorMichiel <redacted>
Wed, 24 Dec 2014 22:04:16 +0000 (23:04 +0100)
committerMichiel <redacted>
Thu, 25 Dec 2014 00:42:41 +0000 (01:42 +0100)
pyva/pyva/src/main/python/trivia/trivia.py

index 3f698372d150d81f6d4ed29cba7370b457bf371e..1017b7da4de0b0215b182f4809f74d060e166584 100644 (file)
@@ -267,20 +267,19 @@ class trivia(
                                                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