Normalize and clean up comments (no more superfluous empty lines)
This commit is contained in:
@@ -18,15 +18,13 @@ def validate(target, guess):
|
||||
copy = list(target)
|
||||
output = [0] * len(target)
|
||||
|
||||
# Look for the green squares :
|
||||
|
||||
# Look for the green squares
|
||||
for idx in range(len(target)):
|
||||
if target[idx] == guess[idx]:
|
||||
output[idx] = 2
|
||||
copy[idx] = None
|
||||
|
||||
# Look for the yellow squares :
|
||||
|
||||
# Look for the yellow squares
|
||||
for idx in range(len(target)):
|
||||
if target[idx] == guess[idx]:
|
||||
continue # ignore the letters that are green
|
||||
@@ -60,19 +58,19 @@ class Game:
|
||||
async def parse(self, message):
|
||||
guess = unidecode(message.content.strip()).upper()
|
||||
|
||||
# if somebody won
|
||||
# if somebody has already won, return silently
|
||||
if self.winner:
|
||||
return
|
||||
|
||||
# if the game was never initialized
|
||||
# same if the game was never initialized
|
||||
if not self.target:
|
||||
return
|
||||
|
||||
# if the message is not comprised of letters (with or without accents) only
|
||||
# same 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
|
||||
# same if the guess is obviously not the same length
|
||||
ratio = 2/3
|
||||
if len(guess) <= len(self.target) * ratio or len(self.target) <= len(guess) * ratio:
|
||||
return
|
||||
@@ -87,6 +85,7 @@ class Game:
|
||||
await self.channel.send(f"{message.author.mention} `{guess}` n'est pas dans mon dictionnaire (ça ne compte pas comme un tour).")
|
||||
return
|
||||
|
||||
# everything is OK, validate the proposal
|
||||
self.tries += 1
|
||||
self.last_player = message.author
|
||||
result = validate(self.target, guess)
|
||||
|
||||
12
run.py
12
run.py
@@ -16,7 +16,6 @@ codenames_games = {}
|
||||
wordle_games = {}
|
||||
|
||||
# Startup
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
print(f"Connecté, nom {bot.user.name}, id {bot.user.id}")
|
||||
@@ -50,12 +49,10 @@ async def on_ready():
|
||||
await wordle_game.reset()
|
||||
|
||||
# Receiving a message
|
||||
|
||||
@bot.event
|
||||
async def on_message(message):
|
||||
|
||||
# Ignore own messages
|
||||
|
||||
if message.author == bot.user:
|
||||
return
|
||||
|
||||
@@ -63,7 +60,6 @@ async def on_message(message):
|
||||
content_lowercase = content.lower()
|
||||
|
||||
# Private messages
|
||||
|
||||
if isinstance(message.channel, discord.channel.DMChannel):
|
||||
games_entered = [codenames_game for codenames_game in codenames_games.values() if codenames_game.get_player(message.author)]
|
||||
|
||||
@@ -79,6 +75,7 @@ async def on_message(message):
|
||||
output += f"{wordle_game.channel.guild} > {wordle_game.channel.name} : {wordle_game.target}\n"
|
||||
await message.author.send(output)
|
||||
|
||||
# Codenames whispers
|
||||
if len(games_entered) == 1:
|
||||
await codenames.process_whisper(games_entered[0], message)
|
||||
elif len(games_entered) > 1:
|
||||
@@ -89,12 +86,10 @@ async def on_message(message):
|
||||
return
|
||||
|
||||
# Help
|
||||
|
||||
if re.search(r"^!(aide|help|commandes)$", content_lowercase):
|
||||
await print_help(message.channel)
|
||||
|
||||
# Judge something
|
||||
|
||||
if regex := re.search(r"^!juger (.+)$", content_lowercase):
|
||||
subject = regex.group(1).strip()
|
||||
score = int(hashlib.md5(bytes(subject.lower(), "utf-8")).hexdigest(), 16) % 2
|
||||
@@ -103,7 +98,6 @@ async def on_message(message):
|
||||
await message.channel.send(output)
|
||||
|
||||
# Dice
|
||||
|
||||
if regex := re.search(r"^!(?P<number>\d+)?d[eé]s?(?P<maximum>\d+)?$", content_lowercase):
|
||||
thrower = message.author.display_name
|
||||
maximum = 6
|
||||
@@ -130,7 +124,6 @@ async def on_message(message):
|
||||
await message.channel.send(output)
|
||||
|
||||
# Codenames commands
|
||||
|
||||
if message.channel.id in codenames_games.keys():
|
||||
|
||||
game = codenames_games[message.channel.id]
|
||||
@@ -163,12 +156,10 @@ async def on_message(message):
|
||||
await codenames.maybe_guess(game, message, regex.group(1))
|
||||
|
||||
# Wordle
|
||||
|
||||
if message.channel.id in wordle_games.keys():
|
||||
await wordle_games[message.channel.id].parse(message)
|
||||
|
||||
# Help
|
||||
|
||||
async def print_help(channel):
|
||||
output = """__Commandes de CamBot__
|
||||
|
||||
@@ -193,7 +184,6 @@ async def print_help(channel):
|
||||
await channel.send(output)
|
||||
|
||||
# Let unprivileged users pin messages
|
||||
|
||||
async def reaction_changed(payload):
|
||||
emoji = payload.emoji
|
||||
if not emoji.is_unicode_emoji():
|
||||
|
||||
Reference in New Issue
Block a user