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

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

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;
@@ -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++) {