mirror of https://github.com/stijndcl/didier
				
				
				
			Allow force-resetting the game
							parent
							
								
									db499f3742
								
							
						
					
					
						commit
						4a137bcad8
					
				| 
						 | 
				
			
			@ -6,6 +6,8 @@ from bson import ObjectId
 | 
			
		|||
from overrides import overrides
 | 
			
		||||
from pydantic import BaseModel, Field, validator
 | 
			
		||||
 | 
			
		||||
from database.constants import WORDLE_GUESS_COUNT
 | 
			
		||||
 | 
			
		||||
__all__ = ["MongoBase", "TemporaryStorage", "WordleGame"]
 | 
			
		||||
 | 
			
		||||
from database.utils.datetime import today_only_date
 | 
			
		||||
| 
						 | 
				
			
			@ -117,3 +119,16 @@ class WordleGame(MongoCollection):
 | 
			
		|||
            raise ValueError(f"guess_distribution must be no longer than 6 elements, found {len(value)}")
 | 
			
		||||
 | 
			
		||||
        return value
 | 
			
		||||
 | 
			
		||||
    def is_game_over(self, word: str) -> bool:
 | 
			
		||||
        """Check if the current game is over"""
 | 
			
		||||
        # No guesses yet
 | 
			
		||||
        if not self.guesses:
 | 
			
		||||
            return False
 | 
			
		||||
 | 
			
		||||
        # Max amount of guesses allowed
 | 
			
		||||
        if len(self.guesses) == WORDLE_GUESS_COUNT:
 | 
			
		||||
            return True
 | 
			
		||||
 | 
			
		||||
        # Found the correct word
 | 
			
		||||
        return self.guesses[-1] == word
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,10 +47,12 @@ class Games(commands.Cog):
 | 
			
		|||
        # Make a guess
 | 
			
		||||
        if guess:
 | 
			
		||||
            # The guess is not a real word
 | 
			
		||||
            if guess not in self.client.wordle_words:
 | 
			
		||||
            if guess.lower() not in self.client.wordle_words:
 | 
			
		||||
                embed = WordleErrorEmbed(message=f"`{guess}` is not a valid word.").to_embed()
 | 
			
		||||
                return await interaction.followup.send(embed=embed)
 | 
			
		||||
 | 
			
		||||
            guess = guess.lower()
 | 
			
		||||
 | 
			
		||||
            await make_wordle_guess(self.client.mongo_db, interaction.user.id, guess)
 | 
			
		||||
 | 
			
		||||
            # Don't re-request the game, we already have it
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -130,7 +130,7 @@ class Tasks(commands.Cog):
 | 
			
		|||
    async def reset_wordle_word(self, forced: bool = False):
 | 
			
		||||
        """Reset the daily Wordle word"""
 | 
			
		||||
        db = self.client.mongo_db
 | 
			
		||||
        word = await set_daily_word(db, random.choice(tuple(self.client.wordle_words)))
 | 
			
		||||
        word = await set_daily_word(db, random.choice(tuple(self.client.wordle_words)), forced=forced)
 | 
			
		||||
        self.client.database_caches.wordle_word.data = [word]
 | 
			
		||||
 | 
			
		||||
    @reset_wordle_word.before_loop
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -108,7 +108,7 @@ class WordleEmbed(EmbedBaseModel):
 | 
			
		|||
        embed.description = "\n\n".join(rows)
 | 
			
		||||
 | 
			
		||||
        # If the game is over, reveal the word
 | 
			
		||||
        if len(self.game.guesses) == WORDLE_GUESS_COUNT or (self.game.guesses and self.game.guesses[-1] == self.word):
 | 
			
		||||
        if self.game.is_game_over(self.word):
 | 
			
		||||
            embed.description += f"\n\nThe word was **{self.word.upper()}**!"
 | 
			
		||||
 | 
			
		||||
        embed.set_footer(text=footer())
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue