mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-02 07:44:25 +00:00
added initial version containing ping/echo command and first draft of the command handling structure
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,6 +1,8 @@
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
.idea/
|
||||
target/
|
||||
*.iml
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
36
abstracto-application/command/command-int/pom.xml
Normal file
36
abstracto-application/command/command-int/pom.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<artifactId>command-int</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>club.minnced</groupId>
|
||||
<artifactId>opus-java</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,11 @@
|
||||
package dev.sheldan.abstracto.command;
|
||||
|
||||
import dev.sheldan.abstracto.command.execution.Configuration;
|
||||
import dev.sheldan.abstracto.command.execution.Context;
|
||||
import dev.sheldan.abstracto.command.execution.Result;
|
||||
|
||||
public interface Command<T> {
|
||||
|
||||
Result execute(Context context);
|
||||
Configuration getConfiguration();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package dev.sheldan.abstracto.command.execution;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter @Setter @Builder
|
||||
public class Configuration {
|
||||
|
||||
private String name;
|
||||
private String module;
|
||||
private String description;
|
||||
private List<Parameter> parameters;
|
||||
private boolean causesReaction;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package dev.sheldan.abstracto.command.execution;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class Context {
|
||||
private TextChannel channel;
|
||||
private User author;
|
||||
private Message message;
|
||||
private Parameters parameters;
|
||||
private JDA jda;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package dev.sheldan.abstracto.command.execution;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter @Setter @Builder
|
||||
public class Parameter {
|
||||
private String name;
|
||||
private Class type;
|
||||
private boolean optional;
|
||||
private boolean remainder;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package dev.sheldan.abstracto.command.execution;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Builder
|
||||
public class Parameters {
|
||||
@Getter
|
||||
private List<Object> parameters;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package dev.sheldan.abstracto.command.execution;
|
||||
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter @Setter @Builder
|
||||
public class Result {
|
||||
private ResultState result;
|
||||
private String message;
|
||||
|
||||
public static Result fromSuccess() {
|
||||
return Result.builder().result(ResultState.SUCCESSFUL).build();
|
||||
}
|
||||
|
||||
public static Result fromError(String message){
|
||||
return Result.builder().result(ResultState.ERROR).message(message).build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package dev.sheldan.abstracto.command.execution;
|
||||
|
||||
public enum ResultState {
|
||||
ERROR, SUCCESSFUL, IGNORED
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package dev.sheldan.abstracto.command.meta;
|
||||
|
||||
|
||||
import dev.sheldan.abstracto.command.Command;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CommandRegistry {
|
||||
Command findCommandByParameters(String name, UnParsedCommandParameter context);
|
||||
Command findCommand(String message);
|
||||
List<Command> getAllCommands();
|
||||
boolean isCommand(Message message);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package dev.sheldan.abstracto.command.meta;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter @Setter
|
||||
public class UnParsedCommandParameter {
|
||||
private List<String> parameters;
|
||||
}
|
||||
28
abstracto-application/command/command-management/pom.xml
Normal file
28
abstracto-application/command/command-management/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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-management</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.command</groupId>
|
||||
<artifactId>command-int</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.core</groupId>
|
||||
<artifactId>core-interface</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,6 @@
|
||||
package dev.sheldan.abstracto.commands.management;
|
||||
|
||||
import dev.sheldan.abstracto.command.Command;
|
||||
|
||||
public abstract class AbstractCommand implements Command {
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package dev.sheldan.abstracto.commands.management;
|
||||
|
||||
import dev.sheldan.abstracto.command.Command;
|
||||
import dev.sheldan.abstracto.command.execution.Configuration;
|
||||
import dev.sheldan.abstracto.command.execution.Parameter;
|
||||
import dev.sheldan.abstracto.command.meta.CommandRegistry;
|
||||
import dev.sheldan.abstracto.command.meta.UnParsedCommandParameter;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class CommandManager implements CommandRegistry {
|
||||
|
||||
@Autowired
|
||||
private List<Command> commands;
|
||||
|
||||
@Override
|
||||
public Command findCommandByParameters(String name, UnParsedCommandParameter unParsedCommandParameter) {
|
||||
Optional<Command> commandOptional = commands.stream().filter((Command o )-> {
|
||||
Configuration configuration = o.getConfiguration();
|
||||
boolean parameterFit;
|
||||
if(configuration.getParameters() != null){
|
||||
boolean paramCountFits = unParsedCommandParameter.getParameters().size() - 1 == configuration.getParameters().size();
|
||||
boolean hasRemainderParameter = configuration.getParameters().stream().anyMatch(Parameter::isRemainder);
|
||||
parameterFit = paramCountFits || hasRemainderParameter;
|
||||
} else {
|
||||
parameterFit = unParsedCommandParameter.getParameters().size() == 0;
|
||||
}
|
||||
return configuration.getName().equals(name) && parameterFit;
|
||||
}).findFirst();
|
||||
if(commandOptional.isPresent()){
|
||||
return commandOptional.get();
|
||||
}
|
||||
throw new CommandNotFoundException();
|
||||
}
|
||||
|
||||
public Command findCommand(String name) {
|
||||
Optional<Command> commandOptional = commands.stream().filter((Command o )-> {
|
||||
Configuration configuration = o.getConfiguration();
|
||||
return configuration.getName().equals(name);
|
||||
}).findFirst();
|
||||
if(commandOptional.isPresent()){
|
||||
return commandOptional.get();
|
||||
}
|
||||
throw new CommandNotFoundException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Command> getAllCommands() {
|
||||
return commands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCommand(Message message) {
|
||||
return message.getContentRaw().startsWith("!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package dev.sheldan.abstracto.commands.management;
|
||||
|
||||
public class CommandNotFoundException extends RuntimeException {
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package dev.sheldan.abstracto.commands.management;
|
||||
|
||||
import dev.sheldan.abstracto.command.Command;
|
||||
import dev.sheldan.abstracto.command.execution.Context;
|
||||
import dev.sheldan.abstracto.command.execution.Parameter;
|
||||
import dev.sheldan.abstracto.command.execution.Parameters;
|
||||
import dev.sheldan.abstracto.command.meta.UnParsedCommandParameter;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CommandReceivedHandler extends ListenerAdapter {
|
||||
|
||||
@Autowired
|
||||
private CommandManager manager;
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(@Nonnull MessageReceivedEvent event) {
|
||||
if(!manager.isCommand(event.getMessage())) {
|
||||
return;
|
||||
}
|
||||
List<String> parameters = Arrays.asList(event.getMessage().getContentStripped().split(" "));
|
||||
UnParsedCommandParameter unparsedParameter = new UnParsedCommandParameter();
|
||||
unparsedParameter.setParameters(parameters.subList(1, parameters.size()));
|
||||
String withoutPrefix = parameters.get(0).substring(1);
|
||||
Command foundCommand = manager.findCommandByParameters(withoutPrefix, unparsedParameter);
|
||||
Parameters parsedParameters = getParsedParameters(unparsedParameter, foundCommand);
|
||||
Context context = Context.builder()
|
||||
.author(event.getAuthor())
|
||||
.channel(event.getTextChannel())
|
||||
.message(event.getMessage())
|
||||
.parameters(parsedParameters)
|
||||
.jda(event.getJDA())
|
||||
.build();
|
||||
foundCommand.execute(context);
|
||||
}
|
||||
|
||||
public Parameters getParsedParameters(UnParsedCommandParameter unParsedCommandParameter, Command command){
|
||||
List<Object> parsedParameters = new ArrayList<>();
|
||||
for (int i = 0; i < unParsedCommandParameter.getParameters().size(); i++) {
|
||||
Parameter param = command.getConfiguration().getParameters().get(i);
|
||||
String value = unParsedCommandParameter.getParameters().get(i);
|
||||
if(param.getType().equals(Integer.class)){
|
||||
parsedParameters.add(Integer.parseInt(value));
|
||||
} else if(param.getType().equals(Double.class)){
|
||||
parsedParameters.add(Double.parseDouble(value));
|
||||
} else {
|
||||
parsedParameters.add(value);
|
||||
}
|
||||
}
|
||||
return Parameters.builder().parameters(parsedParameters).build();
|
||||
}
|
||||
}
|
||||
22
abstracto-application/command/pom.xml
Normal file
22
abstracto-application/command/pom.xml
Normal file
@@ -0,0 +1,22 @@
|
||||
<?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</groupId>
|
||||
<artifactId>abstracto-application</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>dev.sheldan.abstracto.command</groupId>
|
||||
<artifactId>command</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>command-int</module>
|
||||
<module>command-base</module>
|
||||
<module>command-management</module>
|
||||
</modules>
|
||||
|
||||
|
||||
</project>
|
||||
114
abstracto-application/core/core-impl/pom.xml
Normal file
114
abstracto-application/core/core-impl/pom.xml
Normal file
@@ -0,0 +1,114 @@
|
||||
<?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.core</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<artifactId>core-impl</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-freemarker</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-oauth2-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-quartz</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-cache</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>club.minnced</groupId>
|
||||
<artifactId>opus-java</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.core</groupId>
|
||||
<artifactId>core-interface</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.command</groupId>
|
||||
<artifactId>command-management</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.command</groupId>
|
||||
<artifactId>utility</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.command</groupId>
|
||||
<artifactId>support</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,29 @@
|
||||
package dev.sheldan.abstracto;
|
||||
|
||||
import dev.sheldan.abstracto.service.StartupManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = "dev.sheldan.abstracto")
|
||||
@EnableCaching
|
||||
public class Application implements CommandLineRunner {
|
||||
|
||||
@Autowired
|
||||
private StartupManager startup;
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
startup.startBot();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package dev.sheldan.abstracto.models;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.Table;
|
||||
import java.util.Set;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
@Builder
|
||||
public class Channel {
|
||||
|
||||
@Id
|
||||
@Getter
|
||||
public Long id;
|
||||
|
||||
@Getter
|
||||
@ManyToMany(mappedBy = "channels")
|
||||
private Set<ChannelGroup> groups;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package dev.sheldan.abstracto.models;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Set;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
public class ChannelGroup {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Getter
|
||||
private Long id;
|
||||
|
||||
@Column
|
||||
@Getter @Setter
|
||||
private String groupName;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
name = "channel_in_group",
|
||||
joinColumns = @JoinColumn(name = "group_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "channel_id"))
|
||||
@Getter
|
||||
private Set<Channel> channels;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package dev.sheldan.abstracto.models;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.hibernate.annotations.OnDelete;
|
||||
import org.hibernate.annotations.OnDeleteAction;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
public class PostTarget {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Getter
|
||||
private Long id;
|
||||
|
||||
@Column(unique = true)
|
||||
@Getter
|
||||
private String name;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY, optional = false)
|
||||
@JoinColumn(name = "id", nullable = false)
|
||||
@Getter
|
||||
private Channel channel;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package dev.sheldan.abstracto.models;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
public class Role {
|
||||
|
||||
@Id
|
||||
@Getter
|
||||
private Long id;
|
||||
|
||||
@Column(unique = true)
|
||||
@Getter @Setter
|
||||
private String name;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package dev.sheldan.abstracto.repository;
|
||||
|
||||
import dev.sheldan.abstracto.models.Channel;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ChannelRepository extends JpaRepository<Channel, Long> {
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package dev.sheldan.abstracto.service;
|
||||
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.utils.cache.CacheFlag;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.util.EnumSet;
|
||||
|
||||
@Service
|
||||
public class BotService implements Bot {
|
||||
|
||||
private JDA instance;
|
||||
|
||||
@Override
|
||||
public void login() throws LoginException {
|
||||
JDABuilder builder = new JDABuilder(System.getenv("TOKEN"));
|
||||
|
||||
builder.setDisabledCacheFlags(EnumSet.of(CacheFlag.ACTIVITY, CacheFlag.VOICE_STATE));
|
||||
builder.setBulkDeleteSplittingEnabled(false);
|
||||
|
||||
this.instance = builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JDA getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package dev.sheldan.abstracto.service;
|
||||
|
||||
import dev.sheldan.abstracto.commands.management.CommandReceivedHandler;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class StartupManager implements Startup {
|
||||
|
||||
@Autowired
|
||||
private BotService service;
|
||||
|
||||
@Autowired
|
||||
private List<? extends ListenerAdapter> listeners;
|
||||
|
||||
@Override
|
||||
public void startBot() throws LoginException {
|
||||
service.login();
|
||||
listeners.forEach(o -> service.getInstance().addEventListener(o));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
spring.datasource.url=jdbc:postgresql://localhost:5432/abstracto
|
||||
spring.datasource.username= abstracto
|
||||
spring.datasource.password= abstracto
|
||||
|
||||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
|
||||
spring.jpa.hibernate.ddl-auto = update
|
||||
26
abstracto-application/core/core-interface/pom.xml
Normal file
26
abstracto-application/core/core-interface/pom.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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.core</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<artifactId>core-interface</artifactId>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package dev.sheldan.abstracto.service;
|
||||
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
@Service
|
||||
public interface Bot {
|
||||
void login() throws LoginException;
|
||||
JDA getInstance();
|
||||
void shutdown();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package dev.sheldan.abstracto.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
@Service
|
||||
public interface Startup {
|
||||
public void startBot() throws LoginException;
|
||||
}
|
||||
21
abstracto-application/core/pom.xml
Normal file
21
abstracto-application/core/pom.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?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</groupId>
|
||||
<artifactId>abstracto-application</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>dev.sheldan.abstracto.core</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>core-interface</module>
|
||||
<module>core-impl</module>
|
||||
</modules>
|
||||
|
||||
|
||||
</project>
|
||||
47
abstracto-application/pom.xml
Normal file
47
abstracto-application/pom.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto</groupId>
|
||||
<artifactId>abstracto</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>abstracto-application</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<modules>
|
||||
<module>command</module>
|
||||
<module>core</module>
|
||||
</modules>
|
||||
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
<version>${jda.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>club.minnced</groupId>
|
||||
<artifactId>opus-java</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
15
database/pom.xml
Normal file
15
database/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</groupId>
|
||||
<artifactId>abstracto</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>database</artifactId>
|
||||
|
||||
|
||||
</project>
|
||||
11
database/src/main/resources/docker-compose.yml
Normal file
11
database/src/main/resources/docker-compose.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
version: '3.1'
|
||||
|
||||
services:
|
||||
db:
|
||||
image: postgres
|
||||
restart: always
|
||||
ports:
|
||||
- "5432:5432"
|
||||
environment:
|
||||
POSTGRES_PASSWORD: abstracto
|
||||
POSTGRES_USER: abstracto
|
||||
37
pom.xml
Normal file
37
pom.xml
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.2.RELEASE</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<groupId>dev.sheldan.abstracto</groupId>
|
||||
<artifactId>abstracto</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
|
||||
<properties>
|
||||
<jda.version>4.0.0_73</jda.version>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
<module>abstracto-application</module>
|
||||
<module>database</module>
|
||||
</modules>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jcenter</id>
|
||||
<name>jcenter-bintray</name>
|
||||
<url>https://jcenter.bintray.com</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
||||
Reference in New Issue
Block a user