Use BeautifulTable library to make nice tables :3

This commit is contained in:
2022-12-09 22:28:37 -06:00
parent 59d1dc4afb
commit 133af80aad
4 changed files with 232 additions and 178 deletions

View File

@@ -6,6 +6,8 @@
import datetime
from beautifultable import BeautifulTable
from database.models import GameModel as Game, GuessModel as Guess
from game.base import BaseGameManager
from game.process_guess import ProcessGuess
@@ -82,26 +84,33 @@ class EndGameManager(BaseGameManager):
("Play closed!\n" + "However, there were not enough participants.")
)
message = (
"Closed this play! Here are the results\n"
+ "PLAYER | GUESS | DIFFERENCE | POINTS GAINED | TOTAL POINTS\n"
)
message = "Closed this play! Here are the results:"
message += "\n```\n"
table = BeautifulTable()
table.column_headers = [
"PLAYER",
"GUESS",
"DIFFERENCE",
"POINTS GAINED",
"TOTAL POINTS",
]
pitch_value = await self.update_pitch_value()
guess_processor = ProcessGuess(
game=self, pitch_value=pitch_value, message=message
game=self, pitch_value=pitch_value, message=table
)
(
message,
table,
closest_player_id,
furthest_player_id,
) = guess_processor.process_guesses()
message += (
f"\nCongrats <@{closest_player_id}>! You were the closest!\n"
+ f"Sorry <@{furthest_player_id}>, you were way off"
)
message += str(table)
message += "\n```\n"
message += f"Congrats <@{closest_player_id}>! You were the closest!\n"
message += f"Sorry <@{furthest_player_id}>, you were way off\n"
await self.message.channel.send(message)

View File

@@ -134,7 +134,15 @@ class ProcessGuess:
self.update_difference_value()
self.update_player_total_points()
self.message += f"{guess.player.player_name} | {guess.guess} | {difference} | {difference_score} | {(guess.player.total_points + difference_score)}\n"
self.message.rows.append(
[
guess.player.player_name,
guess.guess,
difference,
difference_score,
guess.player.total_points + difference_score,
]
)
if guess.guess == winner:
closest_player_id = guess.player.player_id