nicer leaderboard + timing
This commit is contained in:
3 files changed
+8
-4
No files matched your search
+2
-1
@@ -27,12 +27,12 @@ class Event(app_commands.Group):
|
||||
async def stop(self, interaction: Interaction) -> None:
|
||||
if not self.hasPermission(interaction.user): await interaction.response.send_message("You don't have permission to use this command.", ephemeral=True)
|
||||
if not self.bot._running: await interaction.response.send_message("Event already stopped", ephemeral=True)
|
||||
self.bot.scrape_file.stop()
|
||||
|
||||
# Reset trackers
|
||||
self.bot._running = False
|
||||
self.bot.log_file = ""
|
||||
self.bot.log_index = -1
|
||||
self.bot.start_time = -1
|
||||
self.bot.players = []
|
||||
self.bot.gamertags = []
|
||||
self.bot.message_id = ""
|
||||
@@ -43,6 +43,7 @@ class Event(app_commands.Group):
|
||||
self.ssh = None
|
||||
|
||||
await interaction.response.send_message("Stopping event leaderboard...", ephemeral=True)
|
||||
self.bot.scrape_file.stop()
|
||||
|
||||
async def setup(bot: commands.Bot) -> None:
|
||||
bot.tree.add_command(Event(bot, name="event", description="start or stop an event leaderboard"))
|
||||
@@ -129,7 +129,6 @@ def readLogFromIndex(
|
||||
bot.gamertags.append(gt_data.group("gamertag"))
|
||||
continue
|
||||
|
||||
print("done reading logs...")
|
||||
return
|
||||
|
||||
def getLatestDir(sftp: SFTPClient, remote_path: str) -> str:
|
||||
|
||||
@@ -5,6 +5,7 @@ from discord.ext import commands
|
||||
from discord.ext import tasks
|
||||
from discord import Object
|
||||
from os import listdir, getcwd
|
||||
from time import time
|
||||
import requests
|
||||
|
||||
from handlers.sftp import createSSHClient
|
||||
@@ -18,6 +19,7 @@ class ReforgerStats(commands.Bot):
|
||||
self._running: bool = False
|
||||
self.log_dir: str = ""
|
||||
self.log_index: int = -1
|
||||
self.start_time: int = -1
|
||||
self.message_id: str = ""
|
||||
self.players: list[dict] = []
|
||||
self.gamertags: list[str] = []
|
||||
@@ -49,10 +51,11 @@ class ReforgerStats(commands.Bot):
|
||||
|
||||
async def createLeaderboardEmbed(self, players: list[dict]) -> dict:
|
||||
sorted_players = sorted(players, key=lambda a: a["kills"], reverse=True)
|
||||
description = ""
|
||||
current: int = round(time())
|
||||
description = f"From <t:{self.start_time}> to <t:{current}>"
|
||||
rank = 1
|
||||
for player in sorted_players:
|
||||
description += f"> **{rank}.** {player['gamertag']}\n> ***Kills*** {player['kills']}\n> ***Deaths*** {player['deaths']}\n\n"
|
||||
description += f"> **{rank}.** {player['gamertag']}\n`{player['KDR']}` KDR - `{player['kills']}` Kill{'s' if player['kills'] > 1 or player['kills'] == 0 else ''} `{player['deaths']}` Death{'s' if player['deaths'] > 1 or player['deaths'] == 0 else ''}\n"
|
||||
rank += 1
|
||||
|
||||
return {
|
||||
@@ -90,6 +93,7 @@ class ReforgerStats(commands.Bot):
|
||||
|
||||
if self.log_index == -1:
|
||||
self.log_index = len(lines) - 1
|
||||
self.start_time = round(time())
|
||||
getPlayers(self, lines) # Get all players from this log file to add to self.players / self.gamertags
|
||||
return
|
||||
|
||||
|
||||
Reference in new issue
Block a user