2023-09-26 12:58:40 +03:00
|
|
|
if self.MESSAGE.text == "!ping":
|
|
|
|
current_time = time.time()
|
|
|
|
delay = current_time - 7200 - float(self.MESSAGE.date.strftime('+%s'))
|
|
|
|
self.RESPONSE = f"Pong in {delay} seconds"
|
2023-09-21 19:32:56 +03:00
|
|
|
|
2023-09-26 12:58:40 +03:00
|
|
|
if not os.path.exists(self.path + "scoreboard/"):
|
|
|
|
os.mkdir(self.path + "scoreboard/")
|
|
|
|
|
|
|
|
def append_score(path, name, data):
|
|
|
|
open(path + f"scoreboard/{name}", "a").write(data)
|
|
|
|
|
|
|
|
user_id = self.MESSAGE.from_user.id
|
|
|
|
chat_id = self.MESSAGE.chat.id
|
|
|
|
first_name = self.MESSAGE.from_user.first_name
|
|
|
|
last_name = self.MESSAGE.from_user.last_name
|
|
|
|
username = self.MESSAGE.from_user.username
|
|
|
|
|
|
|
|
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":
|
|
|
|
current_time = time.time()
|
|
|
|
delay = current_time - 7200 - float(self.MESSAGE.date.strftime('+%s'))
|
|
|
|
self.RESPONSE = f"Ping in {delay} seconds"
|
|
|
|
|
|
|
|
if not os.path.exists(self.path + "pong-scoreboard/"):
|
|
|
|
os.mkdir(self.path + "pong-scoreboard/")
|
|
|
|
|
|
|
|
def append_score(path, name, data):
|
|
|
|
open(path + f"pong-scoreboard/{name}", "a").write(data)
|
|
|
|
|
|
|
|
user_id = self.MESSAGE.from_user.id
|
|
|
|
chat_id = self.MESSAGE.chat.id
|
|
|
|
first_name = self.MESSAGE.from_user.first_name
|
|
|
|
last_name = self.MESSAGE.from_user.last_name
|
|
|
|
username = self.MESSAGE.from_user.username
|
|
|
|
|
|
|
|
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":
|
|
|
|
def read_score(path, name):
|
|
|
|
if os.path.exists(path + f"scoreboard/{name}"):
|
|
|
|
return open(path + f"scoreboard/{name}").read()
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
if not os.path.exists(self.path + "scoreboard/"):
|
|
|
|
os.mkdir(self.path + "scoreboard/")
|
|
|
|
|
|
|
|
results = []
|
|
|
|
for name in os.listdir(self.path + "scoreboard/"):
|
|
|
|
data = [i for i in read_score(self.path, name).split("\n") if i != ""]
|
|
|
|
data.sort(key = lambda x: float(x.split()[6]))
|
|
|
|
results.append(data[0].split())
|
|
|
|
|
|
|
|
print(results)
|
|
|
|
|
|
|
|
results.sort(key = lambda x: 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.FORMAT = "HTML"
|
|
|
|
|
|
|
|
elif self.MESSAGE.text == "!pongtop":
|
|
|
|
def read_score(path, name):
|
|
|
|
if os.path.exists(path + f"pong-scoreboard/{name}"):
|
|
|
|
return open(path + f"pong-scoreboard/{name}").read()
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
if not os.path.exists(self.path + "pong-scoreboard/"):
|
|
|
|
os.mkdir(self.path + "pong-scoreboard/")
|
|
|
|
|
|
|
|
results = []
|
|
|
|
for name in os.listdir(self.path + "pong-scoreboard/"):
|
|
|
|
data = [i for i in read_score(self.path, name).split("\n") if i != ""]
|
|
|
|
data.sort(key = lambda x: float(x.split()[6]))
|
|
|
|
results.append(data[0].split())
|
|
|
|
|
|
|
|
print(results)
|
|
|
|
|
|
|
|
results.sort(key = lambda x: 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.FORMAT = "HTML"
|
|
|
|
|
|
|
|
elif self.MESSAGE.text == "!pingantitop":
|
|
|
|
def read_score(path, name):
|
|
|
|
if os.path.exists(path + f"scoreboard/{name}"):
|
|
|
|
return open(path + f"scoreboard/{name}").read()
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
if not os.path.exists(self.path + "scoreboard/"):
|
|
|
|
os.mkdir(self.path + "scoreboard/")
|
|
|
|
|
|
|
|
results = []
|
|
|
|
for name in os.listdir(self.path + "scoreboard/"):
|
|
|
|
data = [i for i in read_score(self.path, name).split("\n") if i != ""]
|
|
|
|
data.sort(key = lambda x: float(x.split()[6]))
|
|
|
|
results.append(data[-1].split())
|
|
|
|
|
|
|
|
print(results)
|
|
|
|
|
|
|
|
results.sort(key = lambda x: x[6])
|
|
|
|
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.FORMAT = "HTML"
|
|
|
|
|
|
|
|
elif self.MESSAGE.text == "!pongantitop":
|
|
|
|
def read_score(path, name):
|
|
|
|
if os.path.exists(path + f"pong-scoreboard/{name}"):
|
|
|
|
return open(path + f"pong-scoreboard/{name}").read()
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
if not os.path.exists(self.path + "pong-scoreboard/"):
|
|
|
|
os.mkdir(self.path + "pong-scoreboard/")
|
|
|
|
|
|
|
|
results = []
|
|
|
|
for name in os.listdir(self.path + "pong-scoreboard/"):
|
|
|
|
data = [i for i in read_score(self.path, name).split("\n") if i != ""]
|
|
|
|
data.sort(key = lambda x: float(x.split()[6]))
|
|
|
|
results.append(data[-1].split())
|
|
|
|
|
|
|
|
print(results)
|
|
|
|
|
|
|
|
results.sort(key = lambda x: x[6])
|
|
|
|
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.FORMAT = "HTML"
|