Complete message command parser and listener
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
The message command listener is now completed and the bot now also supports message-based commands with multiple aliases.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package wtf.beatrice.hidekobot.commands.message;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import wtf.beatrice.hidekobot.Cache;
|
||||
import wtf.beatrice.hidekobot.objects.MessageCommand;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class CommandsCommand implements MessageCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
return new LinkedList<>(Collections.singletonList("commands"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(MessageReceivedEvent event, String label, String[] args) {
|
||||
|
||||
StringBuilder commandsList = new StringBuilder();
|
||||
commandsList.append("Recognized message commands: ");
|
||||
|
||||
LinkedList<MessageCommand> messageCommands = Cache.getMessageCommandListener().getRegisteredCommands();
|
||||
for(int i = 0; i < messageCommands.size(); i++)
|
||||
{
|
||||
commandsList.append("`")
|
||||
.append(messageCommands.get(i).getCommandLabels().get(0))
|
||||
.append("`");
|
||||
if(i+1 != messageCommands.size())
|
||||
{ commandsList.append(", "); }
|
||||
|
||||
}
|
||||
|
||||
event.getMessage().reply(commandsList.toString()).queue();
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package wtf.beatrice.hidekobot.commands.message;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import wtf.beatrice.hidekobot.objects.MessageCommand;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class HelloCommand implements MessageCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
return new LinkedList<>(Arrays.asList("hi", "hello", "heya"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(MessageReceivedEvent event, String label, String[] args)
|
||||
{
|
||||
String senderId = event.getMessage().getAuthor().getId();
|
||||
event.getMessage().reply("Hi, <@" + senderId + ">! :sparkles:").queue();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user