Skip to content

Commit

Permalink
[AB-xxx] updating version to a newer commit
Browse files Browse the repository at this point in the history
making more commands for user installable
  • Loading branch information
Sheldan committed Apr 12, 2024
1 parent 03eef96 commit a1693bf
Show file tree
Hide file tree
Showing 29 changed files with 60 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public CommandConfiguration getConfiguration() {
.slashCommandConfig(slashCommandConfig)
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
.templated(true)
.userInstallable(true)
.supportsEmbedException(true)
.causesReaction(true)
.parameters(parameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public CommandConfiguration getConfiguration() {
.slashCommandConfig(slashCommandConfig)
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
.templated(true)
.userInstallable(true)
.supportsEmbedException(true)
.causesReaction(true)
.parameters(parameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public CommandConfiguration getConfiguration() {
.name(LOVE_CALC_COMMAND)
.slashCommandConfig(slashCommandConfig)
.async(true)
.userInstallable(true)
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
.templated(true)
.supportsEmbedException(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public CommandConfiguration getConfiguration() {
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
.templated(true)
.async(true)
.userInstallable(true)
.slashCommandConfig(slashCommandConfig)
.supportsEmbedException(true)
.parameters(parameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public CommandConfiguration getConfiguration() {
.name(ROLL_COMMAND)
.slashCommandConfig(slashCommandConfig)
.async(true)
.userInstallable(true)
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
.templated(true)
.supportsEmbedException(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public CommandConfiguration getConfiguration() {
.slashCommandConfig(slashCommandConfig)
.module(EntertainmentModuleDefinition.ENTERTAINMENT)
.templated(true)
.userInstallable(true)
.supportsEmbedException(true)
.causesReaction(true)
.parameters(parameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public CommandConfiguration getConfiguration() {
.name("amongusText")
.module(UtilityModuleDefinition.UTILITY)
.templated(true)
.userInstallable(true)
.supportsEmbedException(true)
.async(true)
.slashCommandConfig(slashCommandConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public CommandConfiguration getConfiguration() {
.name("bonk")
.module(UtilityModuleDefinition.UTILITY)
.templated(true)
.userInstallable(true)
.supportsEmbedException(true)
.async(true)
.slashCommandConfig(slashCommandConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public CommandConfiguration getConfiguration() {
.name("pat")
.module(UtilityModuleDefinition.UTILITY)
.templated(true)
.userInstallable(true)
.supportsEmbedException(true)
.async(true)
.slashCommandConfig(slashCommandConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public CommandConfiguration getConfiguration() {
.name("triggered")
.module(UtilityModuleDefinition.UTILITY)
.templated(true)
.userInstallable(true)
.supportsEmbedException(true)
.async(true)
.slashCommandConfig(slashCommandConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.sheldan.abstracto.core.command.condition.ConditionResult;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import dev.sheldan.abstracto.modmail.condition.ModMailContextCondition;
import dev.sheldan.abstracto.modmail.condition.detail.NotInModMailThreadConditionDetail;
import dev.sheldan.abstracto.modmail.model.database.ModMailThread;
Expand Down Expand Up @@ -45,6 +46,9 @@ public ConditionResult shouldExecute(CommandContext commandContext, Command comm

@Override
public ConditionResult shouldExecute(SlashCommandInteractionEvent slashCommandInteractionEvent, Command command) {
if(ContextUtils.isNotGuildAware(slashCommandInteractionEvent)) {
return ConditionResult.SUCCESS;
}
Optional<ModMailThread> threadOptional = modMailThreadManagementService.getByChannelOptional(channelManagementService.loadChannel(slashCommandInteractionEvent.getChannel()));
if(threadOptional.isPresent()) {
return ConditionResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public CommandConfiguration getConfiguration() {
.templated(true)
.slashCommandConfig(slashCommandConfig)
.async(true)
.userInstallable(true)
.aliases(aliases)
.supportsEmbedException(true)
.causesReaction(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public CommandConfiguration getConfiguration() {
.name(OPEN_WEATHER_MAP_COMMAND)
.module(UtilityModuleDefinition.UTILITY)
.templated(true)
.userInstallable(true)
.slashCommandConfig(slashCommandConfig)
.async(true)
.supportsEmbedException(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public CommandConfiguration getConfiguration() {
.slashCommandConfig(slashCommandConfig)
.async(true)
.aliases(aliases)
.userInstallable(true)
.supportsEmbedException(true)
.causesReaction(false)
.parameters(parameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public CommandConfiguration getConfiguration() {
.templated(true)
.slashCommandConfig(slashCommandConfig)
.async(true)
.userInstallable(true)
.aliases(aliases)
.supportsEmbedException(true)
.causesReaction(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public CommandConfiguration getConfiguration() {
.module(UtilityModuleDefinition.UTILITY)
.slashCommandConfig(slashCommandConfig)
.templated(true)
.userInstallable(true)
.async(true)
.aliases(aliases)
.supportsEmbedException(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.sheldan.abstracto.core.command.execution.ResultState;
import dev.sheldan.abstracto.core.command.service.CommandCoolDownService;
import dev.sheldan.abstracto.core.command.service.PostCommandExecution;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -35,7 +36,9 @@ public boolean supportsSlash() {
public void executeSlash(SlashCommandInteractionEvent interaction, CommandResult commandResult, Command command) {
ResultState result = commandResult.getResult();
if(result.equals(ResultState.SUCCESSFUL) || result.equals(ResultState.IGNORED)) {
commandCoolDownService.updateCoolDowns(command, interaction);
if(ContextUtils.isGuildAware(interaction)) {
commandCoolDownService.updateCoolDowns(command, interaction);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public CommandConfiguration getConfiguration() {
.aliases(Arrays.asList("docu", "docs"))
.module(SupportModuleDefinition.SUPPORT)
.help(helpInfo)
.userInstallable(true)
.slashCommandConfig(slashCommandConfig)
.templated(true)
.causesReaction(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public CommandConfiguration getConfiguration() {
.module(UtilityModuleDefinition.UTILITY)
.templated(true)
.async(true)
.userInstallable(true)
.help(helpInfo)
.slashCommandConfig(slashCommandConfig)
.causesReaction(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public CommandConfiguration getConfiguration() {
.module(UtilityModuleDefinition.UTILITY)
.templated(true)
.async(true)
.userInstallable(true)
.help(helpInfo)
.slashCommandConfig(slashCommandConfig)
.causesReaction(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import dev.sheldan.abstracto.core.templating.model.AttachedFile;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.templating.service.TemplateService;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageEmbed;
Expand Down Expand Up @@ -270,17 +271,19 @@ public CompletableFuture<InteractionHook> replyMessageToSend(MessageToSend messa
action = callback.reply(".");
}
action = action.setComponents(actionRows);
Long serverId = callback.getGuild().getIdLong();
AServer server = serverManagementService.loadServer(serverId);
actionRows.forEach(components -> components.forEach(component -> {
if(component instanceof ActionComponent) {
String id = ((ActionComponent)component).getId();
MessageToSend.ComponentConfig payload = messageToSend.getComponentPayloads().get(id);
if(payload != null && payload.getPersistCallback()) {
componentPayloadManagementService.createPayload(id, payload.getPayload(), payload.getPayloadType(), payload.getComponentOrigin(), server, payload.getComponentType());
if(ContextUtils.isGuildAware(callback)) {
Long serverId = callback.getGuild().getIdLong();
AServer server = serverManagementService.loadServer(serverId);
actionRows.forEach(components -> components.forEach(component -> {
if(component instanceof ActionComponent) {
String id = ((ActionComponent)component).getId();
MessageToSend.ComponentConfig payload = messageToSend.getComponentPayloads().get(id);
if(payload != null && payload.getPersistCallback()) {
componentPayloadManagementService.createPayload(id, payload.getPayload(), payload.getPayloadType(), payload.getComponentOrigin(), server, payload.getComponentType());
}
}
}
}));
}));
}
}

if(messageToSend.getEphemeral()) {
Expand All @@ -292,12 +295,11 @@ public CompletableFuture<InteractionHook> replyMessageToSend(MessageToSend messa
action = action.setEphemeral(messageToSend.getEphemeral());
}
}
if(callback.getHook().getInteraction().hasGuild()) {
if(ContextUtils.isGuildAware(callback)) {
Set<Message.MentionType> allowedMentions = allowedMentionService.getAllowedMentionsFor(callback.getMessageChannel(), messageToSend);
if(action != null) {
if (action != null) {
action.setAllowedMentions(allowedMentions);
}

}

if(action == null) {
Expand All @@ -308,10 +310,7 @@ public CompletableFuture<InteractionHook> replyMessageToSend(MessageToSend messa

@Override
public CompletableFuture<InteractionHook> replyMessage(String templateKey, Object model, IReplyCallback callback) {
Long serverId = null;
if(callback.getHook().getInteraction().hasGuild()) {
serverId = callback.getGuild().getIdLong();
}
Long serverId = callback.getGuild().getIdLong();
MessageToSend messageToSend = templateService.renderTemplateToMessageToSend(templateKey, model, serverId);
return replyMessageToSend(messageToSend, callback);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ public List<Command> getSlashCommands() {
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
try {
if(commands == null || commands.isEmpty()) return;
if(event.hasGuild()) {
log.debug("Executing slash command in guild {} from user {}.", event.getGuild().getIdLong(), event.getMember().getIdLong());
}
log.debug("Executing slash command in guild {} from user {}.", event.getGuild().getIdLong(), event.getMember().getIdLong());
CompletableFuture.runAsync(() -> self.executeListenerLogic(event), slashCommandExecutor).exceptionally(throwable -> {
log.error("Failed to execute listener logic in async slash command event.", throwable);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.sheldan.abstracto.core.command.condition.detail.AdminModeDetail;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.service.ServerService;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
Expand Down Expand Up @@ -42,7 +43,7 @@ public ConditionResult shouldExecute(CommandContext context, Command command) {

@Override
public ConditionResult shouldExecute(SlashCommandInteractionEvent slashCommandInteractionEvent, Command command) {
if(!slashCommandInteractionEvent.hasGuild()) {
if(ContextUtils.isNotGuildAware(slashCommandInteractionEvent)) {
return ConditionResult.SUCCESS;
}
boolean adminModeActive = service.adminModeActive(slashCommandInteractionEvent.getGuild());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CoolDownCheckResult;
import dev.sheldan.abstracto.core.command.service.CommandCoolDownService;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -39,7 +40,7 @@ public ConditionResult shouldExecute(CommandContext commandContext, Command comm

@Override
public ConditionResult shouldExecute(SlashCommandInteractionEvent slashCommandInteractionEvent, Command command) {
if(!slashCommandInteractionEvent.hasGuild()) {
if(ContextUtils.isNotGuildAware(slashCommandInteractionEvent)) {
return ConditionResult.SUCCESS;
}
commandCoolDownService.takeLock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.service.FeatureConfigService;
import dev.sheldan.abstracto.core.service.FeatureFlagService;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -29,7 +30,7 @@ public ConditionResult shouldExecute(CommandContext context, Command command) {

@Override
public ConditionResult shouldExecute(SlashCommandInteractionEvent slashCommandInteractionEvent, Command command) {
if(!slashCommandInteractionEvent.hasGuild()) {
if(ContextUtils.isNotGuildAware(slashCommandInteractionEvent)) {
return ConditionResult.SUCCESS;
}
Long serverId = slashCommandInteractionEvent.getGuild().getIdLong();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.config.FeatureMode;
import dev.sheldan.abstracto.core.service.FeatureModeService;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -50,7 +51,7 @@ private ConditionResult checkFeatureModeCondition(Command command, Long serverId

@Override
public ConditionResult shouldExecute(SlashCommandInteractionEvent slashCommandInteractionEvent, Command command) {
if(!slashCommandInteractionEvent.hasGuild()) {
if(ContextUtils.isNotGuildAware(slashCommandInteractionEvent)) {
return ConditionResult.SUCCESS;
}
Long serverId = slashCommandInteractionEvent.getGuild().getIdLong();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import dev.sheldan.abstracto.core.service.RoleImmunityService;
import dev.sheldan.abstracto.core.service.RoleService;
import dev.sheldan.abstracto.core.utils.CompletableFutureList;
import dev.sheldan.abstracto.core.utils.ContextUtils;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
Expand Down Expand Up @@ -113,7 +114,7 @@ public void checkConditions(CommandConfiguration commandConfig, List<Object> par

@Override
public CompletableFuture<ConditionResult> shouldExecuteAsync(SlashCommandInteractionEvent event, Command command) {
if(!event.hasGuild()) {
if(ContextUtils.isNotGuildAware(event)) {
return CompletableFuture.completedFuture(ConditionResult.SUCCESS);
}
CommandConfiguration commandConfig = command.getConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,21 @@
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.interactions.Interaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

@Component
@Slf4j
public class ContextUtils {

@Autowired
private ChannelManagementService channelManagementService;

@Autowired
private UserInServerManagementService userInServerManagementService;

@Autowired
private MemberService memberService;
public static boolean isGuildAware(Interaction interaction) {
return !isNotGuildAware(interaction);
}

public <T extends UserInitiatedServerContext> UserInitiatedServerContext fromMessage(CachedMessage message, Class<T> clazz) {
Method m = null;
GuildChannelMember guildChannelMember = memberService.getServerChannelUser(message.getServerId(), message.getChannelId(), message.getAuthor().getAuthorId());
try {
m = clazz.getMethod("builder");
UserInitiatedServerContext.UserInitiatedServerContextBuilder<?, ?> builder = (UserInitiatedServerContext.UserInitiatedServerContextBuilder) m.invoke(null, null);
return builder
.member(guildChannelMember.getMember())
.guild(guildChannelMember.getGuild())
.messageChannel((GuildMessageChannel) guildChannelMember.getTextChannel())
.build();
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
log.error("Failed to execute builder method", e);
}
throw new AbstractoRunTimeException("Failed to create UserInitiatedServerContext from message");
public static boolean isNotGuildAware(Interaction interaction) {
return interaction.getGuild() == null || interaction.getGuild().isDetached();
}
}

0 comments on commit a1693bf

Please sign in to comment.