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

action_items: add reactions #59

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
56 changes: 53 additions & 3 deletions src/extensions/action_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@


@action_items.include
@arc.with_hook(restrict_to_channels(channel_ids=[CHANNEL_IDS["action-items"]]))
@arc.with_hook(restrict_to_roles(role_ids=[ROLE_IDS["committee"]]))
# @arc.with_hook(restrict_to_channels(channel_ids=[CHANNEL_IDS["action-items"]]))
# @arc.with_hook(restrict_to_roles(role_ids=[ROLE_IDS["committee"]]))
@arc.slash_command(
"action_items",
"Display the action items from the MD",
Expand Down Expand Up @@ -95,14 +95,20 @@ async def get_action_items(

# send each bullet point separately
for item in formatted_bullet_points:
await action_items.client.rest.create_message(
item = await action_items.client.rest.create_message(
CHANNEL_IDS["action-items"],
mentions_everyone=False,
user_mentions=True,
role_mentions=True,
content=item,
)

await action_items.client.rest.add_reaction(
channel=item.channel_id,
message=item.id,
emoji="✅",
)

# respond with success if it executes successfully
await ctx.respond(
"✅ Action Items sent successfully!",
Expand All @@ -111,6 +117,50 @@ async def get_action_items(
return


@action_items.listen()
async def action_item_reaction(event: hikari.ReactionAddEvent) -> None:
bot_user = await action_items.client.rest.fetch_my_user()
bot_user_id = bot_user.id

# ignore if not ✅
if event.emoji_name != "✅":
return
# ignore bot reactions
if event.user_id == bot_user_id:
return

# fetch the message that was reacted to
message = await action_items.client.rest.fetch_message(
event.channel_id, event.message_id
)

if not message.author.is_bot:
return

# extract user and role mentions from the message content
mention_regex = r"<@!?(\d+)>|<@&(\d+)>"
mentions = re.findall(mention_regex, message.content)

# make a single list of both user and role mentions
mentioned_ids = [int(user_id or role_id) for user_id, role_id in mentions]

if not mentioned_ids:
return

member = await action_items.client.rest.fetch_member(event.guild_id, event.user_id)

is_mentioned_user = event.user_id in mentioned_ids
has_mentioned_role = any(role_id in mentioned_ids for role_id in member.role_ids)

if is_mentioned_user or has_mentioned_role:
# add strikethrough and checkmark
updated_content = f"- ✅ ~~{message.content[1:]}~~"
await action_items.client.rest.edit_message(
event.channel_id, event.message_id, content=updated_content
)
return


@arc.loader
def loader(client: arc.GatewayClient) -> None:
client.add_plugin(action_items)