Skip to content

Add moderation actions table #298

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

Merged
merged 6 commits into from
Dec 10, 2021
Merged

Add moderation actions table #298

merged 6 commits into from
Dec 10, 2021

Conversation

Zabuzard
Copy link
Member

@Zabuzard Zabuzard commented Dec 3, 2021

Overview

Implements and closes #297. This is a crucial pre-requisite that blocks a whole list of features that are currently either being developed or in planning:

This feature basically logs each moderation action (ban, kick, mute, ...) in a database table, with all necessary information such as target, author, timestamp, reason and more. This can then be used by other classes later to retrieve information (see list of blocked features).

Details

The implementation adds a new database table moderation_actions:

CREATE TABLE moderation_actions
(
    case_id           INTEGER   NOT NULL PRIMARY KEY AUTOINCREMENT,
    issued_at         TIMESTAMP NOT NULL,
    guild_id          BIGINT    NOT NULL,
    author_id         BIGINT    NOT NULL,
    target_id         BIGINT    NOT NULL,
    action_type       TEXT      NOT NULL,
    action_expires_at TIMESTAMP,
    reason            TEXT      NOT NULL
)

which is hidden behind a helper class ModerationActionsStore with retrieval methods such as:

  • getActionsByTypeAscending
  • getActionsByTargetAscending
  • getActionsByAuthorAscending
  • findActionByCaseId

(while those methods are not used right now, they will be used very soon by the mentioned features)

to add a new entry, one calls

  • addAction

Additionally, the store has been integrated into all currently existing commands:

  • BanCommand
  • UnbanCommand
  • KickCommand

so those commands will now also correctly add the entry to the database, when executed.

Notes

The point in time commands call the addAction method as of now is slightly off the actual point in time the action is executed.

Simplified speaking, we have

addAction(...);
guild.ban(...);

while the ban command is obviously a rest action that might be executed slightly deferred. That said, we could potentially use

guild.ban(...)
  .map(result -> {
    addAction(...);
    return result;
  });

in most cases instead (but maybe not all). However, the time will then still be slightly offset (even if its just some milliseconds).

(I wrote it like that to stay consistent with the point in time we have our actual log message being written. So if we should change this, the log also has to go into the map call)

tl;dr: It is not really possible to get the exact timestamp that the action is executed at. Hence, future methods that are added to ModerationActionsStore, such as timestamp-based retrieval (thinking about #280), must be implemented with a time variance in mind (action closest to timestamp ...).

Checklist

  • Create the store
  • Integrate the store
  • Add a note to the class that timestamps might be slightly off
  • Javadoc
  • Fix Linter issues
  • Testing

@Zabuzard Zabuzard force-pushed the feature/mod_actions_table branch from c793b88 to 5d214eb Compare December 7, 2021 17:22
@Zabuzard Zabuzard enabled auto-merge (rebase) December 7, 2021 18:13
RealYusufIsmail
RealYusufIsmail previously approved these changes Dec 7, 2021
Copy link
Contributor

@RealYusufIsmail RealYusufIsmail left a comment

Choose a reason for hiding this comment

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

I have looked thorough it and all looks good.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 9, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@Zabuzard Zabuzard merged commit 2bc2331 into develop Dec 10, 2021
@Zabuzard Zabuzard deleted the feature/mod_actions_table branch December 10, 2021 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority: major
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create mod actions database table
4 participants