All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.dv8tion.jda.api.entities.automod.build.TriggerConfig Maven / Gradle / Ivy

Go to download

Java wrapper for the popular chat & VOIP service: Discord https://discord.com

There is a newer version: 5.1.0
Show newest version
/*
 * Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.dv8tion.jda.api.entities.automod.build;

import net.dv8tion.jda.api.entities.automod.AutoModRule;
import net.dv8tion.jda.api.entities.automod.AutoModRule.KeywordPreset;
import net.dv8tion.jda.api.entities.automod.AutoModTriggerType;
import net.dv8tion.jda.api.utils.data.SerializableData;

import javax.annotation.Nonnull;
import java.util.Collection;

/**
 * Configuration for {@link AutoModRule}, which defines under what conditions the rule should be triggered.
 *
 * 

Each rule is limited to a single trigger type. You can use the various factory methods on this interface to create a config. * *

Supported factories: *

    *
  • {@link #mentionSpam(int)} - Trigger on mention thresholds in messages
  • *
  • {@link #antiSpam()} - Trigger on spam content in messages (classified by Discord magic)
  • *
  • {@link #keywordFilter(Collection)}/{@link #patternFilter(Collection)} - Trigger on messages containing certain keywords or regex patterns
  • *
  • {@link #presetKeywordFilter(AutoModRule.KeywordPreset...)} - Trigger on messages containing words from predefined lists
  • *
* *

Example
*

{@code
 * AutoModRuleData rule = AutoModRule.onMessage("Invite Links",
 *   TriggerConfig.keywordFilter("discord.gg/*") // trigger on all invite links
 *     .setAllowList("discord.gg/discord-api")   // except certain whitelisted ones
 * );
 * }
* * @see AutoModRule */ public interface TriggerConfig extends SerializableData { /** * The type of trigger for this config. * * @return {@link AutoModTriggerType} */ @Nonnull AutoModTriggerType getType(); /** * Trigger on mention thresholds in messages. * * @param mentionLimit * The maximum number of unique mentions allowed in a message (1-{@value AutoModRule#MAX_MENTION_LIMIT}) * * @throws IllegalArgumentException * If the provided mention limit is not between 1 and {@value AutoModRule#MAX_MENTION_LIMIT} * * @return {@link MentionSpamTriggerConfig} */ @Nonnull static MentionSpamTriggerConfig mentionSpam(int mentionLimit) { return new MentionSpamTriggerConfig(mentionLimit); } /** * Trigger on spam content in messages (classified by Discord magic). * * @return {@link AntiSpamTriggerConfig} */ @Nonnull static AntiSpamTriggerConfig antiSpam() { return new AntiSpamTriggerConfig(); } /** * Trigger on messages containing certain keywords or regex patterns. *
Keywords are matched case-insensitively, and may also contain whitespace. * *

You can use wildcards at the keyword boundaries to extend the matches: *
{@code "foo*"} can match {@code "foo"}, {@code "foobar"}, {@code "foo-bar"}, etc. *
{@code "*foo*"} can match {@code "foo"}, {@code "foobar"}, {@code "barfoo"}, etc. *
{@code "*foo"} can match {@code "foo"}, {@code "barfoo"}, {@code "bar-foo"}, etc. * *

You can also use regex patterns using {@link #patternFilter(Collection)} or {@link CustomKeywordTriggerConfig#addPatterns(Collection)}. * * @param keywords * The keywords to match (case-insensitive) * * @throws IllegalArgumentException *

    *
  • If any of the keywords are empty, blank, or null
  • *
  • If more than {@value AutoModRule#MAX_KEYWORD_AMOUNT} keywords are added
  • *
  • If any of the keywords is longer than {@value AutoModRule#MAX_KEYWORD_LENGTH} characters
  • *
* * @return {@link CustomKeywordTriggerConfig} */ @Nonnull static CustomKeywordTriggerConfig keywordFilter(@Nonnull Collection keywords) { return new CustomKeywordTriggerConfig().addKeywords(keywords); } /** * Trigger on messages containing certain keywords or regex patterns. *
Keywords are matched case-insensitively, and may also contain whitespace. * *

You can use wildcards at the keyword boundaries to extend the matches: *
{@code "foo*"} can match {@code "foo"}, {@code "foobar"}, {@code "foo-bar"}, etc. *
{@code "*foo*"} can match {@code "foo"}, {@code "foobar"}, {@code "barfoo"}, etc. *
{@code "*foo"} can match {@code "foo"}, {@code "barfoo"}, {@code "bar-foo"}, etc. * *

You can also use regex patterns using {@link #patternFilter(String...)} or {@link CustomKeywordTriggerConfig#addPatterns(String...)}. * * @param keywords * The keywords to match (case-insensitive) * * @throws IllegalArgumentException *

    *
  • If any of the keywords are empty, blank, or null
  • *
  • If more than {@value AutoModRule#MAX_KEYWORD_AMOUNT} keywords are added
  • *
  • If any of the keywords is longer than {@value AutoModRule#MAX_KEYWORD_LENGTH} characters
  • *
* * @return {@link CustomKeywordTriggerConfig} */ @Nonnull static CustomKeywordTriggerConfig keywordFilter(@Nonnull String... keywords) { return new CustomKeywordTriggerConfig().addKeywords(keywords); } /** * Trigger on messages containing certain keywords regex patterns. *
Keyword patterns are matched case-insensitively, and may also contain whitespace. * *

Patterns may use anything supported by the rust regex crate. * You can use a validator such as Rustexp to validate your pattern. * *

You can also use simple substring keywords using {@link #keywordFilter(String...)} or {@link CustomKeywordTriggerConfig#addKeywords(String...)}. * * @param patterns * The keyword patterns to match * * @throws IllegalArgumentException *

    *
  • If any of the patterns are empty, blank, or null
  • *
  • If more than {@value AutoModRule#MAX_PATTERN_AMOUNT} patterns are added
  • *
  • If any of the patterns is longer than {@value AutoModRule#MAX_PATTERN_LENGTH} characters
  • *
* * @return {@link CustomKeywordTriggerConfig} */ @Nonnull static CustomKeywordTriggerConfig patternFilter(@Nonnull Collection patterns) { return new CustomKeywordTriggerConfig().addPatterns(patterns); } /** * Trigger on messages containing certain keywords regex patterns. *
Keyword patterns are matched case-insensitively, and may also contain whitespace. * *

Patterns may use anything supported by the rust regex crate. * You can use a validator such as Rustexp to validate your pattern. * *

You can also use simple substring keywords using {@link #keywordFilter(String...)} or {@link CustomKeywordTriggerConfig#addKeywords(String...)}. * * @param patterns * The keyword patterns to match * * @throws IllegalArgumentException *

    *
  • If any of the patterns are empty, blank, or null
  • *
  • If more than {@value AutoModRule#MAX_PATTERN_AMOUNT} patterns are added
  • *
  • If any of the patterns is longer than {@value AutoModRule#MAX_PATTERN_LENGTH} characters
  • *
* * @return {@link CustomKeywordTriggerConfig} */ @Nonnull static CustomKeywordTriggerConfig patternFilter(@Nonnull String... patterns) { return new CustomKeywordTriggerConfig().addPatterns(patterns); } /** * Trigger on keywords from predefined lists. * * @param presets * The presets to enable * * @throws IllegalArgumentException * If null or {@link KeywordPreset#UNKNOWN} is provided * * @return {@link PresetKeywordTriggerConfig} */ @Nonnull static PresetKeywordTriggerConfig presetKeywordFilter(@Nonnull Collection presets) { return new PresetKeywordTriggerConfig().enablePresets(presets); } /** * Trigger on keywords from predefined lists. * * @param presets * The presets to enable * * @throws IllegalArgumentException * If null or {@link KeywordPreset#UNKNOWN} is provided * * @return {@link PresetKeywordTriggerConfig} */ @Nonnull static PresetKeywordTriggerConfig presetKeywordFilter(@Nonnull AutoModRule.KeywordPreset... presets) { return new PresetKeywordTriggerConfig().enablePresets(presets); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy