2022-11-11 04:42:38 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Copyright 2022 - c0de <c0de@c0de.dev>
|
|
|
|
# Licensed under the MIT License (https://opensource.org/licenses/MIT)
|
|
|
|
|
2022-12-10 04:30:36 +00:00
|
|
|
# pylint: disable=not-an-iterable,missing-module-docstring,too-few-public-methods
|
2022-11-11 04:42:38 +00:00
|
|
|
|
|
|
|
from database.models import PlayerModel as Player
|
2022-11-12 02:06:14 +00:00
|
|
|
from game.base import BaseGameManager
|
2022-11-11 04:42:38 +00:00
|
|
|
|
2022-11-11 04:44:24 +00:00
|
|
|
|
2022-11-11 04:42:38 +00:00
|
|
|
class PointsManager(BaseGameManager):
|
2024-04-23 22:19:20 +00:00
|
|
|
"""Commands that run when a player wants to view the session leaderboard"""
|
2022-11-11 04:42:38 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
2022-11-11 18:52:54 +00:00
|
|
|
self.commands.append(("points", self.points))
|
2022-11-11 04:42:38 +00:00
|
|
|
|
|
|
|
async def points(self):
|
|
|
|
"""
|
|
|
|
Points command - returns a table ordered from highest to lowest
|
|
|
|
of the players and their points
|
|
|
|
"""
|
|
|
|
message = (
|
|
|
|
"\nPlayers, who played recently, with their points highest to lowest\n\n"
|
|
|
|
)
|
2022-12-10 18:36:36 +00:00
|
|
|
message += "Player | Total Points | Last Played\n"
|
2022-11-11 04:42:38 +00:00
|
|
|
|
|
|
|
players = Player.select(
|
|
|
|
Player.player_name, Player.total_points, Player.last_update
|
2024-04-23 22:19:20 +00:00
|
|
|
).order_by(Player.total_points.desc())
|
2022-11-11 04:42:38 +00:00
|
|
|
|
|
|
|
for player in players:
|
2022-12-10 18:36:36 +00:00
|
|
|
message += (
|
|
|
|
" | ".join(
|
|
|
|
[
|
|
|
|
player.player_name,
|
|
|
|
str(player.total_points),
|
|
|
|
str(player.last_update)[:-10],
|
|
|
|
]
|
|
|
|
)
|
|
|
|
+ "\n"
|
|
|
|
)
|
2022-11-11 04:42:38 +00:00
|
|
|
|
|
|
|
return await self.message.channel.send(message)
|