diff --git a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java index d4e2caa2..d3318094 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java +++ b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java @@ -73,6 +73,7 @@ public static void initialize() throws LoginException { new MuteCommand(), new MutedCommand(), new UnmuteCommand(), + new LockCommand(), new VerifyCommand(), new PollCommand(), new IdeaCommand(), 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 31b96766..6f4bd53a 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 @@ -33,7 +33,7 @@ public static ParsedArgumentSet parseArgs(Command command, String[] args, Comman rawArguments.pushStack(); } catch (MissingArgumentException exception) { if (argumentContainer.isOptional()) { - parsedArgs.put(identifier, new ParsedArgument<>(identifier, argumentContainer.getDefaultValue())); + parsedArgs.put(identifier, new ParsedArgument<>(identifier, argumentContainer.getDefaultValue(event))); } else { exception.setContext(command, i, event); throw exception; 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 251ea868..c6dcfd07 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 @@ -23,7 +23,7 @@ public ParsedArgument parse(String identifier, ArgumentStack.RawArgumentStack for (int i = 0; i < arguments; i++) { try { - approvedArgumentValues.add(arg.parseValue(rawArgs, event)); + approvedArgumentValues.add(arg.parsed(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 120f846f..fece9a02 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 @@ -3,7 +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.SingleArgumentContainer; -import com.diamondfire.helpbot.bot.command.argument.impl.types.Argument; +import com.diamondfire.helpbot.bot.command.argument.impl.types.*; import com.diamondfire.helpbot.bot.events.CommandEvent; import java.util.Deque; @@ -20,10 +20,10 @@ public ParsedArgument parse(String identifier, ArgumentStack.RawArgumentStack Deque rawArgs = args.popStack(); Argument arg = getContainer().getArgument(); - if (rawArgs.peek() == null) { + if (rawArgs.peek() == null && !(arg instanceof FallbackArgument)) { throw new MissingArgumentException("Expected an argument, but got nothing."); } - return new ParsedArgument<>(identifier, arg.parseValue(rawArgs, event)); + return new ParsedArgument<>(identifier, arg.parsed(rawArgs, event)); } } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/types/ArgumentContainer.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/types/ArgumentContainer.java index 29c5e165..2e82c021 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/types/ArgumentContainer.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/types/ArgumentContainer.java @@ -1,19 +1,25 @@ package com.diamondfire.helpbot.bot.command.argument.impl.parsing.types; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.parser.ArgumentParser; +import com.diamondfire.helpbot.bot.events.CommandEvent; +import java.util.function.Function; -// Argument containers provide essential information for the argument. -// These give a parser. + +/** + * Argument containers provide essential information for the argument. + * These give a parser. + * @param + */ public abstract class ArgumentContainer { - private T defaultValue; + private Function defaultValueFunction; private boolean isOptional; public abstract

> P getParser(); - public ArgumentContainer optional(T defaultValue) { - this.defaultValue = defaultValue; + public ArgumentContainer optional(Function defaultValueFunction) { + this.defaultValueFunction = defaultValueFunction; this.isOptional = true; return this; } @@ -22,8 +28,12 @@ public boolean isOptional() { return isOptional; } - public T getDefaultValue() { - return defaultValue; + public Function getDefaultValueFunction() { + return defaultValueFunction; + } + + public T getDefaultValue(CommandEvent event) { + return getDefaultValueFunction().apply(event); } } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/AbstractSimpleValueFallbackArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/AbstractSimpleValueFallbackArgument.java new file mode 100644 index 00000000..8f3c0e4c --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/AbstractSimpleValueFallbackArgument.java @@ -0,0 +1,19 @@ +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; + +public abstract class AbstractSimpleValueFallbackArgument implements FallbackArgument { + + @Override + @SuppressWarnings("all") + public T parseValue(@NotNull Deque args, CommandEvent event) throws ArgumentException { + return parse(args.peek(), event); + } + + 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 d7ac58f1..25e99fe3 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 @@ -15,7 +15,12 @@ */ public interface Argument { + default T parsed(@NotNull Deque args, CommandEvent event) throws ArgumentException { + return parseValue(args, event); + } + T parseValue(@NotNull Deque args, CommandEvent event) throws ArgumentException; + } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/FallbackArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/FallbackArgument.java new file mode 100644 index 00000000..269ef721 --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/FallbackArgument.java @@ -0,0 +1,39 @@ +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; + +public interface FallbackArgument extends Argument { + + @Override + default T parsed(@NotNull Deque args, CommandEvent event) throws ArgumentException { + T result; + + try { + result = Argument.super.parsed(args, event); + args.pop(); + + } catch (Exception e) { + result = null; + } + + if (result == null) { + return ifFail(event); + + } else { + return result; + } + } + + + /** + * The value to return if the parsed value throws an exception or is null. + * @param event The Command event. + * @return The new value. + */ + T ifFail(CommandEvent event); + +} 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/impl/ClampedIntegerArgument.java similarity index 92% rename from src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/ClampedIntegerArgument.java rename to src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/ClampedIntegerArgument.java index 79f496a7..7d0dc039 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/impl/ClampedIntegerArgument.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.argument.impl.types; +package com.diamondfire.helpbot.bot.command.argument.impl.types.impl; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException; import com.diamondfire.helpbot.bot.events.CommandEvent; 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/impl/DateArgument.java similarity index 84% rename from src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DateArgument.java rename to src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/DateArgument.java index c50c699f..06a9b902 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/impl/DateArgument.java @@ -1,6 +1,7 @@ -package com.diamondfire.helpbot.bot.command.argument.impl.types; +package com.diamondfire.helpbot.bot.command.argument.impl.types.impl; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.AbstractSimpleValueArgument; import com.diamondfire.helpbot.bot.events.CommandEvent; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DateOffsetArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/DateOffsetArgument.java similarity index 75% rename from src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DateOffsetArgument.java rename to src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/DateOffsetArgument.java index 658a2350..31c4d9d2 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DateOffsetArgument.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/DateOffsetArgument.java @@ -1,4 +1,6 @@ -package com.diamondfire.helpbot.bot.command.argument.impl.types; +package com.diamondfire.helpbot.bot.command.argument.impl.types.impl; + +import com.diamondfire.helpbot.bot.command.argument.impl.types.AbstractOffsetArgument; import java.util.Calendar; 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/impl/DefinedObjectArgument.java similarity index 93% rename from src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DefinedObjectArgument.java rename to src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/DefinedObjectArgument.java index c06d463d..cf42c42d 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/impl/DefinedObjectArgument.java @@ -1,7 +1,8 @@ -package com.diamondfire.helpbot.bot.command.argument.impl.types; +package com.diamondfire.helpbot.bot.command.argument.impl.types.impl; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.Argument; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.util.JaroWinkler; import org.jetbrains.annotations.NotNull; 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/impl/DiscordUserArgument.java similarity index 85% rename from src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DiscordUserArgument.java rename to src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/DiscordUserArgument.java index b0eef190..58fc92f9 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/impl/DiscordUserArgument.java @@ -1,6 +1,7 @@ -package com.diamondfire.helpbot.bot.command.argument.impl.types; +package com.diamondfire.helpbot.bot.command.argument.impl.types.impl; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.MalformedArgumentException; +import com.diamondfire.helpbot.bot.command.argument.impl.types.AbstractSimpleValueArgument; import com.diamondfire.helpbot.bot.events.CommandEvent; import net.dv8tion.jda.api.utils.MiscUtil; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/EndlessStringArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/EndlessStringArgument.java similarity index 76% rename from src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/EndlessStringArgument.java rename to src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/EndlessStringArgument.java index ec1a4215..540b6534 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/EndlessStringArgument.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/EndlessStringArgument.java @@ -1,6 +1,7 @@ -package com.diamondfire.helpbot.bot.command.argument.impl.types; +package com.diamondfire.helpbot.bot.command.argument.impl.types.impl; 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; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/Enum/EnumArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/Enum/EnumArgument.java similarity index 93% rename from src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/Enum/EnumArgument.java rename to src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/Enum/EnumArgument.java index 77434925..bffc8d50 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/Enum/EnumArgument.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/Enum/EnumArgument.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.argument.impl.types.Enum; +package com.diamondfire.helpbot.bot.command.argument.impl.types.impl.Enum; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; import com.diamondfire.helpbot.bot.command.argument.impl.types.AbstractSimpleValueArgument; @@ -10,11 +10,10 @@ public class EnumArgument & EnumArgument.InputEnum> extends AbstractSimpleValueArgument { - private EnumSet associatedEnum; + private final EnumSet associatedEnum; - public EnumArgument setEnum(Class anEnum) { + public EnumArgument(Class anEnum) { associatedEnum = EnumSet.allOf(anEnum); - return this; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/Enum/TagProperty.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/Enum/TagProperty.java similarity index 99% rename from src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/Enum/TagProperty.java rename to src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/Enum/TagProperty.java index de1b1fba..7312709e 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/Enum/TagProperty.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/Enum/TagProperty.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.argument.impl.types.Enum; +package com.diamondfire.helpbot.bot.command.argument.impl.types.impl.Enum; import com.diamondfire.helpbot.sys.tag.Tag; import org.jetbrains.annotations.NotNull; 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/impl/IntegerArgument.java similarity index 77% rename from src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/IntegerArgument.java rename to src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/IntegerArgument.java index c2061cfe..22e9fcb9 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/impl/IntegerArgument.java @@ -1,6 +1,7 @@ -package com.diamondfire.helpbot.bot.command.argument.impl.types; +package com.diamondfire.helpbot.bot.command.argument.impl.types.impl; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.AbstractSimpleValueArgument; import com.diamondfire.helpbot.bot.events.CommandEvent; import org.jetbrains.annotations.NotNull; 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/impl/LongArgument.java similarity index 71% rename from src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/LongArgument.java rename to src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/LongArgument.java index 3be8d19d..1647928b 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/impl/LongArgument.java @@ -1,10 +1,11 @@ -package com.diamondfire.helpbot.bot.command.argument.impl.types; +package com.diamondfire.helpbot.bot.command.argument.impl.types.impl; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException; +import com.diamondfire.helpbot.bot.command.argument.impl.types.AbstractSimpleValueArgument; import com.diamondfire.helpbot.bot.events.CommandEvent; import org.jetbrains.annotations.NotNull; -public class LongArgument extends AbstractSimpleValueArgument{ +public class LongArgument extends AbstractSimpleValueArgument { @Override protected Long parse(@NotNull String argument, CommandEvent event) throws ArgumentException { diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/QuoteStringArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/QuoteStringArgument.java similarity index 90% rename from src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/QuoteStringArgument.java rename to src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/QuoteStringArgument.java index f75c1784..90f0b723 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/QuoteStringArgument.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/QuoteStringArgument.java @@ -1,6 +1,7 @@ -package com.diamondfire.helpbot.bot.command.argument.impl.types; +package com.diamondfire.helpbot.bot.command.argument.impl.types.impl; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.Argument; import com.diamondfire.helpbot.bot.events.CommandEvent; import org.jetbrains.annotations.NotNull; 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/impl/StringArgument.java similarity index 64% rename from src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/StringArgument.java rename to src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/StringArgument.java index e8b56065..74025fa7 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/impl/StringArgument.java @@ -1,5 +1,6 @@ -package com.diamondfire.helpbot.bot.command.argument.impl.types; +package com.diamondfire.helpbot.bot.command.argument.impl.types.impl; +import com.diamondfire.helpbot.bot.command.argument.impl.types.AbstractSimpleValueArgument; import com.diamondfire.helpbot.bot.events.CommandEvent; import org.jetbrains.annotations.NotNull; 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/impl/SubCommandArgument.java similarity index 85% rename from src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/SubCommandArgument.java rename to src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/SubCommandArgument.java index c4153ea2..f1636c49 100644 --- 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/impl/SubCommandArgument.java @@ -1,6 +1,7 @@ -package com.diamondfire.helpbot.bot.command.argument.impl.types; +package com.diamondfire.helpbot.bot.command.argument.impl.types.impl; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.AbstractSimpleValueArgument; import com.diamondfire.helpbot.bot.command.impl.*; import com.diamondfire.helpbot.bot.events.CommandEvent; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/TextChannelArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/TextChannelArgument.java new file mode 100644 index 00000000..2fdebedc --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/TextChannelArgument.java @@ -0,0 +1,64 @@ +package com.diamondfire.helpbot.bot.command.argument.impl.types.impl; + +import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.*; +import com.diamondfire.helpbot.bot.events.CommandEvent; +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.*; +import org.jetbrains.annotations.NotNull; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * This argument extends {@link FallbackArgument}. + * + * Will return the channel this command was executed in if an invalid channel was provided by the user. + */ +public class TextChannelArgument extends AbstractSimpleValueFallbackArgument { + + private final Permission[] requiredChannelPermissions; + + public TextChannelArgument() { + this(Permission.EMPTY_PERMISSIONS); + } + + public TextChannelArgument(Permission... requiredChannelPermissions) { + this.requiredChannelPermissions = requiredChannelPermissions; + } + + @Override + protected TextChannel parse(@NotNull String argument, CommandEvent event) throws ArgumentException { + + List mentionedChannels = event.getMessage().getMentionedChannels(); + + for (TextChannel channel : mentionedChannels) { + if (channel.getAsMention().equals(argument) || channel.getId().equals(argument)) { + if (!event.getGuild().getSelfMember().hasPermission(channel, requiredChannelPermissions)) { + + throw new MalformedArgumentException( + "I need the following permissions in this channel: " + + getFormattedPermissionList(requiredChannelPermissions) + ); + } + + return channel; + } + } + + throw new MalformedArgumentException("Invalid channel provided. Must be a valid mention or ID."); + } + + @Override + public TextChannel ifFail(CommandEvent event) { + return event.getChannel(); + } + + public static @NotNull String getFormattedPermissionList(Permission... permissions) { + return "`" + Arrays.stream(permissions) + .map(Permission::getName) + .collect(Collectors.joining("` `")) + + "`"; + } + +} diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/TimeOffsetArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/TimeOffsetArgument.java similarity index 78% rename from src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/TimeOffsetArgument.java rename to src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/TimeOffsetArgument.java index 65e11ed2..2f09d3a6 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/TimeOffsetArgument.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/TimeOffsetArgument.java @@ -1,4 +1,6 @@ -package com.diamondfire.helpbot.bot.command.argument.impl.types; +package com.diamondfire.helpbot.bot.command.argument.impl.types.impl; + +import com.diamondfire.helpbot.bot.command.argument.impl.types.AbstractOffsetArgument; import java.util.Calendar; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/minecraft/DFPlayerArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/minecraft/DFPlayerArgument.java similarity index 99% rename from src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/minecraft/DFPlayerArgument.java rename to src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/minecraft/DFPlayerArgument.java index 9fdce5f7..c1212c48 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/minecraft/DFPlayerArgument.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/minecraft/DFPlayerArgument.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft; +package com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; import com.diamondfire.helpbot.bot.command.argument.impl.types.AbstractSimpleValueArgument; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/minecraft/MojangPlayerUUIDArgument.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/minecraft/MojangPlayerUUIDArgument.java similarity index 99% rename from src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/minecraft/MojangPlayerUUIDArgument.java rename to src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/minecraft/MojangPlayerUUIDArgument.java index d1509aa2..2431e967 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/minecraft/MojangPlayerUUIDArgument.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/minecraft/MojangPlayerUUIDArgument.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft; +package com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft; import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/minecraft/Player.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/minecraft/Player.java similarity index 93% rename from src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/minecraft/Player.java rename to src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/minecraft/Player.java index b6ffb8ca..3007114b 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/minecraft/Player.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/minecraft/Player.java @@ -1,4 +1,4 @@ -package com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft; +package com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft; import java.util.UUID; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/disable/DisableCommandHandler.java b/src/main/java/com/diamondfire/helpbot/bot/command/disable/DisableCommandHandler.java index 14c925e1..7f85937b 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/disable/DisableCommandHandler.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/disable/DisableCommandHandler.java @@ -2,7 +2,7 @@ import com.diamondfire.helpbot.bot.command.CommandHandler; import com.diamondfire.helpbot.bot.command.impl.Command; -import com.diamondfire.helpbot.sys.externalfile.ExternalFiles; +import com.diamondfire.helpbot.sys.externalfile.*; import java.io.*; import java.nio.file.*; @@ -11,7 +11,7 @@ public class DisableCommandHandler { private final List disabledCommands = new ArrayList<>(); - private static final File FILE = ExternalFiles.DISABLED_COMMANDS; + private static final ExternalFile FILE = ExternalFiles.DISABLED_COMMANDS; public boolean isDisabled(Command command) { return disabledCommands.contains(command.getName()); @@ -19,7 +19,8 @@ public boolean isDisabled(Command command) { public void initialize() { try { - List lines = Files.readAllLines(FILE.toPath()); + List lines = FILE.readAllLines(); + for (String cmd : lines) { disable(CommandHandler.getCommand(cmd)); } @@ -32,9 +33,7 @@ public void initialize() { public void save() { String string = String.join("\n", disabledCommands); try { - FILE.delete(); - FILE.createNewFile(); - Files.write(FILE.toPath(), string.getBytes(), StandardOpenOption.WRITE); + FILE.write(string); } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/executor/checks/PermissionCheck.java b/src/main/java/com/diamondfire/helpbot/bot/command/executor/checks/PermissionCheck.java index c233a1e7..86998498 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/executor/checks/PermissionCheck.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/executor/checks/PermissionCheck.java @@ -1,6 +1,6 @@ package com.diamondfire.helpbot.bot.command.executor.checks; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -9,8 +9,8 @@ public class PermissionCheck implements CommandCheck { @Override public boolean check(CommandEvent event) { - return event.getCommand().getPermission().hasPermission(event.getMember()) - || Permission.getOverrides(event.getCommand()).contains(event.getAuthor().getIdLong()); + return event.getCommand().getRank().hasPermission(event.getMember()) + || Rank.getOverrides(event.getCommand()).contains(event.getAuthor().getIdLong()); } @Override @@ -18,7 +18,7 @@ public void buildMessage(CommandEvent event, PresetBuilder builder) { builder.withPreset( new InformativeReply(InformativeReplyType.ERROR, "No Permission!", "Sorry, you do not have permission to use this command. Commands that you are able to use are listed in ?help.") ); - builder.getEmbed().setFooter("Permission Required: " + event.getCommand().getPermission().name()); + builder.getEmbed().setFooter("Permission Required: " + event.getCommand().getRank().name()); } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/Command.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/Command.java index cf9e6e44..d5b14db3 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/Command.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/Command.java @@ -2,7 +2,7 @@ import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.help.HelpContext; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; public abstract class Command { @@ -34,7 +34,7 @@ public ArgumentSet getArguments() { } } - public abstract Permission getPermission(); + public abstract Rank getRank(); public abstract void run(CommandEvent event); } 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 index babcf0a8..cf1f4945 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/SubCommandHolder.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/SubCommandHolder.java @@ -3,7 +3,7 @@ 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.command.argument.impl.types.impl.SubCommandArgument; import com.diamondfire.helpbot.bot.events.CommandEvent; import java.util.*; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/BlockCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/BlockCommand.java index 1a2f5b42..332be2bd 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/BlockCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/BlockCommand.java @@ -1,9 +1,9 @@ package com.diamondfire.helpbot.bot.command.impl.codeblock; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; -import com.diamondfire.helpbot.bot.command.argument.impl.types.DefinedObjectArgument; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.DefinedObjectArgument; import com.diamondfire.helpbot.bot.command.help.*; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.CodeDatabase; import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.*; @@ -52,8 +52,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/CodeCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/CodeCommand.java index 04ddd6b3..4c71f9e3 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/CodeCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/CodeCommand.java @@ -1,7 +1,7 @@ package com.diamondfire.helpbot.bot.command.impl.codeblock; import com.diamondfire.helpbot.bot.command.help.*; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.CodeObject; import com.diamondfire.helpbot.util.Util; @@ -46,8 +46,8 @@ public HelpContext getHelpContext() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/RankCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/RankCommand.java index abef3a98..0792bc5e 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/RankCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/RankCommand.java @@ -1,9 +1,9 @@ package com.diamondfire.helpbot.bot.command.impl.codeblock; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; -import com.diamondfire.helpbot.bot.command.argument.impl.types.DefinedObjectArgument; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.DefinedObjectArgument; import com.diamondfire.helpbot.bot.command.help.*; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.CodeObject; @@ -42,8 +42,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/RawCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/RawCommand.java index 8f4c5bd7..ec9d7a05 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/RawCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/RawCommand.java @@ -1,7 +1,7 @@ package com.diamondfire.helpbot.bot.command.impl.codeblock; import com.diamondfire.helpbot.bot.command.help.*; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.CodeObject; import com.diamondfire.helpbot.util.StringUtil; @@ -45,8 +45,8 @@ public HelpContext getHelpContext() { } @Override - public Permission getPermission() { - return Permission.BOT_DEVELOPER; + public Rank getRank() { + return Rank.BOT_DEVELOPER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/SearchCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/SearchCommand.java index 4b421292..6be5c79d 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/SearchCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/SearchCommand.java @@ -1,7 +1,7 @@ package com.diamondfire.helpbot.bot.command.impl.codeblock; import com.diamondfire.helpbot.bot.command.help.*; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.CodeObject; @@ -32,8 +32,8 @@ public HelpContext getHelpContext() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override 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 ae3fc2d4..9ea47b45 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 @@ -1,7 +1,7 @@ package com.diamondfire.helpbot.bot.command.impl.codeblock; import com.diamondfire.helpbot.bot.command.help.*; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.*; import com.diamondfire.helpbot.util.Util; @@ -81,8 +81,8 @@ public String[] getAliases() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/StoreCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/StoreCommand.java index 853c7e7f..eaffbe6e 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/StoreCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/StoreCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -39,8 +39,8 @@ protected ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/DisableCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/DisableCommand.java index 02b56f26..19914f68 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/DisableCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/DisableCommand.java @@ -2,11 +2,11 @@ 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; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.StringArgument; import com.diamondfire.helpbot.bot.command.disable.CommandDisableFlag; 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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -37,8 +37,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.ADMINISTRATOR; + public Rank getRank() { + return Rank.ADMINISTRATOR; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/EnableCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/EnableCommand.java index 8e64b32a..34fd65be 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/EnableCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/EnableCommand.java @@ -2,11 +2,11 @@ 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; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.StringArgument; import com.diamondfire.helpbot.bot.command.disable.*; 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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -37,8 +37,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.ADMINISTRATOR; + public Rank getRank() { + return Rank.ADMINISTRATOR; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/EvalCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/EvalCommand.java index 220a3966..9970f36f 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/EvalCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/EvalCommand.java @@ -5,7 +5,7 @@ import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.MessageArgument; 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.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.util.EmbedUtil; import net.dv8tion.jda.api.EmbedBuilder; @@ -50,8 +50,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.BOT_DEVELOPER; + public Rank getRank() { + return Rank.BOT_DEVELOPER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/FetchDataCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/FetchDataCommand.java index 0d109001..76dd4483 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/FetchDataCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/FetchDataCommand.java @@ -4,7 +4,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.df.codeinfo.codedatabase.changelog.CodeDifferenceHandler; import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.CodeDatabase; @@ -52,8 +52,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.BOT_DEVELOPER; + public Rank getRank() { + return Rank.BOT_DEVELOPER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/QueryCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/QueryCommand.java index 0e85f3c6..969d24d7 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/QueryCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/QueryCommand.java @@ -4,7 +4,7 @@ import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.MessageArgument; 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.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; @@ -41,8 +41,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.BOT_DEVELOPER; + public Rank getRank() { + return Rank.BOT_DEVELOPER; } @SuppressWarnings("LanguageMismatch") diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/RestartCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/RestartCommand.java index 4ea13503..3be901db 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/RestartCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/RestartCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.bot.restart.RestartHandler; import net.dv8tion.jda.api.EmbedBuilder; @@ -33,8 +33,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.BOT_DEVELOPER; + public Rank getRank() { + return Rank.BOT_DEVELOPER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ActionDumpCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ActionDumpCommand.java index 1e48bcd0..77985973 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ActionDumpCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ActionDumpCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.externalfile.ExternalFiles; @@ -27,8 +27,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ImageDumpCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ImageDumpCommand.java index 9500c7b2..ead9081f 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ImageDumpCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ImageDumpCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -32,8 +32,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/SoundListCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/SoundListCommand.java index c740c18f..bf892b67 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/SoundListCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/SoundListCommand.java @@ -2,7 +2,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.CodeDatabase; @@ -26,8 +26,8 @@ public HelpContext getHelpContext() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/EightBallCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/EightBallCommand.java index f4645e2f..d3c1e9d4 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/EightBallCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/EightBallCommand.java @@ -4,7 +4,7 @@ import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.*; 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.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import net.dv8tion.jda.api.EmbedBuilder; @@ -38,12 +38,12 @@ public HelpContext getHelpContext() { public ArgumentSet compileArguments() { return new ArgumentSet() .addArgument("question", - new SingleArgumentContainer<>(new MessageArgument()).optional("Is vatten super duper cool?")); + new SingleArgumentContainer<>(new MessageArgument()).optional(event -> "Is vatten super duper cool?")); } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/GarfieldCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/GarfieldCommand.java index 05eb8b2a..bfd88b5c 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/GarfieldCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/GarfieldCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.google.gson.JsonParser; import net.dv8tion.jda.api.EmbedBuilder; @@ -33,8 +33,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/IdeaCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/IdeaCommand.java index 2b93c966..f27e66be 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/IdeaCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/IdeaCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import net.dv8tion.jda.api.EmbedBuilder; @@ -29,8 +29,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/NbsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/NbsCommand.java index 5348c249..e6482021 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/NbsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/NbsCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -36,7 +36,7 @@ public HelpContext getHelpContext() { protected ArgumentSet compileArguments() { return new ArgumentSet(); } @Override - public Permission getPermission() { return Permission.USER; } + public Rank getRank() { return Rank.USER; } @Override public void run(CommandEvent event) { diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/OcrCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/OcrCommand.java index 1f9f5b7b..dc90a08c 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/OcrCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/OcrCommand.java @@ -3,10 +3,10 @@ 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; -import com.diamondfire.helpbot.bot.command.argument.impl.types.StringArgument; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.StringArgument; 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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -50,8 +50,8 @@ protected ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/SamQuotesCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/SamQuotesCommand.java index 478a1a1b..9773b903 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/SamQuotesCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/SamQuotesCommand.java @@ -2,10 +2,10 @@ import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; -import com.diamondfire.helpbot.bot.command.argument.impl.types.DefinedObjectArgument; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.DefinedObjectArgument; 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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -50,8 +50,8 @@ public HelpContext getHelpContext() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/HelpCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/HelpCommand.java index 33c261e0..bd7d1a00 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/HelpCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/HelpCommand.java @@ -3,7 +3,7 @@ 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; -import com.diamondfire.helpbot.bot.command.argument.impl.types.DefinedObjectArgument; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.DefinedObjectArgument; import com.diamondfire.helpbot.bot.command.help.*; import com.diamondfire.helpbot.bot.command.impl.Command; import com.diamondfire.helpbot.bot.command.permissions.*; @@ -48,8 +48,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override @@ -65,7 +65,7 @@ public void run(CommandEvent event) { EmbedBuilder homeBuilder = new EmbedBuilder(); homeBuilder.setDescription("Commands that are available to you are listed in the pages below. To select a page, react to the message. Any additional questions may be forwarded to Owen1212055"); homeBuilder.setThumbnail(event.getJDA().getSelfUser().getAvatarUrl()); - homeBuilder.setFooter("Your permissions: " + PermissionHandler.getPermission(event.getMember())); + homeBuilder.setFooter("Your permissions: " + RankHandler.getPermission(event.getMember())); selector.addPage("Home", homeBuilder, true); // Initialize the pages in advance so we can get a nice order. @@ -80,7 +80,7 @@ public void run(CommandEvent event) { for (Command command : commandList) { HelpContext context = command.getHelpContext(); CommandCategory category = context.getCommandCategory(); - if (category != null && command.getPermission().hasPermission(event.getMember())) { + if (category != null && command.getRank().hasPermission(event.getMember())) { EmbedBuilder embedBuilder = categories.get(category); embedBuilder.addField(FormatUtil.displayCommand(command) + " " + FormatUtil.displayArguments(context), context.getDescription(), false); @@ -106,7 +106,7 @@ public void run(CommandEvent event) { builder.addField("Aliases", (command.getAliases().length == 0 ? "None" : String.join(", ", command.getAliases())), false); builder.addField("Argument", FormatUtil.displayArguments(context), true); builder.addField("Category", context.getCommandCategory().toString(), true); - builder.addField("Role Required", String.format("<@&%s>", command.getPermission().getRole()), true); + builder.addField("Role Required", String.format("<@&%s>", command.getRank().getRoleId()), true); event.getChannel().sendMessageEmbeds(builder.build()).queue(); } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/InfoCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/InfoCommand.java index 672fecdf..1cb23b92 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/InfoCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/InfoCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.df.codeinfo.codedatabase.changelog.CodeDifferenceHandler; @@ -35,8 +35,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/PermUnlocksCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/PermUnlocksCommand.java index cf0c418f..341b8bb0 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/PermUnlocksCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/PermUnlocksCommand.java @@ -2,10 +2,10 @@ 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; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.DefinedObjectArgument; 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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -35,18 +35,18 @@ public HelpContext getHelpContext() { public ArgumentSet compileArguments() { return new ArgumentSet() .addArgument("permission", - new DefinedObjectArgument<>(Permission.values()) + new DefinedObjectArgument<>(Rank.values()) ); } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override public void run(CommandEvent event) { - Permission permission = event.getArgument("permission"); + Rank permission = event.getArgument("permission"); PresetBuilder builder = new PresetBuilder() .withPreset( new InformativeReply(InformativeReplyType.INFO, "Commands unlocked by: " + permission, null) @@ -54,16 +54,16 @@ public void run(CommandEvent event) { List commands = new ArrayList<>(); List commandList = new ArrayList<>(CommandHandler.getInstance().getCommands().values()); - commandList.sort(Comparator.comparingInt((command) -> command.getPermission().ordinal())); + commandList.sort(Comparator.comparingInt((command) -> command.getRank().ordinal())); for (Command command : commandList) { - if (command.getPermission().hasPermission(permission)) { + if (command.getRank().hasPermission(permission)) { StringBuilder cmdName = new StringBuilder(); cmdName.append(command.getName()); - if (command.getPermission() != permission) { + if (command.getRank() != permission) { cmdName.append(" (From ") - .append(command.getPermission()) + .append(command.getRank()) .append(')'); } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/PolicyCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/PolicyCommand.java index 6f24423a..d73e6d5b 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/PolicyCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/PolicyCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -34,8 +34,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/RulesCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/RulesCommand.java index c9743aaa..9890b371 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/RulesCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/info/RulesCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.multiselector.MultiSelectorBuilder; import net.dv8tion.jda.api.EmbedBuilder; @@ -33,8 +33,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/ChannelMuteCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/ChannelMuteCommand.java index 207d2b3a..c5ae9956 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/ChannelMuteCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/ChannelMuteCommand.java @@ -3,10 +3,10 @@ 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; -import com.diamondfire.helpbot.bot.command.argument.impl.types.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.*; 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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -14,6 +14,7 @@ import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; import com.diamondfire.helpbot.sys.tasks.impl.MuteExpireTask; import com.diamondfire.helpbot.util.*; +import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.*; import java.time.*; @@ -47,8 +48,8 @@ protected ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.MODERATION; + public Rank getRank() { + return Rank.MODERATION; } @Override @@ -85,7 +86,7 @@ public void run(CommandEvent event) { Guild punishmentGuild = event.getGuild(); TextChannel textChannel = punishmentGuild.getTextChannelById(channel); punishmentGuild.retrieveMemberById(user).queue((member) -> { - textChannel.putPermissionOverride(member).deny(net.dv8tion.jda.api.Permission.MESSAGE_ADD_REACTION, net.dv8tion.jda.api.Permission.MESSAGE_WRITE).queue(); + textChannel.putPermissionOverride(member).deny(Permission.MESSAGE_ADD_REACTION, Permission.MESSAGE_WRITE).queue(); }); HelpBotInstance.getScheduler().schedule(new MuteExpireTask(user, finalDuration, false)); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/DiscussionMuteCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/DiscussionMuteCommand.java index 610af367..edf8aa68 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/DiscussionMuteCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/DiscussionMuteCommand.java @@ -3,10 +3,10 @@ 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; -import com.diamondfire.helpbot.bot.command.argument.impl.types.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.*; 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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -55,12 +55,12 @@ protected ArgumentSet compileArguments() { .addArgument("user", new DiscordUserArgument()) .addArgument("duration", - new SingleArgumentContainer<>(new TimeOffsetArgument()).optional(DateUtil.toDate(nextMonday))); + new SingleArgumentContainer<>(new TimeOffsetArgument()).optional(event -> DateUtil.toDate(nextMonday))); } @Override - public Permission getPermission() { - return Permission.MODERATION; + public Rank getRank() { + return Rank.MODERATION; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/LockCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/LockCommand.java new file mode 100644 index 00000000..c1f4855d --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/LockCommand.java @@ -0,0 +1,115 @@ +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.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.EndlessStringArgument; +import com.diamondfire.helpbot.bot.command.help.*; +import com.diamondfire.helpbot.bot.command.impl.Command; +import com.diamondfire.helpbot.bot.command.permissions.Rank; +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 net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.*; + +import java.util.Arrays; + +public class LockCommand extends Command { + //TODO + @Override + public String getName() { + return "lock"; + } + + @Override + public String[] getAliases() { + return new String[]{ + "unlock" + }; + } + + @Override + public HelpContext getHelpContext() { + return new HelpContext() + .description("Toggles a channel lock.") + .addArgument( + new HelpContextArgument() + .name("channel") + .optional() + ).addArgument( + new HelpContextArgument() + .name("reason") + .optional() + ); + } + + @Override + protected ArgumentSet compileArguments() { + return new ArgumentSet() + .addArgument( + "channel", + new TextChannelArgument(Permission.MANAGE_PERMISSIONS) + ).addArgument( + "reason", + new SingleArgumentContainer<>(new EndlessStringArgument()) + .optional(event -> "No reason provided.") + ); + } + + @Override + public Rank getRank() { + return Rank.MODERATION; + } + + @Override + public void run(CommandEvent event) { + toggleLock( + event.getArgument("channel"), + event.getArgument("reason") + ); + + event.getMessage().addReaction("✅").queue(); + } + + private static final Permission[] LOCK_PERMISSIONS = new Permission[]{ + Permission.MESSAGE_WRITE, + Permission.MESSAGE_ADD_REACTION + }; + + private void toggleLock(TextChannel channel, String reason) { + if (isLocked(channel)) { + unlockChannel(channel, reason); + } else { + lockChannel(channel, reason); + } + } + + @SuppressWarnings("all") + private boolean isLocked(TextChannel channel) { + return !channel.getPermissionOverride(Rank.USER.getRole()).getAllowed() + .containsAll(Arrays.asList(LOCK_PERMISSIONS)); + } + + private void lockChannel(TextChannel channel, String reason) { + channel + .putPermissionOverride(Rank.USER.getRole()) + .deny(LOCK_PERMISSIONS) + .queue(); + + channel.sendMessageEmbeds(new PresetBuilder() + .withPreset(new InformativeReply( + InformativeReplyType.INFO, + "This channel has been locked.\nReason: " + reason + )).getEmbed().build()).queue(); + } + + private void unlockChannel(TextChannel channel, String reason) { + channel + .putPermissionOverride(Rank.USER.getRole()) + .grant(LOCK_PERMISSIONS) + .queue(); + + channel.sendMessage(":unlock: This channel has been unlocked.").queue(); + } +} diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/MuteCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/MuteCommand.java index 385e652d..c5a6a42e 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/MuteCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/MuteCommand.java @@ -3,10 +3,10 @@ import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.*; -import com.diamondfire.helpbot.bot.command.argument.impl.types.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.*; 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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -52,12 +52,12 @@ protected ArgumentSet compileArguments() { .addArgument("duration", new TimeOffsetArgument()) .addArgument("reason", - new SingleArgumentContainer<>(new MessageArgument()).optional("Not Specified")); + new SingleArgumentContainer<>(new MessageArgument()).optional(event -> "Not Specified")); } @Override - public Permission getPermission() { - return Permission.MODERATION; + public Rank getRank() { + return Rank.MODERATION; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/MutedCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/MutedCommand.java index 580030d4..dbcb8a58 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/MutedCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/MutedCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -35,8 +35,8 @@ protected ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.MODERATION; + public Rank getRank() { + return Rank.MODERATION; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java index de68a769..78077174 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java @@ -1,22 +1,19 @@ 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.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.IntegerArgument; 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.permissions.Rank; 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.externalfile.ExternalFileUtil; -import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.entities.*; import java.io.File; import java.nio.file.*; import java.time.format.DateTimeFormatter; -import java.util.*; -import java.util.concurrent.ExecutionException; public class PurgeCommand extends Command { @@ -41,8 +38,8 @@ protected ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.MODERATION; + public Rank getRank() { + return Rank.MODERATION; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/UnmuteCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/UnmuteCommand.java index fa2fc488..b27c133a 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/UnmuteCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/UnmuteCommand.java @@ -2,10 +2,10 @@ import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.*; -import com.diamondfire.helpbot.bot.command.argument.impl.types.DiscordUserArgument; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.DiscordUserArgument; 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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -43,12 +43,12 @@ protected ArgumentSet compileArguments() { .addArgument("user", new DiscordUserArgument()) .addArgument("reason", - new SingleArgumentContainer<>(new MessageArgument()).optional("Not Specified")); + new SingleArgumentContainer<>(new MessageArgument()).optional(event -> "Not Specified")); } @Override - public Permission getPermission() { - return Permission.MODERATION; + public Rank getRank() { + return Rank.MODERATION; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/VerifyCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/VerifyCommand.java index a0c46702..0080d7ec 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/VerifyCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/VerifyCommand.java @@ -1,10 +1,10 @@ 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.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.*; 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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -47,8 +47,8 @@ protected ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.MODERATION; + public Rank getRank() { + return Rank.MODERATION; } @Override 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 index 675d585d..8070b352 100644 --- 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 @@ -1,10 +1,14 @@ 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.impl.EndlessStringArgument; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.QuoteStringArgument; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.StringArgument; import com.diamondfire.helpbot.bot.command.argument.impl.types.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.*; 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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -45,8 +49,8 @@ protected ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.EXPERT + public Rank getRank() { + return Rank.EXPERT .setOverrides(this, 808966728201666620L); } 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 index 8b596a97..a4dfc411 100644 --- 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 @@ -1,11 +1,12 @@ 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.*; -import com.diamondfire.helpbot.bot.command.argument.impl.types.Enum.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.Enum.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.EndlessStringArgument; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -37,16 +38,15 @@ protected ArgumentSet compileArguments() { return new ArgumentSet().addArgument( "activator", new StringArgument() ).addArgument( - "property", new EnumArgument() - .setEnum(TagProperty.class) + "property", new EnumArgument<>(TagProperty.class) ).addArgument( "newValue", new EndlessStringArgument() ); } @Override - public Permission getPermission() { - return Permission.EXPERT + public Rank getRank() { + return Rank.EXPERT .setOverrides(this, 808966728201666620L); } 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 index 3c8c3eeb..e38d5986 100644 --- 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 @@ -4,12 +4,13 @@ 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.permissions.Rank; 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.util.stream.Collectors; import java.io.IOException; import java.util.*; import java.util.stream.Collectors; @@ -32,8 +33,8 @@ protected ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override 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 index 67f2581c..73045d1c 100644 --- 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 @@ -1,10 +1,10 @@ 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.argument.impl.types.impl.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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -38,8 +38,8 @@ protected ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.EXPERT + public Rank getRank() { + return Rank.EXPERT .setOverrides(this, 808966728201666620L); } 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 index 67597ee2..842d95c3 100644 --- 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 @@ -2,7 +2,7 @@ import com.diamondfire.helpbot.bot.command.help.*; import com.diamondfire.helpbot.bot.command.impl.*; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; public class TagCommand extends SubCommandHolder { @@ -28,8 +28,8 @@ public HelpContext getHelpContext() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/AbstractFileListCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/AbstractFileListCommand.java index 9b313df0..c2d5849b 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/AbstractFileListCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/AbstractFileListCommand.java @@ -2,7 +2,7 @@ import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.impl.Command; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.CodeObject; import com.diamondfire.helpbot.sys.externalfile.ExternalFileUtil; @@ -19,8 +19,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } protected void generate(CommandEvent event, List data) { diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/BulkExecuteCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/BulkExecuteCommand.java index 5f57a99b..137eab77 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/BulkExecuteCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/BulkExecuteCommand.java @@ -3,11 +3,11 @@ 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; -import com.diamondfire.helpbot.bot.command.argument.impl.types.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.*; import com.diamondfire.helpbot.bot.command.help.*; import com.diamondfire.helpbot.bot.command.impl.Command; import com.diamondfire.helpbot.bot.command.impl.stats.AbstractPlayerUUIDCommand; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -57,8 +57,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.EXPERT; + public Rank getRank() { + return Rank.EXPERT; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/MimicCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/MimicCommand.java index caebb61d..f9f99cd3 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/MimicCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/MimicCommand.java @@ -4,7 +4,7 @@ import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.MessageArgument; 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.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -32,8 +32,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.BOT_DEVELOPER; + public Rank getRank() { + return Rank.BOT_DEVELOPER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/PollCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/PollCommand.java index f8965927..9d356852 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/PollCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/PollCommand.java @@ -4,7 +4,7 @@ import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.MessageArgument; 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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -41,8 +41,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.ADMINISTRATOR; + public Rank getRank() { + return Rank.ADMINISTRATOR; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/AbstractPlayerUUIDCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/AbstractPlayerUUIDCommand.java index 4e9333ab..dc7a3793 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/AbstractPlayerUUIDCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/AbstractPlayerUUIDCommand.java @@ -2,9 +2,9 @@ import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; -import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft.*; import com.diamondfire.helpbot.bot.command.impl.Command; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; public abstract class AbstractPlayerUUIDCommand extends Command { @@ -17,8 +17,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override 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 a8dd705d..e54787fa 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 @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -41,8 +41,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/CpRequirementsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/CpRequirementsCommand.java index 56dae817..a35af3ef 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/CpRequirementsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/CpRequirementsCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -37,8 +37,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/RetiredListCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/RetiredListCommand.java index ca6d982d..e2fe8931 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/RetiredListCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/RetiredListCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.df.ranks.*; import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; @@ -40,8 +40,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override @@ -56,18 +56,18 @@ public void run(CommandEvent event) { "AND ranks.support = 0")) .compile() .run((result) -> { - Map> retiredList = new HashMap<>(); - retiredList.put(Rank.RETIRED, new ArrayList<>()); - retiredList.put(Rank.EMERITUS, new ArrayList<>()); + Map> retiredList = new HashMap<>(); + retiredList.put(com.diamondfire.helpbot.df.ranks.Rank.RETIRED, new ArrayList<>()); + retiredList.put(com.diamondfire.helpbot.df.ranks.Rank.EMERITUS, new ArrayList<>()); for (ResultSet set : result) { - retiredList.get(Rank.fromBranch(RankBranch.RETIREMENT, set.getInt("retirement"))).add(StringUtil.display(set.getString("name"))); + retiredList.get(com.diamondfire.helpbot.df.ranks.Rank.fromBranch(RankBranch.RETIREMENT, set.getInt("retirement"))).add(StringUtil.display(set.getString("name"))); } EmbedBuilder retired = new EmbedBuilder(); - EmbedUtil.addFields(retired, retiredList.get(Rank.RETIRED), "", "", true); + EmbedUtil.addFields(retired, retiredList.get(com.diamondfire.helpbot.df.ranks.Rank.RETIRED), "", "", true); EmbedBuilder emeritus = new EmbedBuilder(); - EmbedUtil.addFields(emeritus, retiredList.get(Rank.EMERITUS), "", "", true); + EmbedUtil.addFields(emeritus, retiredList.get(com.diamondfire.helpbot.df.ranks.Rank.EMERITUS), "", "", true); builder.addPage("Retired", retired); builder.addPage("Emeritus", emeritus); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/StaffListCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/StaffListCommand.java index b86bfd7b..7206a829 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/StaffListCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/StaffListCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.df.ranks.*; import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; @@ -41,8 +41,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override @@ -56,17 +56,17 @@ public void run(CommandEvent event) { " AND (ranks.support > 0 || ranks.moderation > 0 || ranks.administration > 0 || ranks.builder = 1) AND ranks.retirement = 0")) .compile() .runAsync((result) -> { - Map> ranks = new HashMap<>(); + Map> ranks = new HashMap<>(); registerRank(ranks, - Rank.JRHELPER, - Rank.HELPER, - Rank.EXPERT, - Rank.JRMOD, - Rank.MOD, - Rank.SR_MOD, - Rank.ADMIN, - Rank.OWNER, - Rank.DEVELOPER); + com.diamondfire.helpbot.df.ranks.Rank.JRHELPER, + com.diamondfire.helpbot.df.ranks.Rank.HELPER, + com.diamondfire.helpbot.df.ranks.Rank.EXPERT, + com.diamondfire.helpbot.df.ranks.Rank.JRMOD, + com.diamondfire.helpbot.df.ranks.Rank.MOD, + com.diamondfire.helpbot.df.ranks.Rank.SR_MOD, + com.diamondfire.helpbot.df.ranks.Rank.ADMIN, + com.diamondfire.helpbot.df.ranks.Rank.OWNER, + com.diamondfire.helpbot.df.ranks.Rank.DEVELOPER); for (ResultSet set : result) { String name = StringUtil.display(set.getString("name")); @@ -75,34 +75,34 @@ public void run(CommandEvent event) { int administrationNum = set.getInt("administration"); if (administrationNum > 0) { - ranks.get(Rank.fromBranch(RankBranch.ADMINISTRATION, administrationNum)).add(name); + ranks.get(com.diamondfire.helpbot.df.ranks.Rank.fromBranch(RankBranch.ADMINISTRATION, administrationNum)).add(name); } if (moderationNum == 0 && supportNum > 0 && administrationNum == 0) { - ranks.get(Rank.fromBranch(RankBranch.SUPPORT, supportNum)).add(name); + ranks.get(com.diamondfire.helpbot.df.ranks.Rank.fromBranch(RankBranch.SUPPORT, supportNum)).add(name); } else if (moderationNum > 0 && administrationNum == 0) { - ranks.get(Rank.fromBranch(RankBranch.MODERATION, moderationNum)).add(name); + ranks.get(com.diamondfire.helpbot.df.ranks.Rank.fromBranch(RankBranch.MODERATION, moderationNum)).add(name); } } EmbedBuilder supportPage = new EmbedBuilder(); - EmbedUtil.addFields(supportPage, ranks.get(Rank.EXPERT), "", "Experts"); - EmbedUtil.addFields(supportPage, ranks.get(Rank.HELPER), "", "Helpers"); - EmbedUtil.addFields(supportPage, ranks.get(Rank.JRHELPER), "", "JrHelpers"); + EmbedUtil.addFields(supportPage, ranks.get(com.diamondfire.helpbot.df.ranks.Rank.EXPERT), "", "Experts"); + EmbedUtil.addFields(supportPage, ranks.get(com.diamondfire.helpbot.df.ranks.Rank.HELPER), "", "Helpers"); + EmbedUtil.addFields(supportPage, ranks.get(com.diamondfire.helpbot.df.ranks.Rank.JRHELPER), "", "JrHelpers"); builder.addPage("Support", supportPage); EmbedBuilder modPage = new EmbedBuilder(); - EmbedUtil.addFields(modPage, ranks.get(Rank.SR_MOD), "", "SrMods"); - EmbedUtil.addFields(modPage, ranks.get(Rank.MOD), "", "Mods"); - EmbedUtil.addFields(modPage, ranks.get(Rank.JRMOD), "", "JrMods"); + EmbedUtil.addFields(modPage, ranks.get(com.diamondfire.helpbot.df.ranks.Rank.SR_MOD), "", "SrMods"); + EmbedUtil.addFields(modPage, ranks.get(com.diamondfire.helpbot.df.ranks.Rank.MOD), "", "Mods"); + EmbedUtil.addFields(modPage, ranks.get(com.diamondfire.helpbot.df.ranks.Rank.JRMOD), "", "JrMods"); builder.addPage("Moderation", modPage); EmbedBuilder adminPage = new EmbedBuilder(); - EmbedUtil.addFields(adminPage, ranks.get(Rank.OWNER), "", "Owner"); - EmbedUtil.addFields(adminPage, ranks.get(Rank.ADMIN), "", "Admins"); + EmbedUtil.addFields(adminPage, ranks.get(com.diamondfire.helpbot.df.ranks.Rank.OWNER), "", "Owner"); + EmbedUtil.addFields(adminPage, ranks.get(com.diamondfire.helpbot.df.ranks.Rank.ADMIN), "", "Admins"); builder.addPage("Administration", adminPage); EmbedBuilder devEmbed = new EmbedBuilder(); - EmbedUtil.addFields(devEmbed, ranks.get(Rank.DEVELOPER), "", "DiamondFire Developers"); + EmbedUtil.addFields(devEmbed, ranks.get(com.diamondfire.helpbot.df.ranks.Rank.DEVELOPER), "", "DiamondFire Developers"); Guild guild = event.getGuild(); Role botDev = guild.getRoleById(589238520145510400L); @@ -124,8 +124,8 @@ public void run(CommandEvent event) { } - private void registerRank(Map> map, Rank... ranks) { - for (Rank rank : ranks) { + private void registerRank(Map> map, com.diamondfire.helpbot.df.ranks.Rank... ranks) { + for (com.diamondfire.helpbot.df.ranks.Rank rank : ranks) { map.put(rank, new ArrayList<>()); } } 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 2e868836..c132a647 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 @@ -1,9 +1,9 @@ package com.diamondfire.helpbot.bot.command.impl.stats.graph; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; -import com.diamondfire.helpbot.bot.command.argument.impl.types.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.*; import com.diamondfire.helpbot.bot.command.impl.Command; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.graph.generators.*; @@ -19,8 +19,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/CpCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/CpCommand.java index 5daab72a..756307c4 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/CpCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/CpCommand.java @@ -1,9 +1,9 @@ package com.diamondfire.helpbot.bot.command.impl.stats.individualized; -import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.Player; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft.Player; import com.diamondfire.helpbot.bot.command.help.*; import com.diamondfire.helpbot.bot.command.impl.stats.AbstractPlayerUUIDCommand; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.MinecraftUserPreset; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; @@ -45,8 +45,8 @@ public HelpContext getHelpContext() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/HistoryCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/HistoryCommand.java index 6a1e5cac..fef2a63c 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/HistoryCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/HistoryCommand.java @@ -1,9 +1,9 @@ package com.diamondfire.helpbot.bot.command.impl.stats.individualized; -import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.Player; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft.Player; import com.diamondfire.helpbot.bot.command.help.*; import com.diamondfire.helpbot.bot.command.impl.stats.AbstractPlayerUUIDCommand; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.MinecraftUserPreset; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; @@ -48,13 +48,13 @@ public HelpContext getHelpContext() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override protected void execute(CommandEvent event, Player player) { - if (!Permission.MODERATION.hasPermission(event.getMember()) && !event.getMember().getEffectiveName().equals(player.name())) { + if (!Rank.MODERATION.hasPermission(event.getMember()) && !event.getMember().getEffectiveName().equals(player.name())) { PresetBuilder activePunishmentsPreset = new PresetBuilder() .withPreset( new InformativeReply(InformativeReplyType.ERROR, "You must be a moderator inorder to see other peoples history!") 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 399d7f1a..7f96460c 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 @@ -1,11 +1,10 @@ package com.diamondfire.helpbot.bot.command.impl.stats.individualized; -import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.Player; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft.Player; 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.impl.stats.AbstractPlayerUUIDCommand; -import com.diamondfire.helpbot.bot.command.permissions.Permission; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.MinecraftUserPreset; import com.diamondfire.helpbot.bot.command.reply.feature.informative.InformativeReply; @@ -13,13 +12,11 @@ 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; import net.dv8tion.jda.api.utils.TimeFormat; import java.sql.ResultSet; import java.sql.Timestamp; -import java.time.temporal.ChronoUnit; public class LastJoinedCommand extends AbstractPlayerUUIDCommand { diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/NamesCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/NamesCommand.java index d2db7454..14d33a62 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/NamesCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/NamesCommand.java @@ -1,11 +1,9 @@ package com.diamondfire.helpbot.bot.command.impl.stats.individualized; -import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; -import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; -import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft.*; import com.diamondfire.helpbot.bot.command.help.*; import com.diamondfire.helpbot.bot.command.impl.stats.AbstractPlayerUUIDCommand; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.MinecraftUserPreset; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; @@ -42,8 +40,8 @@ public HelpContext getHelpContext() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/PlotsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/PlotsCommand.java index d7e4a7c6..d3f7c901 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/PlotsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/PlotsCommand.java @@ -1,9 +1,9 @@ package com.diamondfire.helpbot.bot.command.impl.stats.individualized; -import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.Player; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft.Player; import com.diamondfire.helpbot.bot.command.help.*; import com.diamondfire.helpbot.bot.command.impl.stats.AbstractPlayerUUIDCommand; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.MinecraftUserPreset; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; @@ -40,8 +40,8 @@ public HelpContext getHelpContext() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/ProfileCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/ProfileCommand.java index 90a68ac4..3d6de1f7 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/ProfileCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/ProfileCommand.java @@ -1,9 +1,9 @@ package com.diamondfire.helpbot.bot.command.impl.stats.individualized; -import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.Player; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft.Player; import com.diamondfire.helpbot.bot.command.help.*; import com.diamondfire.helpbot.bot.command.impl.stats.AbstractPlayerUUIDCommand; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.MinecraftUserPreset; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; @@ -44,8 +44,8 @@ public HelpContext getHelpContext() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override @@ -75,7 +75,7 @@ protected void execute(CommandEvent event, Player player) { String rankString; { - Rank highRank = RankUtil.getHighRank(set); + com.diamondfire.helpbot.df.ranks.Rank highRank = RankUtil.getHighRank(set); if (highRank == null) { rankString = ""; } else { @@ -87,9 +87,9 @@ protected void execute(CommandEvent event, Player player) { embed.addField("UUID", playerUUID, false); embed.addField("Whois", StringUtil.display(whois.isEmpty() ? "N/A" : whois).replace("\\n", "\n"), false); - Rank[] ranks = RankUtil.getRanks(set); + com.diamondfire.helpbot.df.ranks.Rank[] ranks = RankUtil.getRanks(set); List ranksList = new ArrayList<>(); - for (Rank rank : ranks) { + for (com.diamondfire.helpbot.df.ranks.Rank rank : ranks) { ranksList.add(String.format("[%s]", rank.getRankName())); } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/SkinCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/SkinCommand.java index 373b146a..df6fcd01 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/SkinCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/SkinCommand.java @@ -1,9 +1,9 @@ package com.diamondfire.helpbot.bot.command.impl.stats.individualized; -import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.Player; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft.Player; import com.diamondfire.helpbot.bot.command.help.*; import com.diamondfire.helpbot.bot.command.impl.stats.AbstractPlayerUUIDCommand; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.MinecraftUserPreset; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; @@ -31,8 +31,8 @@ public HelpContext getHelpContext() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/UuidCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/UuidCommand.java index f55ac995..9bca689d 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/UuidCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/UuidCommand.java @@ -1,14 +1,10 @@ package com.diamondfire.helpbot.bot.command.impl.stats.individualized; -import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.Player; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft.Player; import com.diamondfire.helpbot.bot.command.help.HelpContext; import com.diamondfire.helpbot.bot.command.impl.stats.AbstractPlayerUUIDCommand; -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.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; -import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; -import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; //Command exists for easy mobile copy and pasting @@ -25,8 +21,8 @@ public HelpContext getHelpContext() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinDataCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinDataCommand.java index c1070e35..0a77ae1c 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinDataCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinDataCommand.java @@ -2,14 +2,13 @@ import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; -import com.diamondfire.helpbot.bot.command.argument.impl.types.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.*; 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.permissions.Rank; 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.df.ranks.Rank; import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; import com.diamondfire.helpbot.util.*; @@ -51,7 +50,7 @@ public ArgumentSet compileArguments() { .addArgument("date", new DateArgument()) .addArgument("days", - new SingleArgumentContainer<>(new ClampedIntegerArgument(1)).optional(7)) + new SingleArgumentContainer<>(new ClampedIntegerArgument(1)).optional(event -> 7)) .addArgument("daterejoin", new SingleArgumentContainer<>(new DateArgument()).optional(null)) .addArgument("daysrejoin", @@ -60,8 +59,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.ADMINISTRATOR; + public Rank getRank() { + return Rank.ADMINISTRATOR; } @Override @@ -124,10 +123,10 @@ public void run(CommandEvent event) { }); embed.addField(String.format("Players that have joined within %s and %s that have donor ranks.", dateFrom, dateTo), String.join("\n", new String[]{ - format(Rank.OVERLORD) + ranks.get(4), - format(Rank.MYTHIC) + ranks.get(3), - format(Rank.EMPEROR) + " " + ranks.get(2), - format(Rank.NOBLE) + ranks.get(1) + format(com.diamondfire.helpbot.df.ranks.Rank.OVERLORD) + ranks.get(4), + format(com.diamondfire.helpbot.df.ranks.Rank.MYTHIC) + ranks.get(3), + format(com.diamondfire.helpbot.df.ranks.Rank.EMPEROR) + " " + ranks.get(2), + format(com.diamondfire.helpbot.df.ranks.Rank.NOBLE) + ranks.get(1) }), false); @@ -169,7 +168,7 @@ public void run(CommandEvent event) { event.reply(builder); } - private String format(Rank rank) { + private String format(com.diamondfire.helpbot.df.ranks.Rank rank) { return rank.getRankEmote().getAsMention() + " "; } } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinsCommand.java index 3dce51b8..0c42dd4f 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinsCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; @@ -26,7 +26,7 @@ public HelpContext getHelpContext() { public ArgumentSet compileArguments() { return new ArgumentSet(); } @Override - public Permission getPermission() { return Permission.USER; } + public Rank getRank() { return Rank.USER; } @Override public void run(CommandEvent event) { diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/NewPlayersCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/NewPlayersCommand.java index f221c26a..45ee01d2 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/NewPlayersCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/NewPlayersCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -34,8 +34,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/PlayersCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/PlayersCommand.java index 02ef9dfc..75e95183 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/PlayersCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/PlayersCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -39,8 +39,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/PlotCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/PlotCommand.java index d9bbe6c9..93596129 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/PlotCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/PlotCommand.java @@ -1,9 +1,9 @@ package com.diamondfire.helpbot.bot.command.impl.stats.plot; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; -import com.diamondfire.helpbot.bot.command.argument.impl.types.IntegerArgument; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.IntegerArgument; import com.diamondfire.helpbot.bot.command.help.*; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.database.ConnectionProvider; @@ -35,8 +35,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/PlotLocCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/PlotLocCommand.java index ee94dcf8..b17999b2 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/PlotLocCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/PlotLocCommand.java @@ -2,9 +2,9 @@ import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; -import com.diamondfire.helpbot.bot.command.argument.impl.types.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.*; import com.diamondfire.helpbot.bot.command.help.*; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.database.ConnectionProvider; @@ -45,8 +45,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } // If someone who knows MYSQL enough that they can add plotsize as some sort of "local" variable. Go for it. diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/PlotVoteGraphCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/PlotVoteGraphCommand.java index 05f85ffb..c76bfcee 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/PlotVoteGraphCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/PlotVoteGraphCommand.java @@ -1,10 +1,10 @@ package com.diamondfire.helpbot.bot.command.impl.stats.plot; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; -import com.diamondfire.helpbot.bot.command.argument.impl.types.IntegerArgument; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.IntegerArgument; 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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -44,8 +44,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/AbstractSessionLogCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/AbstractSessionLogCommand.java index e8eeeff7..6258d6d0 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/AbstractSessionLogCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/AbstractSessionLogCommand.java @@ -1,8 +1,8 @@ package com.diamondfire.helpbot.bot.command.impl.stats.support; -import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.Player; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft.Player; import com.diamondfire.helpbot.bot.command.impl.stats.AbstractPlayerUUIDCommand; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.externalfile.ExternalFileUtil; import com.diamondfire.helpbot.util.FormatUtil; @@ -16,8 +16,8 @@ public abstract class AbstractSessionLogCommand extends AbstractPlayerUUIDComman abstract protected List getSessions(String player); @Override - public Permission getPermission() { - return Permission.SUPPORT; + public Rank getRank() { + return Rank.SUPPORT; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/DailySessionsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/DailySessionsCommand.java index b5517384..fefc2e78 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/DailySessionsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/DailySessionsCommand.java @@ -2,10 +2,10 @@ import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; -import com.diamondfire.helpbot.bot.command.argument.impl.types.DateArgument; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.DateArgument; 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.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; @@ -51,8 +51,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.SUPPORT; + public Rank getRank() { + return Rank.SUPPORT; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/ExcuseStaffCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/ExcuseStaffCommand.java index 59b30d36..9b253824 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/ExcuseStaffCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/ExcuseStaffCommand.java @@ -3,10 +3,10 @@ import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.*; -import com.diamondfire.helpbot.bot.command.argument.impl.types.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.*; 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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.MinecraftUserPreset; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; @@ -52,13 +52,13 @@ public ArgumentSet compileArguments() { new DateOffsetArgument()) .addArgument("reason", new SingleArgumentContainer<>(new MessageArgument()) - .optional("Not Specified") + .optional(event -> "Not Specified") ); } @Override - public Permission getPermission() { - return Permission.ADMINISTRATOR; + public Rank getRank() { + return Rank.ADMINISTRATOR; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/ExcusedStaffCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/ExcusedStaffCommand.java index 76da174d..4dfc0572 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/ExcusedStaffCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/ExcusedStaffCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -36,8 +36,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.EXPERT; + public Rank getRank() { + return Rank.EXPERT; } @Override @@ -74,7 +74,7 @@ public void run(CommandEvent event) { Date date = set.getDate("excused_till"); String reason = set.getString("reason"); String excused_by = set.getString("excused_by"); - Rank rank = RankUtil.getHighRank(set); + com.diamondfire.helpbot.df.ranks.Rank rank = RankUtil.getHighRank(set); String name = set.getString("name"); if (names.contains(name)) { diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/FindSupporteeNamesCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/FindSupporteeNamesCommand.java index e40fdea9..31e99a29 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/FindSupporteeNamesCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/FindSupporteeNamesCommand.java @@ -1,9 +1,9 @@ package com.diamondfire.helpbot.bot.command.impl.stats.support; -import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.Player; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft.Player; import com.diamondfire.helpbot.bot.command.help.*; import com.diamondfire.helpbot.bot.command.impl.stats.AbstractPlayerUUIDCommand; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.MinecraftUserPreset; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; @@ -34,8 +34,8 @@ public HelpContext getHelpContext() { } @Override - public Permission getPermission() { - return Permission.SUPPORT; + public Rank getRank() { + return Rank.SUPPORT; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/HelpedByCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/HelpedByCommand.java index 07546313..dffe4320 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/HelpedByCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/HelpedByCommand.java @@ -1,9 +1,9 @@ package com.diamondfire.helpbot.bot.command.impl.stats.support; -import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.Player; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft.Player; import com.diamondfire.helpbot.bot.command.help.*; import com.diamondfire.helpbot.bot.command.impl.stats.AbstractPlayerUUIDCommand; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.MinecraftUserPreset; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; @@ -37,8 +37,8 @@ public HelpContext getHelpContext() { } @Override - public Permission getPermission() { - return Permission.SUPPORT; + public Rank getRank() { + return Rank.SUPPORT; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/JoinBadCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/JoinBadCommand.java index 1e68e442..fdf7398f 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/JoinBadCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/JoinBadCommand.java @@ -2,10 +2,10 @@ import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; -import com.diamondfire.helpbot.bot.command.argument.impl.types.ClampedIntegerArgument; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.ClampedIntegerArgument; 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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -42,12 +42,12 @@ public HelpContext getHelpContext() { public ArgumentSet compileArguments() { return new ArgumentSet() .addArgument("days", - new SingleArgumentContainer<>(new ClampedIntegerArgument(1, 100)).optional(30)); + new SingleArgumentContainer<>(new ClampedIntegerArgument(1, 100)).optional(event -> 30)); } @Override - public Permission getPermission() { - return Permission.EXPERT; + public Rank getRank() { + return Rank.EXPERT; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/QueueCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/QueueCommand.java index cf8dbed0..b01fa3b4 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/QueueCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/QueueCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; @@ -40,8 +40,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SessionTopCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SessionTopCommand.java index 989ba2ff..e746161a 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SessionTopCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SessionTopCommand.java @@ -2,10 +2,10 @@ import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.*; -import com.diamondfire.helpbot.bot.command.argument.impl.types.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.*; 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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -47,13 +47,13 @@ public ArgumentSet compileArguments() { new AlternateArgumentContainer<>( new SingleArgumentContainer<>(new ClampedIntegerArgument(1)), new SingleArgumentContainer<>(new DefinedObjectArgument<>("all")) - ).optional(30) + ).optional(event -> 30) ); } @Override - public Permission getPermission() { - return Permission.SUPPORT; + public Rank getRank() { + return Rank.SUPPORT; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/StatsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/StatsCommand.java index d17a72fd..93f702e7 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/StatsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/StatsCommand.java @@ -2,11 +2,11 @@ import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; -import com.diamondfire.helpbot.bot.command.argument.impl.types.TimeOffsetArgument; -import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.Player; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.TimeOffsetArgument; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft.Player; import com.diamondfire.helpbot.bot.command.help.*; import com.diamondfire.helpbot.bot.command.impl.stats.AbstractPlayerUUIDCommand; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.MinecraftUserPreset; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; @@ -49,8 +49,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.RETIRED_SUPPORT; + public Rank getRank() { + return Rank.RETIRED_SUPPORT; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/StatsGraphCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/StatsGraphCommand.java index 2a64900b..987f6a37 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/StatsGraphCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/StatsGraphCommand.java @@ -1,9 +1,9 @@ package com.diamondfire.helpbot.bot.command.impl.stats.support; -import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.Player; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft.Player; import com.diamondfire.helpbot.bot.command.help.*; import com.diamondfire.helpbot.bot.command.impl.stats.AbstractPlayerUUIDCommand; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; @@ -39,8 +39,8 @@ public HelpContext getHelpContext() { } @Override - public Permission getPermission() { - return Permission.SUPPORT; + public Rank getRank() { + return Rank.SUPPORT; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SupportBadCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SupportBadCommand.java index 2bd1b2ac..33fd7885 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SupportBadCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SupportBadCommand.java @@ -2,10 +2,10 @@ import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; -import com.diamondfire.helpbot.bot.command.argument.impl.types.ClampedIntegerArgument; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.ClampedIntegerArgument; 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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -45,14 +45,14 @@ public HelpContext getHelpContext() { public ArgumentSet compileArguments() { return new ArgumentSet() .addArgument("count", - new SingleArgumentContainer<>(new ClampedIntegerArgument(0)).optional(5)) + new SingleArgumentContainer<>(new ClampedIntegerArgument(0)).optional(event -> 5)) .addArgument("days", - new SingleArgumentContainer<>(new ClampedIntegerArgument(0)).optional(30)); + new SingleArgumentContainer<>(new ClampedIntegerArgument(0)).optional(event -> 30)); } @Override - public Permission getPermission() { - return Permission.SUPPORT; + public Rank getRank() { + return Rank.SUPPORT; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SupportBannedPlayersCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SupportBannedPlayersCommand.java index 9b32e30e..f354f20c 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SupportBannedPlayersCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SupportBannedPlayersCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -34,8 +34,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.EXPERT; + public Rank getRank() { + return Rank.EXPERT; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SupporteeStatsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SupporteeStatsCommand.java index c564a846..76b63e90 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SupporteeStatsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SupporteeStatsCommand.java @@ -1,9 +1,9 @@ package com.diamondfire.helpbot.bot.command.impl.stats.support; -import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.Player; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft.Player; import com.diamondfire.helpbot.bot.command.help.*; import com.diamondfire.helpbot.bot.command.impl.stats.AbstractPlayerUUIDCommand; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.MinecraftUserPreset; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; @@ -40,8 +40,8 @@ public HelpContext getHelpContext() { } @Override - public Permission getPermission() { - return Permission.SUPPORT; + public Rank getRank() { + return Rank.SUPPORT; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/TimeTopCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/TimeTopCommand.java index 058241a7..86d2970a 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/TimeTopCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/TimeTopCommand.java @@ -2,10 +2,10 @@ import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.*; -import com.diamondfire.helpbot.bot.command.argument.impl.types.*; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.*; 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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -47,12 +47,12 @@ public ArgumentSet compileArguments() { new AlternateArgumentContainer<>( new SingleArgumentContainer<>(new ClampedIntegerArgument(1)), new SingleArgumentContainer<>(new DefinedObjectArgument<>("all")) - ).optional(30)); + ).optional(event -> 30)); } @Override - public Permission getPermission() { - return Permission.SUPPORT; + public Rank getRank() { + return Rank.SUPPORT; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/TotalStatsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/TotalStatsCommand.java index a7222f0e..c1c0f631 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/TotalStatsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/TotalStatsCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -34,8 +34,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.SUPPORT; + public Rank getRank() { + return Rank.SUPPORT; } // It would be nice if someone with more SQL experience could remake these to be more condensed. diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/WhoHelpedCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/WhoHelpedCommand.java index fe239d6a..c5ee3338 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/WhoHelpedCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/WhoHelpedCommand.java @@ -1,9 +1,9 @@ package com.diamondfire.helpbot.bot.command.impl.stats.support; -import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.Player; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft.Player; import com.diamondfire.helpbot.bot.command.help.*; import com.diamondfire.helpbot.bot.command.impl.stats.AbstractPlayerUUIDCommand; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.MinecraftUserPreset; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; @@ -37,8 +37,8 @@ public HelpContext getHelpContext() { } @Override - public Permission getPermission() { - return Permission.SUPPORT; + public Rank getRank() { + return Rank.SUPPORT; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/AbstractLeaderboardCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/AbstractLeaderboardCommand.java index 9b1e7ee3..9b5e2750 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/AbstractLeaderboardCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/AbstractLeaderboardCommand.java @@ -2,9 +2,9 @@ import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; -import com.diamondfire.helpbot.bot.command.argument.impl.types.StringArgument; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.StringArgument; import com.diamondfire.helpbot.bot.command.impl.Command; -import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -24,8 +24,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/ActivePlotsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/ActivePlotsCommand.java index ff9a1bf1..4adb0239 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/ActivePlotsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/ActivePlotsCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -39,8 +39,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/CpTopCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/CpTopCommand.java index 818f992a..7fb24d4b 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/CpTopCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/CpTopCommand.java @@ -2,10 +2,10 @@ import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; -import com.diamondfire.helpbot.bot.command.argument.impl.types.ClampedIntegerArgument; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.ClampedIntegerArgument; 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.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -39,13 +39,13 @@ public HelpContext getHelpContext() { @Override public ArgumentSet compileArguments() { return new ArgumentSet().addArgument("place", - new SingleArgumentContainer<>(new ClampedIntegerArgument(1)).optional(1) + new SingleArgumentContainer<>(new ClampedIntegerArgument(1)).optional(event -> 1) ); } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/DiscordBoostersCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/DiscordBoostersCommand.java index 48374965..669c17d7 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/DiscordBoostersCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/DiscordBoostersCommand.java @@ -3,14 +3,13 @@ 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.command.permissions.Rank; 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.DateUtil; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.*; -import net.dv8tion.jda.api.utils.TimeFormat; import java.awt.*; import java.text.SimpleDateFormat; @@ -42,8 +41,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/TokenTopCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/TokenTopCommand.java index daaeb3ae..07f8f605 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/TokenTopCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/TokenTopCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -39,8 +39,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/TrendingPlotsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/TrendingPlotsCommand.java index 3e25f3ee..c192e244 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/TrendingPlotsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/TrendingPlotsCommand.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -35,8 +35,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/VoteGivenLeaderboard.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/VoteGivenLeaderboard.java index fd8727b8..c05bdcbc 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/VoteGivenLeaderboard.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/VoteGivenLeaderboard.java @@ -3,7 +3,7 @@ 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.command.permissions.Rank; import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; @@ -40,8 +40,8 @@ public ArgumentSet compileArguments() { } @Override - public Permission getPermission() { - return Permission.USER; + public Rank getRank() { + return Rank.USER; } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/permissions/Permission.java b/src/main/java/com/diamondfire/helpbot/bot/command/permissions/Rank.java similarity index 66% rename from src/main/java/com/diamondfire/helpbot/bot/command/permissions/Permission.java rename to src/main/java/com/diamondfire/helpbot/bot/command/permissions/Rank.java index 8f69f446..2d36a5d0 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/permissions/Permission.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/permissions/Rank.java @@ -1,12 +1,13 @@ package com.diamondfire.helpbot.bot.command.permissions; +import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.bot.command.impl.Command; -import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.*; import java.util.*; import java.util.stream.Collectors; -public enum Permission { +public enum Rank { BOT_DEVELOPER(589238520145510400L, 999), DEVELOPER(519740942861860874L, 999), // Ask DragonSlasher, not me. @@ -17,32 +18,32 @@ public enum Permission { RETIRED_SUPPORT(235159617108181003L, 2), USER(349434193517740033L, 1); - private static final HashMap roleMap = new HashMap<>(); + private static final HashMap roleMap = new HashMap<>(); private static final HashMap> overrides = new HashMap<>(); static { - for (Permission perm : values()) { - roleMap.put(perm.getRole(), perm); + for (Rank perm : values()) { + roleMap.put(perm.getRoleId(), perm); } } private final long role; private final int permissionLevel; - Permission(long roleID, int permissionLevel) { + Rank(long roleID, int permissionLevel) { this.role = roleID; this.permissionLevel = permissionLevel; } - public static Permission fromRole(long roleID) { - Permission perm = roleMap.get(roleID); + public static Rank fromRole(long roleID) { + Rank perm = roleMap.get(roleID); if (perm == null) { return USER; } return perm; } - public Permission setOverrides(Command command, Long... userIds) { + public Rank setOverrides(Command command, Long... userIds) { overrides.put(command, Arrays.stream(userIds).collect(Collectors.toSet())); return this; } @@ -51,7 +52,11 @@ public static Set getOverrides(Command command) { return Objects.requireNonNullElse(overrides.get(command), new HashSet<>()); } - public long getRole() { + public Role getRole() { + return HelpBotInstance.getJda().getRoleById(getRoleId()); + } + + public long getRoleId() { return role; } @@ -60,10 +65,10 @@ public int getPermissionLevel() { } public boolean hasPermission(Member member) { - return hasPermission(PermissionHandler.getPermission(member)); + return hasPermission(RankHandler.getPermission(member)); } - public boolean hasPermission(Permission permission) { + public boolean hasPermission(Rank permission) { return getPermissionLevel() <= permission.getPermissionLevel(); } } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/permissions/PermissionHandler.java b/src/main/java/com/diamondfire/helpbot/bot/command/permissions/RankHandler.java similarity index 54% rename from src/main/java/com/diamondfire/helpbot/bot/command/permissions/PermissionHandler.java rename to src/main/java/com/diamondfire/helpbot/bot/command/permissions/RankHandler.java index aa31a24c..aefdd541 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/permissions/PermissionHandler.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/permissions/RankHandler.java @@ -5,20 +5,20 @@ import java.util.Comparator; -public class PermissionHandler { +public class RankHandler { - public static Permission getPermission(Member member) { + public static Rank getPermission(Member member) { // Return user if guild isn't df guild. if (member.getGuild().getIdLong() != HelpBotInstance.DF_GUILD) { - return Permission.USER; + return Rank.USER; } //Calculates the highest permission that the member has access to. - Permission perm = member.getRoles().stream() - .map((role) -> Permission.fromRole(role.getIdLong())) - .max(Comparator.comparingInt(Permission::getPermissionLevel)) - .orElse(Permission.USER); + Rank perm = member.getRoles().stream() + .map((role) -> Rank.fromRole(role.getIdLong())) + .max(Comparator.comparingInt(Rank::getPermissionLevel)) + .orElse(Rank.USER); return perm; } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/reply/feature/MinecraftUserPreset.java b/src/main/java/com/diamondfire/helpbot/bot/command/reply/feature/MinecraftUserPreset.java index 1bc49208..8c0eba9a 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/reply/feature/MinecraftUserPreset.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/reply/feature/MinecraftUserPreset.java @@ -1,6 +1,6 @@ package com.diamondfire.helpbot.bot.command.reply.feature; -import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.Player; +import com.diamondfire.helpbot.bot.command.argument.impl.types.impl.minecraft.Player; import com.diamondfire.helpbot.util.Util; import net.dv8tion.jda.api.EmbedBuilder; diff --git a/src/main/java/com/diamondfire/helpbot/df/codeinfo/codedatabase/changelog/CodeDifferenceHandler.java b/src/main/java/com/diamondfire/helpbot/df/codeinfo/codedatabase/changelog/CodeDifferenceHandler.java index c16efc3f..5684eac1 100644 --- a/src/main/java/com/diamondfire/helpbot/df/codeinfo/codedatabase/changelog/CodeDifferenceHandler.java +++ b/src/main/java/com/diamondfire/helpbot/df/codeinfo/codedatabase/changelog/CodeDifferenceHandler.java @@ -130,9 +130,11 @@ private static List readDiff(BufferedReader... readers) throws IOExc JsonObject jsonObject = null; try { jsonObject = JsonParser.parseReader(readerJson).getAsJsonObject(); + } catch (Exception e) { System.out.println("Old db is corrupted, rewriting!"); - Files.copy(ExternalFiles.DB.toPath(), ExternalFiles.DB_COMPARE.toPath(), StandardCopyOption.REPLACE_EXISTING); + + ExternalFiles.DB.copy(ExternalFiles.DB_COMPARE); } jsonObjects.add(jsonObject); diff --git a/src/main/java/com/diamondfire/helpbot/sys/externalfile/ExternalFile.java b/src/main/java/com/diamondfire/helpbot/sys/externalfile/ExternalFile.java new file mode 100644 index 00000000..4196bf12 --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/sys/externalfile/ExternalFile.java @@ -0,0 +1,58 @@ +package com.diamondfire.helpbot.sys.externalfile; + +import com.google.gson.*; +import org.jetbrains.annotations.NotNull; + +import java.io.*; +import java.nio.file.*; +import java.util.List; + +public class ExternalFile extends File { + + public ExternalFile(@NotNull String pathname) { + super(pathname); + } + + public String read() throws IOException { + return new String(Files.readAllBytes(toPath())); + } + + public List readAllLines() throws IOException { + return Files.readAllLines(toPath()); + } + + public void write(byte[] content) throws IOException { + delete(); + createNewFile(); + + Files.write(toPath(), content, StandardOpenOption.WRITE); + } + + public void write(String content) throws IOException { + write(content.getBytes()); + } + + public void write(JsonObject json) throws IOException { + write(json.toString()); + } + + public String getExtension() { + return getPath().replaceFirst("^.*\\.", ""); + } + + public JsonObject parseJson() throws IOException { + if (!getExtension().equals(ExternalFileType.JSON.getExtension())) { + throw new UnsupportedOperationException(); + } + + return JsonParser.parseString(read()).getAsJsonObject(); + } + + public void copy(File file) throws IOException { + copy(file.toPath()); + } + + public void copy(Path path) throws IOException { + Files.copy(toPath(), path, StandardCopyOption.REPLACE_EXISTING); + } +} diff --git a/src/main/java/com/diamondfire/helpbot/sys/externalfile/ExternalFileBuilder.java b/src/main/java/com/diamondfire/helpbot/sys/externalfile/ExternalFileBuilder.java index 668d8c29..7cca7706 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/externalfile/ExternalFileBuilder.java +++ b/src/main/java/com/diamondfire/helpbot/sys/externalfile/ExternalFileBuilder.java @@ -1,11 +1,12 @@ package com.diamondfire.helpbot.sys.externalfile; -import java.io.File; +import java.io.*; public class ExternalFileBuilder { String fileName; - String fileType = "unk"; + ExternalFileType fileType = ExternalFileType.UNKNOWN; + byte[] defaultContent = null; boolean directory = false; public ExternalFileBuilder setName(String fileName) { @@ -13,32 +14,54 @@ public ExternalFileBuilder setName(String fileName) { return this; } - public ExternalFileBuilder setFileType(String fileType) { + public ExternalFileBuilder setFileType(ExternalFileType fileType) { this.fileType = fileType; return this; } + public ExternalFileBuilder setDefaultContent(byte[] defaultContent) { + this.defaultContent = defaultContent; + return this; + } + + public ExternalFileBuilder setDefaultContent(String defaultContent) { + return setDefaultContent(defaultContent.getBytes()); + } + + public ExternalFileBuilder isDirectory() { + this.directory = true; + return this; + } + public ExternalFileBuilder isDirectory(boolean directory) { this.directory = directory; return this; } - public File buildFile() { - File file = new File(fileName + (directory ? "" : "." + fileType)); + public ExternalFile buildFile() { + ExternalFile file = new ExternalFile(fileName + (directory ? "" : "." + fileType.getExtension())); try { if (!file.exists()) { if (directory) { file.mkdir(); + } else { file.createNewFile(); + + if (defaultContent == null) { + defaultContent = fileType.getDefaultContent(); + } + if (defaultContent != null) { + file.write(defaultContent); + } } } - } catch (Exception e) { - e.printStackTrace(); + } catch (IOException err) { + err.printStackTrace(); } - return file; + return file; } } diff --git a/src/main/java/com/diamondfire/helpbot/sys/externalfile/ExternalFileType.java b/src/main/java/com/diamondfire/helpbot/sys/externalfile/ExternalFileType.java new file mode 100644 index 00000000..1e96a8b0 --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/sys/externalfile/ExternalFileType.java @@ -0,0 +1,37 @@ +package com.diamondfire.helpbot.sys.externalfile; + +public enum ExternalFileType { + + UNKNOWN("unk"), + + TEXT("txt"), + JSON("json", "{}"), + + PNG("png") + ; + + private final String extension; + private final byte[] defaultContent; + + ExternalFileType(String extension, byte[] defaultContent) { + this.extension = extension; + this.defaultContent = defaultContent; + } + + ExternalFileType(String extension, String defaultContent) { + this(extension, defaultContent.getBytes()); + } + + ExternalFileType(String extension) { + this(extension, (byte[]) null); + } + + public String getExtension() { + return extension; + } + + public byte[] getDefaultContent() { + return defaultContent; + } + +} 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 6d85802b..10cc187e 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/externalfile/ExternalFiles.java +++ b/src/main/java/com/diamondfire/helpbot/sys/externalfile/ExternalFiles.java @@ -4,66 +4,82 @@ public interface ExternalFiles { - File DB = new ExternalFileBuilder() - .isDirectory(false) + ExternalFile DB = new ExternalFileBuilder() .setName("db") - .setFileType("json") + .setFileType(ExternalFileType.JSON) .buildFile(); - File DB_COMPARE = new ExternalFileBuilder() - .isDirectory(false) + ExternalFile DB_COMPARE = new ExternalFileBuilder() .setName("db_last") - .setFileType("json") + .setFileType(ExternalFileType.JSON) .buildFile(); - File OTHER_CACHE_DIR = new ExternalFileBuilder() - .isDirectory(true) + ExternalFile OTHER_CACHE_DIR = new ExternalFileBuilder() + .isDirectory() .setName("other_cache") .buildFile(); - File IMAGES_DIR = new ExternalFileBuilder() - .isDirectory(true) + ExternalFile IMAGES_DIR = new ExternalFileBuilder() + .isDirectory() .setName("images") .buildFile(); - File SAM_DIR = new ExternalFileBuilder() - .isDirectory(true) + ExternalFile SAM_DIR = new ExternalFileBuilder() + .isDirectory() .setName("samquotes") .buildFile(); - File CONFIG = new ExternalFileBuilder() - .isDirectory(false) + ExternalFile CONFIG = new ExternalFileBuilder() .setName("config") - .setFileType("json") + .setFileType(ExternalFileType.JSON) + .setDefaultContent(""" + { + "token": "bot token", + "prefix": "?", + "dev_bot": true, + + "mc_email": "Minecraft@email.com", + "mc_password": "MinecraftPassword", + + "db_link": "jdbc:db_type://ip:port/schema", + "db_user": "dbuser", + "db_password": "dbpassword", + + "guild": 0, + "log_channel": 0, + "discussion_channel": 0, + "muted_role": 0, + "verified_role": 0, + + "role_react_channel": 0, + "role_react_message": 0 + + }""") .buildFile(); - File DISABLED_COMMANDS = new ExternalFileBuilder() - .isDirectory(false) + ExternalFile DISABLED_COMMANDS = new ExternalFileBuilder() .setName("disabled_commands") - .setFileType("txt") + .setFileType(ExternalFileType.TEXT) .buildFile(); - File FILTER = new ExternalFileBuilder() - .isDirectory(false) + ExternalFile FILTER = new ExternalFileBuilder() .setName("swear_filter") - .setFileType("json") + .setFileType(ExternalFileType.JSON) .buildFile(); - File SAMMAN = new ExternalFileBuilder() + ExternalFile SAMMAN = new ExternalFileBuilder() .isDirectory(false) .setName("samman") - .setFileType("png") + .setFileType(ExternalFileType.PNG) .buildFile(); - File TAGS = new ExternalFileBuilder() - .isDirectory(false) + ExternalFile TAGS = new ExternalFileBuilder() .setName("tags") - .setFileType("json") + .setFileType(ExternalFileType.JSON) .buildFile(); - File SAM_QUOTES = new ExternalFileBuilder() - .isDirectory(false) + ExternalFile SAM_QUOTES = new ExternalFileBuilder() .setName("samquotes") - .setFileType("txt") + .setFileType(ExternalFileType.TEXT) .buildFile(); } 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 7c381d92..56f19836 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 @@ -18,9 +18,8 @@ public class SwearFilter extends ChatFilter { static { try { - byte[] content = Files.readAllBytes(ExternalFiles.FILTER.toPath()); - JsonObject object = JsonParser.parseString(new String(content)).getAsJsonObject(); + JsonObject object = ExternalFiles.FILTER.parseJson(); Collections.addAll(EQUAL_SWEARS, Util.fromJsonArray(object.getAsJsonArray("equal"))); PREFIX_SWEARS = Util.fromJsonArray(object.getAsJsonArray("prefix")); diff --git a/src/main/java/com/diamondfire/helpbot/sys/tag/TagHandler.java b/src/main/java/com/diamondfire/helpbot/sys/tag/TagHandler.java index 5784dd9f..b6497c58 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/tag/TagHandler.java +++ b/src/main/java/com/diamondfire/helpbot/sys/tag/TagHandler.java @@ -1,6 +1,6 @@ package com.diamondfire.helpbot.sys.tag; -import com.diamondfire.helpbot.sys.externalfile.ExternalFiles; +import com.diamondfire.helpbot.sys.externalfile.*; import com.diamondfire.helpbot.sys.tag.exceptions.*; import com.diamondfire.helpbot.util.serializer.*; import com.google.gson.*; @@ -14,7 +14,7 @@ public class TagHandler { private static final List TAGS = new ArrayList<>(); - private static final File FILE = ExternalFiles.TAGS; + private static final ExternalFile FILE = ExternalFiles.TAGS; static { try { @@ -30,17 +30,15 @@ public static List getTags() { public static void cacheJson() throws IOException { // Read the file and update the cache - String content = new String(Files.readAllBytes(FILE.toPath())); + JsonObject json = FILE.parseJson(); - if (content.isEmpty()) { - content = "{}"; - } - - JsonObject obj = JsonParser.parseString(content).getAsJsonObject(); + List objects = json.keySet().stream() + .map(key -> json.get(key).getAsJsonObject()) + .collect(Collectors.toList()); - for (String key : obj.keySet()) { + for (JsonObject object : objects) { TAGS.add(TagSerializer.getInstance().deserialize( - obj.get(key).getAsJsonObject() + object )); } } @@ -48,13 +46,11 @@ public static void cacheJson() throws IOException { public static void save() throws IOException { JsonObject json = new JsonObject(); - for (Tag tag : TAGS) { - json.add(tag.getActivator(), tag.serialize()); - } + TAGS.forEach(tag -> json.add( + tag.getActivator(), tag.serialize() + )); - FILE.delete(); - FILE.createNewFile(); - Files.write(FILE.toPath(), json.toString().getBytes(), StandardOpenOption.WRITE); + FILE.write(json); } public static void newTag(Tag tag) throws TagAlreadyExistsException, IOException {