Emote filter, Chat filter improvements, Disable commands, and custom

commands
This commit is contained in:
Ghoti 2020-06-04 23:37:10 -05:00
parent a0df294674
commit f05582baaf
16 changed files with 331 additions and 79 deletions

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.fpghoti</groupId>
<artifactId>Biscuit</artifactId>
<version>1.2.2</version>
<version>1.3</version>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
@ -17,6 +17,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
@ -25,6 +26,7 @@
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<encoding>UTF-8</encoding>
<archive>
<manifest>
<mainClass>com.fpghoti.biscuit.Main</mainClass>
@ -42,6 +44,7 @@
<goal>shade</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<minimizeJar>true</minimizeJar>
</configuration>
</execution>
@ -74,6 +77,10 @@
<id>soluvas-public-thirdparty</id>
<url>http://nexus.bippo.co.id/nexus/content/repositories/soluvas-public-thirdparty/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
@ -214,5 +221,9 @@
<scope>compile</scope>
</dependency>
</dependencies>
<properties>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

18
pom.xml
View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.fpghoti</groupId>
<artifactId>Biscuit</artifactId>
<version>1.2.3</version>
<version>1.3</version>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
@ -19,6 +19,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
@ -28,6 +29,7 @@
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<encoding>UTF-8</encoding>
<archive>
<manifest>
<mainClass>com.fpghoti.biscuit.Main</mainClass>
@ -46,6 +48,7 @@
<goal>shade</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<minimizeJar>true</minimizeJar>
</configuration>
</execution>
@ -53,6 +56,10 @@
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<repositories>
<repository>
<id>spigot-repo</id>
@ -78,8 +85,17 @@
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.CrabMustard</groupId>
<artifactId>emoji-java</artifactId>
<version>v5.1.1-fixed</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>

View File

