Skip to content

Refine JHO tag-notification cleanup to avoid replacement messages#102

Merged
r-hensley merged 4 commits into
masterfrom
copilot/fix-message-edit-exception
May 23, 2026
Merged

Refine JHO tag-notification cleanup to avoid replacement messages#102
r-hensley merged 4 commits into
masterfrom
copilot/fix-message-edit-exception

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 23, 2026

The JHO untagged-user follow-up was creating a replacement message when the original alert could no longer be edited. This changes the cleanup path so the temporary notification is either edited in place or deleted, without emitting a second notification.

  • Notification cleanup behavior

    • Keep the in-place edit only when the alert is still the latest message in the channel.
    • Skip the edit and delete immediately when newer channel activity already makes ghost notifications irrelevant.
  • Old-message fallback

    • Preserve the edit attempt for the “latest message” case.
    • If Discord rejects that edit with error 30046, delete the notification instead of sending a replacement message.
    • Continue to re-raise unrelated HTTPException cases.

The cleanup logic is implemented directly at the call site in the event flow rather than through a separate helper.

if getattr(sent_msg.channel, "last_message_id", None) == sent_msg.id:
    try:
        await sent_msg.edit(content=new_msg)
        return
    except discord.HTTPException as e:
        if e.code != 30046:
            raise

await sent_msg.delete()

Copilot AI and others added 3 commits May 23, 2026 07:09
Agent-Logs-Url: https://github.com/r-hensley/Rai/sessions/1b16eacd-42df-49ec-973c-dd8fc78c4295

Co-authored-by: r-hensley <30587035+r-hensley@users.noreply.github.com>
Agent-Logs-Url: https://github.com/r-hensley/Rai/sessions/1b16eacd-42df-49ec-973c-dd8fc78c4295

Co-authored-by: r-hensley <30587035+r-hensley@users.noreply.github.com>
Agent-Logs-Url: https://github.com/r-hensley/Rai/sessions/de389e48-3846-4927-9da1-3591a421d6a7

Co-authored-by: r-hensley <30587035+r-hensley@users.noreply.github.com>
@r-hensley
Copy link
Copy Markdown
Owner

@copilot I feel like the function you created is pretty simple and then the test is basically just testing basic python functionality and is pretty easy to see from the code directly that the code is fine. How necessary is a separated, helper function, and a dedicated test?

Agent-Logs-Url: https://github.com/r-hensley/Rai/sessions/064ee40f-9108-4140-b17e-ab62352677cc

Co-authored-by: r-hensley <30587035+r-hensley@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 23, 2026

@copilot I feel like the function you created is pretty simple and then the test is basically just testing basic python functionality and is pretty easy to see from the code directly that the code is ...

I agreed and simplified it in f0d03f6: the helper is gone, the logic is inlined at the call site, and I removed the helper-only test file. The remaining behavior is unchanged, and python -m pytest tests still passes.

Copilot AI requested a review from r-hensley May 23, 2026 07:54
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts the JHO “untagged user” follow-up cleanup in cogs/events.py to avoid posting replacement notifications when the original alert can’t be edited, preferring in-place edits only when the alert is still the latest channel message and otherwise deleting the temporary notification.

Changes:

  • Only attempts to edit the original notification if it is still the channel’s last_message_id.
  • If the edit fails with Discord error code 30046, deletes the notification instead of sending a replacement.
  • Deletes the original notification when newer channel activity exists (with best-effort delete error handling).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cogs/events.py
@r-hensley r-hensley marked this pull request as ready for review May 23, 2026 08:05
@r-hensley r-hensley merged commit caa2a6f into master May 23, 2026
4 checks passed
@r-hensley r-hensley deleted the copilot/fix-message-edit-exception branch May 23, 2026 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants