Skip to content

Commit

Permalink
Making JDA-Command more lightweight, introducing comparing of commands
Browse files Browse the repository at this point in the history
  • Loading branch information
comportment committed Oct 7, 2017
1 parent f8651e1 commit 1e151ab
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 67 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ For more detailed examples please see the example repository

<h4>Use JDA-Command in your projects today!</h4>

The current promoted version is 1.1.0
The current promoted version is 1.1.1

<h5>Maven</h5>

Expand All @@ -61,13 +61,13 @@ The current promoted version is 1.1.0
<dependency>
<groupId>com.github.Comportment</groupId>
<artifactId>JDA-Command</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</dependency>
<!--Dependency for JDA-->
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>3.2.0_242</version>
<version>3.3.1_286</version>
</dependency>
```

Expand All @@ -83,8 +83,8 @@ repositories {
dependencies {
//JDA-Command dependency
compile 'com.github.Comportment:JDA-Command:1.1.0'
compile 'com.github.Comportment:JDA-Command:1.1.1'
//JDA dependency
compile group: 'net.dv8tion', name: 'JDA', version: '3.2.0_242'
compile group: 'net.dv8tion', name: 'JDA', version: '3.3.1_286'
}
```
11 changes: 3 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>me.diax.comportment</groupId>
<artifactId>JDA-Command</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>

<organization>
<name>Diax Software</name>
Expand All @@ -27,7 +27,7 @@
<role>developer</role>
</roles>
<properties>
<discord>comportment#9489</discord>
<discord>comportment#4475</discord>
<twitter>@ComportmentUK</twitter>
</properties>
</developer>
Expand Down Expand Up @@ -78,13 +78,8 @@
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>3.2.0_242</version>
<version>3.3.1_286</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.8.0-alpha2</version>
</dependency>
</dependencies>
</project>
7 changes: 6 additions & 1 deletion src/main/java/me/diax/comportment/jdacommand/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @author Comportment
* @since 1.0.0
*/
public interface Command {
public interface Command extends Comparable<Command> {

/**
* This is the method called on to execute the command.
Expand Down Expand Up @@ -69,4 +69,9 @@ default String getAttributeValueFromKey(String key) {
default boolean hasAttribute(String key) {
return Arrays.stream(getDescription().attributes()).anyMatch(ca -> ca.key().equals(key));
}

@Override
default int compareTo(Command that) {
return this.getDescription().name().compareTo(that.getDescription().name());
}
}
18 changes: 3 additions & 15 deletions src/main/java/me/diax/comportment/jdacommand/CommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

package me.diax.comportment.jdacommand;

import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.Collections;
Expand All @@ -33,7 +30,6 @@
* @since 1.0.0
*/
public class CommandHandler {
private final Logger logger = LoggerFactory.getLogger("JDA-Command");

/**
* A set of all of the commands that this {@link CommandHandler} has registered.
Expand Down Expand Up @@ -140,19 +136,12 @@ public Command findCommand(String trigger) {
* @param command The {@link Command} to execute.
* @param message The {@link Message} which triggered the command.
* @param args The arguments of the command.
* @throws ExecutionException If the command could not be executed.
* @since 1.0.0
*/
public void execute(Command command, Message message, String args) throws ExecutionException {
public void execute(Command command, Message message, String args) {
CommandDescription cd = command.getDescription();
if (cd == null) return;
//if (cd.args() > args.split("\\s+").length) return;
try {
logger.info("Executing " + cd.name());
command.execute(message, args.trim());
} catch (Exception e) {
throw new ExecutionException(e);
}
command.execute(message, args.trim());
}

/**
Expand All @@ -161,12 +150,11 @@ public void execute(Command command, Message message, String args) throws Execut
* @param trigger The trigger of the command.
* @param message The {@link Message} which triggered the command.
* @param args The args of the command.
* @throws ExecutionException If the command could not be executed.
* @see #findCommand(String)
* @see #execute(Command, Message, String)
* @since 1.0.1
*/
public void findAndExecute(String trigger, Message message, String args) throws ExecutionException {
public void findAndExecute(String trigger, Message message, String args) {
Command command = this.findCommand(trigger);
if (command == null || command.getDescription() == null) return;
this.execute(command, message, args);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ public class JDACommandInfo {
*
* @since 1.0.1
*/
public static final String VERSION = "1.1.0";
public static final String VERSION = "1.1.1";
}

0 comments on commit 1e151ab

Please sign in to comment.