Compare commits

...

3 Commits

Author SHA1 Message Date
febdfaf355 Format points table with beautifultable 2022-12-09 23:20:54 -06:00
9702e1e77a Add reset command / module 2022-12-09 23:20:20 -06:00
ff5e7f310a Sort endgame table by difference 2022-12-09 23:15:28 -06:00
5 changed files with 40 additions and 13 deletions

View File

@ -27,6 +27,7 @@ class HelpManager(BaseGameManager):
+ " You can also add a batter's guess with: "
+ "!resolve <value> <discord id #> <guess>\n"
+ "!points - Shows a table of the most recent players, and their scores\n"
+ "!reset - Removes all the guesses"
+ "!help - Shows this message"
)

View File

@ -14,11 +14,12 @@ from game.new_game import NewGameManager
from game.end_game import EndGameManager
from game.guess import GuessManager
from game.points import PointsManager
from game.reset import ResetManager
from game.help import HelpManager
class GameManager(
NewGameManager, EndGameManager, GuessManager, PointsManager, HelpManager
NewGameManager, EndGameManager, GuessManager, PointsManager, ResetManager, HelpManager
):
"""
Represents what this bot is able to do on a channel (or DMs)

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(
[
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)

View File

@ -47,7 +47,7 @@ class ProcessGuess:
& (Guess.guess > 0)
& (Guess.player.player_id == Player.player_id)
)
.order_by(Guess.guess)
.order_by(Guess.difference)
)
return self.guesses

22
game/reset.py Normal file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python3
# Copyright 2022 - c0de <c0de@c0de.dev>
# Licensed under the MIT License (https://opensource.org/licenses/MIT)
# pylint: disable=missing-module-docstring,too-few-public-methods
from database.models import GuessModel as Guess
from game.base import BaseGameManager
class ResetManager(BaseGameManager):
"""Commands that run when a player asks for help"""
def __init__(self):
super().__init__()
self.commands.append(("reset", self.reset))
async def reset(self):
"""Reset command purges all guesses"""
Guess.delete().where(True).execute()
return await self.message.channel.send("ok")