mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-22 05:06:42 +00:00
added initial version containing ping/echo command and first draft of the command handling structure
This commit is contained in:
46
abstracto-application/command/command-base/pom.xml
Normal file
46
abstracto-application/command/command-base/pom.xml
Normal file
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.command</groupId>
|
||||
<artifactId>command</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
<artifactId>command-base</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>utility</module>
|
||||
<module>support</module>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.command</groupId>
|
||||
<artifactId>command-int</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<configuration>
|
||||
<proc>only</proc>
|
||||
<annotationProcessors>
|
||||
<annotationProcessor>dev.sheldan.abstracto.command.annotations.CommandSpecProcessor</annotationProcessor>
|
||||
</annotationProcessors>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
15
abstracto-application/command/command-base/support/pom.xml
Normal file
15
abstracto-application/command/command-base/support/pom.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>command-base</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.command</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>support</artifactId>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,38 @@
|
||||
package dev.sheldan.abstracto.command.support;
|
||||
|
||||
import dev.sheldan.abstracto.command.Command;
|
||||
import dev.sheldan.abstracto.command.execution.Configuration;
|
||||
import dev.sheldan.abstracto.command.execution.Context;
|
||||
import dev.sheldan.abstracto.command.execution.Result;
|
||||
import dev.sheldan.abstracto.command.meta.CommandRegistry;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class Help implements Command {
|
||||
|
||||
|
||||
@Autowired
|
||||
private CommandRegistry registry;
|
||||
|
||||
@Override
|
||||
public Result execute(Context context) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
registry.getAllCommands().forEach(command -> {
|
||||
builder.addField(command.getConfiguration().getName(), command.getConfiguration().getDescription(), false);
|
||||
});
|
||||
context.getChannel().sendMessage(builder.build()).queue();
|
||||
return Result.fromSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Configuration getConfiguration() {
|
||||
return Configuration.builder()
|
||||
.name("help")
|
||||
.module("utility")
|
||||
.description("Prints the help")
|
||||
.causesReaction(false)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
15
abstracto-application/command/command-base/utility/pom.xml
Normal file
15
abstracto-application/command/command-base/utility/pom.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.command</groupId>
|
||||
<artifactId>command-base</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>utility</artifactId>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,38 @@
|
||||
package dev.sheldan.abstracto.command.utility;
|
||||
|
||||
import dev.sheldan.abstracto.command.Command;
|
||||
import dev.sheldan.abstracto.command.execution.Configuration;
|
||||
import dev.sheldan.abstracto.command.execution.Context;
|
||||
import dev.sheldan.abstracto.command.execution.Parameter;
|
||||
import dev.sheldan.abstracto.command.execution.Result;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class Echo implements Command {
|
||||
|
||||
@Override
|
||||
public Result execute(Context context) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
context.getParameters().getParameters().forEach(o -> {
|
||||
sb.append(o.toString());
|
||||
});
|
||||
context.getChannel().sendMessage(sb.toString()).queue();
|
||||
return Result.fromSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Configuration getConfiguration() {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
parameters.add(Parameter.builder().name("input").type(String.class).remainder(true).build());
|
||||
return Configuration.builder()
|
||||
.name("echo")
|
||||
.module("utility")
|
||||
.description("Echos the input back to the same channel")
|
||||
.causesReaction(false)
|
||||
.parameters(parameters)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package dev.sheldan.abstracto.command.utility;
|
||||
|
||||
import dev.sheldan.abstracto.command.Command;
|
||||
import dev.sheldan.abstracto.command.execution.Configuration;
|
||||
import dev.sheldan.abstracto.command.execution.Context;
|
||||
import dev.sheldan.abstracto.command.execution.Result;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class Ping implements Command {
|
||||
|
||||
@Override
|
||||
public Result execute(Context context) {
|
||||
long ping = context.getJda().getGatewayPing();
|
||||
context.getChannel().sendMessage("Latency: " + ping + " ms.").queue();
|
||||
return Result.fromSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Configuration getConfiguration() {
|
||||
return Configuration.builder()
|
||||
.name("ping")
|
||||
.module("utility")
|
||||
.description("Prints the current bot latency to the discord api")
|
||||
.causesReaction(false)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user