mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-27 14:23:56 +00:00
[AB-96] adding ability to edit/delete modmail messages via editing/deleting the original message causing the message,
adding featuremode to modmail to define whether or not there is a separate message posted to the mod mail thread, to see it easier, renaming modmail related tables to singular, adding some necessary methods (caching) to all entities
This commit is contained in:
@@ -2,11 +2,14 @@ package dev.sheldan.abstracto.core.command.service;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.CommandReceivedHandler;
|
||||
import dev.sheldan.abstracto.core.command.condition.CommandCondition;
|
||||
import dev.sheldan.abstracto.core.command.condition.ConditionResult;
|
||||
import dev.sheldan.abstracto.core.command.condition.ConditionalCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameters;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.UnParsedCommandParameter;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommandInAServer;
|
||||
import dev.sheldan.abstracto.core.command.models.database.AModule;
|
||||
@@ -19,10 +22,12 @@ import dev.sheldan.abstracto.core.models.database.AFeature;
|
||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@@ -44,6 +49,12 @@ public class CommandServiceBean implements CommandService {
|
||||
@Autowired
|
||||
private CommandInServerManagementService commandInServerManagementService;
|
||||
|
||||
@Autowired
|
||||
private CommandRegistry commandRegistry;
|
||||
|
||||
@Autowired
|
||||
private CommandReceivedHandler commandReceivedHandler;
|
||||
|
||||
@Override
|
||||
public ACommand createCommand(String name, String moduleName, FeatureEnum featureEnum) {
|
||||
AModule module = moduleManagementService.getOrCreate(moduleName);
|
||||
@@ -151,6 +162,14 @@ public class CommandServiceBean implements CommandService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Parameters> getParametersForCommand(String commandName, Message messageContainingContent) {
|
||||
String contentStripped = messageContainingContent.getContentRaw();
|
||||
UnParsedCommandParameter unParsedParameter = new UnParsedCommandParameter(contentStripped);
|
||||
Command command = commandRegistry.findCommandByParameters(commandName, unParsedParameter);
|
||||
return commandReceivedHandler.getParsedParameters(unParsedParameter, command, messageContainingContent);
|
||||
}
|
||||
|
||||
private ConditionResult checkConditions(CommandContext commandContext, Command command, List<CommandCondition> conditions) {
|
||||
if(conditions != null) {
|
||||
for (CommandCondition condition : conditions) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Entity
|
||||
@Table(name = "lock")
|
||||
@@ -13,7 +14,7 @@ import javax.persistence.*;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public class ALock {
|
||||
public class ALock implements Serializable {
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
|
||||
@@ -130,10 +130,7 @@ public class BotServiceBean implements BotService {
|
||||
Optional<TextChannel> textChannelOptional = getTextChannelFromServerOptional(serverId, channelId);
|
||||
if(textChannelOptional.isPresent()) {
|
||||
TextChannel textChannel = textChannelOptional.get();
|
||||
return textChannel.deleteMessageById(messageId).submit().exceptionally(throwable -> {
|
||||
log.warn("Deleting the message {} in channel {} in guild {} failed.", messageId, channelId, serverId, throwable);
|
||||
return null;
|
||||
});
|
||||
return textChannel.deleteMessageById(messageId).submit();
|
||||
} else {
|
||||
log.warn("Could not find channel {} in guild {} to delete message {} in.", channelId, serverId, messageId);
|
||||
}
|
||||
|
||||
@@ -275,9 +275,25 @@ public class MessageServiceBean implements MessageService {
|
||||
channelService.sendEmbedTemplateInChannel(template, model, privateChannel).get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Message> sendMessageToSendToUser(User user, MessageToSend messageToSend) {
|
||||
return user.openPrivateChannel().submit().thenCompose(privateChannel -> channelService.sendMessageToSendToChannel(messageToSend, privateChannel).get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Message> sendMessageToUser(User user, String text) {
|
||||
log.trace("Sending direct string message to user {}.", user.getIdLong());
|
||||
return user.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessage(text)).submit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> deleteMessageInChannelWithUser(User user, Long messageId) {
|
||||
log.info("Deleting message {} in channel with user {}.", messageId, user.getIdLong());
|
||||
return user.openPrivateChannel().flatMap(privateChannel -> privateChannel.deleteMessageById(messageId)).submit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> editMessageInDMChannel(User user, MessageToSend messageToSend, Long messageId) {
|
||||
return user.openPrivateChannel().submit().thenCompose(privateChannel -> channelService.editMessageInAChannelFuture(messageToSend, privateChannel, messageId).thenApply(message -> null));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user