-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure no profane wiki searches and other commands
Signed-off-by: Joshua Castle <[email protected]>
- Loading branch information
Showing
12 changed files
with
114 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/org/geysermc/discordbot/commands/filter/FilteredSlashCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.geysermc.discordbot.commands.filter; | ||
|
||
import com.jagrosh.jdautilities.command.SlashCommand; | ||
import com.jagrosh.jdautilities.command.SlashCommandEvent; | ||
import net.dv8tion.jda.api.EmbedBuilder; | ||
import net.dv8tion.jda.api.interactions.commands.OptionMapping; | ||
import net.dv8tion.jda.api.interactions.commands.OptionType; | ||
import org.geysermc.discordbot.listeners.SwearHandler; | ||
import org.geysermc.discordbot.storage.ServerSettings; | ||
import org.geysermc.discordbot.util.BotColors; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public abstract class FilteredSlashCommand extends SlashCommand { | ||
@Override | ||
protected final void execute(SlashCommandEvent event) { | ||
Pattern filterPattern = null; | ||
for (OptionMapping option : event.getOptions()) { | ||
if (option.getType() != OptionType.STRING) continue; | ||
if ((filterPattern = SwearHandler.checkString(option.getAsString())) != null) break; | ||
} | ||
|
||
if (filterPattern != null) { | ||
event.reply(event.getUser().getAsMention() + | ||
" your command cannot be processed because it contains profanity! Please read our rules for more information.") | ||
.setEphemeral(true).queue(); | ||
|
||
// Log the event | ||
if (event.getGuild() != null) { | ||
String channel = event.getChannel() == null ? "Unknown" : event.getChannel().getAsMention(); | ||
|
||
ServerSettings.getLogChannel(event.getGuild()).sendMessageEmbeds(new EmbedBuilder() | ||
.setTitle("Profanity blocked command") | ||
.setDescription("**Sender:** " + event.getUser().getAsMention() + "\n" + | ||
"**Channel:** " + channel + "\n" + | ||
"**Regex:** `" + filterPattern + "`\n" + | ||
"**Command:** " + event.getCommandString()) | ||
.setColor(BotColors.FAILURE.getColor()) | ||
.build()).queue(); | ||
} | ||
return; | ||
} | ||
|
||
executeFiltered(event); | ||
} | ||
|
||
protected abstract void executeFiltered(SlashCommandEvent event); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.