✨
This commit is contained in:
@ -106,9 +106,9 @@ class WordleCog(commands.Cog):
|
||||
self.bot = bot
|
||||
|
||||
@cog_ext.cog_subcommand(**params["wordle_start"])
|
||||
async def wordle_start(self, ctx, letters = 5, hard = False):
|
||||
async def wordle_start(self, ctx, letters = 5):
|
||||
"""Start a game of wordle."""
|
||||
await self.bot.games.wordle.start(ctx, letters, hard)
|
||||
await self.bot.games.wordle.start(ctx, letters)
|
||||
|
||||
@cog_ext.cog_subcommand(**params["wordle_guess"])
|
||||
async def wordle_guess(self, ctx, guess):
|
||||
|
@ -5,6 +5,8 @@ from PIL import Image, ImageDraw
|
||||
|
||||
from .game_base import DatabaseGame, BaseDrawer
|
||||
|
||||
from gwendolyn.exceptions import GameNotInDatabase
|
||||
|
||||
IMAGE_MARGIN = 90
|
||||
SQUARE_SIZE = 150
|
||||
SQUARE_PADDING = 25
|
||||
@ -38,13 +40,21 @@ class WordleGame(DatabaseGame):
|
||||
"api_key": api_key
|
||||
}
|
||||
|
||||
async def start(self, ctx, letters: int, hard: bool):
|
||||
async def start(self, ctx, letters: int):
|
||||
if self._test_document(str(ctx.channel_id)):
|
||||
await ctx.send("There is already a wordle game in this channel.")
|
||||
self.bot.log("There was already a game going on")
|
||||
return
|
||||
|
||||
params = self._APIPARAMS
|
||||
params["minLength"] = letters
|
||||
params["maxLength"] = letters
|
||||
word = "-"
|
||||
while "-" in word or "." in word:
|
||||
response = requests.get(self._API_url, params=params)
|
||||
if response.json() == []:
|
||||
ctx.send("Could not find a word. Try again")
|
||||
return
|
||||
word = list(response.json()[0]["word"].upper())
|
||||
|
||||
self.bot.log(f"Found the word \"{''.join(word)}\"")
|
||||
@ -60,7 +70,15 @@ class WordleGame(DatabaseGame):
|
||||
|
||||
for i, letter in enumerate(guess):
|
||||
if letter in word and result[i] != "*":
|
||||
if guess[:i].count(letter) < word.count(letter):
|
||||
same_letter = guess[:i].count(letter)
|
||||
same_letter += len(
|
||||
[
|
||||
l for j,l in
|
||||
enumerate(guess[i:])
|
||||
if guess[i:][j] == letter and result[i:][j] == "*"
|
||||
]
|
||||
)
|
||||
if same_letter < word.count(letter):
|
||||
result[i] = "-"
|
||||
|
||||
return result
|
||||
@ -71,11 +89,16 @@ class WordleGame(DatabaseGame):
|
||||
return
|
||||
|
||||
guess = list(guess.upper())
|
||||
try:
|
||||
game = self.access_document(str(ctx.channel_id))
|
||||
except GameNotInDatabase:
|
||||
await ctx.send("No game in channel")
|
||||
return
|
||||
|
||||
if len(guess) != len(game['word']):
|
||||
await ctx.send(
|
||||
f"Your guess must be {len(game['word'])} letters long")
|
||||
return
|
||||
|
||||
await ctx.send(f"Guessed {''.join(guess)}")
|
||||
result = self._get_result(guess, game['word'])
|
||||
@ -88,9 +111,15 @@ class WordleGame(DatabaseGame):
|
||||
}
|
||||
self._update_document(str(ctx.channel_id), updater)
|
||||
|
||||
if result == ["*" for _ in game['word']] or len(game['guesses']) == 6:
|
||||
if result == ["*" for _ in game['word']]:
|
||||
await ctx.send("You guessed the word! Adding 15 GwendoBucks to your account")
|
||||
self.bot.money.addMoney(f"#{ctx.author_id}", 15)
|
||||
await self._end_game(ctx.channel)
|
||||
elif len(game['guesses']) == 5:
|
||||
await ctx.send(f"You used up all available guesses. The word was '{''.join(game['word'])}'")
|
||||
await self._end_game(ctx.channel)
|
||||
else:
|
||||
print(len(game['guesses']))
|
||||
await self._delete_old_image(ctx.channel)
|
||||
await self._send_image(ctx.channel)
|
||||
|
||||
@ -152,6 +181,7 @@ class WordleDrawer(BaseDrawer):
|
||||
colors = self._determine_colors(game['results'][i])
|
||||
self._draw_row(i, drawer, font, guess, colors)
|
||||
|
||||
if len(game["guesses"]) < 6:
|
||||
self._draw_row(
|
||||
len(game['guesses']),
|
||||
drawer,
|
||||
|
@ -394,12 +394,6 @@
|
||||
"description" : "How many letters the word should be",
|
||||
"type": 4,
|
||||
"required": "false"
|
||||
},
|
||||
{
|
||||
"name": "hard",
|
||||
"description" : "Whether the game should be in 'hard mode'",
|
||||
"type": 5,
|
||||
"required": "false"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
Reference in New Issue
Block a user