diff --git a/battleroyale/core.py b/battleroyale/core.py index 7008652..b9e91ca 100644 --- a/battleroyale/core.py +++ b/battleroyale/core.py @@ -47,7 +47,7 @@ from .constants import SWORDS from .converters import EmojiConverter from .game import Game -from .utils import _cooldown, _get_attachments, exceptions, guild_roughly_chunked +from .utils import _cooldown, _get_attachments, exceptions, guild_roughly_chunked, truncate from .views import JoinGameView log: logging.Logger = logging.getLogger("red.seina.battleroyale") @@ -533,18 +533,20 @@ async def _leaderboard( leaderboard = leaderboard[:10] table = pt.PrettyTable() table.title = "Battle Royale Leaderboard" - table.field_names = ["#", "User", "Wins", "Games", "Kills", "Deaths"] + table.field_names = ["#", "Games / Wins / Kills / Deaths", "User"] for index, (user_id, user_data) in enumerate(leaderboard, start=1): if (user := ctx.bot.get_user(int(user_id))) is None: continue table.add_row( row=[ index, - user.display_name, - user_data["wins"], - user_data["games"], - user_data["kills"], - user_data["deaths"], + "{} / {} / {} / {}".format( + user_data["games"], + user_data["wins"], + user_data["kills"], + user_data["deaths"], + ), + truncate(user.display_name, max=10), ] ) description = box(table.get_string(), lang="sml") diff --git a/battleroyale/utils.py b/battleroyale/utils.py index 51cb8b9..cf2cae9 100644 --- a/battleroyale/utils.py +++ b/battleroyale/utils.py @@ -98,3 +98,10 @@ def _cooldown(ctx: commands.Context) -> Optional[commands.Cooldown]: def guild_roughly_chunked(guild: discord.Guild) -> bool: return len(guild.members) / guild.member_count > 0.9 + + +def truncate(text: str, *, max: int) -> str: + if len(text) <= max: + return text + truncated: str = text[: max - 3] + return truncated + "..."