Refactoring and simplifying the code that checks whether a message is a wordle proposal or not.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import random
|
import random
|
||||||
|
import re
|
||||||
from unidecode import unidecode
|
from unidecode import unidecode
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from .settings import *
|
from .settings import *
|
||||||
@@ -57,28 +58,25 @@ class Game:
|
|||||||
await self.channel.send(f"Il y a un nouveau mot à deviner ! Il fait {len(self.target)} lettres.")
|
await self.channel.send(f"Il y a un nouveau mot à deviner ! Il fait {len(self.target)} lettres.")
|
||||||
|
|
||||||
async def parse(self, message):
|
async def parse(self, message):
|
||||||
content = message.content.strip()
|
guess = unidecode(message.content.strip()).upper()
|
||||||
if (len(content) >= 1 and content[0] == "-") or self.winner or not self.target: # special char, or somebody won, or never initialized
|
|
||||||
|
# if somebody won
|
||||||
|
if self.winner:
|
||||||
return
|
return
|
||||||
|
|
||||||
# if the user is just chatting
|
# if the game was never initialized
|
||||||
if " " in content:
|
if not self.target:
|
||||||
return
|
return
|
||||||
# if the guess is obviously not the same length (just chatting)
|
|
||||||
|
# if the message is not comprised of letters (with or without accents) only
|
||||||
|
if not re.match(r"^[A-Z]*$", guess):
|
||||||
|
return
|
||||||
|
|
||||||
|
# if the guess is obviously not the same length
|
||||||
ratio = 2/3
|
ratio = 2/3
|
||||||
if len(content) <= len(self.target) * ratio or len(self.target) <= len(content) * ratio:
|
if len(guess) <= len(self.target) * ratio or len(self.target) <= len(guess) * ratio:
|
||||||
return
|
|
||||||
# if the user post an emoji
|
|
||||||
if content[0] == ":":
|
|
||||||
return
|
|
||||||
# if the user post a link
|
|
||||||
if "://" in content:
|
|
||||||
return
|
|
||||||
# if the user post a gif (not sure about this one)
|
|
||||||
if len(content) == 0:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
guess = unidecode(content).upper()
|
|
||||||
if WORDLE_FORCE_ALTERNATION and message.author == self.last_player:
|
if WORDLE_FORCE_ALTERNATION and message.author == self.last_player:
|
||||||
await self.channel.send(f"{message.author.mention} Laisse un peu jouer les autres !")
|
await self.channel.send(f"{message.author.mention} Laisse un peu jouer les autres !")
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user