Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve qol for multiple attachment reactions #73

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading