From f226b293dedc668af97490acedf02728d22263d7 Mon Sep 17 00:00:00 2001 From: Simon Junod Date: Tue, 5 Apr 2022 13:43:25 +0200 Subject: [PATCH] Normalize and clean up comments (no more superfluous empty lines) --- cambot/wordle.py | 15 +++++++-------- run.py | 11 +---------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/cambot/wordle.py b/cambot/wordle.py index 803b9f0..412d365 100644 --- a/cambot/wordle.py +++ b/cambot/wordle.py @@ -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) diff --git a/run.py b/run.py index 79f5726..5f79a71 100755 --- a/run.py +++ b/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: @@ -94,7 +91,6 @@ async def on_message(message): 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 +99,6 @@ async def on_message(message): await message.channel.send(output) # Dice - if regex := re.search(r"^!(?P\d+)?d[eé]s?(?P\d+)?$", content_lowercase): thrower = message.author.display_name maximum = 6 @@ -130,7 +125,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 +157,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 +185,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():