@ -10,7 +10,6 @@ import com.fpghoti.biscuit.commands.BaseCommand;
import com.fpghoti.biscuit.commands.CommandListener;
import com.fpghoti.biscuit.commands.client.AddCommand;
import com.fpghoti.biscuit.commands.client.ChanIDCommand;
import com.fpghoti.biscuit.commands.client.ChnameCommand;
import com.fpghoti.biscuit.commands.client.DivideCommand;
import com.fpghoti.biscuit.commands.client.ToggleRoleCommand;
import com.fpghoti.biscuit.commands.client.HelpCommand;
@ -97,7 +96,6 @@ public class Main {
commands.add(new RecentSpammersCommand());
commands.add(new ChanIDCommand());
commands.add(new UIDCommand());
commands.add(new ChnameCommand());
commands.add(new ToggleRoleCommand());
commands.add(new SquareRootCommand());
commands.add(new AddCommand());

View File

@ -13,6 +13,12 @@ public abstract class BaseCommand{
protected List<String> identifiers;
protected List<String> notes;
public BaseCommand(String name, String description, String usage) {
this.name = name;
this.description = description;
this.usage = usage;
}
public BaseCommand() {
this.identifiers = new ArrayList<String>();
this.notes = new ArrayList<String>();

View File

@ -6,6 +6,8 @@ import java.util.List;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.util.PermUtil;
import com.fpghoti.biscuit.util.Util;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@ -33,6 +35,18 @@ public class CommandManager {
}
public boolean dispatch(MessageReceivedEvent e, String label, String[] args) {
if(e != null) {
if(Util.contains(PropertiesRetrieval.disabledCommands(), label)) {
return false;
}
if(!PermUtil.isAdmin(e.getMember()) && Util.contains(PropertiesRetrieval.disabledUserCommands(), label)) {
return false;
}
}
String input = label + " ";
for (String s : args) {
input += s + " ";
@ -68,6 +82,17 @@ public class CommandManager {
((ConsoleCommand)match).execute(trimmedArgs);
}
}
}else {
if(Util.contains(PropertiesRetrieval.getCustomCmds(), label)) {
CustomCommand cc = new CustomCommand(label);
if(args.length >= 1) {
commandReply(e, "``Command:" + " " + cc.getName() + "``");
commandReply(e, "``Description:" + " " + cc.getDescription() + "``");
commandReply(e, "``Usage:" + " " + cc.getUsage() + "``");
}else {
commandReply(e, CustomCommand.fixPlaceholders(e, cc.getMessage()));
}
}
}
return true;
}

View File

@ -0,0 +1,53 @@
package com.fpghoti.biscuit.commands;
import com.fpghoti.biscuit.config.ConfigRetrieval;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
public class CustomCommand extends BaseCommand {
public static String fixPlaceholders(MessageReceivedEvent event, String msg) {
msg = msg.replace("<user>", event.getAuthor().getAsMention());
return msg;
}
private String name;
public CustomCommand(String name) {
this.name = name;
}
@Override
public String getName() {
return this.name;
}
@Override
public String getUsage() {
return PropertiesRetrieval.getCommandSignifier() + name;
}
@Override
public String getDescription() {
String desc = ConfigRetrieval.getFromConfig("cc-" + name + "-description");
if(desc == null) {
return "null";
}
return desc;
}
@Override
public CommandType getType() {
return null;
}
public String getMessage() {
String msg = ConfigRetrieval.getFromConfig("cc-" + name + "-message");
if(msg == null) {
return "null";
}
return msg;
}
}

View File

@ -1,31 +0,0 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.util.PermUtil;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
public class ChnameCommand extends ClientCommand{
public ChnameCommand() {
name = "Channel Name";
description = "Retrieves the channel name.";
usage = PropertiesRetrieval.getCommandSignifier() + "chname";
minArgs = 0;
maxArgs = 0;
identifiers.add("chname");
}
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit b = Main.getBiscuit();
b.log(event.getAuthor().getName() + " issued a command: -chname");
if(PermUtil.isMod(event.getMember()) || PermUtil.canMute(event.getMember())) {
event.getTextChannel().sendMessage("DEBUG: " + event.getTextChannel().getName()).queue();
}
}
}

View File

@ -1,11 +1,13 @@
package com.fpghoti.biscuit.commands.client;
import java.util.ArrayList;
import java.util.List;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.commands.BaseCommand;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.commands.CustomCommand;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.util.Util;
@ -36,13 +38,27 @@ public class HelpCommand extends ClientCommand {
}
}
List<BaseCommand> commands = biscuit.getCommandManager().getCommands();
List<BaseCommand> commands = new ArrayList<BaseCommand>();
String[] ccs = PropertiesRetrieval.getCustomCmds();
for(String s : ccs) {
if(!Util.contains(PropertiesRetrieval.disabledCommands(), s)) {
CustomCommand cc = new CustomCommand(s);
commands.add(cc);
}
}
for(BaseCommand bc : biscuit.getCommandManager().getCommands()) {
String bclabel = bc.getUsage().split(" ")[0];
if(!Util.contains(PropertiesRetrieval.disabledCommands(), bclabel.replace(PropertiesRetrieval.getCommandSignifier(), ""))) {
commands.add(bc);
}
}
int pageCount = (int) Math.ceil((double) commands.size() / 8);
if (pg > pageCount) {
pg = pageCount;
}
event.getTextChannel().sendMessage("**Use " + PropertiesRetrieval.getCommandSignifier() + "help [Page #] to navigate the different pages.**").queue();
event.getTextChannel().sendMessage("[" + Integer.toString(pg) + "/" + Integer.toString(pageCount) + "] **Bot Commands:**").queue();
String msg = "";
for (int i = 0; i < 8; i++) {

View File

@ -90,6 +90,11 @@ public class ConfigRetrieval {
added = addProperty("Captcha-Reward-Role", "cleared", prop, added);
added = addProperty("No-Captcha-Kick", "false", prop, added);
added = addProperty("No-Captcha-Kick-Time", "10", prop, added);
added = addProperty("Block-Unicode-Emotes", "baby,snake,squid", prop, added);
added = addProperty("Block-Custom-Emotes", "badfish,fix,bigleaf", prop, added);
added = addProperty("Custom-Command-Names", "", prop, added);
added = addProperty("DisabledCommands", "cmd1,cmd2,cmd3", prop, added);
added = addProperty("DisabledUserCommands", "cmd4,cmd5,cmd6", prop, added);
return added;
}

View File

@ -73,4 +73,23 @@ public class PropertiesRetrieval {
return ConfigRetrieval.getFromConfig("ToggleRoles").replace(" ", "").split(",");
}
public static String[] blockedUnicodeEmotes(){
return ConfigRetrieval.getFromConfig("Block-Unicode-Emotes").replace(" ", "").split(",");
}
public static String[] blockedCustomEmotes(){
return ConfigRetrieval.getFromConfig("Block-Custom-Emotes").replace(" ", "").split(",");
}
public static String[] getCustomCmds(){
return ConfigRetrieval.getFromConfig("Custom-Command-Names").replace(" ", "").split(",");
}
public static String[] disabledCommands(){
return ConfigRetrieval.getFromConfig("DisabledCommands").replace(" ", "").split(",");
}
public static String[] disabledUserCommands(){
return ConfigRetrieval.getFromConfig("DisabledUserCommands").replace(" ", "").split(",");
}
}

