mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-26 13:46:19 +00:00
added command to set emotes to emote keys
added emote support to command parameters
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package dev.sheldan.abstracto.core.commands.utility;
|
||||
|
||||
import dev.sheldan.abstracto.command.Command;
|
||||
import dev.sheldan.abstracto.command.execution.CommandConfiguration;
|
||||
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.management.EmoteManagementService;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class SetEmote implements Command {
|
||||
|
||||
@Autowired
|
||||
private EmoteManagementService emoteManagementService;
|
||||
|
||||
@Override
|
||||
public Result execute(CommandContext commandContext) {
|
||||
String emoteKey = (String) commandContext.getParameters().getParameters().get(0);
|
||||
Object o = commandContext.getParameters().getParameters().get(1);
|
||||
if(o instanceof String) {
|
||||
String emote = (String) o;
|
||||
emoteManagementService.setEmoteToDefaultEmote(emoteKey, emote, commandContext.getGuild().getIdLong());
|
||||
} else {
|
||||
Emote emote = (Emote) o;
|
||||
emoteManagementService.setEmoteToCustomEmote(emoteKey, emote, commandContext.getGuild().getIdLong());
|
||||
}
|
||||
return Result.fromSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter emoteKey = Parameter.builder().name("emoteKey").type(String.class).description("The internal key of the emote").build();
|
||||
Parameter emote = Parameter.builder().name("emote").type(net.dv8tion.jda.api.entities.Emote.class).description("The emote to be used").build();
|
||||
List<Parameter> parameters = Arrays.asList(emoteKey, emote);
|
||||
return CommandConfiguration.builder()
|
||||
.name("setEmote")
|
||||
.module(UtilityModule.UTILITY)
|
||||
.parameters(parameters)
|
||||
.description("Configures the emote key pointing towards a defined emote")
|
||||
.causesReaction(true)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,11 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class UtilityModule implements Module {
|
||||
|
||||
public static final String UTILITY = "utility";
|
||||
|
||||
@Override
|
||||
public ModuleInfo getInfo() {
|
||||
return ModuleInfo.builder().name("utility").description("General utilities").build();
|
||||
return ModuleInfo.builder().name(UTILITY).description("General utilities").build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,6 +5,7 @@ import dev.sheldan.abstracto.core.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.repository.EmoteRepository;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -28,6 +29,37 @@ public class EmoteManagementServiceBean implements EmoteManagementService {
|
||||
return repository.findAEmoteByNameAndServerRef(name, server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AEmote setEmoteToCustomEmote(String name, String emoteKey, Long emoteId, Boolean animated, Long serverId) {
|
||||
AEmote existing = loadEmoteByName(name, serverId);
|
||||
existing.setEmoteKey(emoteKey);
|
||||
existing.setEmoteId(emoteId);
|
||||
existing.setAnimated(animated);
|
||||
existing.setCustom(true);
|
||||
repository.save(existing);
|
||||
return existing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AEmote setEmoteToCustomEmote(String name, Emote emote, Long serverId) {
|
||||
AEmote existing = loadEmoteByName(name, serverId);
|
||||
existing.setCustom(true);
|
||||
existing.setAnimated(emote.isAnimated());
|
||||
existing.setEmoteId(emote.getIdLong());
|
||||
existing.setEmoteKey(emote.getName());
|
||||
repository.save(existing);
|
||||
return existing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AEmote setEmoteToDefaultEmote(String name, String emoteKey, Long serverId) {
|
||||
AEmote existing = loadEmoteByName(name, serverId);
|
||||
existing.setEmoteKey(emoteKey);
|
||||
existing.setCustom(false);
|
||||
repository.save(existing);
|
||||
return existing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AEmote createCustomEmote(String name, String emoteKey, Long emoteId, Boolean animated) {
|
||||
AEmote emote = AEmote.builder()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package dev.sheldan.abstracto.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.PostTarget;
|
||||
import dev.sheldan.abstracto.core.management.PostTargetManagement;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.core.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.templating.TemplateService;
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package dev.sheldan.abstracto.core.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
|
||||
public interface EmoteManagementService {
|
||||
AEmote loadEmote(Long id);
|
||||
AEmote loadEmoteByName(String name, Long serverId);
|
||||
AEmote setEmoteToCustomEmote(String name, String emoteKey, Long emoteId, Boolean animated, Long serverId);
|
||||
AEmote setEmoteToCustomEmote(String name, Emote emote, Long serverId);
|
||||
AEmote setEmoteToDefaultEmote(String name, String emoteKey, Long serverId);
|
||||
AEmote createCustomEmote(String name, String emoteKey, Long emoteId, Boolean animated);
|
||||
AEmote createDefaultEmote(String name, String emoteKey);
|
||||
}
|
||||
|
||||
@@ -20,15 +20,19 @@ public class AEmote {
|
||||
private String name;
|
||||
|
||||
@Column
|
||||
@Setter
|
||||
private String emoteKey;
|
||||
|
||||
@Column
|
||||
@Setter
|
||||
private Long emoteId;
|
||||
|
||||
@Column
|
||||
@Setter
|
||||
private Boolean animated;
|
||||
|
||||
@Column
|
||||
@Setter
|
||||
private Boolean custom;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
|
||||
Reference in New Issue
Block a user