Added a timeout for the 'force alternation' mode, so the same player can play again after some time
This commit is contained in:
@@ -17,6 +17,7 @@ WORDLE_SLOWMODE = 0
|
|||||||
WORDLE_MINLENGTH = 8
|
WORDLE_MINLENGTH = 8
|
||||||
WORDLE_MAXLENGTH = 10
|
WORDLE_MAXLENGTH = 10
|
||||||
WORDLE_FORCE_ALTERNATION = True
|
WORDLE_FORCE_ALTERNATION = True
|
||||||
|
WORDLE_ALTERNATION_TIMEOUT = 300
|
||||||
|
|
||||||
HEARTBEAT = 60
|
HEARTBEAT = 60
|
||||||
EPHEMERIS = 0
|
EPHEMERIS = 0
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import random
|
|||||||
import re
|
import re
|
||||||
from unidecode import unidecode
|
from unidecode import unidecode
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from datetime import datetime
|
||||||
|
from math import ceil
|
||||||
from .settings import *
|
from .settings import *
|
||||||
|
|
||||||
with open(WORDLE_VALID_WORDS, "r") as f:
|
with open(WORDLE_VALID_WORDS, "r") as f:
|
||||||
@@ -44,6 +46,7 @@ class Game:
|
|||||||
self.last_player = None
|
self.last_player = None
|
||||||
self.scores = None
|
self.scores = None
|
||||||
self.tried = None
|
self.tried = None
|
||||||
|
self.last_datetime = None
|
||||||
|
|
||||||
async def reset(self):
|
async def reset(self):
|
||||||
output = ""
|
output = ""
|
||||||
@@ -55,6 +58,7 @@ class Game:
|
|||||||
self.last_player = None
|
self.last_player = None
|
||||||
self.scores = defaultdict(int)
|
self.scores = defaultdict(int)
|
||||||
self.tried = set()
|
self.tried = set()
|
||||||
|
self.last_datetime = None
|
||||||
await self.channel.edit(slowmode_delay=WORDLE_SLOWMODE)
|
await self.channel.edit(slowmode_delay=WORDLE_SLOWMODE)
|
||||||
output += f"Il y a un nouveau mot à deviner ! Il fait {len(self.target)} lettres."
|
output += f"Il y a un nouveau mot à deviner ! Il fait {len(self.target)} lettres."
|
||||||
await self.channel.send(output)
|
await self.channel.send(output)
|
||||||
@@ -81,9 +85,11 @@ class Game:
|
|||||||
|
|
||||||
# check for errors and react accordingly
|
# check for errors and react accordingly
|
||||||
error = False
|
error = False
|
||||||
if WORDLE_FORCE_ALTERNATION and message.author == self.last_player:
|
if WORDLE_FORCE_ALTERNATION and message.author == self.last_player and (elapsed := (datetime.now() - self.last_datetime).total_seconds()) < WORDLE_ALTERNATION_TIMEOUT:
|
||||||
await message.add_reaction("\N{BUSTS IN SILHOUETTE}")
|
await message.add_reaction("\N{BUSTS IN SILHOUETTE}")
|
||||||
error = True
|
error = True
|
||||||
|
remaining = ceil(WORDLE_ALTERNATION_TIMEOUT - elapsed)
|
||||||
|
await self.channel.send(f"{message.author.mention} : tu pourras rejouer dans {remaining} seconde{'s' if remaining > 1 else ''}")
|
||||||
if len(guess) != len(self.target):
|
if len(guess) != len(self.target):
|
||||||
await message.add_reaction("\N{LEFT RIGHT ARROW}")
|
await message.add_reaction("\N{LEFT RIGHT ARROW}")
|
||||||
error = True
|
error = True
|
||||||
@@ -96,6 +102,7 @@ class Game:
|
|||||||
# everything is OK, validate the proposal
|
# everything is OK, validate the proposal
|
||||||
self.tries += 1
|
self.tries += 1
|
||||||
self.last_player = message.author
|
self.last_player = message.author
|
||||||
|
self.last_datetime = datetime.now()
|
||||||
result = validate(self.target, guess)
|
result = validate(self.target, guess)
|
||||||
points = 0
|
points = 0
|
||||||
for idx, letter in enumerate(guess):
|
for idx, letter in enumerate(guess):
|
||||||
|
|||||||
Reference in New Issue
Block a user