diff --git a/src/main/java/com/diamondfire/helpbot/HelpBot.java b/src/main/java/com/diamondfire/helpbot/HelpBot.java index ec980141..bba770ef 100644 --- a/src/main/java/com/diamondfire/helpbot/HelpBot.java +++ b/src/main/java/com/diamondfire/helpbot/HelpBot.java @@ -4,13 +4,16 @@ import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.df.codeinfo.codedatabase.changelog.CodeDifferenceHandler; import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.CodeDatabase; +import com.diamondfire.helpbot.sys.tag.TagHandler; import javax.security.auth.login.LoginException; +import java.io.IOException; public class HelpBot { - public static void main(String[] args) throws LoginException { + public static void main(String[] args) throws LoginException, IOException { CodeDatabase.initialize(); + TagHandler.cacheJson(); HelpBotInstance.initialize(); CodeDifferenceHandler.refresh(); } diff --git a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java index 4d573211..6a44cae5 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java +++ b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java @@ -2,12 +2,21 @@ import com.diamondfire.helpbot.bot.command.CommandHandler; import com.diamondfire.helpbot.bot.command.impl.codeblock.*; -import com.diamondfire.helpbot.bot.command.impl.other.*; +import com.diamondfire.helpbot.bot.command.impl.other.StoreCommand; +import com.diamondfire.helpbot.bot.command.impl.other.dev.*; +import com.diamondfire.helpbot.bot.command.impl.other.dumps.*; +import com.diamondfire.helpbot.bot.command.impl.other.fun.*; +import com.diamondfire.helpbot.bot.command.impl.other.info.*; +import com.diamondfire.helpbot.bot.command.impl.other.mod.*; +import com.diamondfire.helpbot.bot.command.impl.other.tag.TagCommand; +import com.diamondfire.helpbot.bot.command.impl.other.util.*; import com.diamondfire.helpbot.bot.command.impl.stats.*; import com.diamondfire.helpbot.bot.command.impl.stats.graph.*; import com.diamondfire.helpbot.bot.command.impl.stats.individualized.*; +import com.diamondfire.helpbot.bot.command.impl.stats.metrics.*; import com.diamondfire.helpbot.bot.command.impl.stats.plot.*; import com.diamondfire.helpbot.bot.command.impl.stats.support.*; +import com.diamondfire.helpbot.bot.command.impl.stats.top.*; import com.diamondfire.helpbot.bot.config.Config; import com.diamondfire.helpbot.bot.events.*; import com.diamondfire.helpbot.sys.tasks.TaskRegistry; @@ -117,7 +126,8 @@ public static void initialize() throws LoginException { new DailySessionsCommand(), new EightBallCommand(), new OcrCommand(), - new JoinsCommand() + new JoinsCommand(), + new TagCommand() ); JDABuilder builder = JDABuilder.createDefault(config.getToken()) diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/CommandHandler.java b/src/main/java/com/diamondfire/helpbot/bot/command/CommandHandler.java index f1b8db72..9f3a9e30 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/CommandHandler.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/CommandHandler.java @@ -1,6 +1,5 @@ package com.diamondfire.helpbot.bot.command; -import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.bot.command.disable.DisableCommandHandler; import com.diamondfire.helpbot.bot.command.executor.CommandExecutor; import com.diamondfire.helpbot.bot.command.impl.Command; @@ -44,8 +43,12 @@ public void register(Command... commands) { } + public void run(CommandEvent e, String[] args) { + COMMAND_EXECUTOR.run(e, args); + } + public void run(CommandEvent e) { - COMMAND_EXECUTOR.run(e); + run(e, e.getRawArgs()); } public HashMap getCommands() { diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/exceptions/ArgumentException.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/exceptions/ArgumentException.java index 513d87b4..b04f9379 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/exceptions/ArgumentException.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/exceptions/ArgumentException.java @@ -1,6 +1,8 @@ package com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions; -import com.diamondfire.helpbot.bot.command.impl.Command; +import com.diamondfire.helpbot.bot.HelpBotInstance; +import com.diamondfire.helpbot.bot.command.impl.*; +import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.util.FormatUtil; public class ArgumentException extends Exception { @@ -16,11 +18,17 @@ public String getEmbedMessage() { return message; } - public void setContext(Command command, int pos) { + public void setContext(Command command, int pos, CommandEvent event) { String[] args = FormatUtil.getArgumentDisplay(command.getHelpContext()); args[pos] = "**" + args[pos] + "**"; String argMessage = FormatUtil.displayCommand(command) + " " + String.join(" ", args); + if (command instanceof SubCommand) { + String prefix = HelpBotInstance.getConfig().getPrefix(); + + argMessage = event.getRawArgs()[0] + " " + argMessage.substring(prefix.length()); + } + message = argMessage + "\n\n" + getMessage(); } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/parser/AlternateArgumentParser.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/parser/AlternateArgumentParser.java index 0b7b0458..aa794e5b 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/parser/AlternateArgumentParser.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/parser/AlternateArgumentParser.java @@ -3,6 +3,7 @@ import com.diamondfire.helpbot.bot.command.argument.impl.parsing.*; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.*; +import com.diamondfire.helpbot.bot.events.CommandEvent; public class AlternateArgumentParser extends ArgumentParser, A> { @@ -11,10 +12,10 @@ public AlternateArgumentParser(AlternateArgumentContainer container) { } @Override - public ParsedArgument parse(String identifier, ArgumentStack.RawArgumentStack args) throws ArgumentException { + public ParsedArgument parse(String identifier, ArgumentStack.RawArgumentStack args, CommandEvent event) throws ArgumentException { for (ArgumentContainer container : getContainer().getAlternatives()) { try { - return new ParsedArgument<>(identifier, container.getParser().parse(identifier, args).getValue()); + return new ParsedArgument<>(identifier, container.getParser().parse(identifier, args, event).getValue()); } catch (ArgumentException ignored) { } } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/parser/ArgumentParser.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/parser/ArgumentParser.java index 4e6bce11..31b96766 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/parser/ArgumentParser.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/parser/ArgumentParser.java @@ -4,6 +4,7 @@ import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.ArgumentContainer; import com.diamondfire.helpbot.bot.command.impl.Command; +import com.diamondfire.helpbot.bot.events.CommandEvent; import java.util.*; @@ -16,7 +17,7 @@ public ArgumentParser(T container) { this.container = container; } - public static ParsedArgumentSet parseArgs(Command command, String[] args) throws ArgumentException { + public static ParsedArgumentSet parseArgs(Command command, String[] args, CommandEvent event) throws ArgumentException { Map> parsedArgs = new HashMap<>(); ArgumentStack stack = new ArgumentStack(command.getArguments().getArguments(), Arrays.asList(args)); int arguments = stack.getArguments().size(); @@ -28,17 +29,17 @@ public static ParsedArgumentSet parseArgs(Command command, String[] args) throws String identifier = argument.getIdentifier(); try { - parsedArgs.put(identifier, argumentContainer.getParser().parse(identifier, rawArguments)); + parsedArgs.put(identifier, argumentContainer.getParser().parse(identifier, rawArguments, event)); rawArguments.pushStack(); } catch (MissingArgumentException exception) { if (argumentContainer.isOptional()) { parsedArgs.put(identifier, new ParsedArgument<>(identifier, argumentContainer.getDefaultValue())); } else { - exception.setContext(command, i); + exception.setContext(command, i, event); throw exception; } } catch (MalformedArgumentException exception) { - exception.setContext(command, i); + exception.setContext(command, i, event); throw exception; } } @@ -46,7 +47,7 @@ public static ParsedArgumentSet parseArgs(Command command, String[] args) throws return new ParsedArgumentSet(parsedArgs); } - public abstract ParsedArgument parse(String identifier, ArgumentStack.RawArgumentStack args) throws ArgumentException; + public abstract ParsedArgument parse(String identifier, ArgumentStack.RawArgumentStack args, CommandEvent event) throws ArgumentException; protected T getContainer() { return container; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/parser/MultiArgumentParser.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/parser/MultiArgumentParser.java index 1da2a3b7..251ea868 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/parser/MultiArgumentParser.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/parser/MultiArgumentParser.java @@ -4,6 +4,7 @@ import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.MultiArgumentContainer; import com.diamondfire.helpbot.bot.command.argument.impl.types.Argument; +import com.diamondfire.helpbot.bot.events.CommandEvent; import java.util.*; @@ -14,7 +15,7 @@ public MultiArgumentParser(MultiArgumentContainer container) { } @Override - public ParsedArgument parse(String identifier, ArgumentStack.RawArgumentStack args) throws ArgumentException { + public ParsedArgument parse(String identifier, ArgumentStack.RawArgumentStack args, CommandEvent event) throws ArgumentException { Deque rawArgs = args.popStack(); List approvedArgumentValues = new ArrayList<>(); Argument arg = getContainer().getArgument(); @@ -22,7 +23,7 @@ public ParsedArgument parse(String identifier, ArgumentStack.RawArgumentStack for (int i = 0; i < arguments; i++) { try { - approvedArgumentValues.add(arg.parseValue(rawArgs)); + approvedArgumentValues.add(arg.parseValue(rawArgs, event)); } catch (Exception e) { break; } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/parser/SingleArgumentParser.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/parser/SingleArgumentParser.java index 287cff41..120f846f 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/parser/SingleArgumentParser.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/parser/SingleArgumentParser.java @@ -4,6 +4,7 @@ import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; import com.diamondfire.helpbot.bot.command.argument.impl.types.Argument; +import com.diamondfire.helpbot.bot.events.CommandEvent; import java.util.Deque; @@ -15,7 +16,7 @@ public SingleArgumentParser(SingleArgumentContainer container) { } @Override - public ParsedArgument parse(String identifier, ArgumentStack.RawArgumentStack args) throws ArgumentException { + public ParsedArgument parse(String identifier, ArgumentStack.RawArgumentStack args, CommandEvent event) throws ArgumentException { Deque rawArgs = args.popStack(); Argument arg = getContainer().getArgument(); @@ -23,6 +24,6 @@ public ParsedArgument parse(String identifier, ArgumentStack.RawArgumentStack throw new MissingArgumentException("Expected an argument, but got nothing."); } - return new ParsedArgument<>(identifier, arg.parseValue(rawArgs)); + return new ParsedArgument<>(identifier, arg.parseValue(rawArgs, event)); } } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/types/MessageArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/types/MessageArgument.java index fc6adeb6..45087da0 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/types/MessageArgument.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/types/MessageArgument.java @@ -2,6 +2,7 @@ import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException; import com.diamondfire.helpbot.bot.command.argument.impl.types.Argument; +import com.diamondfire.helpbot.bot.events.CommandEvent; import org.jetbrains.annotations.NotNull; import java.util.Deque; @@ -9,7 +10,7 @@ public class MessageArgument implements Argument { @Override - public String parseValue(@NotNull Deque args) throws ArgumentException { + public String parseValue(@NotNull Deque args, CommandEvent event) throws ArgumentException { return String.join(" ", args); } } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/AbstractOffsetArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/AbstractOffsetArgument.java index ebbe6db7..00b1dbb3 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/AbstractOffsetArgument.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/AbstractOffsetArgument.java @@ -1,6 +1,7 @@ package com.diamondfire.helpbot.bot.command.argument.impl.types; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; +import com.diamondfire.helpbot.bot.events.CommandEvent; import org.jetbrains.annotations.NotNull; import java.util.*; @@ -18,7 +19,7 @@ public AbstractOffsetArgument(boolean reverse) { } @Override - protected Date parse(@NotNull String argument) throws ArgumentException { + protected Date parse(@NotNull String argument, CommandEvent event) throws ArgumentException { Calendar calendar = Calendar.getInstance(); int offset = 0; boolean modified = false; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/AbstractSimpleValueArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/AbstractSimpleValueArgument.java index dcb81ec5..14ca00d8 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/AbstractSimpleValueArgument.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/AbstractSimpleValueArgument.java @@ -1,6 +1,7 @@ package com.diamondfire.helpbot.bot.command.argument.impl.types; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException; +import com.diamondfire.helpbot.bot.events.CommandEvent; import org.jetbrains.annotations.NotNull; import java.util.Deque; @@ -8,10 +9,10 @@ public abstract class AbstractSimpleValueArgument implements Argument { @Override - public T parseValue(@NotNull Deque args) throws ArgumentException { - return parse(args.pop()); + public T parseValue(@NotNull Deque args, CommandEvent event) throws ArgumentException { + return parse(args.pop(), event); } - protected abstract T parse(@NotNull String argument) throws ArgumentException; + protected abstract T parse(@NotNull String argument, CommandEvent event) throws ArgumentException; } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/Argument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/Argument.java index b6f671e4..d7ac58f1 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/Argument.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/Argument.java @@ -2,6 +2,7 @@ import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException; +import com.diamondfire.helpbot.bot.events.CommandEvent; import org.jetbrains.annotations.NotNull; import java.util.Deque; @@ -14,7 +15,7 @@ */ public interface Argument { - T parseValue(@NotNull Deque args) throws ArgumentException; + T parseValue(@NotNull Deque args, CommandEvent event) throws ArgumentException; } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/ClampedIntegerArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/ClampedIntegerArgument.java index 8ef2ceea..79f496a7 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/ClampedIntegerArgument.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/ClampedIntegerArgument.java @@ -1,6 +1,7 @@ package com.diamondfire.helpbot.bot.command.argument.impl.types; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException; +import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.util.Util; import org.jetbrains.annotations.NotNull; @@ -20,8 +21,8 @@ public ClampedIntegerArgument(int min, int max) { } @Override - public Integer parse(@NotNull String msg) throws ArgumentException { - int num = super.parse(msg); + public Integer parse(@NotNull String msg, CommandEvent event) throws ArgumentException { + int num = super.parse(msg, event); if (num <= max && num >= min) { return num; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DateArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DateArgument.java index 815fdae6..c50c699f 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DateArgument.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DateArgument.java @@ -1,6 +1,7 @@ package com.diamondfire.helpbot.bot.command.argument.impl.types; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; +import com.diamondfire.helpbot.bot.events.CommandEvent; import org.jetbrains.annotations.NotNull; import java.text.*; @@ -19,7 +20,7 @@ public DateArgument(String format) { } @Override - public Date parse(@NotNull String msg) throws ArgumentException { + public Date parse(@NotNull String msg, CommandEvent event) throws ArgumentException { try { return format.parse(msg); } catch (ParseException parseException) { diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DefinedObjectArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DefinedObjectArgument.java index f22b5991..c06d463d 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DefinedObjectArgument.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DefinedObjectArgument.java @@ -2,6 +2,7 @@ import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; +import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.util.JaroWinkler; import org.jetbrains.annotations.NotNull; @@ -26,7 +27,7 @@ public DefinedObjectArgument(boolean trailing, @NotNull T... options) { } @Override - public T parseValue(@NotNull Deque args) throws ArgumentException { + public T parseValue(@NotNull Deque args, CommandEvent event) throws ArgumentException { String compareString; if (trailing) { compareString = String.join(" ", args); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DiscordUserArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DiscordUserArgument.java index 85bce2e9..b0eef190 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DiscordUserArgument.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DiscordUserArgument.java @@ -1,6 +1,7 @@ package com.diamondfire.helpbot.bot.command.argument.impl.types; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.MalformedArgumentException; +import com.diamondfire.helpbot.bot.events.CommandEvent; import net.dv8tion.jda.api.utils.MiscUtil; import org.jetbrains.annotations.NotNull; @@ -11,7 +12,7 @@ public class DiscordUserArgument extends AbstractSimpleValueArgument { private final Pattern pattern = Pattern.compile("<@!?(\\d+)>"); @Override - public Long parse(@NotNull String msg) throws MalformedArgumentException { + public Long parse(@NotNull String msg, CommandEvent event) throws MalformedArgumentException { try { return Long.parseLong(msg); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/IntegerArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/IntegerArgument.java index d30b42a4..c2061cfe 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/IntegerArgument.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/IntegerArgument.java @@ -1,12 +1,13 @@ package com.diamondfire.helpbot.bot.command.argument.impl.types; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; +import com.diamondfire.helpbot.bot.events.CommandEvent; import org.jetbrains.annotations.NotNull; public class IntegerArgument extends AbstractSimpleValueArgument { @Override - public Integer parse(@NotNull String msg) throws ArgumentException { + public Integer parse(@NotNull String msg, CommandEvent event) throws ArgumentException { try { return Integer.parseInt(msg); } catch (NumberFormatException exception) { diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/LongArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/LongArgument.java index dad4cc9c..3be8d19d 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/LongArgument.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/LongArgument.java @@ -1,12 +1,13 @@ package com.diamondfire.helpbot.bot.command.argument.impl.types; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException; +import com.diamondfire.helpbot.bot.events.CommandEvent; import org.jetbrains.annotations.NotNull; public class LongArgument extends AbstractSimpleValueArgument{ @Override - protected Long parse(@NotNull String argument) throws ArgumentException { + protected Long parse(@NotNull String argument, CommandEvent event) throws ArgumentException { return Long.parseLong(argument); } } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/MinecraftPlayerUUIDArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/MinecraftPlayerUUIDArgument.java index 30802910..035d735e 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/MinecraftPlayerUUIDArgument.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/MinecraftPlayerUUIDArgument.java @@ -2,6 +2,7 @@ import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException; +import com.diamondfire.helpbot.bot.events.CommandEvent; import com.google.gson.*; import okhttp3.*; import org.jetbrains.annotations.NotNull; @@ -12,7 +13,7 @@ public class MinecraftPlayerUUIDArgument extends AbstractSimpleValueArgument { @Override - protected UUID parse(@NotNull String argument) throws ArgumentException { + protected UUID parse(@NotNull String argument, CommandEvent event) throws ArgumentException { if (argument.contains("-") || argument.length() > 16) { return UUID.fromString(argument); } else { diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/StringArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/StringArgument.java index a50da829..e8b56065 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/StringArgument.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/StringArgument.java @@ -1,11 +1,12 @@ package com.diamondfire.helpbot.bot.command.argument.impl.types; +import com.diamondfire.helpbot.bot.events.CommandEvent; import org.jetbrains.annotations.NotNull; public class StringArgument extends AbstractSimpleValueArgument { @Override - public String parse(@NotNull String msg) { + public String parse(@NotNull String msg, CommandEvent event) { return msg; } } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/SubCommandArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/SubCommandArgument.java new file mode 100644 index 00000000..c4153ea2 --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/SubCommandArgument.java @@ -0,0 +1,24 @@ +package com.diamondfire.helpbot.bot.command.argument.impl.types; + +import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; +import com.diamondfire.helpbot.bot.command.impl.*; +import com.diamondfire.helpbot.bot.events.CommandEvent; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.stream.Collectors; + +public class SubCommandArgument extends AbstractSimpleValueArgument { + + @Override + public SubCommand parse(@NotNull String msg, CommandEvent event) throws ArgumentException { + try { + return Arrays.stream(((SubCommandHolder) event.getCommand()).getSubCommands()) + .filter(s -> s.getName().equals(msg)).collect(Collectors.toList()).get(0); + } catch (IndexOutOfBoundsException e) { + throw new MalformedArgumentException( + "Not a valid subcommand. Choose from " + event.getCommand().getHelpContext().getArguments().get(0).getArgumentName()); + } + } + +} diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/executor/CommandExecutor.java b/src/main/java/com/diamondfire/helpbot/bot/command/executor/CommandExecutor.java index 4d4d099b..72a1b4af 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/executor/CommandExecutor.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/executor/CommandExecutor.java @@ -19,10 +19,10 @@ public class CommandExecutor { new MutedCheck(), new DisabledCheck(), new PermissionCheck(), - new CommandLog(), + new CommandLog() }; - public void run(CommandEvent e) { + public void run(CommandEvent e, String[] args) { Command command = e.getCommand(); if (command == null) { return; @@ -38,7 +38,7 @@ public void run(CommandEvent e) { } } - e.pushArguments(e.getMessage().getContentRaw().split(" ")); + e.pushArguments(args); command.run(e); } catch (ArgumentException exception) { builder.withPreset( diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/executor/checks/DisabledCheck.java b/src/main/java/com/diamondfire/helpbot/bot/command/executor/checks/DisabledCheck.java index f0351920..8f43e4d9 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/executor/checks/DisabledCheck.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/executor/checks/DisabledCheck.java @@ -1,6 +1,5 @@ package com.diamondfire.helpbot.bot.command.executor.checks; -import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.bot.command.CommandHandler; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/executor/checks/MutedCheck.java b/src/main/java/com/diamondfire/helpbot/bot/command/executor/checks/MutedCheck.java index 1352b30a..fd88cc76 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/executor/checks/MutedCheck.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/executor/checks/MutedCheck.java @@ -1,6 +1,6 @@ package com.diamondfire.helpbot.bot.command.executor.checks; -import com.diamondfire.helpbot.bot.command.impl.other.MuteCommand; +import com.diamondfire.helpbot.bot.command.impl.other.mod.MuteCommand; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.events.CommandEvent; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/SubCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/SubCommand.java new file mode 100644 index 00000000..52771daa --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/SubCommand.java @@ -0,0 +1,4 @@ +package com.diamondfire.helpbot.bot.command.impl; + +public abstract class SubCommand extends Command { +} diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/SubCommandHolder.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/SubCommandHolder.java new file mode 100644 index 00000000..babcf0a8 --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/SubCommandHolder.java @@ -0,0 +1,35 @@ +package com.diamondfire.helpbot.bot.command.impl; + +import com.diamondfire.helpbot.bot.HelpBotInstance; +import com.diamondfire.helpbot.bot.command.CommandHandler; +import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; +import com.diamondfire.helpbot.bot.command.argument.impl.types.SubCommandArgument; +import com.diamondfire.helpbot.bot.events.CommandEvent; + +import java.util.*; + +public abstract class SubCommandHolder extends Command { + + @Override + public ArgumentSet compileArguments() { + return new ArgumentSet().addArgument( + "subcommand", new SubCommandArgument() + ); + } + + @Override + public void run(CommandEvent event) { + SubCommand subcommand = event.getArgument("subcommand"); + event.setCommand(subcommand); + + String[] rawArgs = event.getRawArgs(); + rawArgs[0] = rawArgs[0].substring(HelpBotInstance.getConfig().getPrefix().length()); + + List args = new ArrayList<>(Arrays.asList(rawArgs)); + args.remove(1); + + CommandHandler.getInstance().run(event, args.toArray(String[]::new)); + } + + public abstract SubCommand[] getSubCommands(); +} diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/TagsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/TagsCommand.java index 32edad71..f57dd592 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/TagsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/TagsCommand.java @@ -77,7 +77,7 @@ public String getName() { @Override public String[] getAliases() { - return new String[]{"codetags", "tag"}; + return new String[]{"codetags"}; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/DisableCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/DisableCommand.java similarity index 95% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/DisableCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/DisableCommand.java index 8e47af31..02b56f26 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/DisableCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/DisableCommand.java @@ -1,6 +1,5 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.dev; -import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.bot.command.CommandHandler; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.types.StringArgument; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/EnableCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/EnableCommand.java similarity index 95% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/EnableCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/EnableCommand.java index 42ab8d50..8e64b32a 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/EnableCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/EnableCommand.java @@ -1,6 +1,5 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.dev; -import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.bot.command.CommandHandler; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.types.StringArgument; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/EvalCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/EvalCommand.java similarity index 89% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/EvalCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/EvalCommand.java index 1f06305e..8d23dae3 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/EvalCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/EvalCommand.java @@ -1,22 +1,18 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.dev; import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.MessageArgument; -import com.diamondfire.helpbot.bot.command.help.CommandCategory; -import com.diamondfire.helpbot.bot.command.help.HelpContext; -import com.diamondfire.helpbot.bot.command.help.HelpContextArgument; +import com.diamondfire.helpbot.bot.command.help.*; import com.diamondfire.helpbot.bot.command.impl.Command; import com.diamondfire.helpbot.bot.command.permissions.Permission; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.util.EmbedUtil; import net.dv8tion.jda.api.EmbedBuilder; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; +import javax.script.*; import java.awt.*; -import java.io.PrintWriter; -import java.io.StringWriter; +import java.io.*; import java.util.List; import java.util.stream.Collectors; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/FetchDataCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/FetchDataCommand.java similarity index 99% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/FetchDataCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/FetchDataCommand.java index f8b02db6..b1497b7b 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/FetchDataCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/FetchDataCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.dev; import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/QueryCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/QueryCommand.java similarity index 98% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/QueryCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/QueryCommand.java index d0b8febd..848ee77f 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/QueryCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/QueryCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.dev; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.MessageArgument; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/RestartCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/RestartCommand.java similarity index 96% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/RestartCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/RestartCommand.java index 008d3e2f..4a54dcf4 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/RestartCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/RestartCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.dev; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.help.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/ActionDumpCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ActionDumpCommand.java similarity index 94% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/ActionDumpCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ActionDumpCommand.java index f15f4d00..1e48bcd0 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/ActionDumpCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ActionDumpCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.dumps; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.help.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/ImageDumpCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ImageDumpCommand.java similarity index 97% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/ImageDumpCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ImageDumpCommand.java index 2e8281d4..4c333d50 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/ImageDumpCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ImageDumpCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.dumps; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.help.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SoundListCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/SoundListCommand.java similarity index 86% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SoundListCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/SoundListCommand.java index 0099754c..c740c18f 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SoundListCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/SoundListCommand.java @@ -1,6 +1,7 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.dumps; import com.diamondfire.helpbot.bot.command.help.*; +import com.diamondfire.helpbot.bot.command.impl.other.util.AbstractFileListCommand; import com.diamondfire.helpbot.bot.command.permissions.Permission; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.CodeDatabase; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/EightBallCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/EightBallCommand.java similarity index 97% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/EightBallCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/EightBallCommand.java index b45242ba..52ed829e 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/EightBallCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/EightBallCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.fun; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/GarfieldCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/GarfieldCommand.java similarity index 97% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/GarfieldCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/GarfieldCommand.java index 441c3f68..00a50e08 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/GarfieldCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/GarfieldCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.fun; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.help.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/IdeaCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/IdeaCommand.java similarity index 99% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/IdeaCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/IdeaCommand.java index c8144dbd..ab0280d8 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/IdeaCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/IdeaCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.fun; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.help.*; @@ -6,6 +6,7 @@ import com.diamondfire.helpbot.bot.command.permissions.Permission; import com.diamondfire.helpbot.bot.events.CommandEvent; import net.dv8tion.jda.api.EmbedBuilder; + import java.util.Random; public class IdeaCommand extends Command { diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/NbsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/NbsCommand.java similarity index 91% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/NbsCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/NbsCommand.java index 5da1bebe..b18ca2f9 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/NbsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/NbsCommand.java @@ -1,26 +1,21 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.fun; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; -import com.diamondfire.helpbot.bot.command.help.CommandCategory; -import com.diamondfire.helpbot.bot.command.help.HelpContext; +import com.diamondfire.helpbot.bot.command.help.*; import com.diamondfire.helpbot.bot.command.impl.Command; import com.diamondfire.helpbot.bot.command.permissions.Permission; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; -import com.diamondfire.helpbot.bot.command.reply.feature.informative.InformativeReply; -import com.diamondfire.helpbot.bot.command.reply.feature.informative.InformativeReplyType; +import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.util.nbs.*; -import com.google.gson.Gson; -import com.google.gson.JsonObject; +import com.google.gson.*; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.*; import java.awt.*; import java.io.*; import java.net.*; import java.nio.charset.StandardCharsets; - import java.util.Scanner; public class NbsCommand extends Command { diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/OcrCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/OcrCommand.java similarity index 97% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/OcrCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/OcrCommand.java index d38c9dbb..1f9f5b7b 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/OcrCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/OcrCommand.java @@ -1,6 +1,5 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.fun; -import com.diamondfire.helpbot.HelpBot; import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/SamQuotesCommand.java similarity index 99% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/SamQuotesCommand.java index a262587b..0928c27e 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/SamQuotesCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.fun; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/HelpCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/HelpCommand.java similarity index 98% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/HelpCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/HelpCommand.java index 63df0137..d027f00b 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/HelpCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/HelpCommand.java @@ -1,6 +1,5 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.info; -import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.bot.command.CommandHandler; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/InfoCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/InfoCommand.java similarity index 97% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/InfoCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/InfoCommand.java index 2c41ec27..672fecdf 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/InfoCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/InfoCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.info; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.help.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/PermUnlocksCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/PermUnlocksCommand.java similarity index 96% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/PermUnlocksCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/PermUnlocksCommand.java index a7c5d9f3..cf0c418f 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/PermUnlocksCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/PermUnlocksCommand.java @@ -1,6 +1,5 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.info; -import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.bot.command.CommandHandler; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.types.DefinedObjectArgument; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/PolicyCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/PolicyCommand.java similarity index 97% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/PolicyCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/PolicyCommand.java index bffca2c7..6f24423a 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/PolicyCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/PolicyCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.info; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.help.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/RulesCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/RulesCommand.java similarity index 99% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/RulesCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/RulesCommand.java index 037d388a..c9743aaa 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/RulesCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/RulesCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.info; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.help.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/ChannelMuteCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/ChannelMuteCommand.java similarity index 98% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/ChannelMuteCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/ChannelMuteCommand.java index 9fd41661..207d2b3a 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/ChannelMuteCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/ChannelMuteCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.mod; import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/DiscussionMuteCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/DiscussionMuteCommand.java similarity index 98% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/DiscussionMuteCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/DiscussionMuteCommand.java index ec3118e8..610af367 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/DiscussionMuteCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/DiscussionMuteCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.mod; import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/MuteCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/MuteCommand.java similarity index 98% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/MuteCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/MuteCommand.java index 8f5a7483..b616d6d9 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/MuteCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/MuteCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.mod; import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/MutedCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/MutedCommand.java similarity index 97% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/MutedCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/MutedCommand.java index 72a5be77..580030d4 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/MutedCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/MutedCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.mod; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.help.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/UnmuteCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/UnmuteCommand.java similarity index 98% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/UnmuteCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/UnmuteCommand.java index 3f172237..fa2fc488 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/UnmuteCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/UnmuteCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.mod; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/VerifyCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/VerifyCommand.java similarity index 98% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/VerifyCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/VerifyCommand.java index af75980b..a0c46702 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/VerifyCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/VerifyCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.mod; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.types.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/tag/AddTagSubCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/tag/AddTagSubCommand.java new file mode 100644 index 00000000..6597ed6b --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/tag/AddTagSubCommand.java @@ -0,0 +1,86 @@ +package com.diamondfire.helpbot.bot.command.impl.other.tag; + +import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; +import com.diamondfire.helpbot.bot.command.argument.impl.types.StringArgument; +import com.diamondfire.helpbot.bot.command.help.*; +import com.diamondfire.helpbot.bot.command.impl.SubCommand; +import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; +import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; +import com.diamondfire.helpbot.bot.events.CommandEvent; +import com.diamondfire.helpbot.sys.tag.*; + +import java.io.IOException; +import java.util.*; + +public class AddTagSubCommand extends SubCommand { + + @Override + public String getName() { + return "add"; + } + + @Override + public HelpContext getHelpContext() { + return new HelpContext() + .addArgument( + new HelpContextArgument() + .name("activator"), + new HelpContextArgument() + .name("title"), + new HelpContextArgument() + .name("response") + ); + } + + @Override + protected ArgumentSet compileArguments() { + return new ArgumentSet().addArgument( + "activator", new StringArgument() + ).addArgument( + "title", new StringArgument() + ).addArgument( + "response", new StringArgument() + ); + } + + @Override + public Permission getPermission() { + return Permission.EXPERT; + } + + @Override + public void run(CommandEvent event) { + // Get new activator and title + String activator = event.getArgument("activator"); + String title = event.getArgument("title"); + title = title.replaceAll("%space%", " "); + + // Get response + List splitArgs = new LinkedList<>(Arrays.asList(event.getMessage().getContentRaw() + .split(" +"))); + String response = String.join(" ", splitArgs.subList(4, splitArgs.size())); + + // Construct Tag + Tag tag = new Tag(activator, title, response, event.getAuthor().getIdLong(), ""); + + try { + TagHandler.newTag(tag); + PresetBuilder preset = new PresetBuilder() + .withPreset( + new InformativeReply(InformativeReplyType.SUCCESS, "Success", "Successfully added a new tag.") + ); + event.reply(preset); + + } catch (TagAlreadyExistsException | IOException err) { + PresetBuilder preset = new PresetBuilder() + .withPreset( + new InformativeReply(InformativeReplyType.ERROR, err.getMessage()) + ); + event.reply(preset); + } + } + +} + + diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/tag/EditTagSubCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/tag/EditTagSubCommand.java new file mode 100644 index 00000000..8a615fcb --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/tag/EditTagSubCommand.java @@ -0,0 +1,95 @@ +package com.diamondfire.helpbot.bot.command.impl.other.tag; + +import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; +import com.diamondfire.helpbot.bot.command.argument.impl.types.StringArgument; +import com.diamondfire.helpbot.bot.command.help.*; +import com.diamondfire.helpbot.bot.command.impl.SubCommand; +import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; +import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; +import com.diamondfire.helpbot.bot.events.CommandEvent; +import com.diamondfire.helpbot.sys.tag.*; + +import java.io.IOException; +import java.util.*; + +public class EditTagSubCommand extends SubCommand { + + @Override + public String getName() { + return "edit"; + } + + @Override + public HelpContext getHelpContext() { + return new HelpContext() + .addArgument( + new HelpContextArgument() + .name("activator"), + new HelpContextArgument() + .name("property") + ); + } + + @Override + protected ArgumentSet compileArguments() { + return new ArgumentSet().addArgument( + "activator", new StringArgument() + ).addArgument( + "property", new StringArgument() + ); + } + + @Override + public Permission getPermission() { + return Permission.EXPERT; + } + + @Override + public void run(CommandEvent event) { + // Get activator and property + String activator = event.getArgument("activator"); + String prop = event.getArgument("property"); + + // Check if property is valid + TagProperty property = TagProperty.getByProperty(prop); + if (property == null || !property.isModifiable()) { + PresetBuilder preset = new PresetBuilder() + .withPreset( + new InformativeReply(InformativeReplyType.ERROR, + "This is not a valid property. Choose from: `activator`, `title`, `response`, `image`") + ); + event.reply(preset); + return; + } + + // Get new value + List splitArgs = new LinkedList<>(Arrays.asList(event.getMessage().getContentRaw() + .split(" +"))); + String newValue = String.join(" ", splitArgs.subList(4, splitArgs.size())); + if (property == TagProperty.IMAGE && newValue.equals("none")) newValue = ""; + + try { + Tag tag = TagHandler.getTag(activator); + property.edit(tag, newValue); + TagHandler.saveToJson(); + + PresetBuilder preset = new PresetBuilder() + .withPreset( + new InformativeReply(InformativeReplyType.SUCCESS, "Successfully modified tag.") + ); + event.reply(preset); + + } catch (TagDoesntExistException | IOException err) { + PresetBuilder preset = new PresetBuilder() + .withPreset( + new InformativeReply(InformativeReplyType.ERROR, err.getMessage()) + ); + event.reply(preset); + err.printStackTrace(); + } + } + +} + + diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/tag/ListTagsSubCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/tag/ListTagsSubCommand.java new file mode 100644 index 00000000..fed351bf --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/tag/ListTagsSubCommand.java @@ -0,0 +1,67 @@ +package com.diamondfire.helpbot.bot.command.impl.other.tag; + +import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; +import com.diamondfire.helpbot.bot.command.help.HelpContext; +import com.diamondfire.helpbot.bot.command.impl.SubCommand; +import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; +import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; +import com.diamondfire.helpbot.bot.events.CommandEvent; +import com.diamondfire.helpbot.sys.tag.*; + +import java.io.IOException; +import java.util.List; + +public class ListTagsSubCommand extends SubCommand { + + @Override + public String getName() { + return "list"; + } + + @Override + public HelpContext getHelpContext() { + return new HelpContext(); + } + + @Override + protected ArgumentSet compileArguments() { + return new ArgumentSet(); + } + + @Override + public Permission getPermission() { + return Permission.USER; + } + + @Override + public void run(CommandEvent event) { + try { + List tags = TagHandler.getTags(); + String string = ""; + + if (tags.size() == 0) { + string = "*None*"; + + } else { + for (Tag tag : tags) { + string += "`" + tag.getActivator() + "` "; + } + } + + PresetBuilder preset = new PresetBuilder() + .withPreset( + new InformativeReply(InformativeReplyType.INFO, "Tags", + "A list of all custom command tags added.\n\n"+string) + ); + + event.reply(preset); + + } catch (IOException e) { + e.printStackTrace(); + } + } + +} + + diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/tag/RemoveTagSubCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/tag/RemoveTagSubCommand.java new file mode 100644 index 00000000..6511d6f9 --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/tag/RemoveTagSubCommand.java @@ -0,0 +1,70 @@ +package com.diamondfire.helpbot.bot.command.impl.other.tag; + +import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; +import com.diamondfire.helpbot.bot.command.argument.impl.types.StringArgument; +import com.diamondfire.helpbot.bot.command.help.*; +import com.diamondfire.helpbot.bot.command.impl.SubCommand; +import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; +import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; +import com.diamondfire.helpbot.bot.events.CommandEvent; +import com.diamondfire.helpbot.sys.tag.*; + +import java.io.IOException; + +public class RemoveTagSubCommand extends SubCommand { + + @Override + public String getName() { + return "remove"; + } + + @Override + public HelpContext getHelpContext() { + return new HelpContext() + .addArgument( + new HelpContextArgument() + .name("activator") + ); + } + + @Override + protected ArgumentSet compileArguments() { + return new ArgumentSet() + .addArgument( + "activator", new StringArgument() + ); + } + + @Override + public Permission getPermission() { + return Permission.EXPERT; + } + + @Override + public void run(CommandEvent event) { + // Get activator + String activator = event.getArgument("activator"); + + try { + TagHandler.deleteTag(activator); + PresetBuilder preset = new PresetBuilder() + .withPreset( + new InformativeReply(InformativeReplyType.SUCCESS, + "Successfully deleted tag with activator `"+activator+"`.") + ); + event.reply(preset); + + } catch (TagDoesntExistException | IOException err) { + PresetBuilder preset = new PresetBuilder() + .withPreset( + new InformativeReply(InformativeReplyType.ERROR, + err.getMessage()) + ); + event.reply(preset); + } + } + +} + + diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/tag/TagCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/tag/TagCommand.java new file mode 100644 index 00000000..70d16cb4 --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/tag/TagCommand.java @@ -0,0 +1,45 @@ +package com.diamondfire.helpbot.bot.command.impl.other.tag; + +import com.diamondfire.helpbot.bot.command.help.*; +import com.diamondfire.helpbot.bot.command.impl.*; +import com.diamondfire.helpbot.bot.command.permissions.Permission; + +public class TagCommand extends SubCommandHolder { + + @Override + public String getName() { + return "tag"; + } + + @Override + public HelpContext getHelpContext() { + return new HelpContext() + .description("Controls custom command tags. Notes:\n- New: Use \"%space%\" in the title for spaces."+ + "\n- Edit: Use \"none\" for image to remove the image.") + .category(CommandCategory.OTHER) + .addArgument( + new HelpContextArgument() + .name("add/edit/remove/list"), + new HelpContextArgument() + .name("...") + .optional() + ); + } + + @Override + public Permission getPermission() { + return Permission.USER; + } + + @Override + public SubCommand[] getSubCommands() { + return new SubCommand[]{ + new AddTagSubCommand(), + new EditTagSubCommand(), + new RemoveTagSubCommand(), + new ListTagsSubCommand() + }; + } +} + + diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/AbstractFileListCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/AbstractFileListCommand.java similarity index 96% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/AbstractFileListCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/AbstractFileListCommand.java index 0ce9c7f8..c327a46d 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/AbstractFileListCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/AbstractFileListCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.util; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.impl.Command; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/BulkExecuteCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/BulkExecuteCommand.java similarity index 96% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/BulkExecuteCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/BulkExecuteCommand.java index 38792e17..5f57a99b 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/BulkExecuteCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/BulkExecuteCommand.java @@ -1,6 +1,5 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.util; -import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.bot.command.CommandHandler; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.MultiArgumentContainer; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/MimicCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/MimicCommand.java similarity index 95% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/MimicCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/MimicCommand.java index 5580d8a6..77188ff3 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/MimicCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/MimicCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.util; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.MessageArgument; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/PollCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/PollCommand.java similarity index 98% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/other/PollCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/PollCommand.java index 7a9cef95..5410690e 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/PollCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/PollCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.other; +package com.diamondfire.helpbot.bot.command.impl.other.util; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.MessageArgument; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/BoostersCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/BoostersCommand.java index f1a84c73..a8dd705d 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/BoostersCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/BoostersCommand.java @@ -9,15 +9,14 @@ import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; -import com.diamondfire.helpbot.util.FormatUtil; -import com.diamondfire.helpbot.util.Util; +import com.diamondfire.helpbot.util.*; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Emote; import java.sql.ResultSet; public class BoostersCommand extends Command { - private static long[] emotes = new long[]{809172442957217812L, 809172442496630815L}; + private static final long[] emotes = new long[]{809172442957217812L, 809172442496630815L}; @Override public String getName() { diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/graph/AbstractGraphCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/graph/AbstractGraphCommand.java index ca7aea34..2e868836 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/graph/AbstractGraphCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/graph/AbstractGraphCommand.java @@ -6,7 +6,6 @@ import com.diamondfire.helpbot.bot.command.permissions.Permission; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.graph.generators.*; -import com.diamondfire.helpbot.sys.graph.generators.context.TimeGraphContext; public abstract class AbstractGraphCommand extends Command { diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/LastJoinedCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/LastJoinedCommand.java index a7aa9605..fb82a4fe 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/LastJoinedCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/LastJoinedCommand.java @@ -14,7 +14,6 @@ import java.sql.*; import java.time.temporal.ChronoUnit; -import java.util.concurrent.TimeUnit; public class LastJoinedCommand extends AbstractPlayerUUIDCommand { diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/JoinDataCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinDataCommand.java similarity index 99% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/JoinDataCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinDataCommand.java index 626f414c..c1070e35 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/JoinDataCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinDataCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.stats; +package com.diamondfire.helpbot.bot.command.impl.stats.metrics; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/JoinsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinsCommand.java similarity index 94% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/JoinsCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinsCommand.java index 983c5b53..b4bf73ba 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/JoinsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinsCommand.java @@ -1,48 +1,48 @@ -package com.diamondfire.helpbot.bot.command.impl.stats; - -import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; -import com.diamondfire.helpbot.bot.command.help.*; -import com.diamondfire.helpbot.bot.command.impl.Command; -import com.diamondfire.helpbot.bot.command.permissions.Permission; -import com.diamondfire.helpbot.bot.events.CommandEvent; -import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; -import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; -import com.diamondfire.helpbot.util.FormatUtil; -import net.dv8tion.jda.api.EmbedBuilder; - -public class JoinsCommand extends Command { - - @Override - public String getName() { return "joins"; } - - @Override - public HelpContext getHelpContext() { - return new HelpContext() - .description("Shows the total amount of unique players that have joined DiamondFire before.") - .category(CommandCategory.GENERAL_STATS); - } - - @Override - public ArgumentSet compileArguments() { return new ArgumentSet(); } - - @Override - public Permission getPermission() { return Permission.USER; } - - @Override - public void run(CommandEvent event) { - EmbedBuilder builder = new EmbedBuilder(); - - builder.setTitle("Total Joins"); - - // gets the total amount of players that have joined before - new DatabaseQuery() - .query(new BasicQuery("SELECT COUNT(*) AS count FROM players")) - .compile() - .run((result) -> { - String count = FormatUtil.formatNumber(result.getResult().getInt("count")); - builder.setDescription(String.format("A total of %s players have joined DiamondFire before!", count)); - }); - - event.getChannel().sendMessage(builder.build()).queue(); - } -} +package com.diamondfire.helpbot.bot.command.impl.stats.metrics; + +import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; +import com.diamondfire.helpbot.bot.command.help.*; +import com.diamondfire.helpbot.bot.command.impl.Command; +import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.events.CommandEvent; +import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; +import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; +import com.diamondfire.helpbot.util.FormatUtil; +import net.dv8tion.jda.api.EmbedBuilder; + +public class JoinsCommand extends Command { + + @Override + public String getName() { return "joins"; } + + @Override + public HelpContext getHelpContext() { + return new HelpContext() + .description("Shows the total amount of unique players that have joined DiamondFire before.") + .category(CommandCategory.GENERAL_STATS); + } + + @Override + public ArgumentSet compileArguments() { return new ArgumentSet(); } + + @Override + public Permission getPermission() { return Permission.USER; } + + @Override + public void run(CommandEvent event) { + EmbedBuilder builder = new EmbedBuilder(); + + builder.setTitle("Total Joins"); + + // gets the total amount of players that have joined before + new DatabaseQuery() + .query(new BasicQuery("SELECT COUNT(*) AS count FROM players")) + .compile() + .run((result) -> { + String count = FormatUtil.formatNumber(result.getResult().getInt("count")); + builder.setDescription(String.format("A total of %s players have joined DiamondFire before!", count)); + }); + + event.getChannel().sendMessage(builder.build()).queue(); + } +} diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/NewPlayersCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/NewPlayersCommand.java similarity index 97% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/NewPlayersCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/NewPlayersCommand.java index c39cae10..f221c26a 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/NewPlayersCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/NewPlayersCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.stats; +package com.diamondfire.helpbot.bot.command.impl.stats.metrics; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.help.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/PlayersCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/PlayersCommand.java similarity index 97% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/PlayersCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/PlayersCommand.java index bc4e3bb4..02ef9dfc 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/PlayersCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/PlayersCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.stats; +package com.diamondfire.helpbot.bot.command.impl.stats.metrics; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.help.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/QueueCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/QueueCommand.java similarity index 97% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/QueueCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/QueueCommand.java index 3a1302f9..cf8dbed0 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/QueueCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/QueueCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.stats; +package com.diamondfire.helpbot.bot.command.impl.stats.support; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.help.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SessionsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SessionsCommand.java index b5781ca4..0e76bf03 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SessionsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SessionsCommand.java @@ -27,7 +27,7 @@ public HelpContext getHelpContext() { } @Override - protected List getSessions(String player) { + protected List getSessions(String player) { List sessions = new ArrayList<>(); new DatabaseQuery() .query(new BasicQuery("SELECT * FROM support_sessions WHERE staff = ? ORDER BY time", (statement) -> statement.setString(1, player))) diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/AbstractLeaderboardCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/AbstractLeaderboardCommand.java similarity index 97% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/AbstractLeaderboardCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/AbstractLeaderboardCommand.java index 096c6486..9b1e7ee3 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/AbstractLeaderboardCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/AbstractLeaderboardCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.stats; +package com.diamondfire.helpbot.bot.command.impl.stats.top; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/ActivePlotsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/ActivePlotsCommand.java similarity index 97% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/ActivePlotsCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/ActivePlotsCommand.java index 5ce3e26b..ff9a1bf1 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/ActivePlotsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/ActivePlotsCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.stats; +package com.diamondfire.helpbot.bot.command.impl.stats.top; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.help.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/CpTopCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/CpTopCommand.java similarity index 97% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/CpTopCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/CpTopCommand.java index d869a9e0..818f992a 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/CpTopCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/CpTopCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.stats; +package com.diamondfire.helpbot.bot.command.impl.stats.top; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/DiscordBoostersCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/DiscordBoostersCommand.java similarity index 66% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/DiscordBoostersCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/DiscordBoostersCommand.java index 9ab574a4..d623bcb1 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/DiscordBoostersCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/DiscordBoostersCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.stats; +package com.diamondfire.helpbot.bot.command.impl.stats.top; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.help.*; @@ -7,12 +7,13 @@ import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; -import com.diamondfire.helpbot.util.StringUtil; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.*; import java.awt.*; -import java.util.Comparator; +import java.text.SimpleDateFormat; +import java.util.List; +import java.util.*; public class DiscordBoostersCommand extends Command { @@ -48,22 +49,37 @@ public void run(CommandEvent event) { Guild guild = event.getGuild(); PresetBuilder preset = new PresetBuilder() .withPreset( - new InformativeReply(InformativeReplyType.INFO, "Current Discord Boosters", null) + new InformativeReply(InformativeReplyType.INFO, "Discord Server Boosters", null) ); EmbedBuilder embed = preset.getEmbed(); embed.setThumbnail("https://cdn.discordapp.com/emojis/699936318398136341.png?v=1"); event.getGuild().findMembers((member -> member.getTimeBoosted() != null)).onSuccess((members) -> { - embed.setDescription(StringUtil.listView("> ", true, members.stream() - .sorted(Comparator.comparing(Member::getTimeBoosted)) - .map(Member::getEffectiveName) - .toArray(String[]::new))); + members.sort(Comparator.comparing(Member::getTimeBoosted)); + embed.setDescription("A list of members that are currently boosting this Discord server.\n\n"+ + getFormattedBoosters(members)); embed.setColor(new Color(255, 115, 250)); event.reply(preset); guild.pruneMemberCache(); }); } + private static String getFormattedBoosters(List members) { + if (members.size() == 0) return "*None*"; + + else { + SimpleDateFormat format = new SimpleDateFormat("y'y'M'm'D'd'"); + + List elements = new ArrayList<>(); + for (Member member : members) { + String timeBoosted = format.format(member.getTimeBoosted()); + elements.add(member.getAsMention() + " - " + timeBoosted); + } + + return String.join("\n", elements); + } + } + } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/TokenTopCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/TokenTopCommand.java similarity index 97% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/TokenTopCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/TokenTopCommand.java index d13ca3d9..daaeb3ae 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/TokenTopCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/TokenTopCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.stats; +package com.diamondfire.helpbot.bot.command.impl.stats.top; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.help.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/TrendingPlotsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/TrendingPlotsCommand.java similarity index 97% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/TrendingPlotsCommand.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/TrendingPlotsCommand.java index 5fe26fe9..3e25f3ee 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/TrendingPlotsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/TrendingPlotsCommand.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.stats; +package com.diamondfire.helpbot.bot.command.impl.stats.top; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.help.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/VoteGivenLeaderboard.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/VoteGivenLeaderboard.java similarity index 97% rename from src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/VoteGivenLeaderboard.java rename to src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/VoteGivenLeaderboard.java index a1a141bb..fd8727b8 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/VoteGivenLeaderboard.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/VoteGivenLeaderboard.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.impl.stats; +package com.diamondfire.helpbot.bot.command.impl.stats.top; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.help.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/reply/feature/informative/InformativeReplyType.java b/src/main/java/com/diamondfire/helpbot/bot/command/reply/feature/informative/InformativeReplyType.java index bef112af..53b373a2 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/reply/feature/informative/InformativeReplyType.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/reply/feature/informative/InformativeReplyType.java @@ -5,9 +5,9 @@ import java.awt.*; public enum InformativeReplyType { - SUCCESS("Success!", Color.GREEN), + SUCCESS("Success!", new Color(46, 204, 113)), INFO("Notice!", null), - ERROR("Error!", Color.RED); + ERROR("Error!", new Color(231, 76, 60)); private final String title; private final Color color; diff --git a/src/main/java/com/diamondfire/helpbot/bot/events/CommandEvent.java b/src/main/java/com/diamondfire/helpbot/bot/events/CommandEvent.java index c0bf75d9..4a5bcac7 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/events/CommandEvent.java +++ b/src/main/java/com/diamondfire/helpbot/bot/events/CommandEvent.java @@ -7,7 +7,6 @@ import com.diamondfire.helpbot.bot.command.argument.impl.parsing.parser.ArgumentParser; import com.diamondfire.helpbot.bot.command.impl.Command; import com.diamondfire.helpbot.bot.command.reply.*; -import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -15,7 +14,7 @@ public class CommandEvent extends GuildMessageReceivedEvent { - private final Command command; + private Command command; private final ReplyHandler replyHandler = new ReplyHandler(getChannel()); //TODO Cleanup and refactor this. // I'd like to see stuff like replying be put into it's whole own section and refactored as well. @@ -27,7 +26,6 @@ public CommandEvent(Message message) { String[] rawArgs = getMessage().getContentDisplay().split(" "); String commandPrefix = rawArgs[0].substring(HelpBotInstance.getConfig().getPrefix().length()).toLowerCase(); - Command cmd = CommandHandler.getInstance().getCommands().get(commandPrefix.toLowerCase()); if (cmd == null) { this.aliasedUsed = commandPrefix.toLowerCase(); @@ -38,13 +36,17 @@ public CommandEvent(Message message) { } public void pushArguments(String[] rawArgs) throws ArgumentException { - this.parsedArgumentSet = ArgumentParser.parseArgs(command, Arrays.copyOfRange(rawArgs, 1, rawArgs.length)); + this.parsedArgumentSet = ArgumentParser.parseArgs(command, Arrays.copyOfRange(rawArgs, 1, rawArgs.length), this); } public Command getCommand() { return command; } + public void setCommand(Command command) { + this.command = command; + } + public void reply(PresetBuilder preset) { replyHandler.reply(preset, getChannel()); } @@ -64,4 +66,8 @@ public ReplyHandler getReplyHandler() { public String getAliasUsed() { return aliasedUsed; } + + public String[] getRawArgs() { + return getMessage().getContentRaw().split("\\s+"); + } } diff --git a/src/main/java/com/diamondfire/helpbot/bot/events/GuildJoinEvent.java b/src/main/java/com/diamondfire/helpbot/bot/events/GuildJoinEvent.java index d3ed8928..0080879d 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/events/GuildJoinEvent.java +++ b/src/main/java/com/diamondfire/helpbot/bot/events/GuildJoinEvent.java @@ -1,7 +1,6 @@ package com.diamondfire.helpbot.bot.events; import com.diamondfire.helpbot.bot.HelpBotInstance; -import com.diamondfire.helpbot.sys.rolereact.RoleReactListener; import com.diamondfire.helpbot.sys.tasks.impl.MuteExpireTask; import com.diamondfire.helpbot.util.Util; import net.dv8tion.jda.api.entities.Member; diff --git a/src/main/java/com/diamondfire/helpbot/bot/events/MessageEvent.java b/src/main/java/com/diamondfire/helpbot/bot/events/MessageEvent.java index dd91a836..0286059b 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/events/MessageEvent.java +++ b/src/main/java/com/diamondfire/helpbot/bot/events/MessageEvent.java @@ -12,6 +12,7 @@ public class MessageEvent extends ListenerAdapter { private static final MessageAcceptor[] acceptors = { new ReportAcceptor(), new FilterAcceptor(), + new TagAcceptor(), new CommandAcceptor(), new VerifyAcceptor() }; diff --git a/src/main/java/com/diamondfire/helpbot/df/codeinfo/codedatabase/db/datatypes/DisplayIcon.java b/src/main/java/com/diamondfire/helpbot/df/codeinfo/codedatabase/db/datatypes/DisplayIcon.java index 148b14a3..07364aba 100644 --- a/src/main/java/com/diamondfire/helpbot/df/codeinfo/codedatabase/db/datatypes/DisplayIcon.java +++ b/src/main/java/com/diamondfire/helpbot/df/codeinfo/codedatabase/db/datatypes/DisplayIcon.java @@ -2,7 +2,6 @@ import com.diamondfire.helpbot.util.*; import com.google.gson.*; -import org.jetbrains.annotations.Nullable; import java.util.*; diff --git a/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/constants/CodeBlockEnum.java b/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/constants/CodeBlockEnum.java index 47c9ab9b..71fbde28 100644 --- a/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/constants/CodeBlockEnum.java +++ b/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/constants/CodeBlockEnum.java @@ -1,6 +1,5 @@ package com.diamondfire.helpbot.df.codeinfo.viewables.constants; -import com.diamondfire.helpbot.HelpBot; import com.diamondfire.helpbot.bot.HelpBotInstance; import net.dv8tion.jda.api.entities.Emote; diff --git a/src/main/java/com/diamondfire/helpbot/sys/externalfile/ExternalFiles.java b/src/main/java/com/diamondfire/helpbot/sys/externalfile/ExternalFiles.java index 95799afc..49a2616c 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/externalfile/ExternalFiles.java +++ b/src/main/java/com/diamondfire/helpbot/sys/externalfile/ExternalFiles.java @@ -1,7 +1,6 @@ package com.diamondfire.helpbot.sys.externalfile; import java.io.File; -import java.net.URL; public interface ExternalFiles { @@ -55,4 +54,10 @@ public interface ExternalFiles { .setName("samman") .setFileType("png") .buildFile(); + + File TAGS = new ExternalFileBuilder() + .isDirectory(false) + .setName("tags") + .setFileType("json") + .buildFile(); } diff --git a/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/CommandAcceptor.java b/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/CommandAcceptor.java index 5b48c619..32aa4562 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/CommandAcceptor.java +++ b/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/CommandAcceptor.java @@ -16,4 +16,4 @@ public boolean accept(Message message) { return false; } -} +} \ No newline at end of file diff --git a/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/ReportAcceptor.java b/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/ReportAcceptor.java index 9b7b523f..5b0219fa 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/ReportAcceptor.java +++ b/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/ReportAcceptor.java @@ -4,12 +4,10 @@ import club.minnced.discord.webhook.external.JDAWebhookClient; import club.minnced.discord.webhook.send.WebhookMessageBuilder; import com.diamondfire.helpbot.bot.HelpBotInstance; -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.*; import java.net.URL; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; +import java.util.concurrent.*; public class ReportAcceptor implements MessageAcceptor { diff --git a/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/TagAcceptor.java b/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/TagAcceptor.java new file mode 100644 index 00000000..09f886de --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/TagAcceptor.java @@ -0,0 +1,34 @@ +package com.diamondfire.helpbot.sys.message.acceptors; + +import com.diamondfire.helpbot.bot.HelpBotInstance; +import com.diamondfire.helpbot.sys.tag.*; +import net.dv8tion.jda.api.entities.Message; + +import java.io.IOException; + +public class TagAcceptor implements MessageAcceptor { + + @Override + public boolean accept(Message message) { + if (message.getContentDisplay().startsWith(HelpBotInstance.getConfig().getPrefix()) && !message.getAuthor().isBot()) { + String parsedText = message.getContentStripped().substring(HelpBotInstance.getConfig().getPrefix().length()) + .replaceFirst(" .*$", ""); + + try { + // Get Tag and send response + Tag tag = TagHandler.getTag(parsedText); + tag.sendResponse(message.getTextChannel()); + + // Delete origin message + message.delete().queue(); + + } catch (TagDoesntExistException | IOException ignored) { + return false; + } + + return true; + } + + return false; + } +} diff --git a/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/VerifyAcceptor.java b/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/VerifyAcceptor.java index f71f127b..b1493bf9 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/VerifyAcceptor.java +++ b/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/VerifyAcceptor.java @@ -1,6 +1,6 @@ package com.diamondfire.helpbot.sys.message.acceptors; -import com.diamondfire.helpbot.bot.command.impl.other.VerifyCommand; +import com.diamondfire.helpbot.bot.command.impl.other.mod.VerifyCommand; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; diff --git a/src/main/java/com/diamondfire/helpbot/sys/message/filter/filters/SwearFilter.java b/src/main/java/com/diamondfire/helpbot/sys/message/filter/filters/SwearFilter.java index 91a5dbeb..7c381d92 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/message/filter/filters/SwearFilter.java +++ b/src/main/java/com/diamondfire/helpbot/sys/message/filter/filters/SwearFilter.java @@ -67,12 +67,8 @@ public boolean filterString(String message, FilterData data) { // This is fairly easy to bypass, but still good to have String concatenated = getImplicit(message.replace(" ", "")); - - if (BLOCKED_MESSAGES.contains(concatenated)) { - return true; - } - - return false; + + return BLOCKED_MESSAGES.contains(concatenated); } private static final HashMap CHARACTER_MAP; diff --git a/src/main/java/com/diamondfire/helpbot/sys/multiselector/MultiSelector.java b/src/main/java/com/diamondfire/helpbot/sys/multiselector/MultiSelector.java index 52c74a72..4b6db69a 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/multiselector/MultiSelector.java +++ b/src/main/java/com/diamondfire/helpbot/sys/multiselector/MultiSelector.java @@ -6,7 +6,6 @@ import net.dv8tion.jda.api.entities.Emoji; import net.dv8tion.jda.api.interactions.components.Button; - import java.util.*; public class MultiSelector { diff --git a/src/main/java/com/diamondfire/helpbot/sys/tag/Tag.java b/src/main/java/com/diamondfire/helpbot/sys/tag/Tag.java new file mode 100644 index 00000000..cce56291 --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/sys/tag/Tag.java @@ -0,0 +1,86 @@ +package com.diamondfire.helpbot.sys.tag; + +import com.google.gson.JsonObject; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.entities.*; + +public class Tag { + + private String activator; + private String title; + private String response; + private long authorId; + private String image; + + public Tag(String activator, String title, String response, long authorId, String image) { + this.activator = activator; + this.title = title; + this.response = response; + this.authorId = authorId; + this.image = image; + } + + public String getActivator() { + return activator; + } + + public void setActivator(String activator) { + this.activator = activator.replaceAll(" ", ""); + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getResponse() { + return this.response; + } + + public void setResponse(String response) { + this.response = response; + } + + public long getAuthorId() { + return this.authorId; + } + + public void setAuthorId(long authorId) { + this.authorId = authorId; + } + + public String getImage() { + return this.image; + } + + public void setImage(String image) { + this.image = image; + } + + public JsonObject asJson() { + JsonObject json = new JsonObject(); + json.addProperty("activator", this.activator); + json.addProperty("title", this.title); + json.addProperty("response", this.response); + json.addProperty("authorId", this.authorId); + json.addProperty("image", this.image); + + return json; + } + + public void sendResponse(TextChannel channel) { + User user = channel.getJDA().retrieveUserById(getAuthorId()).complete(); + + EmbedBuilder embed = new EmbedBuilder() + .setTitle(getTitle()) + .setDescription(getResponse()+"\n\u200b") + .setColor(0x969dba) + .setFooter("Written by "+user.getAsTag(), user.getAvatarUrl()); + if (!getImage().equals("")) embed.setImage(getImage()); + + channel.sendMessage(embed.build()).queue(); + } +} diff --git a/src/main/java/com/diamondfire/helpbot/sys/tag/TagAlreadyExistsException.java b/src/main/java/com/diamondfire/helpbot/sys/tag/TagAlreadyExistsException.java new file mode 100644 index 00000000..7713406e --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/sys/tag/TagAlreadyExistsException.java @@ -0,0 +1,8 @@ +package com.diamondfire.helpbot.sys.tag; + +public class TagAlreadyExistsException extends Exception { + public TagAlreadyExistsException(String message) { + super(message); + } + +} diff --git a/src/main/java/com/diamondfire/helpbot/sys/tag/TagDoesntExistException.java b/src/main/java/com/diamondfire/helpbot/sys/tag/TagDoesntExistException.java new file mode 100644 index 00000000..d420efab --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/sys/tag/TagDoesntExistException.java @@ -0,0 +1,7 @@ +package com.diamondfire.helpbot.sys.tag; + +public class TagDoesntExistException extends Exception { + public TagDoesntExistException(String message) { + super(message); + } +} diff --git a/src/main/java/com/diamondfire/helpbot/sys/tag/TagHandler.java b/src/main/java/com/diamondfire/helpbot/sys/tag/TagHandler.java new file mode 100644 index 00000000..21a660ee --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/sys/tag/TagHandler.java @@ -0,0 +1,84 @@ +package com.diamondfire.helpbot.sys.tag; + +import com.diamondfire.helpbot.sys.externalfile.ExternalFiles; +import com.google.gson.*; + +import java.io.*; +import java.nio.file.*; +import java.util.*; +import java.util.stream.Collectors; + +public class TagHandler { + + private static final List tags = new ArrayList<>(); + private static final File FILE = ExternalFiles.TAGS; + + public static List getTags() throws IOException { + return tags; + } + + public static void cacheJson() throws IOException { + // read the file and update the cache + String content = new String(Files.readAllBytes(FILE.toPath())); + if (content.length() == 0) content = "{}"; + JsonObject obj = JsonParser.parseString(content).getAsJsonObject(); + + for (String key : obj.keySet()) { + JsonObject tag = obj.get(key).getAsJsonObject(); + tags.add(new Tag(tag.get("activator").getAsString(), + tag.get("title").getAsString(), + tag.get("response").getAsString(), + tag.get("authorId").getAsLong(), + tag.get("image").getAsString())); + } + } + + public static void saveToJson() throws IOException { + JsonObject json = new JsonObject(); + + for (Tag tag : tags) { + JsonObject obj = new JsonObject(); + obj.addProperty("activator", tag.getActivator()); + obj.addProperty("title", tag.getTitle()); + obj.addProperty("response", tag.getResponse()); + obj.addProperty("authorId", tag.getAuthorId()); + obj.addProperty("image", tag.getImage()); + + json.add(tag.getActivator(), obj); + } + + FILE.delete(); + FILE.createNewFile(); + Files.write(FILE.toPath(), json.toString().getBytes(), StandardOpenOption.WRITE); + } + + public static void newTag(Tag tag) throws TagAlreadyExistsException, IOException { + // check if tag with equal activator already exists + if (tags.stream().anyMatch(t -> t.getActivator().equals(tag.getActivator()))) { + throw new TagAlreadyExistsException("A tag with this activator already exists."); + } + + // implement the new tag + tags.add(tag); + saveToJson(); + } + + public static void deleteTag(String activator) throws TagDoesntExistException, IOException { + // get tag + check if it exists + Tag tag = getTag(activator); + + // remove the tag + tags.remove(tag); + saveToJson(); + } + + public static void deleteTag(Tag tag) throws TagDoesntExistException, IOException { + deleteTag(tag.getActivator()); + } + + public static Tag getTag(String activator) throws TagDoesntExistException, IOException { + List tag = tags.stream().filter(t -> t.getActivator().equals(activator)).collect(Collectors.toList()); + if (tag.size() == 0) throw new TagDoesntExistException("A tag with activator `"+activator+"` does not exist."); + return tag.get(0); + } +} diff --git a/src/main/java/com/diamondfire/helpbot/sys/tag/TagProperty.java b/src/main/java/com/diamondfire/helpbot/sys/tag/TagProperty.java new file mode 100644 index 00000000..5172e552 --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/sys/tag/TagProperty.java @@ -0,0 +1,59 @@ +package com.diamondfire.helpbot.sys.tag; + +public enum TagProperty { + ACTIVATOR("activator", true){ + @Override + public void edit(Tag tag, String newValue) { + tag.setActivator(newValue); + } + }, + TITLE("title", true) { + @Override + public void edit(Tag tag, String newValue) { + tag.setTitle(newValue); + } + }, + RESPONSE("response", true) { + @Override + public void edit(Tag tag, String newValue) { + tag.setResponse(newValue); + } + }, + AUTHOR_ID("authorId", false) { + @Override + public void edit(Tag tag, String newValue) { + throw new UnsupportedOperationException("The `"+this.getProperty()+"` property cannot be modified."); + } + }, + IMAGE("image", true) { + @Override + public void edit(Tag tag, String newValue) { + tag.setImage(newValue); + } + }; + + private final String property; + private final boolean modifiable; + + TagProperty(String property, boolean modifiable) { + this.property = property; + this.modifiable = modifiable; + } + + public String getProperty() { + return property; + } + + public boolean isModifiable() { + return modifiable; + } + + public static TagProperty getByProperty(String prop) { + for (TagProperty tagProperty : TagProperty.values()) { + if (tagProperty.getProperty().equals(prop)) return tagProperty; + } + return null; + } + + public abstract void edit(Tag tag, String newValue); +} diff --git a/src/main/java/com/diamondfire/helpbot/sys/tasks/MidnightTask.java b/src/main/java/com/diamondfire/helpbot/sys/tasks/MidnightTask.java index 2533e2fa..73017f03 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/tasks/MidnightTask.java +++ b/src/main/java/com/diamondfire/helpbot/sys/tasks/MidnightTask.java @@ -1,7 +1,6 @@ package com.diamondfire.helpbot.sys.tasks; import java.time.*; -import java.time.chrono.ChronoLocalDateTime; import java.util.TimeZone; import java.util.concurrent.TimeUnit; diff --git a/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/CodeDatabaseTask.java b/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/CodeDatabaseTask.java index 6acea964..20b2b007 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/CodeDatabaseTask.java +++ b/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/CodeDatabaseTask.java @@ -1,6 +1,6 @@ package com.diamondfire.helpbot.sys.tasks.impl; -import com.diamondfire.helpbot.bot.command.impl.other.FetchDataCommand; +import com.diamondfire.helpbot.bot.command.impl.other.dev.FetchDataCommand; import com.diamondfire.helpbot.sys.tasks.MidnightTask; public class CodeDatabaseTask implements MidnightTask { diff --git a/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/GraphChannelTask.java b/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/GraphChannelTask.java index 62182dfd..b43d1a34 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/GraphChannelTask.java +++ b/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/GraphChannelTask.java @@ -1,7 +1,6 @@ package com.diamondfire.helpbot.sys.tasks.impl; import com.diamondfire.helpbot.bot.HelpBotInstance; -import com.diamondfire.helpbot.bot.command.impl.stats.graph.*; import com.diamondfire.helpbot.sys.graph.generators.*; import com.diamondfire.helpbot.sys.graph.generators.context.TimeGraphContext; import com.diamondfire.helpbot.sys.tasks.MidnightTask; diff --git a/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/MuteExpireTask.java b/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/MuteExpireTask.java index 458b800d..4ba55a70 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/MuteExpireTask.java +++ b/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/MuteExpireTask.java @@ -1,7 +1,7 @@ package com.diamondfire.helpbot.sys.tasks.impl; import com.diamondfire.helpbot.bot.HelpBotInstance; -import com.diamondfire.helpbot.bot.command.impl.other.*; +import com.diamondfire.helpbot.bot.command.impl.other.mod.*; import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; import com.diamondfire.helpbot.sys.tasks.OneTimeTask; diff --git a/src/main/java/com/diamondfire/helpbot/util/DateUtil.java b/src/main/java/com/diamondfire/helpbot/util/DateUtil.java index 58cadcee..1dabcae6 100644 --- a/src/main/java/com/diamondfire/helpbot/util/DateUtil.java +++ b/src/main/java/com/diamondfire/helpbot/util/DateUtil.java @@ -1,8 +1,7 @@ package com.diamondfire.helpbot.util; import java.sql.Timestamp; -import java.time.Instant; -import java.time.LocalDate; +import java.time.*; import java.util.*; @SuppressWarnings("deprecation") diff --git a/src/main/java/com/diamondfire/helpbot/util/IOUtil.java b/src/main/java/com/diamondfire/helpbot/util/IOUtil.java index 295066a7..16ef1cae 100644 --- a/src/main/java/com/diamondfire/helpbot/util/IOUtil.java +++ b/src/main/java/com/diamondfire/helpbot/util/IOUtil.java @@ -76,7 +76,7 @@ public static File zipFile(Path path, String fileName) throws IOException { public static File getFileFromSite(String url, String name) { - try (InputStream in = new URL(url).openStream();) { + try (InputStream in = new URL(url).openStream()) { File tempFile = ExternalFileUtil.generateFile(name); Files.write(tempFile.toPath(), in.readAllBytes(), StandardOpenOption.WRITE); diff --git a/src/main/java/com/diamondfire/helpbot/util/nbs/NBSDecoder.java b/src/main/java/com/diamondfire/helpbot/util/nbs/NBSDecoder.java index a38628cf..7031b3ae 100644 --- a/src/main/java/com/diamondfire/helpbot/util/nbs/NBSDecoder.java +++ b/src/main/java/com/diamondfire/helpbot/util/nbs/NBSDecoder.java @@ -52,7 +52,7 @@ private static SongData parse(InputStream inputStream, File songFile) throws IOE speed = actualSpeed / 100f; //speed dataInputStream.readBoolean(); //autosave dataInputStream.readByte(); //autosave duration - timeSignature = (short) dataInputStream.readByte(); //time signature + timeSignature = dataInputStream.readByte(); //time signature readInt(dataInputStream); //minutes spent readInt(dataInputStream); //left clicks readInt(dataInputStream); //right clicks @@ -222,7 +222,7 @@ private static SongData parse(InputStream inputStream, File songFile) throws IOE } } } - stringBuilder.append(columnStringBuilder.toString()); + stringBuilder.append(columnStringBuilder); } } diff --git a/src/main/java/com/diamondfire/helpbot/util/nbs/NBSToTemplate.java b/src/main/java/com/diamondfire/helpbot/util/nbs/NBSToTemplate.java index 6eee3ec0..c5bf54e7 100644 --- a/src/main/java/com/diamondfire/helpbot/util/nbs/NBSToTemplate.java +++ b/src/main/java/com/diamondfire/helpbot/util/nbs/NBSToTemplate.java @@ -91,7 +91,7 @@ public String convert() { if (currentNotes.length() > 1930) { currentNotes = new StringBuilder(revertString); - currentBlock.append(String.format(",{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"%s\"}},\"slot\":%d}", currentNotes.toString(), slot)); + currentBlock.append(String.format(",{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"%s\"}},\"slot\":%d}", currentNotes, slot)); currentNotes.setLength(0); noteCount = 0; finalNote = true; @@ -101,7 +101,7 @@ public String convert() { if (i >= songData.length - 1) { if (!finalNote) { - currentBlock.append(String.format(",{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"%s\"}},\"slot\":%d}", currentNotes.toString(), slot)); + currentBlock.append(String.format(",{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"%s\"}},\"slot\":%d}", currentNotes, slot)); currentNotes.setLength(0); } closeChest = true; @@ -117,7 +117,7 @@ public String convert() { } currentBlock.append(String.format("]},\"action\":\"%s\"},", varActionType)); - code.append(currentBlock.toString()); + code.append(currentBlock); currentBlock.setLength(0); currentNotes.setLength(0); @@ -148,7 +148,7 @@ public String convert() { currentSlot++; } instList.append("]},\"action\":\"CreateList\"},"); - code.append(instList.toString()); + code.append(instList); } //CreateList: songData diff --git a/src/main/java/com/diamondfire/helpbot/util/textgen/CacheData.java b/src/main/java/com/diamondfire/helpbot/util/textgen/CacheData.java index c016036e..5f372846 100644 --- a/src/main/java/com/diamondfire/helpbot/util/textgen/CacheData.java +++ b/src/main/java/com/diamondfire/helpbot/util/textgen/CacheData.java @@ -1,8 +1,7 @@ package com.diamondfire.helpbot.util.textgen; import java.io.*; -import java.util.ArrayList; -import java.util.Arrays; +import java.util.*; import static com.diamondfire.helpbot.util.textgen.MarkovManipulation.addWord;