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

Add automod support #2429

Merged
merged 39 commits into from
May 20, 2023
Merged

Add automod support #2429

merged 39 commits into from
May 20, 2023

Conversation

MinnDevelopment
Copy link
Member

@MinnDevelopment MinnDevelopment commented Mar 26, 2023

Pull Request Etiquette

Changes

  • Internal code
  • Library interface (affecting end-user code)
  • Documentation
  • Other: _____

Closes Issue: NaN

Description

This implements the AutoMod API.

Reference: https://discord.com/developers/docs/resources/auto-moderation

Example

Creating an automod rule:

guild.createAutoModRule(
  AutoModRule.onMessage("No morbius memes", TriggerConfig.keywordFilter("*morb*"))
             .putResponses(AutoModResponse.blockMessage("This meme is unfunny."))
).queue();

Here, AutoModRule.onMessage(...) creates a rule of event type MESSAGE_SEND with the name No morbius memes. The trigger config sets the trigger type to KEYWORD and sets the keyword_filter to ["*morb*"].

Bots can react to auto-mod rule activations using the AutoModExecutionEvent:

public void onAutoModExecution(AutoModExecutionEvent event) {
  long user = event.getUserIdLong();
  if (event.getRuleIdLong() == BAN_RULE) {
    event.getGuild().ban(user, 0, TimeUnit.DAYS).queue();
  }
}

Note that access to AutoModExecution#getContent also requires the MESSAGE_CONTENT intent.

TODO

  • Creating rules
  • Modifying rules (manager)
  • Deleting rules
  • Getting existing rules
  • Events
    • GatewayIntent#fromEvents
  • Audit Logs
  • Permissions
  • Checks
  • Documentation
  • ErrorResponse constants

Potential Additions:

@MinnDevelopment MinnDevelopment added type: feature status: documentation needed lacks documentation, either partially or completely labels Mar 26, 2023
@MinnDevelopment MinnDevelopment removed the status: documentation needed lacks documentation, either partially or completely label Apr 2, 2023
@MinnDevelopment MinnDevelopment marked this pull request as ready for review April 2, 2023 13:58
@MinnDevelopment MinnDevelopment mentioned this pull request Apr 2, 2023
6 tasks
@MinnDevelopment MinnDevelopment merged commit ab32257 into master May 20, 2023
1 check passed
@MinnDevelopment MinnDevelopment deleted the feature/automod branch May 20, 2023 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant