✨
This commit is contained in:
@ -106,9 +106,9 @@ class WordleCog(commands.Cog):
|
|||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@cog_ext.cog_subcommand(**params["wordle_start"])
|
@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."""
|
"""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"])
|
@cog_ext.cog_subcommand(**params["wordle_guess"])
|
||||||
async def wordle_guess(self, ctx, guess):
|
async def wordle_guess(self, ctx, guess):
|
||||||
|
@ -5,6 +5,8 @@ from PIL import Image, ImageDraw
|
|||||||
|
|
||||||
from .game_base import DatabaseGame, BaseDrawer
|
from .game_base import DatabaseGame, BaseDrawer
|
||||||
|
|
||||||
|
from gwendolyn.exceptions import GameNotInDatabase
|
||||||
|
|
||||||
IMAGE_MARGIN = 90
|
IMAGE_MARGIN = 90
|
||||||
SQUARE_SIZE = 150
|
SQUARE_SIZE = 150
|
||||||
SQUARE_PADDING = 25
|
SQUARE_PADDING = 25
|
||||||
@ -38,13 +40,21 @@ class WordleGame(DatabaseGame):
|
|||||||
"api_key": api_key
|
"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 = self._APIPARAMS
|
||||||
params["minLength"] = letters
|
params["minLength"] = letters
|
||||||
params["maxLength"] = letters
|
params["maxLength"] = letters
|
||||||
word = "-"
|
word = "-"
|
||||||
while "-" in word or "." in word:
|
while "-" in word or "." in word:
|
||||||
response = requests.get(self._API_url, params=params)
|
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())
|
word = list(response.json()[0]["word"].upper())
|
||||||
|
|
||||||
self.bot.log(f"Found the word \"{''.join(word)}\"")
|
self.bot.log(f"Found the word \"{''.join(word)}\"")
|
||||||
@ -60,7 +70,15 @@ class WordleGame(DatabaseGame):
|
|||||||
|
|
||||||
for i, letter in enumerate(guess):
|
for i, letter in enumerate(guess):
|
||||||
if letter in word and result[i] != "*":
|
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] = "-"
|
result[i] = "-"
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@ -71,11 +89,16 @@ class WordleGame(DatabaseGame):
|
|||||||
return
|
return
|
||||||
|
|
||||||
guess = list(guess.upper())
|
guess = list(guess.upper())
|
||||||
game = self.access_document(str(ctx.channel_id))
|
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']):
|
if len(guess) != len(game['word']):
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
f"Your guess must be {len(game['word'])} letters long")
|
f"Your guess must be {len(game['word'])} letters long")
|
||||||
|
return
|
||||||
|
|
||||||
await ctx.send(f"Guessed {''.join(guess)}")
|
await ctx.send(f"Guessed {''.join(guess)}")
|
||||||
result = self._get_result(guess, game['word'])
|
result = self._get_result(guess, game['word'])
|
||||||
@ -88,9 +111,15 @@ class WordleGame(DatabaseGame):
|
|||||||
}
|
}
|
||||||
self._update_document(str(ctx.channel_id), updater)
|
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)
|
await self._end_game(ctx.channel)
|
||||||
else:
|
else:
|
||||||
|
print(len(game['guesses']))
|
||||||
await self._delete_old_image(ctx.channel)
|
await self._delete_old_image(ctx.channel)
|
||||||
await self._send_image(ctx.channel)
|
await self._send_image(ctx.channel)
|
||||||
|
|
||||||
@ -152,13 +181,14 @@ class WordleDrawer(BaseDrawer):
|
|||||||
colors = self._determine_colors(game['results'][i])
|
colors = self._determine_colors(game['results'][i])
|
||||||
self._draw_row(i, drawer, font, guess, colors)
|
self._draw_row(i, drawer, font, guess, colors)
|
||||||
|
|
||||||
self._draw_row(
|
if len(game["guesses"]) < 6:
|
||||||
len(game['guesses']),
|
self._draw_row(
|
||||||
drawer,
|
len(game['guesses']),
|
||||||
font,
|
drawer,
|
||||||
" "*len(game['word']),
|
font,
|
||||||
border_color=WRITING_BORDER_COLOR
|
" "*len(game['word']),
|
||||||
)
|
border_color=WRITING_BORDER_COLOR
|
||||||
|
)
|
||||||
|
|
||||||
for i in range(5 - len(game['guesses'])):
|
for i in range(5 - len(game['guesses'])):
|
||||||
self._draw_row(
|
self._draw_row(
|
||||||
|
@ -394,12 +394,6 @@
|
|||||||
"description" : "How many letters the word should be",
|
"description" : "How many letters the word should be",
|
||||||
"type": 4,
|
"type": 4,
|
||||||
"required": "false"
|
"required": "false"
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "hard",
|
|
||||||
"description" : "Whether the game should be in 'hard mode'",
|
|
||||||
"type": 5,
|
|
||||||
"required": "false"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user