mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-24 21:53:22 +00:00
added template support to echo
replaced HashMaps for templates with concrete models, so the interface is easier known added rendering method for objects directly added default parameters available for commands split up service beans for server/channel into management and service bean added server reference in AChannel refactored join/leave listener
This commit is contained in:
@@ -2,11 +2,11 @@ package dev.sheldan.abstracto.command.channels;
|
||||
|
||||
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.CommandContext;
|
||||
import dev.sheldan.abstracto.command.execution.Parameter;
|
||||
import dev.sheldan.abstracto.command.execution.Result;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.core.management.ChannelManagementService;
|
||||
import dev.sheldan.abstracto.core.management.PostTargetManagement;
|
||||
import net.dv8tion.jda.api.entities.GuildChannel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -19,17 +19,17 @@ import java.util.List;
|
||||
public class SetPostTargetCommand implements Command {
|
||||
|
||||
@Autowired
|
||||
private PostTargetService postTargetService;
|
||||
private PostTargetManagement postTargetManagement;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
private ChannelManagementService channelManagementService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Result execute(Context context) {
|
||||
GuildChannel channel = (GuildChannel) context.getParameters().getParameters().get(1);
|
||||
String targetName = (String) context.getParameters().getParameters().get(0);
|
||||
postTargetService.createOrUpdate(targetName, channel.getIdLong(), channel.getGuild().getIdLong());
|
||||
public Result execute(CommandContext commandContext) {
|
||||
GuildChannel channel = (GuildChannel) commandContext.getParameters().getParameters().get(1);
|
||||
String targetName = (String) commandContext.getParameters().getParameters().get(0);
|
||||
postTargetManagement.createOrUpdate(targetName, channel.getIdLong(), channel.getGuild().getIdLong());
|
||||
return Result.fromSuccess();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,22 +26,4 @@
|
||||
</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>
|
||||
@@ -11,8 +11,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Service
|
||||
@@ -23,10 +21,10 @@ public class Help implements Command {
|
||||
private ModuleRegistry registry;
|
||||
|
||||
@Override
|
||||
public Result execute(Context context) {
|
||||
public Result execute(CommandContext commandContext) {
|
||||
CommandHierarchy commandStructure = registry.getDetailedModules();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if(context.getParameters().getParameters().isEmpty()){
|
||||
if(commandContext.getParameters().getParameters().isEmpty()){
|
||||
sb.append("Help | Module overview \n");
|
||||
sb.append("```");
|
||||
commandStructure.getRootModules().forEach(packedModule -> {
|
||||
@@ -35,7 +33,7 @@ public class Help implements Command {
|
||||
});
|
||||
sb.append("```");
|
||||
} else {
|
||||
String parameterValue = context.getParameters().getParameters().get(0).toString();
|
||||
String parameterValue = commandContext.getParameters().getParameters().get(0).toString();
|
||||
PackedModule module = commandStructure.getModuleWithName(parameterValue);
|
||||
if(module != null){
|
||||
sb.append("Help | Module overview \n");
|
||||
@@ -53,7 +51,7 @@ public class Help implements Command {
|
||||
}
|
||||
}
|
||||
|
||||
context.getChannel().sendMessage(sb.toString()).queue();
|
||||
commandContext.getChannel().sendMessage(sb.toString()).queue();
|
||||
return Result.fromSuccess();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,14 @@ package dev.sheldan.abstracto.command.utility;
|
||||
import dev.sheldan.abstracto.command.Command;
|
||||
import dev.sheldan.abstracto.command.HelpInfo;
|
||||
import dev.sheldan.abstracto.command.execution.Configuration;
|
||||
import dev.sheldan.abstracto.command.execution.Context;
|
||||
import dev.sheldan.abstracto.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.command.execution.Parameter;
|
||||
import dev.sheldan.abstracto.command.execution.Result;
|
||||
import dev.sheldan.abstracto.command.utility.model.EchoModel;
|
||||
import dev.sheldan.abstracto.templating.TemplateService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -14,13 +18,20 @@ import java.util.List;
|
||||
@Service
|
||||
public class Echo implements Command {
|
||||
|
||||
private static final String TEMPLATE_NAME = "echo";
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Override
|
||||
public Result execute(Context context) {
|
||||
@Transactional
|
||||
public Result execute(CommandContext commandContext) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
context.getParameters().getParameters().forEach(o -> {
|
||||
commandContext.getParameters().getParameters().forEach(o -> {
|
||||
sb.append(o.toString());
|
||||
});
|
||||
context.getChannel().sendMessage(sb.toString()).queue();
|
||||
EchoModel model = EchoModel.parentBuilder().parent(commandContext.getCommandTemplateContext()).text(sb.toString()).build();
|
||||
commandContext.getChannel().sendMessage(templateService.renderTemplate(TEMPLATE_NAME, model)).queue();
|
||||
return Result.fromSuccess();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,14 @@ 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.CommandContext;
|
||||
import dev.sheldan.abstracto.command.execution.Result;
|
||||
import dev.sheldan.abstracto.command.utility.model.PingModel;
|
||||
import dev.sheldan.abstracto.templating.TemplateService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@Service
|
||||
public class Ping implements Command {
|
||||
|
||||
@@ -21,12 +20,11 @@ public class Ping implements Command {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Result execute(Context context) {
|
||||
long ping = context.getJda().getGatewayPing();
|
||||
HashMap<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("latency", ping);
|
||||
String text = templateService.renderTemplate(PING_TEMPLATE, parameters);
|
||||
context.getChannel().sendMessage(text).queue();
|
||||
public Result execute(CommandContext commandContext) {
|
||||
long ping = commandContext.getJda().getGatewayPing();
|
||||
PingModel model = PingModel.parentBuilder().parent(commandContext.getCommandTemplateContext()).latency(ping).build();
|
||||
String text = templateService.renderTemplate(PING_TEMPLATE, model);
|
||||
commandContext.getChannel().sendMessage(text).queue();
|
||||
return Result.fromSuccess();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package dev.sheldan.abstracto.command.utility.model;
|
||||
|
||||
|
||||
import dev.sheldan.abstracto.command.execution.CommandTemplateContext;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class EchoModel extends CommandTemplateContext {
|
||||
private String text;
|
||||
|
||||
@Builder(builderMethodName = "parentBuilder")
|
||||
private EchoModel(CommandTemplateContext parent, String text) {
|
||||
super(parent);
|
||||
this.text = text;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package dev.sheldan.abstracto.command.utility.model;
|
||||
|
||||
import dev.sheldan.abstracto.command.execution.CommandTemplateContext;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class PingModel extends CommandTemplateContext {
|
||||
private Long latency;
|
||||
|
||||
@Builder(builderMethodName = "parentBuilder")
|
||||
private PingModel(CommandTemplateContext parent, Long latency) {
|
||||
super(parent);
|
||||
this.latency = latency;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
${text}
|
||||
Reference in New Issue
Block a user