-
Notifications
You must be signed in to change notification settings - Fork 20
Argument modifications, LockCommand and ExternalFile modifications #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b2e7743
Added Permission Overrides + Moved cacheJson method to static block
ryandev2 d71f09d
lots of thingies
ryandev2 72fda16
Merge remote-tracking branch 'origin/master'
ryandev2 487b5c5
more thingies
ryandev2 d19a790
Merge remote-tracking branch 'origin/master'
ryandev2 1cadfb3
fixes
ryandev2 f69c2fc
ExternalFile refactors
ryandev2 e445c6f
made SwearFilter, DisableCommandHandler and CodeDifferenceHandler tak…
ryandev2 9cb44dd
Requested change #1
ryandev2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...mondfire/helpbot/bot/command/argument/impl/types/AbstractSimpleValueFallbackArgument.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<T> implements FallbackArgument<T> { | ||
|
|
||
| @Override | ||
| @SuppressWarnings("all") | ||
| public T parseValue(@NotNull Deque<String> args, CommandEvent event) throws ArgumentException { | ||
| return parse(args.peek(), event); | ||
| } | ||
|
|
||
| protected abstract T parse(@NotNull String argument, CommandEvent event) throws ArgumentException; | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/FallbackArgument.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<T> extends Argument<T> { | ||
|
|
||
| @Override | ||
| default T parsed(@NotNull Deque<String> 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); | ||
|
|
||
| } |
2 changes: 1 addition & 1 deletion
2
...nt/impl/types/ClampedIntegerArgument.java → ...pl/types/impl/ClampedIntegerArgument.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...and/argument/impl/types/DateArgument.java → ...rgument/impl/types/impl/DateArgument.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...gument/impl/types/DateOffsetArgument.java → ...t/impl/types/impl/DateOffsetArgument.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ent/impl/types/DefinedObjectArgument.java → ...mpl/types/impl/DefinedObjectArgument.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ument/impl/types/DiscordUserArgument.java → .../impl/types/impl/DiscordUserArgument.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ent/impl/types/EndlessStringArgument.java → ...mpl/types/impl/EndlessStringArgument.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...argument/impl/types/Enum/TagProperty.java → ...ent/impl/types/impl/Enum/TagProperty.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
.../argument/impl/types/IntegerArgument.java → ...ment/impl/types/impl/IntegerArgument.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...and/argument/impl/types/LongArgument.java → ...rgument/impl/types/impl/LongArgument.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ument/impl/types/QuoteStringArgument.java → .../impl/types/impl/QuoteStringArgument.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...d/argument/impl/types/StringArgument.java → ...ument/impl/types/impl/StringArgument.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...gument/impl/types/SubCommandArgument.java → ...t/impl/types/impl/SubCommandArgument.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ava/com/diamondfire/helpbot/bot/command/argument/impl/types/impl/TextChannelArgument.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
|
|
||
| /** | ||
| * <strong>This argument extends {@link FallbackArgument}.</strong> | ||
| * | ||
| * Will return the channel this command was executed in if an invalid channel was provided by the user. | ||
| */ | ||
| public class TextChannelArgument extends AbstractSimpleValueFallbackArgument<TextChannel> { | ||
|
|
||
| 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<TextChannel> 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("` `")) | ||
| + "`"; | ||
| } | ||
|
|
||
| } |
4 changes: 3 additions & 1 deletion
4
...gument/impl/types/TimeOffsetArgument.java → ...t/impl/types/impl/TimeOffsetArgument.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...mpl/types/minecraft/DFPlayerArgument.java → ...ypes/impl/minecraft/DFPlayerArgument.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/minecraft/MojangPlayerUUIDArgument.java → ...l/minecraft/MojangPlayerUUIDArgument.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...argument/impl/types/minecraft/Player.java → ...ent/impl/types/impl/minecraft/Player.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.