Emote filter, Chat filter improvements, Disable commands, and custom
commands
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -14,17 +16,17 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
public class HelpCommand extends ClientCommand {
|
||||
|
||||
public HelpCommand() {
|
||||
name = "Help";
|
||||
description = "Pulls up help menu";
|
||||
usage = PropertiesRetrieval.getCommandSignifier() + "help [Page #]";
|
||||
minArgs = 0;
|
||||
maxArgs = 1;
|
||||
identifiers.add("help");
|
||||
}
|
||||
name = "Help";
|
||||
description = "Pulls up help menu";
|
||||
usage = PropertiesRetrieval.getCommandSignifier() + "help [Page #]";
|
||||
minArgs = 0;
|
||||
maxArgs = 1;
|
||||
identifiers.add("help");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, MessageReceivedEvent event) {
|
||||
|
||||
|
||||
Biscuit biscuit = Main.getBiscuit();
|
||||
|
||||
int pg = 1;
|
||||
@@ -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++) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -72,5 +72,24 @@ public class PropertiesRetrieval {
|
||||
public static String[] getToggleRoles(){
|
||||
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(",");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
public static boolean filterWord(String word) {
|
||||
String[] match = findMatchPair(word);
|
||||
if(match != null) {
|
||||
return true;
|
||||
}
|
||||
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")){
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,15 @@ public class Util {
|
||||
public static boolean isDigit(String s){
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user