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

Separate moderator logs from event logs #36

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open

Separate moderator logs from event logs #36

wants to merge 4 commits into from

Conversation

MatthewL246
Copy link
Member

@MatthewL246 MatthewL246 commented Aug 4, 2024

Resolves #34

Changes:

This creates a setting for a mod-log channel, which will log moderator events like punishments and slow-mode configuration. The event-log channel will continue to log user events like message updates and deletions.

Message deletions?

I originally wanted to move moderator-deleted messages into the mod-logs channel, but there are a few issues with this.

  • There is not an easy, reliable way to tell if a message deletion event was done by a moderator or a user. The standard way to check this is by fetching the most recent message deletion audit log event, but this is not fully reliable because the event does not contain the message ID. It only contains the message author and channel where the message was sent, so the only way is to make a guess if the most recent event's author and channel ID match.
  • This might make mod-logs too noisy to be useful, so I don't know if it is worth adding this.

This PR is a draft because a decision on how to handle message deletions has not been made yet. Moderator message deletions have been implemented, with certain pitfalls as noted in a comment.

@MatthewL246 MatthewL246 marked this pull request as ready for review August 5, 2024 00:08
@MatthewL246 MatthewL246 marked this pull request as draft August 5, 2024 00:48
@MatthewL246 MatthewL246 marked this pull request as ready for review August 5, 2024 02:40
src/util.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@wolfendale wolfendale left a comment

Choose a reason for hiding this comment

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

LGTM

src/util.ts Outdated Show resolved Hide resolved
Comment on lines +26 to +44
// * Audit logs will not show up at the same time the message delete event
await new Promise(resolve => setTimeout(resolve, 1000));

const auditLogs = await guild.fetchAuditLogs({
type: AuditLogEvent.MessageDelete,
limit: 5
});
const auditLogEntry = auditLogs.entries.find(entry =>
entry.target.id === message.author.id &&
entry.extra.channel.id === message.channelId &&
Date.now() - entry.createdTimestamp < 5 * 60 * 1000
);
// * This large time range is needed because message delete audit log entries are combined if multiple deletions are
// * performed with the same target user, executor, and channel within 5 minutes. Decreasing this time range would
// * create a risk of false negatives because the combined entry keeps the timestamp of the first deletion.
// ! Edge case: If a user deletes their own message after a moderator deletes one of theirs within 5 minutes and in
// ! the same channel, there will be a false positive mod log entry.

const isDeletedByModerator = auditLogEntry !== undefined;
Copy link
Member

Choose a reason for hiding this comment

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

I do agree with your original message about this not being super great. This looks like it would be very error prone in large servers like ours where tons of messages are deleted all the time. I'm not sure this is worth keeping

Copy link
Member Author

Choose a reason for hiding this comment

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

I've gone back and forth on this. I think that it is worth trying out, but if the edge case is hit often enough that it causes a significant amount of confusion, it should be removed. I don't know how common it is for users to delete their own messages within 5 minutes of one of theirs getting deleted by a mod.

@MatthewL246 MatthewL246 force-pushed the mod-logs branch 2 times, most recently from 313701f to dddc818 Compare August 10, 2024 02:54
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