Handle emoji variations
This commit is contained in:
parent
e9e32279dc
commit
4d6a79522d
1 changed files with 8 additions and 3 deletions
|
|
@ -182,24 +182,28 @@ async def send_message_safe(
|
|||
|
||||
async def on_reaction(client: AsyncClient, room: MatrixRoom, event: ReactionEvent):
|
||||
"""Listens for reaction approvals/denials in the admin room."""
|
||||
print(f"[REACTION] Received '{event.key}' from {event.sender} on event '{event.reacts_to}'")
|
||||
|
||||
if room.room_id != ADMIN_ROOM_ID:
|
||||
return
|
||||
|
||||
# Verify reactor is an authorized admin
|
||||
if event.sender not in ADMIN_MATRIX_IDS:
|
||||
print(f"[REACTION IGNORED] Sender '{event.sender}' is not in ADMIN_MATRIX_IDS.")
|
||||
return
|
||||
|
||||
# matrix-nio exposes target event ID and emoji as direct properties
|
||||
target_event_id = event.reacts_to
|
||||
emoji = event.key
|
||||
|
||||
# Check if this reaction targets an active pending request
|
||||
if not target_event_id or target_event_id not in pending_requests:
|
||||
print(f"[REACTION IGNORED] Event ID '{target_event_id}' not found in pending_requests.")
|
||||
return
|
||||
|
||||
request = pending_requests[target_event_id]
|
||||
|
||||
if emoji == "👍":
|
||||
# Use substring check to catch Unicode variation selectors (e.g. 👍 vs 👍\ufe0f)
|
||||
if "👍" in emoji:
|
||||
# Execute Keycloak Group Addition
|
||||
success, msg = add_user_to_kc_group(
|
||||
request["kc_username"], request["requested_group"]
|
||||
|
|
@ -222,7 +226,7 @@ async def on_reaction(client: AsyncClient, room: MatrixRoom, event: ReactionEven
|
|||
content={"msgtype": "m.notice", "body": user_msg},
|
||||
)
|
||||
|
||||
elif emoji == "👎":
|
||||
elif "👎" in emoji:
|
||||
status_text = (
|
||||
f"❌ **DENIED** by `{event.sender}`\n"
|
||||
f"**User:** `{request['matrix_user']}` → **Group:** `{request['requested_group']}`"
|
||||
|
|
@ -237,6 +241,7 @@ async def on_reaction(client: AsyncClient, room: MatrixRoom, event: ReactionEven
|
|||
},
|
||||
)
|
||||
else:
|
||||
print(f"[REACTION IGNORED] Emoji '{emoji}' is neither 👍 nor 👎.")
|
||||
return # Ignore other reactions
|
||||
|
||||
# Update the original admin room message to reflect resolution status
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue