Created ResponderContext#getOptimizedUsage to get an optimized version of the usage without quotation marks & with merged parameters
This commit is contained in:
parent
91e3e70020
commit
d083b13c54
@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import de.gnmyt.autoresponder.SimpleAutoResponder;
|
import de.gnmyt.autoresponder.SimpleAutoResponder;
|
||||||
|
import de.gnmyt.autoresponder.commands.usage.UsageElement;
|
||||||
import de.gnmyt.autoresponder.commands.usage.UsageException;
|
import de.gnmyt.autoresponder.commands.usage.UsageException;
|
||||||
import de.gnmyt.autoresponder.event.chat.ChatMessageReceivedEvent;
|
import de.gnmyt.autoresponder.event.chat.ChatMessageReceivedEvent;
|
||||||
import de.gnmyt.autoresponder.event.group.GroupMessageReceivedEvent;
|
import de.gnmyt.autoresponder.event.group.GroupMessageReceivedEvent;
|
||||||
@ -103,6 +104,33 @@ public class ResponderContext extends SimpleHttpHandler {
|
|||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the clean usage.
|
||||||
|
* <p>
|
||||||
|
* That means that the optimized usage automatically removes the quotation marks from the usage.
|
||||||
|
* It also moves the last provided usage elements to the needed usage element
|
||||||
|
*
|
||||||
|
* @param usageParts Your current usage
|
||||||
|
* @param usageElements The list of all usage elements needed to run this command
|
||||||
|
* @return the clean usage
|
||||||
|
*/
|
||||||
|
public ArrayList<Object> getOptimizedUsage(ArrayList<Object> usageParts, ArrayList<UsageElement> usageElements) {
|
||||||
|
|
||||||
|
for (int i = usageParts.size() - 1; i >= usageElements.size(); i--) {
|
||||||
|
usageParts.set(i - 1, usageParts.get(i - 1) + " " + usageParts.get(i));
|
||||||
|
usageParts.remove(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < usageParts.size(); i++) {
|
||||||
|
if (usageParts.get(i).toString().startsWith("\""))
|
||||||
|
usageParts.set(i, usageParts.get(i).toString().substring(1));
|
||||||
|
if (usageParts.get(i).toString().endsWith("\""))
|
||||||
|
usageParts.set(i, usageParts.get(i).toString().substring(0, usageParts.get(i).toString().length() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
return usageParts;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the usage error reply
|
* Sends the usage error reply
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user