Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomGuyJCI committed Oct 6, 2024
1 parent 54235ad commit 213e2ae
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
17 changes: 15 additions & 2 deletions orchard/bot/handlers/interactions/commands/reactx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()]:
Expand Down
2 changes: 1 addition & 1 deletion orchard/bot/lib/comm/interactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
23 changes: 18 additions & 5 deletions orchard/scan/sources/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
},
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 213e2ae

Please sign in to comment.