Skip to content

Commit

Permalink
Removed old no longer implemented command
Browse files Browse the repository at this point in the history
Fixed issue with prefix without command
  • Loading branch information
Alf-Melmac committed Jul 7, 2021
1 parent 9783bd8 commit fe49fd7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
1 change: 0 additions & 1 deletion src/main/java/de/webalf/slotbot/model/bot/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public enum Event implements CommandEnum {
ADD_SLOT(AddSlot.class),
BLOCK_SLOT(BlockSlot.class),
DEL_SLOT(DelSlot.class),
EVENT_JSON(Admin.class),
EVENT_PING(EventPing.class),
EVENT_PRINT(EventPrint.class),
RANDOM_SLOT(RandomSlot.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
import org.thymeleaf.util.ArrayUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static de.webalf.slotbot.model.bot.Commands.Event.EVENT_JSON;
import static de.webalf.slotbot.util.StringUtils.isNotEmpty;
import static de.webalf.slotbot.util.bot.MessageUtils.replyAndDelete;
import static de.webalf.slotbot.util.bot.MessageUtils.sendDmAndDeleteMessage;
Expand Down Expand Up @@ -52,6 +49,8 @@ public void onMessageReceived(@NonNull MessageReceivedEvent event) {
final String args = messageText.substring(discordProperties.getPrefix().length()); //Remove prefix
List<String> argList = getArgList(args);

if (argList.isEmpty()) return;
@SuppressWarnings("ConstantConditions") //Checked with if above
final CommandEnum commandEnum = Commands.get(ListUtils.shift(argList));
//Exit if command doesn't exist
if (commandEnum == null) return;
Expand Down Expand Up @@ -101,17 +100,10 @@ private boolean validate(Message message, List<String> argList, CommandEnum comm
* Returns the arguments as a list
*
* @param args all arguments
* @return arguments {@link StringUtils#splitOnSpacesExceptQuotes(String)} or only command and arguments as second string for special commands
* @return arguments {@link StringUtils#splitOnSpacesExceptQuotes(String)}
*/
private List<String> getArgList(@NonNull String args) {
List<String> argList;
if (Arrays.stream(EVENT_JSON.getAnnotation().names()).noneMatch(args.toLowerCase()::matches)) {
argList = StringUtils.splitOnSpacesExceptQuotes(args);
} else {
//For these special commands everything after the command is handled as one argument. Validation and potential splitting must be done by the position called up
argList = new ArrayList<>(Arrays.asList(args.split(" ", 2)));
}
return argList;
return StringUtils.splitOnSpacesExceptQuotes(args);
}

/**
Expand Down

0 comments on commit fe49fd7

Please sign in to comment.