Format points table with beautifultable
This commit is contained in:
parent
9702e1e77a
commit
febdfaf355
@ -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(
|
||||
[
|
||||
table.rows.append([
|
||||
player.player_name,
|
||||
str(player.total_points),
|
||||
str(player.last_update)[:-10],
|
||||
]
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
])
|
||||
|
||||
message += str(table)
|
||||
message += "\n```\n"
|
||||
|
||||
return await self.message.channel.send(message)
|
||||
|
Loading…
Reference in New Issue
Block a user