mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-25 14:06:24 +00:00
added concept of undo actions
used undo actions to delete the mod mail thread channel, if it already reached a certain state when initially setting up the mod mail thread
This commit is contained in:
@@ -168,11 +168,16 @@ public class ChannelServiceBean implements ChannelService {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> deleteTextChannel(AChannel channel) {
|
||||
TextChannel textChannelById = botService.getInstance().getTextChannelById(channel.getId());
|
||||
return deleteTextChannel(channel.getServer().getId(), channel.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> deleteTextChannel(Long serverId, Long channelId) {
|
||||
TextChannel textChannelById = botService.getInstance().getTextChannelById(channelId);
|
||||
if(textChannelById != null) {
|
||||
return textChannelById.delete().submit();
|
||||
}
|
||||
throw new ChannelException(String.format("Failed to delete channel %s in server %s", channel.getId(), channel.getServer().getId()));
|
||||
throw new ChannelException(String.format("Failed to delete channel %s in server %s", channelId, serverId));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.UndoActionException;
|
||||
import dev.sheldan.abstracto.core.models.UndoAction;
|
||||
import dev.sheldan.abstracto.core.models.UndoActionInstance;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class UndoActionServiceBean implements UndoActionService {
|
||||
|
||||
@Autowired
|
||||
private BotService botService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Override
|
||||
public void performActions(List<UndoActionInstance> actionsToPerform) {
|
||||
actionsToPerform.forEach(undoActionInstance -> {
|
||||
UndoAction action = undoActionInstance.getAction();
|
||||
switch (action) {
|
||||
case DELETE_CHANNEL:
|
||||
if(undoActionInstance.getIds().size() != 2) {
|
||||
throw new UndoActionException("Not the correct amount of ides provided for the channel deletion undo action");
|
||||
}
|
||||
deleteChannel(undoActionInstance.getIds().get(0), undoActionInstance.getIds().get(1));
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void deleteChannel(Long serverId, Long channelId) {
|
||||
channelService.deleteTextChannel(serverId, channelId).exceptionally((throwable) -> {
|
||||
log.error("Failed to execute undo action channel delete for channel {} in server {}", channelId, serverId, throwable);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user