[AB-333] providing some dates as separate instants instead of relying on the member attributes

truncating date to day when displaying the date for export emote stats
fixing wrong message when confirming a command and adding missing exception handling
This commit is contained in:
Sheldan
2021-10-14 01:31:52 +02:00
parent 36ca9b11e4
commit 8909e8ebe5
10 changed files with 49 additions and 31 deletions

View File

@@ -313,13 +313,16 @@ public class MuteServiceBean implements MuteService {
finalFuture.complete(null)
).exceptionally(throwable1 -> {
log.error("Unmute log failed to send for mute {} in server {}.", muteId, serverId, throwable1);
finalFuture.complete(null);
finalFuture.completeExceptionally(null);
return null;
});
} else {
finalFuture.complete(null);
}
return null;
}).exceptionally(throwable -> {
finalFuture.completeExceptionally(throwable);
return null;
});
return finalFuture;

View File

@@ -269,6 +269,9 @@ public class WarnServiceBean implements WarnService {
return null;
});
return null;
}).exceptionally(throwable -> {
sendingFuture.completeExceptionally(throwable);
return null;
});
return sendingFuture;

View File

@@ -425,6 +425,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
.builder()
.member(member)
.latestModMailThread(latestThread)
.memberJoinDate(member.getTimeJoined().toInstant())
.pastModMailThreadCount((long)oldThreads.size())
.build();
List<CompletableFuture<Message>> messages = channelService.sendEmbedTemplateInTextChannelList("modmail_thread_header", header, channel);

View File

@@ -6,6 +6,8 @@ import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.api.entities.Member;
import java.time.Instant;
/**
* This is the model used when a new mod mail thread is opened and a message containing some information about the user
* is displayed for the user handling the mod mail thread.
@@ -23,6 +25,7 @@ public class ModMailThreaderHeader {
* for the user
*/
private ModMailThread latestModMailThread;
private Instant memberJoinDate;
/**
* The amount of previous mod mail thread the user has.
*/

View File

@@ -29,6 +29,7 @@ import java.io.File;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@@ -71,7 +72,7 @@ public class ExportEmoteStats extends AbstractConditionableCommand {
if(!parameters.isEmpty()) {
// if a duration is given, subtract this duration from the current point in time
Duration duration = (Duration) parameters.get(0);
statsSince = Instant.now().minus(duration);
statsSince = Instant.now().minus(duration).truncatedTo(ChronoUnit.DAYS);
}
AServer actualServer = serverManagementService.loadServer(commandContext.getGuild().getIdLong());
List<UsedEmote> usedEmotes = usedEmoteManagementService.loadEmoteUsagesForServerSince(actualServer, statsSince);

View File

@@ -50,11 +50,15 @@ public class UserInfo extends AbstractConditionableCommand {
log.info("Force reloading member {} in guild {} for user info.", memberToShow.getId(), memberToShow.getGuild().getId());
return memberService.forceReloadMember(memberToShow).thenCompose(member -> {
model.setMemberInfo(member);
model.setCreationDate(member.getTimeCreated().toInstant());
model.setJoinDate(member.getTimeJoined().toInstant());
return self.sendResponse(commandContext, model)
.thenApply(aVoid -> CommandResult.fromIgnored());
});
} else {
model.setMemberInfo(memberToShow);
model.setCreationDate(memberToShow.getTimeCreated().toInstant());
model.setJoinDate(memberToShow.getTimeJoined().toInstant());
return self.sendResponse(commandContext, model)
.thenApply(aVoid -> CommandResult.fromIgnored());
}

View File

@@ -15,6 +15,8 @@ import org.junit.runner.RunWith;
import org.mockito.*;
import org.mockito.junit.MockitoJUnitRunner;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
@@ -43,6 +45,8 @@ public class UserInfoTest {
CommandContext noParameters = CommandTestUtilities.getNoParameters();
when(noParameters.getAuthor().getGuild()).thenReturn(noParameters.getGuild());
when(noParameters.getAuthor().hasTimeJoined()).thenReturn(true);
when(noParameters.getAuthor().getTimeJoined()).thenReturn(OffsetDateTime.now());
when(noParameters.getAuthor().getTimeCreated()).thenReturn(OffsetDateTime.now());
when(self.sendResponse(eq(noParameters),any(UserInfoModel.class))).thenReturn(CompletableFuture.completedFuture(null));
CompletableFuture<CommandResult> result = testUnit.executeAsync(noParameters);
verify(self, times(1)).sendResponse(eq(noParameters), modelArgumentCaptor.capture());
@@ -56,6 +60,8 @@ public class UserInfoTest {
CommandContext noParameters = CommandTestUtilities.getNoParameters();
when(noParameters.getAuthor().hasTimeJoined()).thenReturn(false);
Member loadedAuthor = Mockito.mock(Member.class);
when(loadedAuthor.getTimeJoined()).thenReturn(OffsetDateTime.now());
when(loadedAuthor.getTimeCreated()).thenReturn(OffsetDateTime.now());
when(noParameters.getAuthor().getGuild()).thenReturn(noParameters.getGuild());
when(memberService.forceReloadMember(noParameters.getAuthor())).thenReturn(CompletableFuture.completedFuture(loadedAuthor));
when(self.sendResponse(eq(noParameters), modelArgumentCaptor.capture())).thenReturn(CompletableFuture.completedFuture(null));
@@ -69,6 +75,8 @@ public class UserInfoTest {
public void executeTestWithParameterLoadedMember() {
Member member = Mockito.mock(Member.class);
when(member.hasTimeJoined()).thenReturn(true);
when(member.getTimeJoined()).thenReturn(OffsetDateTime.now());
when(member.getTimeCreated()).thenReturn(OffsetDateTime.now());
CommandContext parameters = CommandTestUtilities.getWithParameters(Arrays.asList(member));
when(member.getGuild()).thenReturn(parameters.getGuild());
when(self.sendResponse(eq(parameters), modelArgumentCaptor.capture())).thenReturn(CompletableFuture.completedFuture(null));
@@ -85,6 +93,8 @@ public class UserInfoTest {
CommandContext parameters = CommandTestUtilities.getWithParameters(Arrays.asList(member));
when(member.getGuild()).thenReturn(parameters.getGuild());
Member loadedAuthor = Mockito.mock(Member.class);
when(loadedAuthor.getTimeJoined()).thenReturn(OffsetDateTime.now());
when(loadedAuthor.getTimeCreated()).thenReturn(OffsetDateTime.now());
when(memberService.forceReloadMember(member)).thenReturn(CompletableFuture.completedFuture(loadedAuthor));
when(self.sendResponse(eq(parameters), modelArgumentCaptor.capture())).thenReturn(CompletableFuture.completedFuture(null));
CompletableFuture<CommandResult> result = testUnit.executeAsync(parameters);

View File

@@ -6,9 +6,13 @@ import lombok.Setter;
import lombok.experimental.SuperBuilder;
import net.dv8tion.jda.api.entities.Member;
import java.time.Instant;
@Getter
@Setter
@SuperBuilder
public class UserInfoModel extends SlimUserInitiatedServerContext {
private Member memberInfo;
private Instant joinDate;
private Instant creationDate;
}