diff options
author | 2022-10-17 23:07:18 +0100 | |
---|---|---|
committer | 2022-10-19 22:35:13 +0100 | |
commit | 1934b1809eb2408352dfaec9141594de1088eb68 (patch) | |
tree | c575f5df8e86ae2608077006747d1e6787ed0271 | |
parent | `REPO_TOKEN` is no more. (#1119) (diff) |
Remove calls to the deprecated .flatten() method
-rw-r--r-- | bot/exts/holidays/easter/egghead_quiz.py | 36 | ||||
-rw-r--r-- | bot/exts/holidays/halloween/candy_collection.py | 2 |
2 files changed, 31 insertions, 7 deletions
diff --git a/bot/exts/holidays/easter/egghead_quiz.py b/bot/exts/holidays/easter/egghead_quiz.py index 8f3aa6b0..b8d13e87 100644 --- a/bot/exts/holidays/easter/egghead_quiz.py +++ b/bot/exts/holidays/easter/egghead_quiz.py @@ -65,23 +65,43 @@ class EggheadQuiz(commands.Cog): msg = await ctx.fetch_message(msg.id) # Refreshes message - total_no = sum([len(await r.users().flatten()) for r in msg.reactions]) - len(valid_emojis) # - bot's reactions + users = [] + for reaction in msg.reactions: + async for user in reaction.users(): + users.append(user) + + total_no = len(users) - len(valid_emojis) # - bot's reactions if total_no == 0: return await msg.delete() # To avoid ZeroDivisionError if nobody reacts results = ["**VOTES:**"] for emoji, _ in answers: - num = [len(await r.users().flatten()) for r in msg.reactions if str(r.emoji) == emoji][0] - 1 + users = [] + for reaction in msg.reactions: + if str(reaction.emoji) != emoji: + continue + + async for user in reaction.users(): + users.append(user) + break + + num = len(users) - 1 percent = round(100 * num / total_no) s = "" if num == 1 else "s" string = f"{emoji} - {num} vote{s} ({percent}%)" results.append(string) + users = [] + for reaction in msg.reactions: + if str(reaction.emoji) != correct: + continue + + async for user in reaction.users(): + users.append(user) + mentions = " ".join([ - u.mention for u in [ - await r.users().flatten() for r in msg.reactions if str(r.emoji) == correct - ][0] if not u.bot + u.mention for u in users if not u.bot ]) content = f"Well done {mentions} for getting it correct!" if mentions else "Nobody got it right..." @@ -97,7 +117,11 @@ class EggheadQuiz(commands.Cog): @staticmethod async def already_reacted(message: discord.Message, user: Union[discord.Member, discord.User]) -> bool: """Returns whether a given user has reacted more than once to a given message.""" - users = [u.id for reaction in [await r.users().flatten() for r in message.reactions] for u in reaction] + users = [] + for reaction in message.reactions: + async for usr in reaction.users(): + users.append(usr.id) + return users.count(user.id) > 1 # Old reaction plus new reaction @commands.Cog.listener() diff --git a/bot/exts/holidays/halloween/candy_collection.py b/bot/exts/holidays/halloween/candy_collection.py index ee23ed59..e63ea3a2 100644 --- a/bot/exts/holidays/halloween/candy_collection.py +++ b/bot/exts/holidays/halloween/candy_collection.py @@ -90,7 +90,7 @@ class CandyCollection(commands.Cog): recent_message_ids = map( lambda m: m.id, - await self.hacktober_channel.history(limit=10).flatten() + [message async for message in self.hacktober_channel.history(limit=10)] ) if message.id in recent_message_ids: await self.reacted_msg_chance(message) |