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