diff --git a/orchard/bot/handlers/interactions/commands/reactx.py b/orchard/bot/handlers/interactions/commands/reactx.py index 4532451..1ce29cd 100644 --- a/orchard/bot/handlers/interactions/commands/reactx.py +++ b/orchard/bot/handlers/interactions/commands/reactx.py @@ -13,11 +13,24 @@ async def _reactx(body, _): token = body["token"] user_id = body["member"]["user"]["id"] messages = body["data"]["resolved"]["messages"] - number_reactions = ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟"] + number_reactions = [ + "1️⃣", + "2️⃣", + "3️⃣", + "4️⃣", + "5️⃣", + "6️⃣", + "7️⃣", + "8️⃣", + "9️⃣", + "🔟", + ] for key, value in messages.items(): message_id = value["id"] for reaction in number_reactions: - if reaction not in [react["emoji"]["name"] for react in value["reactions"]]: + if reaction not in [ + react["emoji"]["name"] for react in value["reactions"] + ]: continue reaction_users = await i.get_reactions(channel_id, message_id, reaction) if user_id in [reactor["id"] for reactor in reaction_users.json()]: diff --git a/orchard/bot/lib/comm/interactor.py b/orchard/bot/lib/comm/interactor.py index 051032c..7e557e5 100644 --- a/orchard/bot/lib/comm/interactor.py +++ b/orchard/bot/lib/comm/interactor.py @@ -107,7 +107,7 @@ async def react(self, channel_id, message_id, emoji): f"{DISCORD_API_URL}/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me", headers={"Authorization": f"Bot {BOT_TOKEN}"}, ) - + @could_raise async def get_reactions(self, channel_id, message_id, emoji): return await self.client.get( diff --git a/orchard/scan/sources/discord.py b/orchard/scan/sources/discord.py index c7fabef..4093345 100644 --- a/orchard/scan/sources/discord.py +++ b/orchard/scan/sources/discord.py @@ -83,15 +83,15 @@ async def get_metadata(self, iid): async def check_reaction(self, post, emoji): if not "reactions" in post: return False - + if emoji not in [react["emoji"]["name"] for react in post["reactions"]]: return False - + async with Client() as client: react_params = {"limit": 100} reactors = await client.get( f"{DISCORD_API_URL}/channels/{self.channel_id}/messages/{post['id']}/reactions/{urllib.parse.quote(emoji)}", - headers = { + headers={ "user-agent": USER_AGENT, "Authorization": f"Bot {self.bot_token}", }, @@ -141,14 +141,27 @@ async def get_iids(self): remove_attachments = await self.check_reaction(post, "🚫") # a message can only have a maximum of 10 attachments, so we use number reactions - number_reactions = ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟"] + number_reactions = [ + "1️⃣", + "2️⃣", + "3️⃣", + "4️⃣", + "5️⃣", + "6️⃣", + "7️⃣", + "8️⃣", + "9️⃣", + "🔟", + ] # check all attachments and corresponding number reactions. if no number reaction is found, then we ignore every attachment ignore_all_attachments = True attachment_numbers = [] for i, attachment in enumerate(post["attachments"]): if attachment["filename"].endswith(".rdzip"): - if remove_attachments and await self.check_reaction(post, number_reactions[i]): + if remove_attachments and await self.check_reaction( + post, number_reactions[i] + ): ignore_all_attachments = False continue attachment_numbers.append(i)