View File

@ -31,14 +31,12 @@ public class MessageReceiveListener extends ListenerAdapter{
}
}
if(event.getAuthor().isBot() && event.getMessage().getContentRaw().contains("This message contains words not appropriate for this channel.") || (ChatFilter.isNaughty(event.getMessage().getContentDisplay()))){
if(event.getAuthor().isBot() && event.getMessage().getContentRaw().contains("This message contains words not appropriate for this channel.") || (ChatFilter.filter(event))){
MessageQueue.removemessages.put(event.getMessage().getId(), event.getTextChannel());
}
//staff channels do not need filtering, as the filter could actually be a hinderance
if(!event.getChannel().getName().toLowerCase().contains("staff") && ChatFilter.isNaughty(event.getMessage().getContentDisplay())){
String text = event.getMessage().getContentDisplay();
log.info("Removed Msg - REASON NAUGHTY WORD(S) - by " + event.getAuthor().getName() + ": " + text);
if(!event.getChannel().getName().toLowerCase().contains("staff") && ChatFilter.filter(event, false)){
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + " This message contains words not appropriate for this channel.").complete();
MessageQueue.fastremovemessages.put(event.getMessage().getId(), event.getTextChannel());
}

View File

@ -9,7 +9,8 @@ public class FastMsgRemoveTimer extends BiscuitTimer{
public FastMsgRemoveTimer(){
delay = (long) 0;
period = (long) 1*1000;
//period = (long) 1*1000;
period = (long) 250;
}
public void run() {

View File

@ -1,47 +1,148 @@
package com.fpghoti.biscuit.util;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.vdurmont.emoji.EmojiParser;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
public class ChatFilter {
//CHAT FILTER
public static String[] suffixes = {"ing","s","ed","er","es","y","ers","ier","iest","ies","ys"};
public static Boolean isNaughty(String sentence){
public static boolean filter(MessageReceivedEvent event) {
return filter(event, true);
}
public static boolean filter(MessageReceivedEvent event, boolean silent) {
String msg = event.getMessage().getContentDisplay();
//Message removal priority occurs in this order
boolean found = false;
//Naughty word check
boolean filter = (filter(msg));
if(filter) {
if(!silent) {
Main.log.info("Removed Msg - REASON NAUGHTY WORD(S) - by " + event.getAuthor().getName() + ": " + msg);
}
return true;
}
//Custom emote check
for(Emote e : event.getMessage().getEmotes()) {
String name = e.getName();
for(String s : PropertiesRetrieval.blockedCustomEmotes()) {
if(s.equals(name)) {
found = true;
}
}
}
if(found) {
if(!silent) {
Main.log.info("Removed Msg - REASON BLOCKED CUSTOM EMOTE(S) - by " + event.getAuthor().getName() + ": " + msg);
}
return true;
}
//Unicode emote check
for(String u : EmojiParser.extractEmojis(msg)) {
u = EmojiParser.parseToAliases(u).replace(":","");
for(String s : PropertiesRetrieval.blockedUnicodeEmotes()) {
if(s.equalsIgnoreCase(u)) {
found = true;
}
}
}
if(found) {
if(!silent) {
Main.log.info("Removed Msg - REASON BLOCKED UNICODE EMOTE(S) - by " + event.getAuthor().getName() + ": " + msg);
}
return true;
}
return false;
}
public static boolean filter(String sentence){
for(String s : sentence.split(" ")){
if(isNaughtyWord(s)){
if(filterWord(s)){
return true;
}
}
return false;
}
public static Boolean isNaughtyWord(String word){
String wordp = "";
String word2 = word.toLowerCase();
if(word2.length() >= 2 && word2.charAt(word2.length() -1) == '!'){
for(int i = 0; i < word2.length() -1; i++ ){
wordp += word2.charAt(i);
}
word2 = wordp;
}
wordp = "";
for(int i = 0; i < word2.length(); i++ ){
if(word2.charAt(i) != '!'){
wordp += word2.charAt(i);
}else{
wordp += 'i';
}
}
word2 = wordp;
word2 = word2.replaceAll("\\p{Punct}+", "").replaceAll("1", "i").replaceAll("5", "s").replaceAll("6", "g").replaceAll("3", "e");
String[] list = PropertiesRetrieval.getNaughtyWords();
for(String item : list){
if(word.equalsIgnoreCase(item) || word.equalsIgnoreCase(item + "s")){
public static boolean filterWord(String word) {
String[] match = findMatchPair(word);
if(match != null) {
return true;
}
}
word2 = null;
return false;
}
public static String findMatch(String word) {
String[] match = findMatchPair(word);
if(match == null || match[0] == null) {
return null;
}
return match[0];
}
public static String[] findMatchPair(String word) {
String cleaned = "";
word = word.toLowerCase();
if(word.length() >= 2 && word.charAt(word.length() -1) == '!'){
for(int i = 0; i < word.length() -1; i++ ){
cleaned += word.charAt(i);
}
word = cleaned;
}
cleaned = "";
for(int i = 0; i < word.length(); i++ ){
if(word.charAt(i) != '!'){
cleaned += word.charAt(i);
}else{
cleaned += 'i';
}
}
cleaned = cleaned.replace(" ", "");
cleaned = cleaned.replaceAll("\\p{Punct}+", "").replaceAll("1", "i").replaceAll("5", "s").replaceAll("6", "g").replaceAll("3", "e").replaceAll("0", "o").replaceAll("9", "g").replaceAll("8", "b");
if(cleaned.equals("")) {
return null;
}
String[] wordSuf = {null,null};
for(String item : PropertiesRetrieval.getNaughtyWords()) {
if(cleaned.equalsIgnoreCase(item)){
wordSuf[0] = item;
return wordSuf;
}
for(String suffix : suffixes) {
if(cleaned.equalsIgnoreCase(item + suffix)){
wordSuf[0] = item;
wordSuf[1] = suffix;
return wordSuf;
}
String last = item.substring(item.length() - 1);
if(cleaned.equalsIgnoreCase(item + last + suffix)){
wordSuf[0] = item;
wordSuf[1] = last + suffix;
return wordSuf;
}
if(cleaned.equalsIgnoreCase(item + last + last + suffix)){
wordSuf[0] = item;
wordSuf[1] = last + last + suffix;
return wordSuf;
}
}
}
return null;
}
}

View File

@ -32,6 +32,15 @@ public class Util {
return s.matches("[0-9]+");
}
public static boolean contains(String[] list, String s) {
for(String l : list) {
if(s.equals(l)) {
return true;
}
}
return false;
}
public static boolean isDeciDigit(String s){
int i = 0;
String s2 = "";

View File

@ -49,3 +49,26 @@ No-Captcha-Kick = false
#Kick user after this number of minutes has passed without captcha clear
#Due to the way the countdown works, the kick may not happen until at most one minute after
No-Captcha-Kick-Time = 10
#Messages with these unicode emotes will be removed
Block-Unicode-Emotes = baby,snake,squid
#Messages with these custom emotes will be removed
Block-Custom-Emotes = badfish,fix,bigleaf
#Disable these commands for ALL users
DisabledCommands = cmd1,cmd2,cmd3
#Disabled these commands for normal users
DisabledUserCommands = cmd4,cmd5,cmd6
#List your custom commands here. This line will always generate blank.
#Example - Custom-Command-Names = hello,botcheck,apple
Custom-Command-Names =
#Placeholder(s):
#<user> - Mentions the sender
#Setting up custom commands works like this:
#
#cc-hello-message = Hello, <user>!
#cc-hello-description = Greets the sender.