pingtools: fix leaderboard sorting

This commit is contained in:
dymik739 2023-10-09 23:48:08 +03:00
parent 7d0d816ca8
commit 3e38c113d9
1 changed files with 12 additions and 10 deletions

View File

@ -1,4 +1,6 @@
if self.MESSAGE.text == "!ping": msg = self.MESSAGE.text.lower()
if msg == "!ping":
current_time = time.time() current_time = time.time()
delay = current_time - 7200 - float(self.MESSAGE.date.strftime('+%s')) delay = current_time - 7200 - float(self.MESSAGE.date.strftime('+%s'))
self.RESPONSE = f"Pong in {delay} seconds" self.RESPONSE = f"Pong in {delay} seconds"
@ -17,7 +19,7 @@ if self.MESSAGE.text == "!ping":
append_score(self.path, self.MESSAGE.from_user.id, f"{current_time} {user_id} {chat_id} {first_name} {last_name} {username} {delay}\n") append_score(self.path, self.MESSAGE.from_user.id, f"{current_time} {user_id} {chat_id} {first_name} {last_name} {username} {delay}\n")
elif self.MESSAGE.text == "!pong": elif msg == "!pong":
current_time = time.time() current_time = time.time()
delay = current_time - 7200 - float(self.MESSAGE.date.strftime('+%s')) delay = current_time - 7200 - float(self.MESSAGE.date.strftime('+%s'))
self.RESPONSE = f"Ping in {delay} seconds" self.RESPONSE = f"Ping in {delay} seconds"
@ -36,7 +38,7 @@ elif self.MESSAGE.text == "!pong":
append_score(self.path, self.MESSAGE.from_user.id, f"{current_time} {user_id} {chat_id} {first_name} {last_name} {username} {delay}\n") append_score(self.path, self.MESSAGE.from_user.id, f"{current_time} {user_id} {chat_id} {first_name} {last_name} {username} {delay}\n")
elif self.MESSAGE.text == "!pingtop": elif msg == "!pingtop":
def read_score(path, name): def read_score(path, name):
if os.path.exists(path + f"scoreboard/{name}"): if os.path.exists(path + f"scoreboard/{name}"):
return open(path + f"scoreboard/{name}").read() return open(path + f"scoreboard/{name}").read()
@ -54,11 +56,11 @@ elif self.MESSAGE.text == "!pingtop":
print(results) print(results)
results.sort(key = lambda x: x[6]) results.sort(key = lambda x: float(x[6]))
self.RESPONSE = "<u>Ping top</u>:\n" + "\n".join( [f"{i+1}. {v[3]} {v[4]} ({v[5]}) - {v[6]}" for i, v in enumerate(results[:10])] ) self.RESPONSE = "<u>Ping top</u>:\n" + "\n".join( [f"{i+1}. {v[3]} {v[4]} ({v[5]}) - {v[6]}" for i, v in enumerate(results[:10])] )
self.FORMAT = "HTML" self.FORMAT = "HTML"
elif self.MESSAGE.text == "!pongtop": elif msg == "!pongtop":
def read_score(path, name): def read_score(path, name):
if os.path.exists(path + f"pong-scoreboard/{name}"): if os.path.exists(path + f"pong-scoreboard/{name}"):
return open(path + f"pong-scoreboard/{name}").read() return open(path + f"pong-scoreboard/{name}").read()
@ -76,11 +78,11 @@ elif self.MESSAGE.text == "!pongtop":
print(results) print(results)
results.sort(key = lambda x: x[6]) results.sort(key = lambda x: float(x[6]))
self.RESPONSE = "<u>Pong top</u>:\n" + "\n".join( [f"{i+1}. {v[3]} {v[4]} ({v[5]}) - {v[6]}" for i, v in enumerate(results[:10])] ) self.RESPONSE = "<u>Pong top</u>:\n" + "\n".join( [f"{i+1}. {v[3]} {v[4]} ({v[5]}) - {v[6]}" for i, v in enumerate(results[:10])] )
self.FORMAT = "HTML" self.FORMAT = "HTML"
elif self.MESSAGE.text == "!pingantitop": elif msg == "!pingantitop":
def read_score(path, name): def read_score(path, name):
if os.path.exists(path + f"scoreboard/{name}"): if os.path.exists(path + f"scoreboard/{name}"):
return open(path + f"scoreboard/{name}").read() return open(path + f"scoreboard/{name}").read()
@ -98,12 +100,12 @@ elif self.MESSAGE.text == "!pingantitop":
print(results) print(results)
results.sort(key = lambda x: x[6]) results.sort(key = lambda x: float(x[6]))
results = results[::-1] results = results[::-1]
self.RESPONSE = "<u>Ping antitop</u>:\n" + "\n".join( [f"{i+1}. {v[3]} {v[4]} ({v[5]}) - {v[6]}" for i, v in enumerate(results[:10])] ) self.RESPONSE = "<u>Ping antitop</u>:\n" + "\n".join( [f"{i+1}. {v[3]} {v[4]} ({v[5]}) - {v[6]}" for i, v in enumerate(results[:10])] )
self.FORMAT = "HTML" self.FORMAT = "HTML"
elif self.MESSAGE.text == "!pongantitop": elif msg == "!pongantitop":
def read_score(path, name): def read_score(path, name):
if os.path.exists(path + f"pong-scoreboard/{name}"): if os.path.exists(path + f"pong-scoreboard/{name}"):
return open(path + f"pong-scoreboard/{name}").read() return open(path + f"pong-scoreboard/{name}").read()
@ -121,7 +123,7 @@ elif self.MESSAGE.text == "!pongantitop":
print(results) print(results)
results.sort(key = lambda x: x[6]) results.sort(key = lambda x: float(x[6]))
results = results[::-1] results = results[::-1]
self.RESPONSE = "<u>Pong antitop</u>:\n" + "\n".join( [f"{i+1}. {v[3]} {v[4]} ({v[5]}) - {v[6]}" for i, v in enumerate(results[:10])] ) self.RESPONSE = "<u>Pong antitop</u>:\n" + "\n".join( [f"{i+1}. {v[3]} {v[4]} ({v[5]}) - {v[6]}" for i, v in enumerate(results[:10])] )
self.FORMAT = "HTML" self.FORMAT = "HTML"