mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-19 05:08:02 +00:00
[AB-319] splitting emotes into two separate fields (animated and static) for server info
adding emote display model
This commit is contained in:
@@ -9,6 +9,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
|||||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
|
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
|
||||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.models.template.display.EmoteDisplay;
|
||||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||||
import dev.sheldan.abstracto.utility.config.UtilityFeatureDefinition;
|
import dev.sheldan.abstracto.utility.config.UtilityFeatureDefinition;
|
||||||
@@ -30,11 +31,29 @@ public class ServerInfo extends AbstractConditionableCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||||
|
log.info("Displaying serverinfo for server {}", commandContext.getGuild().getId());
|
||||||
|
ServerInfoModel model = buildModel(commandContext);
|
||||||
|
return FutureUtils.toSingleFutureGeneric(
|
||||||
|
channelService.sendEmbedTemplateInTextChannelList("serverinfo_response", model, commandContext.getChannel()))
|
||||||
|
.thenApply(aVoid -> CommandResult.fromIgnored());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ServerInfoModel buildModel(CommandContext commandContext) {
|
||||||
ServerInfoModel model = (ServerInfoModel) ContextConverter.fromCommandContext(commandContext, ServerInfoModel.class);
|
ServerInfoModel model = (ServerInfoModel) ContextConverter.fromCommandContext(commandContext, ServerInfoModel.class);
|
||||||
model.setGuild(commandContext.getGuild());
|
model.setGuild(commandContext.getGuild());
|
||||||
log.info("Displaying serverinfo for server {}", commandContext.getGuild().getId());
|
List<EmoteDisplay> staticEmotes = new ArrayList<>();
|
||||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInTextChannelList("serverinfo_response", model, commandContext.getChannel()))
|
List<EmoteDisplay> animatedEmotes = new ArrayList<>();
|
||||||
.thenApply(aVoid -> CommandResult.fromIgnored());
|
commandContext.getGuild().getEmotes().forEach(emote -> {
|
||||||
|
EmoteDisplay emoteDisplay = EmoteDisplay.fromEmote(emote);
|
||||||
|
if(emote.isAnimated()) {
|
||||||
|
animatedEmotes.add(emoteDisplay);
|
||||||
|
} else {
|
||||||
|
staticEmotes.add(emoteDisplay);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
model.setAnimatedEmotes(animatedEmotes);
|
||||||
|
model.setStaticEmotes(staticEmotes);
|
||||||
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package dev.sheldan.abstracto.utility.model;
|
package dev.sheldan.abstracto.utility.model;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.models.context.UserInitiatedServerContext;
|
import dev.sheldan.abstracto.core.models.context.UserInitiatedServerContext;
|
||||||
|
import dev.sheldan.abstracto.core.models.template.display.EmoteDisplay;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.experimental.SuperBuilder;
|
import lombok.experimental.SuperBuilder;
|
||||||
import net.dv8tion.jda.api.entities.Emote;
|
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -14,5 +14,6 @@ import java.util.List;
|
|||||||
@SuperBuilder
|
@SuperBuilder
|
||||||
public class ServerInfoModel extends UserInitiatedServerContext {
|
public class ServerInfoModel extends UserInitiatedServerContext {
|
||||||
private Guild guild;
|
private Guild guild;
|
||||||
private List<Emote> emotes;
|
private List<EmoteDisplay> staticEmotes;
|
||||||
|
private List<EmoteDisplay> animatedEmotes;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package dev.sheldan.abstracto.core.models.template.display;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import net.dv8tion.jda.api.entities.Emote;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Builder
|
||||||
|
@Setter
|
||||||
|
|
||||||
|
public class EmoteDisplay {
|
||||||
|
private String markDown;
|
||||||
|
private Long emoteId;
|
||||||
|
private String emoteKey;
|
||||||
|
private Boolean animated;
|
||||||
|
private String imageUrl;
|
||||||
|
|
||||||
|
public static EmoteDisplay fromEmote(Emote emote) {
|
||||||
|
return EmoteDisplay
|
||||||
|
.builder()
|
||||||
|
.emoteId(emote.getIdLong())
|
||||||
|
.emoteKey(emote.getName())
|
||||||
|
.animated(emote.isAnimated())
|
||||||
|
.markDown(emote.getAsMention())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user