Compare commits

...

2 Commits

Author SHA1 Message Date
f6860bb43f maybe, maybe not 2022-10-27 00:18:12 -05:00
3c5fead8b0 Allow the bot to see channel messages 2022-10-27 00:04:54 -05:00
2 changed files with 23 additions and 15 deletions

View File

@ -139,7 +139,7 @@ class GameManager:
} }
) )
return pitch_value return int(pitch_value)
# @check_is_running # @check_is_running
async def stop(self): async def stop(self):
@ -169,10 +169,10 @@ class GameManager:
) )
# Minimum of 3 players # Minimum of 3 players
if len(records) < 2: if len(records) < 1:
self.game = None self.game = None
self.is_running = False self.is_running = False
return await self.message.channel.send( await self.message.channel.send(
("Play closed!\n" + "However, there were not enough participants.") ("Play closed!\n" + "However, there were not enough participants.")
) )
@ -181,13 +181,21 @@ class GameManager:
+ "PLAYER | GUESS | DIFFERENCE | POINTS GAINED | TOTAL POINTS\n" + "PLAYER | GUESS | DIFFERENCE | POINTS GAINED | TOTAL POINTS\n"
) )
def get_difference(guess):
difference = abs(guess - pitch_value)
if difference > 500:
return 1000 - difference
return difference
# Determine which guesses are closest and furthest from the pitch_value # Determine which guesses are closest and furthest from the pitch_value
guess_values = [record.guess for record in records] guess_values = [record.guess for record in records]
closest_guess_value = min( closest_guess_value = min(
guess_values, key=lambda guess: abs(guess - pitch_value) guess_values, key=lambda guess: get_difference(guess)
) )
furthest_guess_value = max( furthest_guess_value = max(
guess_values, key=lambda guess: abs(guess - pitch_value) guess_values, key=lambda guess: get_difference(guess)
) )
def get_difference_score(): def get_difference_score():
@ -207,10 +215,10 @@ class GameManager:
if record.guess == furthest_guess_value: if record.guess == furthest_guess_value:
furthest_player_id = record.player.player_id furthest_player_id = record.player.player_id
message += f"{record.player.player_name} | {record.guess} | {difference} | {difference_score}" message += f"{record.player.player_name} | {record.guess} | {difference} | {difference_score} | {record.player.total_points}\n"
message += ( message += (
f"Congrats <@{closest_player_id}>! You were the closest!\n" f"\nCongrats <@{closest_player_id}>! You were the closest!\n"
+ f"Sorry <@{furthest_player_id}>, you were way off" + f"Sorry <@{furthest_player_id}>, you were way off"
) )
@ -241,14 +249,13 @@ class GameManager:
guess_id=uuid.uuid4(), game_id=self.game.game_id, player_id=player_id guess_id=uuid.uuid4(), game_id=self.game.game_id, player_id=player_id
) )
player_guess.update({Guess.guess: value}) Guess.update({"guess": value}).where((Guess.game_id==self.game.game_id) & (Guess.player_id==player_id)).execute()
# if created: if created:
print(dir(self.message.add_reaction))
return await self.message.add_reaction("\N{THUMBS UP SIGN}") return await self.message.add_reaction("\N{THUMBS UP SIGN}")
# return await self.message.channel.send( return await self.message.channel.send(
# f"<@{ str(self.message.author.id) }> your guess has been updated" f"<@{ str(self.message.author.id) }> your guess has been updated"
# ) )
async def points(self): async def points(self):
""" """

View File

@ -6,6 +6,7 @@
import os import os
from discord import Intents
from discord_client.client import GhostBallClient from discord_client.client import GhostBallClient
from database.models import DATABASE, database, create_models from database.models import DATABASE, database, create_models
@ -16,5 +17,5 @@ if __name__ == "__main__":
create_models() create_models()
database.close() database.close()
client = GhostBallClient(intents=None) client = GhostBallClient(intents=Intents.all())
client.run(os.environ.get("discord_token")) client.run(os.environ.get("discord_token"))