mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-26 05:44:42 +00:00
added serverinfo command
added freemarker extension in order to split up elements in fields at a point which makes sense (necessary for emotes to render) added additional check to split fields if they are indeed over the max length
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package dev.sheldan.abstracto.utility.commands;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.UtilityModuleInterface;
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.serverinfo.ServerInfoModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class ServerInfo extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
ServerInfoModel model = (ServerInfoModel) ContextConverter.fromCommandContext(commandContext, ServerInfoModel.class);
|
||||
model.setGuild(commandContext.getGuild());
|
||||
channelService.sendEmbedTemplateInChannel("serverinfo_response", model, commandContext.getChannel());
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("serverInfo")
|
||||
.module(UtilityModuleInterface.UTILITY)
|
||||
.templated(true)
|
||||
.causesReaction(false)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureEnum getFeature() {
|
||||
return UtilityFeature.UTILITY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<#assign additionalInfo><#if count gt 1>${count}<#else><#assign count>${list?size}</#assign><#include "serverinfo_embed_emotes_title_total_emotes"></#if></#assign><#include "serverinfo_embed_emotes_field_title_message">
|
||||
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"title": {
|
||||
"title": "<#assign name=guild.name><#include "serverinfo_embed_title">"
|
||||
},
|
||||
"color" : {
|
||||
"r": 200,
|
||||
"g": 0,
|
||||
"b": 255
|
||||
},
|
||||
"fields": [
|
||||
{
|
||||
"name": "<#include "serverinfo_embed_id_field_title">",
|
||||
"value": "${guild.id}",
|
||||
"inline": "true"
|
||||
},
|
||||
{
|
||||
"name": "<#include "serverinfo_embed_owner_field_title">",
|
||||
"value": "${guild.owner.effectiveName}#${guild.owner.user.discriminator}",
|
||||
"inline": "true"
|
||||
},
|
||||
{
|
||||
"name": "<#include "serverinfo_embed_members_field_title">",
|
||||
"value": "${guild.memberCount}",
|
||||
"inline": "true"
|
||||
},
|
||||
{
|
||||
"name": "<#include "serverinfo_embed_role_count_field_title">",
|
||||
"value": "${guild.roles?size}",
|
||||
"inline": "true"
|
||||
},
|
||||
{
|
||||
"name": "<#include "serverinfo_embed_created_field_title">",
|
||||
"value": "${guild.timeCreated}",
|
||||
"inline": "true"
|
||||
},
|
||||
${safeFieldLength(guild.emotes, 'emote_mention', 'serverinfo_embed_emotes_field_title', 'false')},
|
||||
{
|
||||
"name": "<#include "serverinfo_embed_features_field_title">",
|
||||
"value": "<#list guild.features as feature>${feature}<#else>No features</#list>",
|
||||
"inline": "true"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package dev.sheldan.abstracto.utility.models.template.commands.serverinfo;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.context.UserInitiatedServerContext;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@SuperBuilder
|
||||
public class ServerInfoModel extends UserInitiatedServerContext {
|
||||
private Guild guild;
|
||||
private List<Emote> emotes;
|
||||
}
|
||||
Reference in New Issue
Block a user