fixed some catch blocks to include all exceptions

fixed message sending undo action
This commit is contained in:
Sheldan
2020-05-09 01:32:09 +02:00
parent 0e7add826b
commit 8db1cead57
5 changed files with 23 additions and 5 deletions

View File

@@ -357,9 +357,11 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
list.getFutures().forEach(messageCompletableFuture -> { list.getFutures().forEach(messageCompletableFuture -> {
try { try {
Message message = messageCompletableFuture.get(); Message message = messageCompletableFuture.get();
undoActions.add(UndoActionInstance.getMessageDeleteAction(message.getGuild().getIdLong(), message.getChannel().getIdLong(), message.getIdLong())); undoActions.add(UndoActionInstance.getMessageDeleteAction(message.getChannel().getIdLong(), message.getIdLong()));
} catch (InterruptedException | ExecutionException e) { } catch (InterruptedException | ExecutionException e) {
log.error("Failed to post logging messages.", e); log.error("Failed to post logging messages.", e);
} catch (Exception e) {
log.error("Failed to handle the mod mail log messages.", e);
} }
}); });
self.afterSuccessfulLog(modMailThreadId, feedBack, notifyUser, undoActions); self.afterSuccessfulLog(modMailThreadId, feedBack, notifyUser, undoActions);
@@ -463,6 +465,8 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
} }
} catch (InterruptedException | ExecutionException e) { } catch (InterruptedException | ExecutionException e) {
log.error("Error while executing future to retrieve reaction.", e); log.error("Error while executing future to retrieve reaction.", e);
} catch (Exception e) {
log.error("Failed handle the loaded messages.", e);
} }
}); });
List<CompletableFuture<Message>> completableFutures = new ArrayList<>(); List<CompletableFuture<Message>> completableFutures = new ArrayList<>();
@@ -535,6 +539,8 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
messages.add(messageToAdd); messages.add(messageToAdd);
} catch (InterruptedException | ExecutionException e) { } catch (InterruptedException | ExecutionException e) {
log.error("A future when sending the message to the user was interrupted.", e); log.error("A future when sending the message to the user was interrupted.", e);
} catch (Exception e) {
log.error("Failed to handle the send staff message.", e);
} }
}); });
self.saveMessageIds(messages, modMailThread, moderator, anonymous, true); self.saveMessageIds(messages, modMailThread, moderator, anonymous, true);

View File

@@ -110,6 +110,17 @@ public class BotServiceBean implements BotService {
return CompletableFuture.completedFuture(null); return CompletableFuture.completedFuture(null);
} }
@Override
public CompletableFuture<Void> deleteMessage(Long channelId, Long messageId) {
TextChannel textChannel = getInstance().getTextChannelById(channelId);
if(textChannel != null) {
return textChannel.deleteMessageById(messageId).submit();
} else {
log.warn("Could not find channel {} to delete message {} in.", channelId, messageId);
}
return CompletableFuture.completedFuture(null);
}
@Override @Override
public Optional<Emote> getEmote(Long serverId, AEmote emote) { public Optional<Emote> getEmote(Long serverId, AEmote emote) {
if(!emote.getCustom()) { if(!emote.getCustom()) {

View File

@@ -33,11 +33,11 @@ public class UndoActionServiceBean implements UndoActionService {
deleteChannel(ids.get(0), ids.get(1)); deleteChannel(ids.get(0), ids.get(1));
break; break;
case DELETE_MESSAGE: case DELETE_MESSAGE:
if(ids.size() != 3) { if(ids.size() != 2) {
log.error("Not the correct amount of ids provided for the message deletion undo action."); log.error("Not the correct amount of ids provided for the message deletion undo action.");
break; break;
} }
botService.deleteMessage(ids.get(0), ids.get(1), ids.get(2)); botService.deleteMessage(ids.get(0), ids.get(1));
} }
}); });
} }

View File

@@ -22,11 +22,11 @@ public class UndoActionInstance {
.build(); .build();
} }
public static UndoActionInstance getMessageDeleteAction(Long serverId, Long channelId, Long messageId) { public static UndoActionInstance getMessageDeleteAction(Long channelId, Long messageId) {
return UndoActionInstance return UndoActionInstance
.builder() .builder()
.action(UndoAction.DELETE_MESSAGE) .action(UndoAction.DELETE_MESSAGE)
.ids(Arrays.asList(serverId, channelId, messageId)) .ids(Arrays.asList(channelId, messageId))
.build(); .build();
} }
} }

View File

@@ -24,6 +24,7 @@ public interface BotService {
Member getMemberInServer(AUserInAServer aUserInAServer); Member getMemberInServer(AUserInAServer aUserInAServer);
Member getMemberInServer(AServer server, AUser member); Member getMemberInServer(AServer server, AUser member);
CompletableFuture<Void> deleteMessage(Long serverId, Long channelId, Long messageId); CompletableFuture<Void> deleteMessage(Long serverId, Long channelId, Long messageId);
CompletableFuture<Void> deleteMessage(Long channelId, Long messageId);
Optional<Emote> getEmote(Long serverId, AEmote emote); Optional<Emote> getEmote(Long serverId, AEmote emote);
Optional<TextChannel> getTextChannelFromServer(Guild serverId, Long textChannelId); Optional<TextChannel> getTextChannelFromServer(Guild serverId, Long textChannelId);
Optional<TextChannel> getTextChannelFromServer(Long serverId, Long textChannelId); Optional<TextChannel> getTextChannelFromServer(Long serverId, Long textChannelId);