Skip to content

Commit

Permalink
improve qol for multiple attachment reactions
Browse files Browse the repository at this point in the history
- The number reactions now only account for rdzip attachments position, useful for messages with both image/video embeds and rdzips since it might affect the actual order of attachments
- The bot no longer reacts for numbers greater than the number of rdzips
- Using the reactx command now shows the rdzips that will be ignored (or all rdzips if no number reaction is found)
  • Loading branch information
RandomGuyJCI committed Oct 8, 2024
1 parent 35f752d commit 8fd51f3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
37 changes: 30 additions & 7 deletions orchard/bot/handlers/interactions/commands/reactx.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@


async def _reactx(body, _):
async with Interactor(body["token"]) as i:
async with Interactor(body["token"]) as interactor:
channel_id = body["channel_id"]
token = body["token"]
user_id = body["member"]["user"]["id"]
bot_id = body["application_id"]
messages = body["data"]["resolved"]["messages"]
number_reactions = [
"1️⃣",
Expand All @@ -25,20 +26,42 @@ async def _reactx(body, _):
"9️⃣",
"🔟",
]
ignored_rdzips = []
for key, value in messages.items():
message_id = value["id"]
for reaction in number_reactions:
rdzip_attachments = [
attachment["filename"]
for attachment in value["attachments"]
if attachment["filename"].endswith(".rdzip")
]
for i, reaction in enumerate(number_reactions):
if "reactions" not in value:
continue
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()]:
await i.react(channel_id, message_id, reaction)
await i.react(channel_id, message_id, "🚫")
await i.edit(MessageBuilder().content("done."), "@original")
if i >= len(rdzip_attachments):
continue
reaction_users = await interactor.get_reactions(
channel_id, message_id, reaction
)
for reactor in reaction_users.json():
if bot_id == reactor["id"]:
ignored_rdzips.append(rdzip_attachments[i])
continue
if user_id == reactor["id"]:
ignored_rdzips.append(rdzip_attachments[i])
await interactor.react(channel_id, message_id, reaction)
await interactor.react(channel_id, message_id, "🚫")
result = "Done, now ignoring all rdzips."
if len(ignored_rdzips) > 0:
result = (
"Done, now ignoring the following rdzips:\n```"
+ "\n".join(ignored_rdzips)
+ "\n```"
)
await interactor.edit(MessageBuilder().content(result), "@original")


reactx = SlashRoute(
Expand Down
4 changes: 3 additions & 1 deletion orchard/scan/sources/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,16 @@ async def get_iids(self):
# check all attachments and corresponding number reactions. if no number reaction is found, then we ignore every attachment
ignore_all_attachments = True
attachment_numbers = []
relative_position = 0
for i, attachment in enumerate(post["attachments"]):
if attachment["filename"].endswith(".rdzip"):
if remove_attachments and await self.check_reaction(
post, number_reactions[i]
post, number_reactions[relative_position], True
):
ignore_all_attachments = False
continue
attachment_numbers.append(i)
relative_position += 1

if (not remove_attachments) or (not ignore_all_attachments):
for i in attachment_numbers:
Expand Down

0 comments on commit 8fd51f3

Please sign in to comment.