Format points table with beautifultable

This commit is contained in:
c0de 2022-12-09 23:20:54 -06:00
parent 9702e1e77a
commit febdfaf355

View File

@ -4,6 +4,8 @@
# pylint: disable=not-an-iterable,missing-module-docstring,too-few-public-methods
from beautifultable import BeautifulTable
from database.models import PlayerModel as Player
from game.base import BaseGameManager
@ -23,22 +25,23 @@ class PointsManager(BaseGameManager):
message = (
"\nPlayers, who played recently, with their points highest to lowest\n\n"
)
message += "Player | Total Points | Last Played\n"
message += "```\n"
table = BeautifulTable()
table.column_headers = ["Player", "Total Points", "Last Played"]
players = Player.select(
Player.player_name, Player.total_points, Player.last_update
).order_by(Player.last_update.desc(), Player.total_points.desc())
for player in players:
message += (
" | ".join(
[
player.player_name,
str(player.total_points),
str(player.last_update)[:-10],
]
)
+ "\n"
)
table.rows.append([
player.player_name,
str(player.total_points),
str(player.last_update)[:-10],
])
message += str(table)
message += "\n```\n"
return await self.message.channel.send(message)