mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-24 13:44:33 +00:00
added purge command to delete messages via bulk delete
adapted api of status message service added concept of self destruct command results, these will cause the command message to be deleted
This commit is contained in:
@@ -19,6 +19,10 @@ public class CommandResult {
|
||||
return CommandResult.builder().result(ResultState.SUCCESSFUL).build();
|
||||
}
|
||||
|
||||
public static CommandResult fromSelfDestruct() {
|
||||
return CommandResult.builder().result(ResultState.SELF_DESTRUCT).build();
|
||||
}
|
||||
|
||||
public static CommandResult fromError(String message){
|
||||
return CommandResult.builder().result(ResultState.ERROR).message(message).build();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package dev.sheldan.abstracto.core.command.execution;
|
||||
|
||||
public enum ResultState {
|
||||
ERROR, SUCCESSFUL, IGNORED, CONDITION
|
||||
ERROR, SUCCESSFUL, IGNORED, CONDITION, SELF_DESTRUCT
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.templating.model.MessageToSend;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
|
||||
@@ -16,7 +17,10 @@ public interface MessageService {
|
||||
List<CompletableFuture<Void>> addReactionsToMessageWithFuture(List<String> emoteKeys, Long serverId, Message message);
|
||||
CompletableFuture<Void> deleteMessageInChannelInServer(Long serverId, Long channelId, Long messageId);
|
||||
CompletableFuture<Message> createStatusMessage(MessageToSend messageToSend, AChannel channel);
|
||||
CompletableFuture<Message> createStatusMessage(MessageToSend messageToSend, MessageChannel channel);
|
||||
CompletableFuture<Long> createStatusMessageId(MessageToSend messageToSend, MessageChannel channel);
|
||||
void updateStatusMessage(AChannel channel, Long messageId, MessageToSend messageToSend);
|
||||
void updateStatusMessage(MessageChannel channel, Long messageId, MessageToSend messageToSend);
|
||||
void sendMessageToUser(AUserInAServer userInAServer, String text, TextChannel feedbackChannel);
|
||||
void sendMessageToUser(User user, String text, TextChannel feedbackChannel);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package dev.sheldan.abstracto.core.utils;
|
||||
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Component
|
||||
public class ExceptionUtils {
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Transactional
|
||||
public void handleExceptionIfTemplatable(Throwable throwable, MessageChannel channel) {
|
||||
if(throwable != null) {
|
||||
if(throwable.getCause() instanceof Templatable) {
|
||||
String exceptionText = templateService.renderTemplatable((Templatable) throwable.getCause());
|
||||
channel.sendMessage(exceptionText).queue();
|
||||
} else {
|
||||
channel.sendMessage(throwable.getCause().getMessage()).queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user