From a6b5a560a5f7d4012975322c90b06a1d92031aed Mon Sep 17 00:00:00 2001 From: Presti Date: Fri, 1 Nov 2024 15:09:04 +0100 Subject: [PATCH] Merge Dev stuff onto master. (#374) * Update dependency io.sentry:sentry-spring-boot-starter-jakarta to v7.15.0 * Bump SQL * Start with v5 * Fix everything except Guild stuff I ain't fixing 1,7k lines of code rn gang. * Starts * Continues work on the silly async stuff for backend. * Continues work on the silly async stuff for backend. * ASYNC DONE LETS GO * Revert "Svelte 5" This reverts commit b1bd4f08e6b192ee5497aa7b62eb2bf927b88107. * Reapply "Svelte 5" This reverts commit e19eb1073c472cee6790549fbecf78fdf15dbef5. * V5 should be done now. * Bump version * Bump version --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Backend/pom.xml | 6 +- .../java/de/presti/ree6/backend/Server.java | 43 +- .../de/presti/ree6/backend/WebConfig.java | 2 +- .../backend/controller/GuildController.java | 779 +++----- .../backend/controller/SessionController.java | 38 +- .../controller/SettingsController.java | 89 +- .../ree6/backend/service/GuildService.java | 1694 +++++++++++------ .../ree6/backend/service/SessionService.java | 211 +- .../backend/utils/data/CustomOAuth2Util.java | 2 +- .../utils/data/DatabaseStorageBackend.java | 42 +- .../data/container/ChannelContainer.java | 2 + .../utils/data/container/TicketContainer.java | 2 + Frontend/package-lock.json | 222 ++- Frontend/package.json | 2 +- 14 files changed, 1773 insertions(+), 1361 deletions(-) diff --git a/Backend/pom.xml b/Backend/pom.xml index c0683d3f..225611ba 100644 --- a/Backend/pom.xml +++ b/Backend/pom.xml @@ -12,7 +12,7 @@ de.presti.ree6 Webinterface-Backend - 4.0.17 + 5.0.0 Webinterface-Backend The Backend for the Webinterface @@ -68,7 +68,7 @@ de.ree6 Ree6-SQL - da620ec7a5 + 3.0.0 @@ -88,7 +88,7 @@ io.sentry sentry-spring-boot-starter-jakarta - 7.14.0 + 7.15.0 diff --git a/Backend/src/main/java/de/presti/ree6/backend/Server.java b/Backend/src/main/java/de/presti/ree6/backend/Server.java index c84ab588..4cea85c1 100644 --- a/Backend/src/main/java/de/presti/ree6/backend/Server.java +++ b/Backend/src/main/java/de/presti/ree6/backend/Server.java @@ -82,7 +82,7 @@ public Server(String[] args) { instance = this; String tempVersion = getInstance().getClass().getPackage().getImplementationVersion(); - backendVersion = tempVersion == null ? "4.0.11" : tempVersion; + backendVersion = tempVersion == null ? "5.0.0" : tempVersion; load(args); } @@ -178,32 +178,33 @@ public void load(String[] args) { Runtime.getRuntime().addShutdownHook(new Thread(this::onShutdown)); ThreadUtil.createNewThread(x -> { - List recordings = SQLSession.getSqlConnector().getSqlWorker().getEntityList(new Recording(), "FROM Recording", null); - - if (recordings != null && !recordings.isEmpty()) { - for (Recording recording : recordings) { - if (recording.getCreation() < System.currentTimeMillis() - Duration.ofDays(1).toMillis()) { - SQLSession.getSqlConnector().getSqlWorker().deleteEntity(recording); + SQLSession.getSqlConnector().getSqlWorker().getEntityList(new Recording(), "FROM Recording", null).subscribe(recordings -> { + if (recordings != null && !recordings.isEmpty()) { + for (Recording recording : recordings) { + if (recording.getCreation() < System.currentTimeMillis() - Duration.ofDays(1).toMillis()) { + SQLSession.getSqlConnector().getSqlWorker().deleteEntity(recording).block(); + } } } - } + }); - List twitchIntegrations = SQLSession.getSqlConnector().getSqlWorker().getEntityList(new TwitchIntegration(), "FROM TwitchIntegration", null); - twitchIntegrations.forEach(twitchIntegration -> { - if (twitchIntegration.getLastUpdated().getTime() + (twitchIntegration.getExpiresIn() * 1000L) - Duration.ofMinutes(10).toMillis() <= System.currentTimeMillis()) { - Optional cred = twitchIdentityProvider.refreshCredential(CustomOAuth2Util.convertToOriginal(twitchIntegration)); + SQLSession.getSqlConnector().getSqlWorker().getEntityList(new TwitchIntegration(), "FROM TwitchIntegration", null).subscribe(twitchIntegrations -> { + twitchIntegrations.forEach(twitchIntegration -> { + if (twitchIntegration.getLastUpdated().getTime() + (twitchIntegration.getExpiresIn() * 1000L) - Duration.ofMinutes(10).toMillis() <= System.currentTimeMillis()) { + Optional cred = twitchIdentityProvider.refreshCredential(CustomOAuth2Util.convertToOriginal(twitchIntegration)); - credentialManager.getCredentials().removeIf(credential -> { - if (credential instanceof CustomOAuth2Credential customOAuth2CredentialLocal) { - return customOAuth2CredentialLocal.getDiscordId() == twitchIntegration.getUserId(); - } - return false; - }); + credentialManager.getCredentials().removeIf(credential -> { + if (credential instanceof CustomOAuth2Credential customOAuth2CredentialLocal) { + return customOAuth2CredentialLocal.getDiscordId() == twitchIntegration.getUserId(); + } + return false; + }); - cred.ifPresent(oAuth2Credential -> credentialManager.addCredential("twitch", CustomOAuth2Util.convert(twitchIntegration.getUserId(), oAuth2Credential))); - } + cred.ifPresent(oAuth2Credential -> credentialManager.addCredential("twitch", CustomOAuth2Util.convert(twitchIntegration.getUserId(), oAuth2Credential))); + } + }); + credentialManager.save(); }); - credentialManager.save(); }, throwable -> log.error("Failed running Data clear Thread", throwable), Duration.ofMinutes(5), true, false); } diff --git a/Backend/src/main/java/de/presti/ree6/backend/WebConfig.java b/Backend/src/main/java/de/presti/ree6/backend/WebConfig.java index 7954c072..509b4f6e 100644 --- a/Backend/src/main/java/de/presti/ree6/backend/WebConfig.java +++ b/Backend/src/main/java/de/presti/ree6/backend/WebConfig.java @@ -16,7 +16,7 @@ public class WebConfig implements WebMvcConfigurer { public void addCorsMappings(CorsRegistry registry) { log.info("Setting up CORS"); String allowedDomain = Data.getAllowedDomains(); - log.info("Allowed Domain: " + allowedDomain); + log.info("Allowed Domain: {}", allowedDomain); registry.addMapping("/**").allowedOriginPatterns(allowedDomain); } } \ No newline at end of file diff --git a/Backend/src/main/java/de/presti/ree6/backend/controller/GuildController.java b/Backend/src/main/java/de/presti/ree6/backend/controller/GuildController.java index 7257dc65..b9538b69 100644 --- a/Backend/src/main/java/de/presti/ree6/backend/controller/GuildController.java +++ b/Backend/src/main/java/de/presti/ree6/backend/controller/GuildController.java @@ -15,6 +15,7 @@ import de.presti.ree6.backend.utils.data.container.user.UserContainer; import de.presti.ree6.backend.utils.data.container.user.UserLevelContainer; import de.presti.ree6.sql.SQLSession; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.Resource; @@ -23,11 +24,14 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import reactor.core.publisher.Mono; +import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Objects; +@Slf4j @RestController @RequestMapping("/guilds") public class GuildController { @@ -44,21 +48,17 @@ public GuildController(SessionService sessionService, GuildService guildService) //region Guild Retrieve @GetMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse> retrieveGuilds(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier) { - try { - return new GenericObjectResponse<>(true, sessionService.retrieveGuilds(sessionIdentifier), "Guilds retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono>> retrieveGuilds(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier) { + return sessionService.retrieveGuilds(sessionIdentifier) + .map(x -> x.map(y -> new GenericObjectResponse<>(true, y, "Guilds retrieve!")) + .orElse(new GenericObjectResponse<>(false, null, "Could not retrieve guilds!"))); } @GetMapping(value = "/{guildId}", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse retrieveGuild(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, sessionService.retrieveGuild(sessionIdentifier, guildId, true, true), "Guild retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono> retrieveGuild(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, true, true) + .map(x -> x.map(y -> new GenericObjectResponse<>(true, y, "Guild retrieved!")) + .orElse(new GenericObjectResponse<>(false, null, "Could not retrieve guild!"))); } //endregion @@ -66,21 +66,17 @@ public GenericObjectResponse retrieveGuild(@RequestHeader(name = //region Guild Channel and Role @GetMapping(value = "/{guildId}/channels", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse> retrieveGuildChannels(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, sessionService.retrieveGuild(sessionIdentifier, guildId, true).getChannels(), "Channels retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono>> retrieveGuildChannels(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, true, true) + .map(x -> x.map(y -> new GenericObjectResponse<>(true, y.getChannels(), "Channels retrieved!")) + .orElse(new GenericObjectResponse<>(false, null, "Could not retrieve channels!"))); } @GetMapping(value = "/{guildId}/roles", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse> retrieveGuildRoles(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, sessionService.retrieveGuild(sessionIdentifier, guildId, false, true).getRoles(), "Roles retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono>> retrieveGuildRoles(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, true, true) + .map(x -> x.map(y -> new GenericObjectResponse<>(true, y.getRoles(), "Roles retrieved!")) + .orElse(new GenericObjectResponse<>(false, null, "Could not retrieve roles!"))); } //endregion @@ -88,42 +84,34 @@ public GenericObjectResponse> retrieveGuildRoles(@RequestHea //region Guild Blacklist @GetMapping(value = "/{guildId}/blacklist", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse> retrieveGuildBlacklist(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - List blacklist = SQLSession.getSqlConnector().getSqlWorker().getChatProtectorWords(guildId); - return new GenericObjectResponse<>(true, blacklist, "Blacklist retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, Collections.emptyList(), e.getMessage()); - } + public Mono>> retrieveGuildBlacklist(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId) + .mapNotNull(x -> x.map(y -> SQLSession.getSqlConnector().getSqlWorker().getChatProtectorWords(guildId) + .map(z -> new GenericObjectResponse<>(true, z, "Blacklist retrieved!")).block()) + .orElse(new GenericObjectResponse<>(false, null, "Could not retrieve blacklist!"))); } @PostMapping(value = "/{guildId}/blacklist/remove", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse removeGuildBlacklist(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { - try { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - - SQLSession.getSqlConnector().getSqlWorker().removeChatProtectorWord(guildId, request.value()); - return new GenericResponse(true, "Blacklist removed!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono removeGuildBlacklist(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { + return sessionService.retrieveGuild(sessionIdentifier, guildId) + .map(x -> x.map(y -> { + SQLSession.getSqlConnector().getSqlWorker().removeChatProtectorWord(guildId, request.value()); + return new GenericResponse(true, "Blacklist removed!"); + }).orElse(new GenericResponse(false, "Could not remove!"))); } @PostMapping(value = "/{guildId}/blacklist/add", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse addGuildBlacklist(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { - try { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - - if (!SQLSession.getSqlConnector().getSqlWorker().isChatProtectorSetup(guildId, request.value())) { - SQLSession.getSqlConnector().getSqlWorker().addChatProtectorWord(guildId, request.value()); - return new GenericResponse(true, "Blacklist added!"); - } else { - return new GenericResponse(false, "Word already blacklisted!"); - } - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono addGuildBlacklist(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { + return sessionService.retrieveGuild(sessionIdentifier, guildId) + .map(x -> x.map(y -> SQLSession.getSqlConnector().getSqlWorker().isChatProtectorSetup(guildId, request.value()) + .map(z -> { + if (!z) { + SQLSession.getSqlConnector().getSqlWorker().addChatProtectorWord(guildId, request.value()); + return new GenericResponse(true, "Blacklist added!"); + } else { + return new GenericResponse(false, "Word already blacklisted!"); + } + }).block()).orElse(new GenericResponse(false, "Could not add!"))); } //endregion @@ -131,56 +119,60 @@ public GenericResponse addGuildBlacklist(@RequestHeader(name = "X-Session-Authen //region Guild AutoRole @GetMapping(value = "/{guildId}/autorole", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse> retrieveGuildAutoRole(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, true); - List autoRoles = SQLSession.getSqlConnector().getSqlWorker().getAutoRoles(guildId).stream().map(c -> guildContainer.getRoleById(c.getRoleId())).filter(Objects::nonNull).toList(); - return new GenericObjectResponse<>(true, autoRoles, "AutoRole retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, Collections.emptyList(), e.getMessage()); - } + public Mono>> retrieveGuildAutoRole(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, true) + .map(x -> x.map(y -> SQLSession.getSqlConnector().getSqlWorker().getAutoRoles(guildId) + .map(z -> new GenericObjectResponse<>(true, z.stream() + .map(c -> y.getRoleById(c.getRoleId())).filter(Objects::nonNull).toList(), "AutoRole retrieved!")) + .block()).orElse(new GenericObjectResponse<>(false, Collections.emptyList(), "Couldnt retrieve!"))); } @PostMapping(value = "/{guildId}/autorole/remove", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse removeGuildAutoRole(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { - try { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); + public Mono removeGuildAutoRole(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { + return sessionService.retrieveGuild(sessionIdentifier, guildId) + .map(x -> x.map(y -> { + try { + long roleId = ConverterUtil.convertStringToLong(request.value()); - long roleId = ConverterUtil.convertStringToLong(request.value()); - - if (roleId == -1) { - return new GenericResponse(false, "Role not found!"); - } + if (roleId == -1) { + return new GenericResponse(false, "Role not found!"); + } - SQLSession.getSqlConnector().getSqlWorker().removeAutoRole(guildId, roleId); - return new GenericResponse(true, "AutoRole removed!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + SQLSession.getSqlConnector().getSqlWorker().removeAutoRole(guildId, roleId); + return new GenericResponse(true, "AutoRole removed!"); + } catch (Exception e) { + return new GenericResponse(false, e.getMessage()); + } + }).orElse(new GenericResponse(false, "Could not remove!"))); } @PostMapping(value = "/{guildId}/autorole/add", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse addGuildAutoRole(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { - try { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, true); - - long roleId = ConverterUtil.convertStringToLong(request.value()); - - if (roleId == -1) { - return new GenericResponse(false, "Role not found!"); - } - - if (guildContainer.getRoleById(roleId) == null) throw new IllegalAccessException("Role not found!"); - - if (!SQLSession.getSqlConnector().getSqlWorker().isAutoRoleSetup(guildId, roleId)) { - SQLSession.getSqlConnector().getSqlWorker().addAutoRole(guildId, roleId); - return new GenericResponse(true, "AutoRole added!"); - } else { - return new GenericResponse(false, "Role is already in AutoRole!"); - } - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono addGuildAutoRole(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, true) + .map(x -> x.map(y -> { + try { + long roleId = ConverterUtil.convertStringToLong(request.value()); + + if (roleId == -1) { + return new GenericResponse(false, "Role not found!"); + } + + if (y.getRoleById(roleId) == null) throw new IllegalAccessException("Role not found!"); + + return SQLSession.getSqlConnector().getSqlWorker().isAutoRoleSetup(guildId, roleId) + .map(z -> { + if (!z) { + SQLSession.getSqlConnector().getSqlWorker().addAutoRole(guildId, roleId); + return new GenericResponse(true, "AutoRole added!"); + } else { + return new GenericResponse(false, "Role is already in AutoRole!"); + } + }) + .block(); + } catch (Exception e) { + return new GenericResponse(false, e.getMessage()); + } + }).orElse(new GenericResponse(false, "Could not remove!"))); } //endregion @@ -188,39 +180,41 @@ public GenericResponse addGuildAutoRole(@RequestHeader(name = "X-Session-Authent //region Guild Leaderboard @GetMapping(value = "/{guildId}/leaderboard/voice", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse retrieveLeaderboardVoice(@PathVariable(name = "guildId") long guildId) { - try { - // Call this to check if the guild exists. If not, exception is thrown. - GuildContainer guildContainer = sessionService.retrieveGuild(guildId); - - LeaderboardContainer leaderboardContainer = new LeaderboardContainer(); + public Mono> retrieveLeaderboardVoice(@PathVariable(name = "guildId") long guildId) { + return sessionService.retrieveGuild(guildId) + .map(x -> x.map(y -> { + GuildContainer guildContainer = x.get(); - leaderboardContainer.setVoiceLeaderboard(SQLSession.getSqlConnector().getSqlWorker().getTopVoice(guildId, Data.getLeaderboardTop()).stream().map(c -> new UserLevelContainer(c, new UserContainer(BotWorker.getShardManager().retrieveUserById(c.getUserId()).complete()))).toList()); + return SQLSession.getSqlConnector().getSqlWorker().getTopVoice(guildId, Data.getLeaderboardTop()) + .map(z -> { + LeaderboardContainer leaderboardContainer = new LeaderboardContainer(); - leaderboardContainer.setGuildId(guildContainer.getId()); + leaderboardContainer.setChatLeaderboard(z.stream().map(c -> new UserLevelContainer(c, new UserContainer(BotWorker.getShardManager().retrieveUserById(c.getUserId()).complete()))).toList()); - return new GenericObjectResponse<>(true, leaderboardContainer, "Leaderboard retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + leaderboardContainer.setGuildId(guildContainer.getId()); + return new GenericObjectResponse<>(true, leaderboardContainer, "Leaderboard retrieved!"); + }).block(); + }) + .orElse(new GenericObjectResponse<>(false, null, "Could not retrieve!"))); } @GetMapping(value = "/{guildId}/leaderboard/chat", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse retrieveLeaderboardChat(@PathVariable(name = "guildId") long guildId) { - try { - // Call this to check if the guild exists. If not, exception is thrown. - GuildContainer guildContainer = sessionService.retrieveGuild(guildId); + public Mono> retrieveLeaderboardChat(@PathVariable(name = "guildId") long guildId) { + return sessionService.retrieveGuild(guildId) + .map(x -> x.map(y -> { + GuildContainer guildContainer = x.get(); - LeaderboardContainer leaderboardContainer = new LeaderboardContainer(); + return SQLSession.getSqlConnector().getSqlWorker().getTopChat(guildId, Data.getLeaderboardTop()) + .map(z -> { + LeaderboardContainer leaderboardContainer = new LeaderboardContainer(); - leaderboardContainer.setChatLeaderboard(SQLSession.getSqlConnector().getSqlWorker().getTopChat(guildId, Data.getLeaderboardTop()).stream().map(c -> new UserLevelContainer(c, new UserContainer(BotWorker.getShardManager().retrieveUserById(c.getUserId()).complete()))).toList()); + leaderboardContainer.setChatLeaderboard(z.stream().map(c -> new UserLevelContainer(c, new UserContainer(BotWorker.getShardManager().retrieveUserById(c.getUserId()).complete()))).toList()); - leaderboardContainer.setGuildId(guildContainer.getId()); - - return new GenericObjectResponse<>(true, leaderboardContainer, "Leaderboard retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + leaderboardContainer.setGuildId(guildContainer.getId()); + return new GenericObjectResponse<>(true, leaderboardContainer, "Leaderboard retrieved!"); + }).block(); + }) + .orElse(new GenericObjectResponse<>(false, null, "Could not retrieve!"))); } //endregion @@ -228,12 +222,9 @@ public GenericObjectResponse retrieveLeaderboardChat(@Path // region Guild Stats @GetMapping(value = "/{guildId}/stats", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse retrieveStats(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, guildService.getStats(sessionIdentifier, guildId), "Stats retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono> retrieveStats(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.getStats(sessionIdentifier, guildId) + .map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieve!")); } //endregion @@ -241,33 +232,27 @@ public GenericObjectResponse retrieveStats(@RequestHeader(n // region Guild Chat Autorole @GetMapping(value = "/{guildId}/chatrole", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse> retrieveChatRoles(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, guildService.getChatAutoRoles(sessionIdentifier, guildId), "Chat Autorole retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono>> retrieveChatRoles(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.getChatAutoRoles(sessionIdentifier, guildId) + .map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(Collections.emptyList()), x.isPresent() ? "Retrieved!" : "Could not retrieve!")); } @PostMapping(value = "/{guildId}/chatrole/remove", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse removeChatAutoRole(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest valueRequest) { + public Mono removeChatAutoRole(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest valueRequest) { try { long level = ConverterUtil.convertStringToLong(valueRequest.value()); - guildService.removeChatAutoRole(sessionIdentifier, guildId, level); - return new GenericResponse(true, "Chat Auto-role removed!"); + + return guildService.removeChatAutoRole(sessionIdentifier, guildId, level) + .map(x -> new GenericResponse(x, x ? "Removed!" : "Failed to remove!")); } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); + return Mono.just(new GenericResponse(false, e.getMessage())); } } @PostMapping(value = "/{guildId}/chatrole/add", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse addChatAutoRole(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody LevelAutoRoleRequest levelAutoRoleRequest) { - try { - guildService.addChatAutoRole(sessionIdentifier, guildId, levelAutoRoleRequest.role(), levelAutoRoleRequest.level()); - return new GenericResponse(true, "Chat Auto-role added!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono addChatAutoRole(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody LevelAutoRoleRequest levelAutoRoleRequest) { + return guildService.addChatAutoRole(sessionIdentifier, guildId, levelAutoRoleRequest.role(), levelAutoRoleRequest.level()) + .map(x -> new GenericResponse(x, x ? "Added!" : "Failed to add!")); } //endregion @@ -275,33 +260,27 @@ public GenericResponse addChatAutoRole(@RequestHeader(name = "X-Session-Authenti // region Guild Voice Autorole @GetMapping(value = "/{guildId}/voicerole", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse> retrieveVoiceRoles(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, guildService.getVoiceAutoRoles(sessionIdentifier, guildId), "Voice Autorole retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono>> retrieveVoiceRoles(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.getVoiceAutoRoles(sessionIdentifier, guildId) + .map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(Collections.emptyList()), x.isPresent() ? "Retrieved!" : "Could not retrieve!")); } @PostMapping(value = "/{guildId}/voicerole/remove", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse removeVoiceAutoRole(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest valueRequest) { + public Mono removeVoiceAutoRole(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest valueRequest) { try { long level = ConverterUtil.convertStringToLong(valueRequest.value()); - guildService.removeVoiceAutoRole(sessionIdentifier, guildId, level); - return new GenericResponse(true, "Voice Auto-role removed!"); + + return guildService.removeVoiceAutoRole(sessionIdentifier, guildId, level) + .map(x -> new GenericResponse(x, x ? "Removed!" : "Failed to remove!")); } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); + return Mono.just(new GenericResponse(false, e.getMessage())); } } @PostMapping(value = "/{guildId}/voicerole/add", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse addVoiceAutoRole(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody LevelAutoRoleRequest levelAutoRoleRequest) { - try { - guildService.addVoiceAutoRole(sessionIdentifier, guildId, levelAutoRoleRequest.role(), levelAutoRoleRequest.level()); - return new GenericResponse(true, "Voice Auto-role added!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono addVoiceAutoRole(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody LevelAutoRoleRequest levelAutoRoleRequest) { + return guildService.addVoiceAutoRole(sessionIdentifier, guildId, levelAutoRoleRequest.role(), levelAutoRoleRequest.level()) + .map(x -> new GenericResponse(x, x ? "Added!" : "Failed to add!")); } //endregion @@ -309,23 +288,24 @@ public GenericResponse addVoiceAutoRole(@RequestHeader(name = "X-Session-Authent //region Recording @GetMapping(value = "/recording", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse retrieveRecording(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @RequestParam(name = "recordId") String recordId) { - try { - return new GenericObjectResponse<>(true, guildService.getRecordingContainer(sessionIdentifier, recordId), "Recording retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono> retrieveRecording(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @RequestParam(name = "recordId") String recordId) { + return guildService.getRecordingContainer(sessionIdentifier, recordId) + .map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieve!")); } @GetMapping(value = "/recording/download", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity downloadRecording(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @RequestParam(name = "recordId") String recordId) { - try { - - ByteArrayResource resource = new ByteArrayResource(guildService.getRecordingBytes(sessionIdentifier, recordId)); - return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM).contentLength(resource.contentLength()).header(HttpHeaders.CONTENT_DISPOSITION, ContentDisposition.attachment().filename("recording.wav").build().toString()).body(resource); - } catch (Exception e) { - return ResponseEntity.badRequest().body(null); - } + public Mono> downloadRecording(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @RequestParam(name = "recordId") String recordId) { + return guildService.getRecordingBytes(sessionIdentifier, recordId) + .map(x -> x.map(y -> { + Resource resource = new ByteArrayResource(y); + try { + return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM).contentLength(resource.contentLength()).header(HttpHeaders.CONTENT_DISPOSITION, ContentDisposition.attachment().filename("recording.wav").build().toString()).body(resource); + } catch (IOException e) { + resource = null; + log.error("Failed to download recording", e); + return ResponseEntity.badRequest().body(resource); + } + }).orElse(ResponseEntity.badRequest().body(null))); } //endregion @@ -333,32 +313,21 @@ public ResponseEntity downloadRecording(@RequestHeader(name = "X-Sessi //region Guild Welcome Channel @GetMapping(value = "/{guildId}/welcome", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse retrieveWelcomeChannel(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, guildService.getWelcomeChannel(sessionIdentifier, guildId), "Welcome channel retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono> retrieveWelcomeChannel(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.getWelcomeChannel(sessionIdentifier, guildId) + .map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieve!")); } @PostMapping(value = "/{guildId}/welcome/remove", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse removeWelcomeChannel(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - SQLSession.getSqlConnector().getSqlWorker().deleteEntity(guildService.removeWelcomeChannel(sessionIdentifier, guildId)); - return new GenericResponse(true, "Welcome channel removed!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono removeWelcomeChannel(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.removeWelcomeChannel(sessionIdentifier, guildId) + .map(x -> new GenericResponse(x.isPresent(), x.isPresent() ? "Removed!" : "Failed to remove!")); } @PostMapping(value = "/{guildId}/welcome/add", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse addWelcomeChannel(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { - try { - guildService.updateWelcomeChannel(sessionIdentifier, guildId, request.value()); - return new GenericResponse(true, "Welcome channel added!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono addWelcomeChannel(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { + return guildService.updateWelcomeChannel(sessionIdentifier, guildId, request.value()) + .map(x -> new GenericResponse(x, x ? "Updated!" : "Failed to update!")); } //endregion @@ -366,32 +335,21 @@ public GenericResponse addWelcomeChannel(@RequestHeader(name = "X-Session-Authen //region Guild Log Channel @GetMapping(value = "/{guildId}/log", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse retrieveLogChannel(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, guildService.getLogChannel(sessionIdentifier, guildId), "Log channel retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono> retrieveLogChannel(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.getLogChannel(sessionIdentifier, guildId) + .map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieve!")); } @PostMapping(value = "/{guildId}/log/remove", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse removeLogChannel(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - SQLSession.getSqlConnector().getSqlWorker().deleteEntity(guildService.removeLogChannel(sessionIdentifier, guildId)); - return new GenericResponse(true, "Log channel removed!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono removeLogChannel(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.removeLogChannel(sessionIdentifier, guildId) + .map(x -> new GenericResponse(x.isPresent(), x.isPresent() ? "Removed!" : "Failed to remove!")); } @PostMapping(value = "/{guildId}/log/add", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse addLogChannel(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { - try { - guildService.updateLogChannel(sessionIdentifier, guildId, request.value()); - return new GenericResponse(true, "Log channel added!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono addLogChannel(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { + return guildService.updateLogChannel(sessionIdentifier, guildId, request.value()) + .map(x -> new GenericResponse(x, x ? "Updated!" : "Failed to update!")); } //endregion @@ -401,32 +359,23 @@ public GenericResponse addLogChannel(@RequestHeader(name = "X-Session-Authentica //region Reddit Notifier @GetMapping(value = "/{guildId}/reddit", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse> retrieveRedditNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, guildService.getRedditNotifier(sessionIdentifier, guildId), "Reddit Notifiers retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono>> retrieveRedditNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.getRedditNotifier(sessionIdentifier, guildId) + .map(x -> new GenericObjectResponse<>(true, x, "Notifier received!")); } @PostMapping(value = "/{guildId}/reddit/remove", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse removeRedditNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { - try { - guildService.removeRedditNotifier(sessionIdentifier, guildId, request.value()); - return new GenericResponse(true, "Reddit Notifier removed!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono removeRedditNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { + return guildService.removeRedditNotifier(sessionIdentifier, guildId, request.value()) + .map(x -> x ? new GenericResponse(true, "Notifier remove!") : + new GenericResponse(false, "Couldn't remove Notifier!")); } @PostMapping(value = "/{guildId}/reddit/add", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse addRedditNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericNotifierRequest notifierRequestObject) { - try { - guildService.addRedditNotifier(sessionIdentifier, guildId, notifierRequestObject); - return new GenericResponse(true, "Reddit Notifier added!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono addRedditNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericNotifierRequest notifierRequestObject) { + return guildService.addRedditNotifier(sessionIdentifier, guildId, notifierRequestObject) + .map(x -> x ? new GenericResponse(true, "Notifier added!") : + new GenericResponse(false, "Couldn't add Notifier!")); } //endregion @@ -434,32 +383,23 @@ public GenericResponse addRedditNotifier(@RequestHeader(name = "X-Session-Authen //region Twitch Notifier @GetMapping(value = "/{guildId}/twitch", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse> retrieveTwitchNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, guildService.getTwitchNotifier(sessionIdentifier, guildId), "Twitch Notifiers retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono>> retrieveTwitchNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.getTwitchNotifier(sessionIdentifier, guildId) + .map(x -> new GenericObjectResponse<>(true, x, "Notifier received!")); } @PostMapping(value = "/{guildId}/twitch/remove", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse removeTwitchNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { - try { - guildService.removeTwitchNotifier(sessionIdentifier, guildId, request.value()); - return new GenericResponse(true, "Twitch Notifier removed!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono removeTwitchNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { + return guildService.removeTwitchNotifier(sessionIdentifier, guildId, request.value()) + .map(x -> x ? new GenericResponse(true, "Notifier remove!") : + new GenericResponse(false, "Couldn't remove Notifier!")); } @PostMapping(value = "/{guildId}/twitch/add", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse addTwitchNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericNotifierRequest notifierRequestObject) { - try { - guildService.addTwitchNotifier(sessionIdentifier, guildId, notifierRequestObject); - return new GenericResponse(true, "Twitch Notifier added!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono addTwitchNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericNotifierRequest notifierRequestObject) { + return guildService.addTwitchNotifier(sessionIdentifier, guildId, notifierRequestObject) + .map(x -> x ? new GenericResponse(true, "Notifier added!") : + new GenericResponse(false, "Couldn't add Notifier!")); } @@ -468,32 +408,23 @@ public GenericResponse addTwitchNotifier(@RequestHeader(name = "X-Session-Authen //region Twitter Notifier @GetMapping(value = "/{guildId}/twitter", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse> retrieveTwitterNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, guildService.getTwitterNotifier(sessionIdentifier, guildId), "Twitter Notifiers retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono>> retrieveTwitterNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.getTwitterNotifier(sessionIdentifier, guildId) + .map(x -> new GenericObjectResponse<>(true, x, "Notifier received!")); } @PostMapping(value = "/{guildId}/twitter/remove", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse removeTwitterNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { - try { - guildService.removeTwitterNotifier(sessionIdentifier, guildId, request.value()); - return new GenericResponse(true, "Twitter Notifier removed!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono removeTwitterNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { + return guildService.removeTwitterNotifier(sessionIdentifier, guildId, request.value()) + .map(x -> x ? new GenericResponse(true, "Notifier remove!") : + new GenericResponse(false, "Couldn't remove Notifier!")); } @PostMapping(value = "/{guildId}/twitter/add", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse addTwitterNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericNotifierRequest notifierRequestObject) { - try { - guildService.addTwitterNotifier(sessionIdentifier, guildId, notifierRequestObject); - return new GenericResponse(true, "Twitter Notifier added!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono addTwitterNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericNotifierRequest notifierRequestObject) { + return guildService.addTwitterNotifier(sessionIdentifier, guildId, notifierRequestObject) + .map(x -> x ? new GenericResponse(true, "Notifier added!") : + new GenericResponse(false, "Couldn't add Notifier!")); } //endregion @@ -501,32 +432,23 @@ public GenericResponse addTwitterNotifier(@RequestHeader(name = "X-Session-Authe //region YouTube Notifier @GetMapping(value = "/{guildId}/youtube", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse> retrieveYoutubeNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, guildService.getYouTubeNotifier(sessionIdentifier, guildId), "Youtube Notifiers retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono>> retrieveYoutubeNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.getYouTubeNotifier(sessionIdentifier, guildId) + .map(x -> new GenericObjectResponse<>(true, x, "Notifier received!")); } @PostMapping(value = "/{guildId}/youtube/remove", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse removeYoutubeNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { - try { - guildService.removeYouTubeNotifier(sessionIdentifier, guildId, request.value()); - return new GenericResponse(true, "Youtube Notifier removed!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono removeYoutubeNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { + return guildService.removeYouTubeNotifier(sessionIdentifier, guildId, request.value()) + .map(x -> x ? new GenericResponse(true, "YouTube Notifier remove!") : + new GenericResponse(false, "Couldn't remove YouTube Notifier!")); } @PostMapping(value = "/{guildId}/youtube/add", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse addYoutubeNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericNotifierRequest notifierRequestObject) { - try { - guildService.addYouTubeNotifier(sessionIdentifier, guildId, notifierRequestObject); - return new GenericResponse(true, "Youtube Notifier added!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono addYoutubeNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericNotifierRequest notifierRequestObject) { + return guildService.addYouTubeNotifier(sessionIdentifier, guildId, notifierRequestObject) + .map(x -> x ? new GenericResponse(true, "Notifier added!") : + new GenericResponse(false, "Couldn't add Notifier!")); } //endregion @@ -534,32 +456,23 @@ public GenericResponse addYoutubeNotifier(@RequestHeader(name = "X-Session-Authe //region Instagram Notifier @GetMapping(value = "/{guildId}/instagram", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse> retrieveInstagramNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, guildService.getInstagramNotifier(sessionIdentifier, guildId), "Instagram Notifiers retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono>> retrieveInstagramNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.getInstagramNotifier(sessionIdentifier, guildId) + .map(x -> new GenericObjectResponse<>(true, x, "Notifier received!")); } @PostMapping(value = "/{guildId}/instagram/remove", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse removeInstagramNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { - try { - guildService.removeInstagramNotifier(sessionIdentifier, guildId, request.value()); - return new GenericResponse(true, "Instagram Notifier removed!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono removeInstagramNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { + return guildService.removeInstagramNotifier(sessionIdentifier, guildId, request.value()) + .map(x -> x ? new GenericResponse(true, "Instagram Notifier remove!") : + new GenericResponse(false, "Couldn't remove Instagram Notifier!")); } @PostMapping(value = "/{guildId}/instagram/add", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse addInstagramNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericNotifierRequest notifierRequestObject) { - try { - guildService.addInstagramNotifier(sessionIdentifier, guildId, notifierRequestObject); - return new GenericResponse(true, "Instagram Notifier added!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono addInstagramNotifier(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericNotifierRequest notifierRequestObject) { + return guildService.addInstagramNotifier(sessionIdentifier, guildId, notifierRequestObject) + .map(x -> x ? new GenericResponse(true, "Notifier added!") : + new GenericResponse(false, "Couldn't add Notifier!")); } //endregion @@ -569,40 +482,32 @@ public GenericResponse addInstagramNotifier(@RequestHeader(name = "X-Session-Aut //region Temporal Voice Channels @GetMapping(value = "/{guildId}/temporalvoice", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse retrieveTemporalVoice(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, guildService.getTemporalVoice(sessionIdentifier, guildId), "TemporalVoice channel retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono> retrieveTemporalVoice(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.getTemporalVoice(sessionIdentifier, guildId) + .map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieve!")); } @PostMapping(value = "/{guildId}/temporalvoice/remove", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse removeTemporalVoiceChannel(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - guildService.removeTemporalVoice(sessionIdentifier, guildId); - return new GenericResponse(true, "TemporalVoice channel removed!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono removeTemporalVoiceChannel(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.removeTemporalVoice(sessionIdentifier, guildId) + .map(x -> new GenericResponse(x, x ? "Removed!" : "Failed to remove!")); } @PostMapping(value = "/{guildId}/temporalvoice/add", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse addTemporalVoiceChannel(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { + public Mono addTemporalVoiceChannel(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { try { - long channelId = ConverterUtil.convertStringToLong(request.value()); if (channelId == -1) { - return new GenericResponse(false, "Channel not found!"); + return Mono.just(new GenericResponse(false, "Channel not found!")); } - guildService.updateTemporalVoice(sessionIdentifier, guildId, channelId); - return new GenericResponse(true, "TemporalVoice channel added!"); + return guildService.updateTemporalVoice(sessionIdentifier, guildId, channelId) + .map(x -> new GenericResponse(x, x ? "Added!" : "Failed to add!")); } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); + return Mono.just(new GenericResponse(false, e.getMessage())); } } @@ -611,21 +516,15 @@ public GenericResponse addTemporalVoiceChannel(@RequestHeader(name = "X-Session- //region Opt-Out @GetMapping(value = "/{guildId}/opt-out/check", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse checkOptOut(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericResponse(true, guildService.checkOptOut(sessionIdentifier, guildId)); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono checkOptOut(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.checkOptOut(sessionIdentifier, guildId) + .map(x -> new GenericResponse(x.isPresent(), x.orElse("Error"))); } @GetMapping(value = "/{guildId}/opt-out", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse optOut(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericResponse(true, guildService.optOut(sessionIdentifier, guildId)); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono optOut(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.optOut(sessionIdentifier, guildId) + .map(x -> new GenericResponse(x.isPresent(), x.orElse("Error"))); } //endregion @@ -633,32 +532,21 @@ public GenericResponse optOut(@RequestHeader(name = "X-Session-Authenticator") S //region Tickets @GetMapping(value = "/{guildId}/tickets", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse retrieveTicket(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, guildService.getTicket(sessionIdentifier, guildId), "Tickets retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono> retrieveTicket(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.getTicket(sessionIdentifier, guildId) + .map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieve!")); } @PostMapping(value = "/{guildId}/tickets/remove", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse removeTicket(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - guildService.removeTicket(sessionIdentifier, guildId); - return new GenericResponse(true, "Tickets removed!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono removeTicket(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.removeTicket(sessionIdentifier, guildId) + .map(x -> new GenericResponse(x, x ? "Removed!" : "Failed to remove")); } @PostMapping(value = "/{guildId}/tickets/add", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse addTicket(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody TicketsRequest request) { - try { - guildService.updateTicket(sessionIdentifier, guildId, request.channelId(), request.logChannelId()); - return new GenericResponse(true, "Tickets added!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono addTicket(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody TicketsRequest request) { + return guildService.updateTicket(sessionIdentifier, guildId, request.channelId(), request.logChannelId()) + .map(x -> new GenericResponse(x, x ? "Updated!" : "Failed to update")); } //endregion @@ -666,37 +554,30 @@ public GenericResponse addTicket(@RequestHeader(name = "X-Session-Authenticator" //region Suggestion @GetMapping(value = "/{guildId}/suggestions", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse retrieveSuggestion(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, guildService.getSuggestion(sessionIdentifier, guildId), "Suggestions retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono> retrieveSuggestion(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.getSuggestion(sessionIdentifier, guildId) + .map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieve!")); } @PostMapping(value = "/{guildId}/suggestions/remove", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse removeSuggestion(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - guildService.removeSuggestion(sessionIdentifier, guildId); - return new GenericResponse(true, "Suggestions removed!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono removeSuggestion(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.removeSuggestion(sessionIdentifier, guildId) + .map(x -> new GenericResponse(x, x ? "Removed!" : "Failed to remove")); } @PostMapping(value = "/{guildId}/suggestions/add", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse addSuggestion(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { + public Mono addSuggestion(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { try { long channelId = ConverterUtil.convertStringToLong(request.value()); if (channelId == -1) { - return new GenericResponse(false, "Channel not found!"); + return Mono.just(new GenericResponse(false, "Channel not found!")); } - guildService.updateSuggestion(sessionIdentifier, guildId, channelId); - return new GenericResponse(true, "Suggestions added!"); + return guildService.updateSuggestion(sessionIdentifier, guildId, channelId) + .map(x -> new GenericResponse(x, x ? "Added!" : "Failed to add!")); } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); + return Mono.just(new GenericResponse(false, e.getMessage())); } } @@ -705,80 +586,53 @@ public GenericResponse addSuggestion(@RequestHeader(name = "X-Session-Authentica //region Warnings @GetMapping(value = "/{guildId}/warnings", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse> retrieveWarnings(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, guildService.getWarnings(sessionIdentifier, guildId), "Warnings retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono>> retrieveWarnings(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.getWarnings(sessionIdentifier, guildId) + .map(x -> new GenericObjectResponse<>(true, x, "Retrieved!")); } @PostMapping(value = "/{guildId}/warnings/add", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse addWarnings(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody WarningsRequest request) { - try { - return new GenericObjectResponse<>(true, guildService.addWarnings(sessionIdentifier, guildId, request.userId(), request.warnings()), "Warnings added!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono> addWarnings(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody WarningsRequest request) { + return guildService.addWarnings(sessionIdentifier, guildId, request.userId(), request.warnings()) + .map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(null), x.isPresent() ? "Added" : "Failed to add")); } @PostMapping(value = "/{guildId}/warnings/remove", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse removeWarnings(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody WarningsRequest request) { - try { - return new GenericObjectResponse<>(true, guildService.removeWarnings(sessionIdentifier, guildId, request.userId(), request.warnings()), "Warnings removed!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono> removeWarnings(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody WarningsRequest request) { + return guildService.removeWarnings(sessionIdentifier, guildId, request.userId(), request.warnings()) + .map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(null), x.isPresent() ? "Removed" : "Failed to remove")); } @PostMapping(value = "/{guildId}/warnings/clear", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse clearWarnings(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - guildService.clearWarnings(sessionIdentifier, guildId); - return new GenericResponse(true, "Warnings cleared!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono clearWarnings(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.clearWarnings(sessionIdentifier, guildId) + .map(x -> new GenericResponse(x, x ? "Cleared!" : "Failed to clear")); } //region Punishments @GetMapping(value = "/{guildId}/warnings/punishments", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse> retrievePunishments(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, guildService.getPunishments(sessionIdentifier, guildId), "Punishments retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono>> retrievePunishments(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.getPunishments(sessionIdentifier, guildId) + .map(x -> new GenericObjectResponse<>(true, x, "Retrieved!")); } @PostMapping(value = "/{guildId}/warnings/punishments/clear", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse clearPunishments(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - guildService.clearPunishments(sessionIdentifier, guildId); - return new GenericResponse(true, "Punishments cleared!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono clearPunishments(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.clearPunishments(sessionIdentifier, guildId) + .map(x -> new GenericResponse(x, x ? "Cleared!" : "Failed to clear")); } @PostMapping(value = "/{guildId}/warnings/punishments/add", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse addPunishments(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody PunishmentsRequest request) { - try { - return new GenericObjectResponse<>(true, guildService.addPunishments(sessionIdentifier, guildId, request.neededWarnings(), request.action(), request.timeoutTime(), request.roleId()), "Punishments added!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono> addPunishments(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody PunishmentsRequest request) { + return guildService.addPunishments(sessionIdentifier, guildId, request.neededWarnings(), request.action(), request.timeoutTime(), request.roleId()) + .map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(null), x.isPresent() ? "Added!" : "Failed to add!")); } @PostMapping(value = "/{guildId}/warnings/punishments/remove", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse removePunishments(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { - try { - guildService.removePunishments(sessionIdentifier, guildId, request.value()); - return new GenericResponse(true, "Punishments removed!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono removePunishments(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { + return guildService.removePunishments(sessionIdentifier, guildId, request.value()) + .map(x -> new GenericResponse(x, x ? "Removed!" : "Failed to remove")); } //endregion @@ -788,33 +642,23 @@ public GenericResponse removePunishments(@RequestHeader(name = "X-Session-Authen //region Custom commands @GetMapping(value = "/{guildId}/commands", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse> retrieveCustomCommands(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, guildService.getCustomCommand(sessionIdentifier, guildId), "CustomCommand retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono>> retrieveCustomCommands(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.getCustomCommand(sessionIdentifier, guildId) + .map(x -> new GenericObjectResponse<>(true, x, "Retrieved!")); } @PostMapping(value = "/{guildId}/commands/add", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse addCustomCommand(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody CustomCommandRequest request) { - try { - return new GenericObjectResponse<>(true, guildService.addCustomCommand(sessionIdentifier, guildId, request.name(), request.channelId(), request.message(), request.embedJson()), "CustomCommand added!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono> addCustomCommand(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody CustomCommandRequest request) { + return guildService.addCustomCommand(sessionIdentifier, guildId, request.name(), request.channelId(), request.message(), request.embedJson()) + .map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(null), x.isPresent() ? "Retrieved!" : "Could not retrieve!")); } @PostMapping(value = "/{guildId}/commands/remove", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse removeCustomCommand(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { - try { - guildService.removeCustomCommand(sessionIdentifier, guildId, request.value()); - return new GenericResponse(true, "CustomCommand removed!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono removeCustomCommand(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody GenericValueRequest request) { + return guildService.removeCustomCommand(sessionIdentifier, guildId, request.value()) + .map(x -> x ? new GenericResponse(true, "Removed!") : new GenericResponse(false, "Failed to remove!")); } //endregion @@ -822,32 +666,21 @@ public GenericResponse removeCustomCommand(@RequestHeader(name = "X-Session-Auth //region Reaction Roles @GetMapping(value = "/{guildId}/reactionroles", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse> retrieveReactionRoles(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { - try { - return new GenericObjectResponse<>(true, guildService.retrieveReactionRoles(sessionIdentifier, guildId), "ReactionRoles retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono>> retrieveReactionRoles(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) { + return guildService.retrieveReactionRoles(sessionIdentifier, guildId) + .map(x -> new GenericObjectResponse<>(true, x, "Retrieved!")); } @PostMapping(value = "/{guildId}/reactionroles/add", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse addReactionRole(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody ReactionRoleRequest request) { - try { - guildService.addReactionRole(sessionIdentifier, guildId, request.emojiId(), request.formattedEmoji(), request.channelId(), request.messageId(), request.roleId()); - return new GenericResponse(true, "ReactionRole added!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono addReactionRole(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody ReactionRoleRequest request) { + return guildService.addReactionRole(sessionIdentifier, guildId, request.emojiId(), request.formattedEmoji(), request.channelId(), request.messageId(), request.roleId()) + .map(x -> x ? new GenericResponse(true, "Added!") : new GenericResponse(false, "Failed to add!")); } @PostMapping(value = "/{guildId}/reactionroles/remove", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse removeReactionRole(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody ReactionRoleDeleteRequest request) { - try { - guildService.removeReactionRole(sessionIdentifier, guildId, request.emojiId(), request.messageId()); - return new GenericResponse(true, "ReactionRole removed!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + public Mono removeReactionRole(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @RequestBody ReactionRoleDeleteRequest request) { + return guildService.removeReactionRole(sessionIdentifier, guildId, request.emojiId(), request.messageId()) + .map(x -> x ? new GenericResponse(true, "Removed!") : new GenericResponse(false, "Failed to remove!")); } //endregion diff --git a/Backend/src/main/java/de/presti/ree6/backend/controller/SessionController.java b/Backend/src/main/java/de/presti/ree6/backend/controller/SessionController.java index 96544aa6..f59cd07f 100644 --- a/Backend/src/main/java/de/presti/ree6/backend/controller/SessionController.java +++ b/Backend/src/main/java/de/presti/ree6/backend/controller/SessionController.java @@ -15,6 +15,7 @@ import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.view.RedirectView; +import reactor.core.publisher.Mono; import java.util.List; @@ -47,12 +48,10 @@ public SessionController(SessionService sessionService) { * @return Generic Object Response with the Session. */ @GetMapping(value = "/check", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse checkSession(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier) { - try { - return new GenericObjectResponse<>(true, sessionService.retrieveSession(sessionIdentifier), "Session valid!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono> checkSession(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier) { + return sessionService.retrieveSession(sessionIdentifier) + .map(x -> x.map(sessionContainer -> new GenericObjectResponse<>(true, sessionContainer, "Session valid!")) + .orElseGet(() -> new GenericObjectResponse<>(false, null, "Session not found!"))); } //endregion @@ -66,12 +65,10 @@ public GenericObjectResponse checkSession(@RequestHeader(name * @return Generic Object Response with the Session. */ @GetMapping(value = "/discord", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse completeSession(@RequestParam(name = "code") String code, @RequestParam(name = "state") String state) { - try { - return new GenericObjectResponse<>(true, sessionService.createSession(code, state), "Session created!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + public Mono> completeSession(@RequestParam(name = "code") String code, @RequestParam(name = "state") String state) { + return sessionService.createSession(code, state) + .map(x -> x.map(sessionContainer -> new GenericObjectResponse<>(true, sessionContainer, "Session created")) + .orElseGet(() -> new GenericObjectResponse<>(false, null, "Session creation failed!"))); } /** @@ -117,26 +114,27 @@ public RedirectView createTwitch() { * @return Generic Object Response with the Session. */ @GetMapping(value = "/twitch", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse authenticateTwitch(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @RequestParam(name = "code") String code) { - try { - SessionContainer sessionContainer = sessionService.retrieveSession(sessionIdentifier); + public Mono authenticateTwitch(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @RequestParam(name = "code") String code) { + return sessionService.retrieveSession(sessionIdentifier).map(sessionContainer -> { + if (sessionContainer.isEmpty()) { + return new GenericResponse(false, "Session not found!"); + } + OAuth2Credential oAuth2Credential; try { // Try building the credentials. oAuth2Credential = Server.getInstance().getTwitchIdentityProvider().getCredentialByCode(code); } catch (Exception e) { - throw new IllegalAccessException("Invalid code!"); + return new GenericResponse(false, "Invalid Twitch Code!"); } // Add the credential to the credential manager. - Server.getInstance().getCredentialManager().addCredential("twitch", CustomOAuth2Util.convert(sessionContainer.getOAuthUser().getIdLong(), oAuth2Credential)); + Server.getInstance().getCredentialManager().addCredential("twitch", CustomOAuth2Util.convert(sessionContainer.get().getOAuthUser().getIdLong(), oAuth2Credential)); Server.getInstance().getCredentialManager().save(); return new GenericResponse(true, "Twitch authenticated!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + }); } //endregion diff --git a/Backend/src/main/java/de/presti/ree6/backend/controller/SettingsController.java b/Backend/src/main/java/de/presti/ree6/backend/controller/SettingsController.java index 57c8f16f..ff17d87c 100644 --- a/Backend/src/main/java/de/presti/ree6/backend/controller/SettingsController.java +++ b/Backend/src/main/java/de/presti/ree6/backend/controller/SettingsController.java @@ -11,6 +11,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; +import reactor.core.publisher.Mono; +import reactor.core.scheduler.Schedulers; import java.util.Collections; import java.util.List; @@ -45,14 +47,25 @@ public SettingsController(SessionService sessionService) { * @return Generic Object Response with the Settings. */ @GetMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse> retrieveSettings(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, - @PathVariable(name = "guildId") long guildId) { - try { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - return new GenericObjectResponse<>(true, SQLSession.getSqlConnector().getSqlWorker().getAllSettings(guildId), "Setting retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, Collections.emptyList(), e.getMessage()); - } + public Mono>> retrieveSettings(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, + @PathVariable(name = "guildId") long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId).publishOn(Schedulers.boundedElastic()).mapNotNull(guildOptional -> { + if (guildOptional.isEmpty()) { + return new GenericObjectResponse<>(false, Collections.emptyList(), "Guild doesn't exist."); + } + + return SQLSession.getSqlConnector().getSqlWorker().getAllSettings(guildId) + .map(settings -> { + if (settings.isEmpty()) { + return new GenericObjectResponse<>(false, + SettingsManager.getSettings().stream() + .map(x -> new Setting(guildId, x.getName(), x.getDisplayName(), x.getValue())).toList(), + null); + } + + return new GenericObjectResponse<>(true, settings, null); + }).block(); + }); } /** @@ -63,15 +76,18 @@ public GenericObjectResponse> retrieveSettings(@RequestHeader(name * @return Generic Object Response with the Setting. */ @GetMapping(value = "/{settingName}", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse retrieveSetting(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, + public Mono> retrieveSetting(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @PathVariable(name = "settingName") String settingName) { - try { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - return new GenericObjectResponse<>(true, SQLSession.getSqlConnector().getSqlWorker().getSetting(guildId, settingName), "Setting retrieved!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + return sessionService.retrieveGuild(sessionIdentifier, guildId).publishOn(Schedulers.boundedElastic()).mapNotNull(guildOptional -> { + if (guildOptional.isEmpty()) { + return new GenericObjectResponse<>(false, null, "Guild doesn't exist."); + } + + return SQLSession.getSqlConnector().getSqlWorker().getSetting(guildId, settingName) + .map(setting -> setting.map(x -> new GenericObjectResponse<>(true, x, null)) + .orElseGet(() -> new GenericObjectResponse<>(false, null, "Setting not found!"))).block(); + }); } //endregion @@ -87,18 +103,27 @@ public GenericObjectResponse retrieveSetting(@RequestHeader(name = "X-S * @return Generic Object Response with the updated Setting. */ @PostMapping(value = "/{settingName}/update", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericObjectResponse updateSetting(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, + public Mono> updateSetting(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @PathVariable(name = "settingName") String settingName, @RequestBody GenericValueRequest request) { - try { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - Setting setting = SQLSession.getSqlConnector().getSqlWorker().getSetting(guildId, settingName); - setting.setValue(request.value()); - return new GenericObjectResponse<>(true, SQLSession.getSqlConnector().getSqlWorker().updateEntity(setting), "Setting updated!"); - } catch (Exception e) { - return new GenericObjectResponse<>(false, null, e.getMessage()); - } + return sessionService.retrieveGuild(sessionIdentifier, guildId).publishOn(Schedulers.boundedElastic()).mapNotNull(guildOptional -> { + if (guildOptional.isEmpty()) { + return new GenericObjectResponse<>(false, null, "Guild doesn't exist."); + } + + return SQLSession.getSqlConnector().getSqlWorker().getSetting(guildId, settingName) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(settingOptional -> { + if (settingOptional.isEmpty()) { + return new GenericObjectResponse(false, null, "Setting doesn't exist."); + } + + Setting setting = settingOptional.get(); + setting.setValue(request.value()); + return SQLSession.getSqlConnector().getSqlWorker().updateEntity(setting).map(x -> new GenericObjectResponse<>(true, x, "Setting updated!")).block(); + }).block(); + }); } //endregion @@ -113,19 +138,19 @@ public GenericObjectResponse updateSetting(@RequestHeader(name = "X-Ses * @return Generic Response with the result. */ @GetMapping(value = "/{settingName}/delete", produces = MediaType.APPLICATION_JSON_VALUE) - public GenericResponse deleteSetting(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, + public Mono deleteSetting(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId, @PathVariable(name = "settingName") String settingName) { - try { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); + return sessionService.retrieveGuild(sessionIdentifier, guildId).publishOn(Schedulers.boundedElastic()).mapNotNull(guildOptional -> { + if (guildOptional.isEmpty()) { + return new GenericResponse(false, "Guild doesn't exist."); + } + Setting setting = SettingsManager.getDefault(settingName); setting.setGuildId(guildId); - SQLSession.getSqlConnector().getSqlWorker().setSetting(setting); - return new GenericResponse(true,"Setting deleted!"); - } catch (Exception e) { - return new GenericResponse(false, e.getMessage()); - } + return SQLSession.getSqlConnector().getSqlWorker().updateEntity(setting).map(x -> new GenericResponse(true, "Setting deleted!")).block(); + }); } //endregion diff --git a/Backend/src/main/java/de/presti/ree6/backend/service/GuildService.java b/Backend/src/main/java/de/presti/ree6/backend/service/GuildService.java index 919a060f..634ee3fd 100644 --- a/Backend/src/main/java/de/presti/ree6/backend/service/GuildService.java +++ b/Backend/src/main/java/de/presti/ree6/backend/service/GuildService.java @@ -15,18 +15,21 @@ import de.presti.ree6.sql.entities.custom.CustomCommand; import de.presti.ree6.sql.entities.webhook.*; import de.presti.ree6.sql.keys.GuildUserId; +import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildMessageChannel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; +import reactor.core.scheduler.Schedulers; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; +@Slf4j @Service public class GuildService { @@ -39,131 +42,209 @@ public GuildService(SessionService sessionService) { //region Stats - public GuildStatsContainer getStats(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - return new GuildStatsContainer(SQLSession.getSqlConnector().getSqlWorker().getInvites(guildId).size(), - SQLSession.getSqlConnector().getSqlWorker().getStats(guildId).stream().map(CommandStatsContainer::new).toList()); + public Mono> getStats(String sessionIdentifier, long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId).mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return Optional.empty(); + } + + return Mono.zip(SQLSession.getSqlConnector().getSqlWorker().getInvites(guildId), SQLSession.getSqlConnector().getSqlWorker().getStats(guildId)) + .map(tuple2 -> Optional.of(new GuildStatsContainer(tuple2.getT1().size(), tuple2.getT2().stream().map(CommandStatsContainer::new).toList()))).block(); + }); } - public List getCommandStats(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - return SQLSession.getSqlConnector().getSqlWorker().getStats(guildId).stream().map(CommandStatsContainer::new).toList(); + public Mono>> getCommandStats(String sessionIdentifier, long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId).publishOn(Schedulers.boundedElastic()).mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return Optional.empty(); + } + + return SQLSession.getSqlConnector().getSqlWorker().getStats(guildId) + .map(list -> Optional.of(list.stream().map(CommandStatsContainer::new).toList())).block(); + }); } - public int getInviteCount(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - return SQLSession.getSqlConnector().getSqlWorker().getInvites(guildId).size(); + public Mono getInviteCount(String sessionIdentifier, long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId).publishOn(Schedulers.boundedElastic()).mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return 0; + } + + return SQLSession.getSqlConnector().getSqlWorker().getInvites(guildId) + .map(List::size).block(); + }); } //endregion //region Log channel - public ChannelContainer getLogChannel(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, true); - WebhookLog webhook = SQLSession.getSqlConnector().getSqlWorker().getLogWebhook(guildId); - if (webhook == null) { - return new ChannelContainer(); - } - - if (webhook.getChannelId() != 0) { - return new ChannelContainer(guildContainer.getGuildChannelById(webhook.getChannelId())); - } else { - net.dv8tion.jda.api.entities.Webhook webhook1 = guildContainer.getGuild().retrieveWebhooks().complete().stream() - .filter(entry -> entry.getIdLong() == webhook.getWebhookId() && entry.getToken().equalsIgnoreCase(webhook.getToken())).findFirst().orElse(null); - - if (webhook1 != null) { - webhook.setChannelId(webhook1.getChannel().getIdLong()); - SQLSession.getSqlConnector().getSqlWorker().updateEntity(webhook); - return new ChannelContainer(webhook1); + public Mono> getLogChannel(String sessionIdentifier, long guildId) { + ChannelContainer errorReturnValue = null; + return sessionService.retrieveGuild(sessionIdentifier, guildId, true).publishOn(Schedulers.boundedElastic()).mapNotNull(guildOptional -> { + if (guildOptional.isEmpty()) { + return Optional.empty(); } - } - return new ChannelContainer(); + GuildContainer guildContainer = guildOptional.get(); + + return SQLSession.getSqlConnector().getSqlWorker().getLogWebhook(guildId).publishOn(Schedulers.boundedElastic()).mapNotNull(webhookLogOptional -> { + if (webhookLogOptional.isEmpty()) { + return Optional.ofNullable(ChannelContainer.DEFAULT); + } + + WebhookLog webhook = webhookLogOptional.get(); + + if (webhook.getChannelId() != 0) { + return Optional.of(new ChannelContainer(guildContainer.getGuildChannelById(webhook.getChannelId()))); + } else { + net.dv8tion.jda.api.entities.Webhook webhook1 = guildContainer.getGuild().retrieveWebhooks().complete().stream() + .filter(entry -> entry.getIdLong() == webhook.getWebhookId() && entry.getToken().equalsIgnoreCase(webhook.getToken())).findFirst().orElse(null); + + if (webhook1 != null) { + webhook.setChannelId(webhook1.getChannel().getIdLong()); + SQLSession.getSqlConnector().getSqlWorker().updateEntity(webhook).block(); + return Optional.of(new ChannelContainer(webhook1)); + } + } + + return Optional.ofNullable(errorReturnValue); + }).block(); + }); } - public void updateLogChannel(String sessionIdentifier, long guildId, String channelId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - Guild guild = guildContainer.getGuild(); - StandardGuildMessageChannel channel = guild.getChannelById(StandardGuildMessageChannel.class, channelId); + public Mono updateLogChannel(String sessionIdentifier, long guildId, String channelId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, true).publishOn(Schedulers.boundedElastic()).mapNotNull(guildOptional -> { + if (guildOptional.isEmpty()) { + return false; + } + + GuildContainer guildContainer = guildOptional.get(); + + Guild guild = guildContainer.getGuild(); + StandardGuildMessageChannel channel = guild.getChannelById(StandardGuildMessageChannel.class, channelId); - net.dv8tion.jda.api.entities.Webhook newWebhook = channel.createWebhook("Ree6-Log").complete(); + net.dv8tion.jda.api.entities.Webhook newWebhook = channel.createWebhook("Ree6-Log").complete(); - WebhookWelcome welcome = deleteWelcomeChannel(guild); + deleteLogChannel(guild).block(); - SQLSession.getSqlConnector().getSqlWorker().setLogWebhook(guildId, channel.getIdLong(), newWebhook.getIdLong(), newWebhook.getToken()); + SQLSession.getSqlConnector().getSqlWorker().setLogWebhook(guildId, channel.getIdLong(), newWebhook.getIdLong(), newWebhook.getToken()); + + return true; + }); } - public WebhookLog removeLogChannel(String sessionIdentifier, long guildId) throws IllegalAccessException { - return deleteLogChannel(sessionService.retrieveGuild(sessionIdentifier, guildId).getGuild()); + public Mono> removeLogChannel(String sessionIdentifier, long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId).publishOn(Schedulers.boundedElastic()).mapNotNull(x -> { + if (x.isEmpty()) { + return Optional.empty(); + } + + return deleteLogChannel(x.get().getGuild()).block(); + }); } - private WebhookLog deleteLogChannel(Guild guild) { - WebhookLog webhook = SQLSession.getSqlConnector().getSqlWorker().getLogWebhook(guild.getIdLong()); + private Mono> deleteLogChannel(Guild guild) { + return SQLSession.getSqlConnector().getSqlWorker().getLogWebhook(guild.getIdLong()) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(webhookLogOptional -> { + if (webhookLogOptional.isEmpty()) { + return Optional.empty(); + } - if (webhook != null) { + WebhookLog webhook = webhookLogOptional.get(); guild.retrieveWebhooks().queue(c -> c.stream().filter(entry -> entry.getToken() != null) .filter(entry -> entry.getIdLong() == webhook.getWebhookId() && entry.getToken().equalsIgnoreCase(webhook.getToken())) .forEach(entry -> entry.delete().queue())); - } - return webhook; + return SQLSession.getSqlConnector().getSqlWorker().deleteEntity(webhook).thenReturn(webhookLogOptional).block(); + }); } //endregion //region Welcome channel - public ChannelContainer getWelcomeChannel(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, true); - WebhookWelcome webhook = SQLSession.getSqlConnector().getSqlWorker().getWelcomeWebhook(guildId); - if (webhook == null) { - return new ChannelContainer(); - } - - if (webhook.getChannelId() != 0) { - return new ChannelContainer(guildContainer.getGuildChannelById(webhook.getChannelId())); - } else { - net.dv8tion.jda.api.entities.Webhook webhook1 = guildContainer.getGuild().retrieveWebhooks().complete().stream() - .filter(entry -> entry.getIdLong() == webhook.getWebhookId() && entry.getToken().equalsIgnoreCase(webhook.getToken())).findFirst().orElse(null); - - if (webhook1 != null) { - webhook.setChannelId(webhook1.getChannel().getIdLong()); - SQLSession.getSqlConnector().getSqlWorker().updateEntity(webhook); - return new ChannelContainer(webhook1); + public Mono> getWelcomeChannel(String sessionIdentifier, long guildId) { + ChannelContainer errorReturnValue = null; + return sessionService.retrieveGuild(sessionIdentifier, guildId, true).publishOn(Schedulers.boundedElastic()).mapNotNull(guildOptional -> { + if (guildOptional.isEmpty()) { + return Optional.empty(); } - } - return new ChannelContainer(); + GuildContainer guildContainer = guildOptional.get(); + + return SQLSession.getSqlConnector().getSqlWorker().getWelcomeWebhook(guildId).publishOn(Schedulers.boundedElastic()).mapNotNull(webhookLogOptional -> { + if (webhookLogOptional.isEmpty()) { + return Optional.ofNullable(ChannelContainer.DEFAULT); + } + + WebhookWelcome webhook = webhookLogOptional.get(); + + if (webhook.getChannelId() != 0) { + return Optional.of(new ChannelContainer(guildContainer.getGuildChannelById(webhook.getChannelId()))); + } else { + net.dv8tion.jda.api.entities.Webhook webhook1 = guildContainer.getGuild().retrieveWebhooks().complete().stream() + .filter(entry -> entry.getIdLong() == webhook.getWebhookId() && entry.getToken().equalsIgnoreCase(webhook.getToken())).findFirst().orElse(null); + + if (webhook1 != null) { + webhook.setChannelId(webhook1.getChannel().getIdLong()); + SQLSession.getSqlConnector().getSqlWorker().updateEntity(webhook).block(); + return Optional.of(new ChannelContainer(webhook1)); + } + } + + return Optional.ofNullable(errorReturnValue); + }).block(); + }); } - public void updateWelcomeChannel(String sessionIdentifier, long guildId, String channelId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - Guild guild = guildContainer.getGuild(); + public Mono updateWelcomeChannel(String sessionIdentifier, long guildId, String channelId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, true).publishOn(Schedulers.boundedElastic()).mapNotNull(guildOptional -> { + if (guildOptional.isEmpty()) { + return false; + } + + GuildContainer guildContainer = guildOptional.get(); + + Guild guild = guildContainer.getGuild(); + StandardGuildMessageChannel channel = guild.getChannelById(StandardGuildMessageChannel.class, channelId); - StandardGuildMessageChannel channel = guild.getChannelById(StandardGuildMessageChannel.class, channelId); + net.dv8tion.jda.api.entities.Webhook newWebhook = channel.createWebhook("Ree6-Welcome").complete(); - WebhookWelcome welcome = deleteWelcomeChannel(guild); + deleteWelcomeChannel(guild).block(); - net.dv8tion.jda.api.entities.Webhook newWebhook = channel.createWebhook("Ree6-Welcome").complete(); + SQLSession.getSqlConnector().getSqlWorker().setWelcomeWebhook(guildId, channel.getIdLong(), newWebhook.getIdLong(), newWebhook.getToken()); - SQLSession.getSqlConnector().getSqlWorker().setWelcomeWebhook(guildId, channel.getIdLong(), newWebhook.getIdLong(), newWebhook.getToken()); + return true; + }); } - public WebhookWelcome removeWelcomeChannel(String sessionIdentifier, long guildId) throws IllegalAccessException { - return deleteWelcomeChannel(sessionService.retrieveGuild(sessionIdentifier, guildId).getGuild()); + public Mono> removeWelcomeChannel(String sessionIdentifier, long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId).publishOn(Schedulers.boundedElastic()).mapNotNull(x -> { + if (x.isEmpty()) { + return Optional.empty(); + } + + return deleteWelcomeChannel(x.get().getGuild()).block(); + }); } - private WebhookWelcome deleteWelcomeChannel(Guild guild) { - WebhookWelcome webhook = SQLSession.getSqlConnector().getSqlWorker().getWelcomeWebhook(guild.getIdLong()); + private Mono> deleteWelcomeChannel(Guild guild) { + return SQLSession.getSqlConnector().getSqlWorker().getWelcomeWebhook(guild.getIdLong()) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(webhookLogOptional -> { + if (webhookLogOptional.isEmpty()) { + return Optional.empty(); + } - if (webhook != null) { + WebhookWelcome webhook = webhookLogOptional.get(); guild.retrieveWebhooks().queue(c -> c.stream().filter(entry -> entry.getToken() != null) .filter(entry -> entry.getIdLong() == webhook.getWebhookId() && entry.getToken().equalsIgnoreCase(webhook.getToken())) .forEach(entry -> entry.delete().queue())); - } - return webhook; + return SQLSession.getSqlConnector().getSqlWorker().deleteEntity(webhook).thenReturn(webhookLogOptional).block(); + }); } //endregion @@ -172,191 +253,341 @@ private WebhookWelcome deleteWelcomeChannel(Guild guild) { //region Reddit Notifications - public List getRedditNotifier(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - List subreddits = SQLSession.getSqlConnector().getSqlWorker().getAllRedditWebhooks(guildId); - - return subreddits.stream().map(subreddit -> new NotifierContainer(subreddit.getSubreddit(), subreddit.getMessage(), guildContainer.getGuild().retrieveWebhooks() - .complete().stream().filter(c -> c.getIdLong() == subreddit.getGuildId()).map(ChannelContainer::new).findFirst().orElse(null))).toList(); + public Mono> getRedditNotifier(String sessionIdentifier, long guildId) { + return getNotifier(sessionIdentifier, guildId, 1); } - public void addRedditNotifier(String sessionIdentifier, long guildId, GenericNotifierRequest notifierRequest) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, true); - Guild guild = guildContainer.getGuild(); - StandardGuildMessageChannel channel = guild.getChannelById(StandardGuildMessageChannel.class, notifierRequest.channelId()); - - net.dv8tion.jda.api.entities.Webhook newWebhook = channel.createWebhook("Ree6-RedditNotifier-" + notifierRequest.name()).complete(); - - SQLSession.getSqlConnector().getSqlWorker().addRedditWebhook(guildId, channel.getIdLong(), newWebhook.getIdLong(), newWebhook.getToken(), - notifierRequest.name(), notifierRequest.message()); + public Mono addRedditNotifier(String sessionIdentifier, long guildId, GenericNotifierRequest notifierRequest) { + return addNotifier(sessionIdentifier, guildId, notifierRequest, 1); } - // TODO:: make a universal delete method for webhooks, safe code. - public void removeRedditNotifier(String sessionIdentifier, long guildId, String subreddit) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - SQLSession.getSqlConnector().getSqlWorker().removeRedditWebhook(guildId, subreddit); + public Mono removeRedditNotifier(String sessionIdentifier, long guildId, String subreddit) { + return removeNotifier(sessionIdentifier, guildId, subreddit, 1); } //endregion //region Twitch Notifications - public List getTwitchNotifier(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - List twitchChannels = SQLSession.getSqlConnector().getSqlWorker().getAllTwitchWebhooks(guildId); - - return twitchChannels.stream().map(twitchChannel -> new NotifierContainer(twitchChannel.getName(), twitchChannel.getMessage(), guildContainer.getGuild().retrieveWebhooks() - .complete().stream().filter(c -> c.getIdLong() == twitchChannel.getGuildId()).map(ChannelContainer::new).findFirst().orElse(null))).toList(); + public Mono> getTwitchNotifier(String sessionIdentifier, long guildId) { + return getNotifier(sessionIdentifier, guildId, 2); } - public void addTwitchNotifier(String sessionIdentifier, long guildId, GenericNotifierRequest notifierRequest) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, true); - Guild guild = guildContainer.getGuild(); - StandardGuildMessageChannel channel = guild.getChannelById(StandardGuildMessageChannel.class, notifierRequest.channelId()); - - net.dv8tion.jda.api.entities.Webhook newWebhook = channel.createWebhook("Ree6-TwitchNotifier-" + notifierRequest.name()).complete(); - - SQLSession.getSqlConnector().getSqlWorker().addTwitchWebhook(guildId, channel.getIdLong(), newWebhook.getIdLong(), newWebhook.getToken(), - notifierRequest.name(), notifierRequest.message()); + public Mono addTwitchNotifier(String sessionIdentifier, long guildId, GenericNotifierRequest notifierRequest) { + return addNotifier(sessionIdentifier, guildId, notifierRequest, 2); } - public void removeTwitchNotifier(String sessionIdentifier, long guildId, String channelId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - SQLSession.getSqlConnector().getSqlWorker().removeTwitchWebhook(guildId, channelId); + public Mono removeTwitchNotifier(String sessionIdentifier, long guildId, String channelId) { + return removeNotifier(sessionIdentifier, guildId, channelId, 2); } //endregion //region YouTube Notifications - public List getYouTubeNotifier(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - List youtubers = SQLSession.getSqlConnector().getSqlWorker().getAllYouTubeWebhooks(guildId); - - return youtubers.stream().map(youtuber -> new NotifierContainer(youtuber.getName(), youtuber.getMessage(), guildContainer.getGuild().retrieveWebhooks() - .complete().stream().filter(c -> c.getIdLong() == youtuber.getGuildId()).map(ChannelContainer::new).findFirst().orElse(null))).toList(); + public Mono> getYouTubeNotifier(String sessionIdentifier, long guildId) { + return getNotifier(sessionIdentifier, guildId, 0); } - public void addYouTubeNotifier(String sessionIdentifier, long guildId, GenericNotifierRequest notifierRequest) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, true); - Guild guild = guildContainer.getGuild(); - StandardGuildMessageChannel channel = guild.getChannelById(StandardGuildMessageChannel.class, notifierRequest.channelId()); - - net.dv8tion.jda.api.entities.Webhook newWebhook = channel.createWebhook("Ree6-YoutubeNotifier-" + notifierRequest.name()).complete(); - - SQLSession.getSqlConnector().getSqlWorker().addYouTubeWebhook(guildId, channel.getIdLong(), newWebhook.getIdLong(), newWebhook.getToken(), - notifierRequest.name(), notifierRequest.message()); + public Mono addYouTubeNotifier(String sessionIdentifier, long guildId, GenericNotifierRequest notifierRequest) { + return addNotifier(sessionIdentifier, guildId, notifierRequest, 0); } - public void removeYouTubeNotifier(String sessionIdentifier, long guildId, String channelId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - SQLSession.getSqlConnector().getSqlWorker().removeYouTubeWebhook(guildId, channelId); + public Mono removeYouTubeNotifier(String sessionIdentifier, long guildId, String channelId) { + return removeNotifier(sessionIdentifier, guildId, channelId, 0); } //endregion //region Twitter Notifications - public List getTwitterNotifier(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - List twitterUsers = SQLSession.getSqlConnector().getSqlWorker().getAllTwitterWebhooks(guildId); + public Mono> getTwitterNotifier(String sessionIdentifier, long guildId) { + return getNotifier(sessionIdentifier, guildId, 3); + } - return twitterUsers.stream().map(twitterUser -> new NotifierContainer(twitterUser.getName(), twitterUser.getMessage(), guildContainer.getGuild().retrieveWebhooks() - .complete().stream().filter(c -> c.getIdLong() == twitterUser.getGuildId()).map(ChannelContainer::new).findFirst().orElse(null))).toList(); + public Mono addTwitterNotifier(String sessionIdentifier, long guildId, GenericNotifierRequest notifierRequest) { + return addNotifier(sessionIdentifier, guildId, notifierRequest, 3); } - public void addTwitterNotifier(String sessionIdentifier, long guildId, GenericNotifierRequest notifierRequest) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, true); - Guild guild = guildContainer.getGuild(); - StandardGuildMessageChannel channel = guild.getChannelById(StandardGuildMessageChannel.class, notifierRequest.channelId()); + public Mono removeTwitterNotifier(String sessionIdentifier, long guildId, String name) { + return removeNotifier(sessionIdentifier, guildId, name, 3); + } - net.dv8tion.jda.api.entities.Webhook newWebhook = channel.createWebhook("Ree6-TwitterNotifier-" + notifierRequest.name()).complete(); + //endregion + + //region Instagram Notifications - SQLSession.getSqlConnector().getSqlWorker().addTwitterWebhook(guildId, channel.getIdLong(), newWebhook.getIdLong(), newWebhook.getToken(), - notifierRequest.name(), notifierRequest.message()); + public Mono> getInstagramNotifier(String sessionIdentifier, long guildId) { + return getNotifier(sessionIdentifier, guildId, 4); } - public void removeTwitterNotifier(String sessionIdentifier, long guildId, String name) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - SQLSession.getSqlConnector().getSqlWorker().removeTwitterWebhook(guildId, name); + public Mono addInstagramNotifier(String sessionIdentifier, long guildId, GenericNotifierRequest notifierRequest) { + return addNotifier(sessionIdentifier, guildId, notifierRequest, 4); } - //endregion + public Mono removeInstagramNotifier(String sessionIdentifier, long guildId, String name) { + return removeNotifier(sessionIdentifier, guildId, name, 4); + } - //region Instagram Notifications + //region General + + /** + * Get the notifier based on the typ. + * + * @param sessionIdentifier the Session Identifier. + * @param guildId the Guild ID. + * @param type the typ. 0 -> YT, 1 -> Reddit, 2 -> Twitch, 3 -> Twitter, 4 -> Instagram + * @return a list of the given notifier. + */ + public Mono> getNotifier(String sessionIdentifier, long guildId, int type) { + return sessionService.retrieveGuild(sessionIdentifier, guildId) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(x -> { + if (x.isEmpty()) { + return Collections.emptyList(); + } - public List getInstagramNotifier(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - List instagramUsers = SQLSession.getSqlConnector().getSqlWorker().getAllInstagramWebhooks(guildId); + GuildContainer guildContainer = x.get(); + + switch (type) { + case 1 -> { + return SQLSession.getSqlConnector().getSqlWorker().getAllRedditWebhooks(guildId) + .map(webhooks -> webhooks.stream() + .map(hooks -> new NotifierContainer(hooks.getSubreddit(), hooks.getMessage(), guildContainer.getGuild().retrieveWebhooks() + .complete().stream().filter(c -> c.getIdLong() == hooks.getGuild()).map(ChannelContainer::new).findFirst().orElse(null))).toList()) + .block(); + } + + case 2 -> { + return SQLSession.getSqlConnector().getSqlWorker().getAllTwitchWebhooks(guildId) + .map(webhooks -> webhooks.stream() + .map(hooks -> new NotifierContainer(hooks.getName(), hooks.getMessage(), guildContainer.getGuild().retrieveWebhooks() + .complete().stream().filter(c -> c.getIdLong() == hooks.getGuild()).map(ChannelContainer::new).findFirst().orElse(null))).toList()) + .block(); + } + + case 3 -> { + return SQLSession.getSqlConnector().getSqlWorker().getAllTwitterWebhooks(guildId) + .map(webhooks -> webhooks.stream() + .map(hooks -> new NotifierContainer(hooks.getName(), hooks.getMessage(), guildContainer.getGuild().retrieveWebhooks() + .complete().stream().filter(c -> c.getIdLong() == hooks.getGuild()).map(ChannelContainer::new).findFirst().orElse(null))).toList()) + .block(); + } + + case 4 -> { + return SQLSession.getSqlConnector().getSqlWorker().getAllInstagramWebhooks(guildId) + .map(webhooks -> webhooks.stream() + .map(hooks -> new NotifierContainer(hooks.getName(), hooks.getMessage(), guildContainer.getGuild().retrieveWebhooks() + .complete().stream().filter(c -> c.getIdLong() == hooks.getGuild()).map(ChannelContainer::new).findFirst().orElse(null))).toList()) + .block(); + } + + default -> { + return SQLSession.getSqlConnector().getSqlWorker().getAllYouTubeWebhooks(guildId) + .map(webhooks -> webhooks.stream() + .map(hooks -> new NotifierContainer(hooks.getName(), hooks.getMessage(), guildContainer.getGuild().retrieveWebhooks() + .complete().stream().filter(c -> c.getIdLong() == hooks.getGuild()).map(ChannelContainer::new).findFirst().orElse(null))).toList()) + .block(); + } - return instagramUsers.stream().map(instagramUser -> new NotifierContainer(instagramUser.getName(), instagramUser.getMessage(), guildContainer.getGuild().retrieveWebhooks() - .complete().stream().filter(c -> c.getIdLong() == instagramUser.getGuildId()).map(ChannelContainer::new).findFirst().orElse(null))).toList(); + } + }); } - public void addInstagramNotifier(String sessionIdentifier, long guildId, GenericNotifierRequest notifierRequest) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, true); - Guild guild = guildContainer.getGuild(); - StandardGuildMessageChannel channel = guild.getChannelById(StandardGuildMessageChannel.class, notifierRequest.channelId()); + /** + * Get the notifier based on the typ. + * + * @param sessionIdentifier the Session Identifier. + * @param guildId the Guild ID. + * @param type the typ. 0 -> YT, 1 -> Reddit, 2 -> Twitch, 3 -> Twitter, 4 -> Instagram + * @return a list of the given notifier. + */ + public Mono addNotifier(String sessionIdentifier, long guildId, GenericNotifierRequest notifierRequest, int type) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, true) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(x -> { + if (x.isEmpty()) { + return false; + } + + GuildContainer guildContainer = x.get(); - net.dv8tion.jda.api.entities.Webhook newWebhook = channel.createWebhook("Ree6-InstagramNotifier-" + notifierRequest.name()).complete(); + Guild guild = guildContainer.getGuild(); + StandardGuildMessageChannel channel = guild.getChannelById(StandardGuildMessageChannel.class, notifierRequest.channelId()); - SQLSession.getSqlConnector().getSqlWorker().addInstagramWebhook(guildId, channel.getIdLong(), newWebhook.getIdLong(), newWebhook.getToken(), - notifierRequest.name(), notifierRequest.message()); + if (channel == null) { + return false; + } + + String suffix; + + switch (type) { + case 1 -> suffix = "RedditNotifier"; + case 2 -> suffix = "TwitterNotifier"; + case 3 -> suffix = "TwitchNotifier"; + case 4 -> suffix = "InstagramNotifier"; + default -> suffix = "YoutubeNotifier"; + } + + net.dv8tion.jda.api.entities.Webhook newWebhook = channel.createWebhook("Ree6-" + suffix + "-" + notifierRequest.name()).complete(); + + + switch (type) { + case 1 -> + SQLSession.getSqlConnector().getSqlWorker().addRedditWebhook(guildId, channel.getIdLong(), newWebhook.getIdLong(), newWebhook.getToken(), + notifierRequest.name(), notifierRequest.message()); + + case 2 -> + SQLSession.getSqlConnector().getSqlWorker().addTwitchWebhook(guildId, channel.getIdLong(), newWebhook.getIdLong(), newWebhook.getToken(), + notifierRequest.name(), notifierRequest.message()); + + case 3 -> + SQLSession.getSqlConnector().getSqlWorker().addTwitterWebhook(guildId, channel.getIdLong(), newWebhook.getIdLong(), newWebhook.getToken(), + notifierRequest.name(), notifierRequest.message()); + + case 4 -> + SQLSession.getSqlConnector().getSqlWorker().addInstagramWebhook(guildId, channel.getIdLong(), newWebhook.getIdLong(), newWebhook.getToken(), + notifierRequest.name(), notifierRequest.message()); + + default -> + SQLSession.getSqlConnector().getSqlWorker().addYouTubeWebhook(guildId, channel.getIdLong(), newWebhook.getIdLong(), newWebhook.getToken(), + notifierRequest.name(), notifierRequest.message()); + + } + + return true; + }); } - public void removeInstagramNotifier(String sessionIdentifier, long guildId, String name) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId); - SQLSession.getSqlConnector().getSqlWorker().removeInstagramWebhook(guildId, name); + /** + * Get the notifier based on the typ. + * + * @param sessionIdentifier the Session Identifier. + * @param guildId the Guild ID. + * @param type the typ. 0 -> YT, 1 -> Reddit, 2 -> Twitch, 3 -> Twitter, 4 -> Instagram + * @return a list of the given notifier. + */ + public Mono removeNotifier(String sessionIdentifier, long guildId, String name, int type) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, true) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(x -> { + if (x.isEmpty()) { + return false; + } + + switch (type) { + case 1 -> SQLSession.getSqlConnector().getSqlWorker().removeInstagramWebhook(guildId, name); + + case 2 -> SQLSession.getSqlConnector().getSqlWorker().removeTwitchWebhook(guildId, name); + + case 3 -> SQLSession.getSqlConnector().getSqlWorker().removeTwitterWebhook(guildId, name); + + case 4 -> SQLSession.getSqlConnector().getSqlWorker().removeInstagramWebhook(guildId, name); + + default -> SQLSession.getSqlConnector().getSqlWorker().removeYouTubeWebhook(guildId, name); + + } + + return true; + }); } //endregion //endregion + //endregion + //region LevelRewards //region Chat - public List getChatAutoRoles(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, true); - return SQLSession.getSqlConnector().getSqlWorker().getChatLevelRewards(guildId).entrySet().stream().map(x -> new RoleLevelContainer(x.getKey(), guildContainer.getRoleById(x.getValue()))).toList(); + public Mono>> getChatAutoRoles(String sessionIdentifier, long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, true).publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return Optional.empty(); + } + + GuildContainer guildContainer = guildContainerOptional.get(); + + return SQLSession.getSqlConnector().getSqlWorker().getChatLevelRewards(guildId) + .mapNotNull(levelRewardMap -> Optional.of(levelRewardMap.entrySet().stream() + .map(x -> new RoleLevelContainer(x.getKey(), guildContainer.getRoleById(x.getValue()))).toList())).block(); + }); } - public void addChatAutoRole(String sessionIdentifier, long guildId, long roleId, long level) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, true); + public Mono addChatAutoRole(String sessionIdentifier, long guildId, long roleId, long level) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, true).map(x -> { + if (x.isEmpty()) { + return false; + } + + GuildContainer guildContainer = x.get(); - if (guildContainer.getRoleById(roleId) == null) - throw new IllegalAccessException("Role not found"); + if (guildContainer.getRoleById(roleId) == null) + return false; - SQLSession.getSqlConnector().getSqlWorker().addChatLevelReward(guildId, roleId, level); + SQLSession.getSqlConnector().getSqlWorker().addChatLevelReward(guildId, roleId, level); + return true; + }); } - public void removeChatAutoRole(String sessionIdentifier, long guildId, long level) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, false); - SQLSession.getSqlConnector().getSqlWorker().removeChatLevelReward(guildId, level); + public Mono removeChatAutoRole(String sessionIdentifier, long guildId, long level) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, false).map(x -> { + if (x.isEmpty()) { + return false; + } + + SQLSession.getSqlConnector().getSqlWorker().removeChatLevelReward(guildId, level); + return true; + }); } //endregion //region Voice - public List getVoiceAutoRoles(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, true); - return SQLSession.getSqlConnector().getSqlWorker().getVoiceLevelRewards(guildId).entrySet().stream().map(x -> new RoleLevelContainer(x.getKey(), guildContainer.getRoleById(x.getValue()))).toList(); + public Mono>> getVoiceAutoRoles(String sessionIdentifier, long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, true).publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return Optional.empty(); + } + + GuildContainer guildContainer = guildContainerOptional.get(); + + return SQLSession.getSqlConnector().getSqlWorker().getVoiceLevelRewards(guildId) + .mapNotNull(levelRewardMap -> Optional.of(levelRewardMap.entrySet().stream() + .map(x -> new RoleLevelContainer(x.getKey(), guildContainer.getRoleById(x.getValue()))).toList())).block(); + }); } - public void addVoiceAutoRole(String sessionIdentifier, long guildId, long roleId, long level) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, true); + public Mono addVoiceAutoRole(String sessionIdentifier, long guildId, long roleId, long level) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, true).map(x -> { + if (x.isEmpty()) { + return false; + } + + GuildContainer guildContainer = x.get(); - if (guildContainer.getRoleById(roleId) == null) - throw new IllegalAccessException("Role not found"); + if (guildContainer.getRoleById(roleId) == null) + return false; - SQLSession.getSqlConnector().getSqlWorker().addVoiceLevelReward(guildId, roleId, level); + SQLSession.getSqlConnector().getSqlWorker().addVoiceLevelReward(guildId, roleId, level); + return true; + }); } - public void removeVoiceAutoRole(String sessionIdentifier, long guildId, long level) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, false); - SQLSession.getSqlConnector().getSqlWorker().removeVoiceLevelReward(guildId, level); + public Mono removeVoiceAutoRole(String sessionIdentifier, long guildId, long level) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, false).map(x -> { + if (x.isEmpty()) { + return false; + } + + SQLSession.getSqlConnector().getSqlWorker().removeVoiceLevelReward(guildId, level); + return true; + }); } //endregion @@ -365,591 +596,860 @@ public void removeVoiceAutoRole(String sessionIdentifier, long guildId, long lev //region Recording - public Recording getRecording(String sessionIdentifier, String recordId) throws IllegalAccessException { - SessionContainer sessionContainer = sessionService.retrieveSession(sessionIdentifier); - List guilds = sessionService.retrieveGuilds(sessionIdentifier, false); + public Mono> getRecording(String sessionIdentifier, String recordId) { + Recording errorReturnValue = null; + return sessionService.retrieveSession(sessionIdentifier).publishOn(Schedulers.boundedElastic()).mapNotNull(x -> { + if (x.isEmpty()) { + return Optional.ofNullable(errorReturnValue); + } - Recording recording = SQLSession.getSqlConnector().getSqlWorker().getEntity(new Recording(), "FROM Recording WHERE identifier=:id", Map.of("id", recordId)); + SessionContainer sessionContainer = x.get(); - if (recording == null) - throw new IllegalAccessException("Recording not found!"); + return sessionService.retrieveGuilds(sessionIdentifier, false).publishOn(Schedulers.boundedElastic()).mapNotNull(y -> { + if (y.isEmpty()) { + return Optional.ofNullable(errorReturnValue); + } - if (guilds.stream().anyMatch(g -> g.getId() == recording.getGuildId())) { - boolean found = false; + List guilds = y.get(); - for (JsonElement element : recording.getJsonArray()) { - if (element.isJsonPrimitive()) { - JsonPrimitive primitive = element.getAsJsonPrimitive(); - if (primitive.isString() && primitive.getAsString().equalsIgnoreCase(String.valueOf(sessionContainer.getUser().getId()))) { - found = true; - break; + return SQLSession.getSqlConnector().getSqlWorker().getEntity(new Recording(), "FROM Recording WHERE identifier=:id", + Map.of("id", recordId)).map(recordingOptional -> { + if (recordingOptional.isEmpty()) { + return Optional.ofNullable(errorReturnValue); } - } - } - if (found) { - return recording; - } else { - throw new IllegalAccessException("You were not part of this recording."); - } - } else { - throw new IllegalAccessException("You were not part of the Guild this recording was made in!"); - } + Recording recording = recordingOptional.get(); + + if (guilds.stream().anyMatch(g -> g.getId() == recording.getGuildId())) { + boolean found = false; + + for (JsonElement element : recording.getJsonArray()) { + if (element.isJsonPrimitive()) { + JsonPrimitive primitive = element.getAsJsonPrimitive(); + if (primitive.isString() && primitive.getAsString().equalsIgnoreCase(String.valueOf(sessionContainer.getUser().getId()))) { + found = true; + break; + } + } + } + + if (found) { + return recordingOptional; + } else { + log.warn("User {} tried accessing a recording he is not part of.", sessionContainer.getUser().getId()); + return Optional.ofNullable(errorReturnValue); + } + } else { + log.warn("User {} tried accessing a recording he is not part of.", sessionContainer.getUser().getId()); + return Optional.ofNullable(errorReturnValue); + } + }).block(); + }).block(); + }); } - public RecordContainer getRecordingContainer(String sessionIdentifier, String recordId) throws IllegalAccessException { - return new RecordContainer(getRecording(sessionIdentifier, recordId)); + public Mono> getRecordingContainer(String sessionIdentifier, String recordId) { + return getRecording(sessionIdentifier, recordId).map(x -> x.map(RecordContainer::new)); } - public byte[] getRecordingBytes(String sessionIdentifier, String recordId) throws IllegalAccessException { - Recording recording = getRecording(sessionIdentifier, recordId); - SQLSession.getSqlConnector().getSqlWorker().deleteEntity(recording); - return recording.getRecording(); + public Mono> getRecordingBytes(String sessionIdentifier, String recordId) { + return getRecording(sessionIdentifier, recordId).publishOn(Schedulers.boundedElastic()).mapNotNull(x -> { + if (x.isEmpty()) { + return Optional.empty(); + } + + return SQLSession.getSqlConnector().getSqlWorker().deleteEntity(x.get()).thenReturn(Optional.ofNullable(x.get().getRecording())).block(); + }); } //endregion //region Temporal Voice - public ChannelContainer getTemporalVoice(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, true, false); - TemporalVoicechannel temporalVoicechannel = SQLSession.getSqlConnector().getSqlWorker() - .getEntity(new TemporalVoicechannel(), "FROM TemporalVoicechannel WHERE guildChannelId.guildId=:gid", Map.of("gid", guildId)); - - if (temporalVoicechannel == null) - return new ChannelContainer(); + public Mono> getTemporalVoice(String sessionIdentifier, long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, true, false).publishOn(Schedulers.boundedElastic()).mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return Optional.empty(); + } - return guildContainer.getChannelById(temporalVoicechannel.getVoiceChannelId()); + return SQLSession.getSqlConnector().getSqlWorker() + .getEntity(new TemporalVoicechannel(), "FROM TemporalVoicechannel WHERE guildChannelId.guildId=:gid", Map.of("gid", guildId)) + .map(temporalVoicechannelOptional -> temporalVoicechannelOptional + .map(temporalVoicechannel -> guildContainerOptional.get().getChannelById(temporalVoicechannel.getVoiceChannelId())) + .or(() -> Optional.ofNullable(ChannelContainer.DEFAULT))).block(); + }); } - public void updateTemporalVoice(String sessionIdentifier, long guildId, long channelId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, true, false); - - if (guildContainer.getChannelById(channelId) == null) - throw new IllegalAccessException("Channel not found"); - - TemporalVoicechannel temporalVoicechannel = SQLSession.getSqlConnector().getSqlWorker() - .getEntity(new TemporalVoicechannel(), "FROM TemporalVoicechannel WHERE guildChannelId.guildId=:gid", Map.of("gid", guildId)); + public Mono updateTemporalVoice(String sessionIdentifier, long guildId, long channelId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, true, false).publishOn(Schedulers.boundedElastic()).mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return false; + } - if (temporalVoicechannel != null) { - SQLSession.getSqlConnector().getSqlWorker().deleteEntity(temporalVoicechannel); - temporalVoicechannel.getGuildChannelId().setChannelId(channelId); - } else { - temporalVoicechannel = new TemporalVoicechannel(guildId, channelId); - } + GuildContainer guildContainer = guildContainerOptional.get(); - SQLSession.getSqlConnector().getSqlWorker().updateEntity(temporalVoicechannel); + if (guildContainer.getChannelById(channelId) == null) + return false; + + return SQLSession.getSqlConnector().getSqlWorker() + .getEntity(new TemporalVoicechannel(), "FROM TemporalVoicechannel WHERE guildChannelId.guildId=:gid", Map.of("gid", guildId)) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(temporalVoicechannelOptional -> { + TemporalVoicechannel temporalVoicechannel = temporalVoicechannelOptional.orElse(new TemporalVoicechannel(guildId, channelId)); + if (temporalVoicechannelOptional.isPresent()) { + SQLSession.getSqlConnector().getSqlWorker().deleteEntity(temporalVoicechannel).block(); + temporalVoicechannel.getGuildChannelId().setChannelId(channelId); + } + + return SQLSession.getSqlConnector().getSqlWorker().updateEntity(temporalVoicechannel).thenReturn(true).block(); + }).block(); + }); } - public void removeTemporalVoice(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, false); + public Mono removeTemporalVoice(String sessionIdentifier, long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, false).publishOn(Schedulers.boundedElastic()).mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return false; + } - TemporalVoicechannel temporalVoicechannel = SQLSession.getSqlConnector().getSqlWorker() - .getEntity(new TemporalVoicechannel(), "FROM TemporalVoicechannel WHERE guildId=:gid", Map.of("gid", guildId)); + return SQLSession.getSqlConnector().getSqlWorker() + .getEntity(new TemporalVoicechannel(), "FROM TemporalVoicechannel WHERE guildId=:gid", Map.of("gid", guildId)) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(temporalVoicechannelOptional -> { + if (temporalVoicechannelOptional.isEmpty()) { + return false; + } - if (temporalVoicechannel != null) { - SQLSession.getSqlConnector().getSqlWorker().deleteEntity(temporalVoicechannel); - } + return SQLSession.getSqlConnector().getSqlWorker().deleteEntity(temporalVoicechannelOptional.get()).thenReturn(true).block(); + }).block(); + }); } //endregion //region OptOut - public String checkOptOut(String sessionIdentifier, long guildId) throws IllegalAccessException { - SessionContainer sessionContainer = sessionService.retrieveSession(sessionIdentifier); - return SQLSession.getSqlConnector().getSqlWorker().isOptOut(guildId, sessionContainer.getUser().getId()) ? "optedOut" : "optedIn"; - } + public Mono> checkOptOut(String sessionIdentifier, long guildId) { + return sessionService.retrieveSession(sessionIdentifier).publishOn(Schedulers.boundedElastic()).mapNotNull(x -> { + if (x.isEmpty()) { + return Optional.empty(); + } - public String optOut(String sessionIdentifier, long guildId) throws IllegalAccessException { - SessionContainer sessionContainer = sessionService.retrieveSession(sessionIdentifier); - if (!SQLSession.getSqlConnector().getSqlWorker().isOptOut(guildId, sessionContainer.getUser().getId())) { - SQLSession.getSqlConnector().getSqlWorker().optOut(guildId, sessionContainer.getUser().getId()); - return "Opted out!"; - } else { - SQLSession.getSqlConnector().getSqlWorker().optIn(guildId, sessionContainer.getUser().getId()); - return "Opted in!"; - } + return SQLSession.getSqlConnector().getSqlWorker().isOptOut(guildId, x.get().getUser().getId()).map(y -> Optional.of(y ? "optedOut" : "optedIn")).block(); + }); } - //endregion + public Mono> optOut(String sessionIdentifier, long guildId) { + return sessionService.retrieveSession(sessionIdentifier).publishOn(Schedulers.boundedElastic()).mapNotNull(x -> { + if (x.isEmpty()) { + return Optional.empty(); + } - //region Ticket + SessionContainer sessionContainer = x.get(); - public TicketContainer getTicket(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, true, false); - Tickets tickets = SQLSession.getSqlConnector().getSqlWorker().getEntity(new Tickets(), "FROM Tickets WHERE guildId=:gid", Map.of("gid", guildId)); + return SQLSession.getSqlConnector().getSqlWorker().isOptOut(guildId, sessionContainer.getUser().getId()).map(y -> { + if (y) { + SQLSession.getSqlConnector().getSqlWorker().optIn(guildId, sessionContainer.getUser().getId()); + return Optional.of("Opted in!"); + } else { + SQLSession.getSqlConnector().getSqlWorker().optOut(guildId, sessionContainer.getUser().getId()); + return Optional.of("Opted out!"); + } - if (tickets == null) { - return new TicketContainer(); - } + }).block(); + }); + } - TicketContainer ticketContainer = new TicketContainer(); - ticketContainer.setTicketCount(tickets.getTicketCount()); - ticketContainer.setChannel(guildContainer.getChannelById(tickets.getChannelId())); - ticketContainer.setCategory(guildContainer.getCategoryById(tickets.getTicketCategory())); + //endregion + //region Ticket - ChannelContainer logChannel = guildContainer.getChannelById(tickets.getLogChannelId()); + public Mono> getTicket(String sessionIdentifier, long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, true, false) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return Optional.empty(); + } - if (tickets.getLogChannelId() == 0) { - guildContainer.getGuild().retrieveWebhooks().queue(x -> { - Tickets updateTickets = SQLSession.getSqlConnector().getSqlWorker().getEntity(new Tickets(), "FROM Tickets WHERE guildId=:gid", Map.of("gid", guildId)); - if (updateTickets == null) return; + GuildContainer guildContainer = guildContainerOptional.get(); - net.dv8tion.jda.api.entities.Webhook webhook = x.stream().filter(entry -> entry.getToken() != null) - .filter(entry -> entry.getToken().equalsIgnoreCase(tickets.getLogChannelWebhookToken())) - .findFirst().orElse(null); + return SQLSession.getSqlConnector().getSqlWorker().getEntity(new Tickets(), "FROM Tickets WHERE guildId=:gid", Map.of("gid", guildId)) + .map(ticketOptional -> { + if (ticketOptional.isEmpty()) { + return Optional.ofNullable(TicketContainer.DEFAULT); + } - if (webhook != null) { - updateTickets.setLogChannelId(webhook.getChannel().getIdLong()); - SQLSession.getSqlConnector().getSqlWorker().updateEntity(updateTickets); - } - }); - } + Tickets tickets = ticketOptional.get(); - if (logChannel == null) { - logChannel = new ChannelContainer(); - } + TicketContainer ticketContainer = new TicketContainer(); + ticketContainer.setTicketCount(tickets.getTicketCount()); + ticketContainer.setChannel(guildContainer.getChannelById(tickets.getChannelId())); + ticketContainer.setCategory(guildContainer.getCategoryById(tickets.getTicketCategory())); - ticketContainer.setLogChannel(logChannel); - ticketContainer.setTicketOpenMessage(SQLSession.getSqlConnector().getSqlWorker().getSetting(guildId, "message_ticket_open").getStringValue()); - ticketContainer.setTicketMenuMessage(SQLSession.getSqlConnector().getSqlWorker().getSetting(guildId, "message_ticket_menu").getStringValue()); + ChannelContainer logChannel = guildContainer.getChannelById(tickets.getLogChannelId()); - return ticketContainer; - } + if (tickets.getLogChannelId() == 0) { + guildContainer.getGuild().retrieveWebhooks().queue(x -> { + Optional updateTicketOptional = SQLSession.getSqlConnector().getSqlWorker().getEntity(new Tickets(), "FROM Tickets WHERE guildId=:gid", Map.of("gid", guildId)).block(); + if (updateTicketOptional == null || updateTicketOptional.isEmpty()) return; - public void updateTicket(String sessionIdentifier, long guildId, long channelId, long logChannelId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, true, false); + Tickets updateTickets = updateTicketOptional.get(); - Guild guild = guildContainer.getGuild(); + net.dv8tion.jda.api.entities.Webhook webhook = x.stream().filter(entry -> entry.getToken() != null) + .filter(entry -> entry.getToken().equalsIgnoreCase(tickets.getLogChannelWebhookToken())) + .findFirst().orElse(null); - Tickets tickets = SQLSession.getSqlConnector().getSqlWorker().getEntity(new Tickets(), - "FROM Tickets WHERE guildId=:gid", Map.of("gid", guildId)); + if (webhook != null) { + updateTickets.setLogChannelId(webhook.getChannel().getIdLong()); + SQLSession.getSqlConnector().getSqlWorker().updateEntity(updateTickets).block(); + } + }); + } - boolean requireChannel = false; + if (logChannel == null) { + logChannel = new ChannelContainer(); + } - if (tickets == null) { - tickets = new Tickets(); - tickets.setGuildId(guildId); - requireChannel = true; - } + ticketContainer.setLogChannel(logChannel); + Optional setting = SQLSession.getSqlConnector().getSqlWorker().getSetting(guildId, "message_ticket_open").block(); + if (setting.isPresent()) { + ticketContainer.setTicketOpenMessage(setting.get().getStringValue()); + } - if (channelId != 0) { - if (guildContainer.getChannelById(channelId) == null) - throw new IllegalAccessException("Channel not found"); + setting = SQLSession.getSqlConnector().getSqlWorker().getSetting(guildId, "message_ticket_menu").block(); + if (setting.isPresent()) { + ticketContainer.setTicketMenuMessage(setting.get().getStringValue()); + } - tickets.setChannelId(channelId); - } else if (requireChannel) { - throw new IllegalAccessException("Channel not found"); - } + return Optional.of(ticketContainer); + }) + .block(); + }); + } - if (logChannelId != 0) { - StandardGuildMessageChannel channel = guild.getChannelById(StandardGuildMessageChannel.class, logChannelId); + public Mono updateTicket(String sessionIdentifier, long guildId, long channelId, long logChannelId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, true, false) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return false; + } - Tickets finalTickets = tickets; - guild.retrieveWebhooks().queue(c -> c.stream().filter(entry -> entry.getToken() != null) - .filter(entry -> entry.getIdLong() == finalTickets.getLogChannelId() && entry.getToken().equalsIgnoreCase(finalTickets.getLogChannelWebhookToken())) - .forEach(entry -> entry.delete().queue())); + GuildContainer guildContainer = guildContainerOptional.get(); + Guild guild = guildContainer.getGuild(); + + return SQLSession.getSqlConnector().getSqlWorker().getEntity(new Tickets(), + "FROM Tickets WHERE guildId=:gid", Map.of("gid", guildId)) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(ticketOptional -> { + if (ticketOptional.isEmpty()) { + return false; + } + + AtomicBoolean requireChannel = new AtomicBoolean(false); + + Tickets tickets = ticketOptional.orElseGet(() -> { + Tickets ticket = new Tickets(); + ticket.setChannelId(channelId); + requireChannel.set(true); + return ticket; + }); + + if (channelId != 0) { + if (guildContainer.getChannelById(channelId) == null) + return false; + + tickets.setChannelId(channelId); + } else if (requireChannel.get()) { + return false; + } + + if (logChannelId != 0) { + StandardGuildMessageChannel channel = guild.getChannelById(StandardGuildMessageChannel.class, logChannelId); + + Tickets finalTickets = tickets; + guild.retrieveWebhooks().queue(c -> c.stream().filter(entry -> entry.getToken() != null) + .filter(entry -> entry.getIdLong() == finalTickets.getLogChannelId() && entry.getToken().equalsIgnoreCase(finalTickets.getLogChannelWebhookToken())) + .forEach(entry -> entry.delete().queue())); + + net.dv8tion.jda.api.entities.Webhook newWebhook = channel.createWebhook("Ticket-Log").complete(); + tickets.setLogChannelWebhookToken(newWebhook.getToken()); + tickets.setLogChannelWebhookId(newWebhook.getIdLong()); + tickets.setLogChannelId(channel.getIdLong()); + } + + return SQLSession.getSqlConnector().getSqlWorker().updateEntity(tickets).thenReturn(true).block(); + }) + .block(); + }); + } - net.dv8tion.jda.api.entities.Webhook newWebhook = channel.createWebhook("Ticket-Log").complete(); - tickets.setLogChannelWebhookToken(newWebhook.getToken()); - tickets.setLogChannelWebhookId(newWebhook.getIdLong()); - tickets.setLogChannelId(channel.getIdLong()); - } + public Mono removeTicket(String sessionIdentifier, long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, false) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return false; + } - SQLSession.getSqlConnector().getSqlWorker().updateEntity(tickets); - } + GuildContainer guildContainer = guildContainerOptional.get(); - public void removeTicket(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, false); + return SQLSession.getSqlConnector().getSqlWorker().getEntity(new Tickets(), + "FROM Tickets WHERE guildId=:gid", Map.of("gid", guildId)) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(ticketOptional -> { + if (ticketOptional.isEmpty()) { + return false; + } - Tickets tickets = SQLSession.getSqlConnector().getSqlWorker().getEntity(new Tickets(), - "FROM Tickets WHERE guildId=:gid", Map.of("gid", guildId)); + Tickets tickets = ticketOptional.get(); - if (tickets != null) { - guildContainer.getGuild().retrieveWebhooks().queue(c -> c.stream().filter(entry -> entry.getToken() != null) - .filter(entry -> entry.getIdLong() == tickets.getLogChannelId() && entry.getToken().equalsIgnoreCase(tickets.getLogChannelWebhookToken())) - .forEach(entry -> entry.delete().queue())); + guildContainer.getGuild().retrieveWebhooks().queue(c -> c.stream().filter(entry -> entry.getToken() != null) + .filter(entry -> entry.getIdLong() == tickets.getLogChannelId() && entry.getToken().equalsIgnoreCase(tickets.getLogChannelWebhookToken())) + .forEach(entry -> entry.delete().queue())); - SQLSession.getSqlConnector().getSqlWorker().deleteEntity(tickets); - } + return SQLSession.getSqlConnector().getSqlWorker().deleteEntity(tickets).thenReturn(true).block(); + }) + .block(); + }); } //endregion //region Suggestion - public ChannelContainer getSuggestion(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, true, false); - - Suggestions suggestions = SQLSession.getSqlConnector().getSqlWorker().getEntity(new Suggestions(), - "FROM Suggestions WHERE guildChannelId.guildId = :id", Map.of("id", guildId)); + public Mono> getSuggestion(String sessionIdentifier, long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, true, false).publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return Optional.empty(); + } - if (suggestions == null) - return new ChannelContainer(); + GuildContainer guildContainer = guildContainerOptional.get(); - return guildContainer.getChannelById(suggestions.getGuildChannelId().getChannelId()); + return SQLSession.getSqlConnector().getSqlWorker().getEntity(new Suggestions(), + "FROM Suggestions WHERE guildChannelId.guildId = :id", Map.of("id", guildId)) + .map(suggestionOptional -> suggestionOptional + .map(x -> guildContainer.getChannelById(suggestionOptional.get().getChannelId())).or(() -> Optional.of(ChannelContainer.DEFAULT))) + .block(); + }); } - public void updateSuggestion(String sessionIdentifier, long guildId, long channelId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, true, false); - - Guild guild = guildContainer.getGuild(); - - Suggestions suggestions = SQLSession.getSqlConnector().getSqlWorker().getEntity(new Suggestions(), - "FROM Suggestions WHERE guildChannelId.guildId = :id", Map.of("id", guildId)); - - boolean requireChannel = false; + public Mono updateSuggestion(String sessionIdentifier, long guildId, long channelId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, true, false).publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return false; + } - if (suggestions == null) { - suggestions = new Suggestions(); - suggestions.setGuildId(guildId); - requireChannel = true; - } + GuildContainer guildContainer = guildContainerOptional.get(); + + return SQLSession.getSqlConnector().getSqlWorker().getEntity(new Suggestions(), + "FROM Suggestions WHERE guildChannelId.guildId = :id", Map.of("id", guildId)) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(suggestionOptional -> { + AtomicBoolean requireChannel = new AtomicBoolean(false); + + Suggestions suggestion = suggestionOptional.orElseGet(() -> { + Suggestions suggestions = new Suggestions(); + suggestions.setGuildId(guildId); + requireChannel.set(true); + return suggestions; + }); + + if (channelId != 0) { + if (guildContainer.getChannelById(channelId) == null) + return false; + } else if (requireChannel.get()) { + return false; + } + + return SQLSession.getSqlConnector().getSqlWorker().updateEntity(suggestion).thenReturn(true).block(); + }).block(); + }); + } - if (channelId != 0) { - if (guildContainer.getChannelById(channelId) == null) - throw new IllegalAccessException("Channel not found"); - } else if (requireChannel) { - throw new IllegalAccessException("Channel not found"); - } + public Mono removeSuggestion(String sessionIdentifier, long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, false).publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return false; + } - SQLSession.getSqlConnector().getSqlWorker().updateEntity(suggestions); - } + GuildContainer guildContainer = guildContainerOptional.get(); - public void removeSuggestion(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, false); + return SQLSession.getSqlConnector().getSqlWorker().getEntity(new Tickets(), + "FROM Tickets WHERE guildId=:gid", Map.of("gid", guildId)) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(ticketOptional -> { + if (ticketOptional.isEmpty()) { + return false; + } - Tickets tickets = SQLSession.getSqlConnector().getSqlWorker().getEntity(new Tickets(), - "FROM Tickets WHERE guildId=:gid", Map.of("gid", guildId)); + Tickets tickets = ticketOptional.get(); - if (tickets != null) { - guildContainer.getGuild().retrieveWebhooks().queue(c -> c.stream().filter(entry -> entry.getToken() != null) - .filter(entry -> entry.getIdLong() == tickets.getLogChannelId() && entry.getToken().equalsIgnoreCase(tickets.getLogChannelWebhookToken())) - .forEach(entry -> entry.delete().queue())); + guildContainer.getGuild().retrieveWebhooks().queue(c -> c.stream().filter(entry -> entry.getToken() != null) + .filter(entry -> entry.getIdLong() == tickets.getLogChannelId() && entry.getToken().equalsIgnoreCase(tickets.getLogChannelWebhookToken())) + .forEach(entry -> entry.delete().queue())); - SQLSession.getSqlConnector().getSqlWorker().deleteEntity(tickets); - } + return SQLSession.getSqlConnector().getSqlWorker().deleteEntity(tickets).thenReturn(true).block(); + }).block(); + }); } - //endregion +//endregion //region Warnings - public List getWarnings(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, false); + public Mono> getWarnings(String sessionIdentifier, long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, false) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return Collections.emptyList(); + } + + GuildContainer guildContainer = guildContainerOptional.get(); - return SQLSession.getSqlConnector().getSqlWorker().getEntityList(new Warning(), - "FROM Warning WHERE guildUserId.guildId = :gid", - Map.of("gid", guildId)).stream().map(c -> new WarningContainer(c, new UserContainer(guildContainer.getGuild().retrieveMemberById(c.getUserId()).complete()))).toList(); + return SQLSession.getSqlConnector().getSqlWorker().getEntityList(new Warning(), + "FROM Warning WHERE guildUserId.guildId = :gid", + Map.of("gid", guildId)) + .map(warnings -> warnings.stream() + .map(c -> new WarningContainer(c, new UserContainer(guildContainer.getGuild().retrieveMemberById(c.getUserId()).complete()))).toList()) + .block(); + }); } - public WarningContainer addWarnings(String sessionIdentifier, long guildId, long userId, String warnings) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, false); - - Member member = guildContainer.getGuild().retrieveMemberById(userId).complete(); + public Mono> addWarnings(String sessionIdentifier, long guildId, long userId, String warnings) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, false) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return Optional.empty(); + } - if (member == null) { - throw new IllegalAccessException("Member not found"); - } + GuildContainer guildContainer = guildContainerOptional.get(); - Warning warning = SQLSession.getSqlConnector().getSqlWorker().getEntity(new Warning(), - "FROM Warning WHERE guildId = :gid AND userId = :uid", - Map.of("gid", guildId, "uid", userId)); + Member member = guildContainer.getGuild().retrieveMemberById(userId).complete(); - if (warning == null) { - warning = new Warning(new GuildUserId(guildId, userId), 0); - } + if (member == null) + return Optional.empty(); - int additionWarnings = 1; + return SQLSession.getSqlConnector().getSqlWorker().getEntity(new Warning(), + "FROM Warning WHERE guildId = :gid AND userId = :uid", + Map.of("gid", guildId, "uid", userId)) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(warningOptional -> { + Warning warning = warningOptional.orElse(new Warning(new GuildUserId(guildId, userId), 0)); - try { - additionWarnings = Integer.parseInt(warnings); - } catch (NumberFormatException ignored) { - } + int additionWarnings = 1; - warning.setWarnings(warning.getWarnings() + additionWarnings); + try { + additionWarnings = Integer.parseInt(warnings); + } catch (NumberFormatException ignored) { + } - warning = SQLSession.getSqlConnector().getSqlWorker().updateEntity(warning); + warning.setWarnings(warning.getWarnings() + additionWarnings); - return new WarningContainer(warning, new UserContainer(member)); + return SQLSession.getSqlConnector().getSqlWorker().updateEntity(warning) + .map(updatedWarning -> Optional.of(new WarningContainer(updatedWarning, new UserContainer(member)))) + .block(); + }) + .block(); + }); } - public WarningContainer removeWarnings(String sessionIdentifier, long guildId, long userId, String warnings) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, false); - - Member member = guildContainer.getGuild().retrieveMemberById(userId).complete(); - - if (member == null) { - throw new IllegalAccessException("Member not found"); - } - - Warning warning = SQLSession.getSqlConnector().getSqlWorker().getEntity(new Warning(), - "FROM Warning WHERE guildUserId.guildId = :gid AND guildUserId.userId = :uid", - Map.of("gid", guildId, "uid", userId)); - - if (warning == null) { - warning = new Warning(new GuildUserId(guildId, userId), 0); - } - - int additionWarnings = 1; - - try { - additionWarnings = Integer.parseInt(warnings); - } catch (NumberFormatException ignored) { - } + public Mono> removeWarnings(String sessionIdentifier, long guildId, long userId, String warnings) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, false) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return Optional.empty(); + } - warning.setWarnings(warning.getWarnings() - additionWarnings); + GuildContainer guildContainer = guildContainerOptional.get(); - if (warning.getWarnings() < 0) - warning.setWarnings(0); + Member member = guildContainer.getGuild().retrieveMemberById(userId).complete(); - warning = SQLSession.getSqlConnector().getSqlWorker().updateEntity(warning); + if (member == null) { + return Optional.empty(); + } - return new WarningContainer(warning, new UserContainer(member)); + return SQLSession.getSqlConnector().getSqlWorker().getEntity(new Warning(), + "FROM Warning WHERE guildUserId.guildId = :gid AND guildUserId.userId = :uid", + Map.of("gid", guildId, "uid", userId)) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(warningOptional -> { + Warning warning = warningOptional.orElse(new Warning(new GuildUserId(guildId, userId), 0)); + int additionWarnings = 1; + + try { + additionWarnings = Integer.parseInt(warnings); + } catch (NumberFormatException ignored) { + } + + warning.setWarnings(warning.getWarnings() - additionWarnings); + + if (warning.getWarnings() < 0) + warning.setWarnings(0); + + return SQLSession.getSqlConnector().getSqlWorker().updateEntity(warning) + .map(updatedWarning -> Optional.of(new WarningContainer(updatedWarning, new UserContainer(member)))) + .block(); + }) + .block(); + }); } - public void clearWarnings(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, false); + public Mono clearWarnings(String sessionIdentifier, long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, false) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return false; + } - SQLSession.getSqlConnector().getSqlWorker().getEntityList(new Warning(), - "FROM Warning WHERE guildUserId.guildId = :gid", - Map.of("gid", guildId)).forEach(SQLSession.getSqlConnector().getSqlWorker()::deleteEntity); + return SQLSession.getSqlConnector().getSqlWorker().getEntityList(new Warning(), + "FROM Warning WHERE guildUserId.guildId = :gid", + Map.of("gid", guildId)).map(warnings -> { + warnings.forEach(warning -> + SQLSession.getSqlConnector().getSqlWorker().deleteEntity(warning).block()); + return true; + }).block(); + }); } //region Punishments - public List getPunishments(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, true); + public Mono> getPunishments(String sessionIdentifier, long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, true) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return Collections.emptyList(); + } + + GuildContainer guildContainer = guildContainerOptional.get(); - return SQLSession.getSqlConnector().getSqlWorker().getEntityList(new Punishments(), - "FROM Punishments WHERE guildAndId.guildId = :gid", - Map.of("gid", guildId)).stream().map(c -> new PunishmentContainer(c, guildContainer)).toList(); + return SQLSession.getSqlConnector().getSqlWorker().getEntityList(new Punishments(), + "FROM Punishments WHERE guildAndId.guildId = :gid", + Map.of("gid", guildId)).map(punishments -> punishments.stream().map(punishment -> new PunishmentContainer(punishment, guildContainer)).toList()) + .block(); + }); } - public void clearPunishments(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, false); + public Mono clearPunishments(String sessionIdentifier, long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, false) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return false; + } - SQLSession.getSqlConnector().getSqlWorker().getEntityList(new Punishments(), - "FROM Punishments WHERE guildAndId.guildId = :gid", - Map.of("gid", guildId)).forEach(c -> SQLSession.getSqlConnector().getSqlWorker().deleteEntity(c)); + return SQLSession.getSqlConnector().getSqlWorker().getEntityList(new Punishments(), + "FROM Punishments WHERE guildAndId.guildId = :gid", + Map.of("gid", guildId)).map(x -> { + x.forEach(punishment -> SQLSession.getSqlConnector().getSqlWorker().deleteEntity(punishment).block()); + return true; + }).block(); + }); } - public void removePunishments(String sessionIdentifier, long guildId, String punishmentId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, false); + public Mono removePunishments(String sessionIdentifier, long guildId, String punishmentId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, false) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return false; + } + + GuildContainer guildContainer = guildContainerOptional.get(); - Punishments punishments = SQLSession.getSqlConnector().getSqlWorker().getEntity(new Punishments(), - "FROM Punishments WHERE guildAndId.guildId = :gid AND id = :id", - Map.of("gid", guildId, "id", punishmentId)); + return SQLSession.getSqlConnector().getSqlWorker().getEntity(new Punishments(), + "FROM Punishments WHERE guildAndId.guildId = :gid AND id = :id", + Map.of("gid", guildId, "id", punishmentId)) + .publishOn(Schedulers.boundedElastic()) + .map(punishmentOptional -> { + if (punishmentOptional.isEmpty()) { + return false; + } - if (punishments == null) - throw new IllegalAccessException("Punishment not found"); + Punishments punishments = punishmentOptional.get(); - if (punishments.getGuild() != guildContainer.getGuild().getIdLong()) - throw new IllegalAccessException("Punishment not found"); + if (punishments.getGuild() != guildContainer.getGuild().getIdLong()) + return false; - SQLSession.getSqlConnector().getSqlWorker().deleteEntity(punishments); + SQLSession.getSqlConnector().getSqlWorker().deleteEntity(punishments).block(); + return true; + }) + .block(); + }); } - public PunishmentContainer addPunishments(String sessionIdentifier, long guildId, String neededWarnings, String action, String timeoutTime, long roleId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, true); + public Mono> addPunishments(String sessionIdentifier, long guildId, String neededWarnings, String action, String timeoutTime, long roleId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, true) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return Optional.empty(); + } - Punishments punishments = new Punishments(); - punishments.setGuildId(guildId); + GuildContainer guildContainer = guildContainerOptional.get(); - try { - int warnings = Integer.parseInt(neededWarnings); - if (warnings < 0) - throw new IllegalAccessException("Invalid warnings"); + Punishments punishments = new Punishments(); + punishments.setGuildId(guildId); - int actionInt = Integer.parseInt(action); + try { + int warnings = Integer.parseInt(neededWarnings); + if (warnings < 0) + return Optional.empty(); - if (actionInt < 0 || actionInt > 5) - throw new IllegalAccessException("Invalid action"); + int actionInt = Integer.parseInt(action); - if (actionInt == 2 || actionInt == 3) { - if (roleId != 0 || guildContainer.getGuild().getRoleById(roleId) == null) - throw new IllegalAccessException("Role not found"); - } + if (actionInt < 0 || actionInt > 5) + return Optional.empty(); - long timeout = timeoutTime != null ? Long.parseLong(timeoutTime) : 0; + if (actionInt == 2 || actionInt == 3) { + if (roleId != 0 || guildContainer.getGuild().getRoleById(roleId) == null) + return Optional.empty(); + } - punishments.setWarnings(warnings); - punishments.setAction(actionInt); + long timeout = timeoutTime != null ? Long.parseLong(timeoutTime) : 0; - if (timeoutTime != null) - punishments.setTimeoutTime(timeout); + punishments.setWarnings(warnings); + punishments.setAction(actionInt); - if (roleId != 0) - punishments.setRoleId(roleId); - } catch (NumberFormatException e) { - throw new IllegalAccessException("Invalid number format"); - } + if (timeoutTime != null) + punishments.setTimeoutTime(timeout); - return new PunishmentContainer(SQLSession.getSqlConnector().getSqlWorker().updateEntity(punishments), guildContainer); + if (roleId != 0) + punishments.setRoleId(roleId); + } catch (NumberFormatException e) { + return Optional.empty(); + } + + return SQLSession.getSqlConnector().getSqlWorker().updateEntity(punishments) + .map(x -> Optional.of(new PunishmentContainer(x, guildContainer))) + .block(); + }); } - //endregion +//endregion - //endregion +//endregion //region Custom Command - public List getCustomCommand(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, true, false); - - return SQLSession.getSqlConnector().getSqlWorker().getEntityList(new CustomCommand(), - "FROM CustomCommand WHERE guildId = :gid", - Map.of("gid", guildId)).stream().map(command -> new CustomCommandContainer(command, guildContainer)).toList(); - } - - public void removeCustomCommand(String sessionIdentifier, long guildId, String commandId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, false, false); - - CustomCommand command = SQLSession.getSqlConnector().getSqlWorker().getEntity(new CustomCommand(), - "FROM CustomCommand WHERE guildId = :gid AND id = :id", - Map.of("gid", guildId, "id", commandId)); + public Mono> getCustomCommand(String sessionIdentifier, long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, true, false) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return Collections.emptyList(); + } - if (command == null) - throw new IllegalAccessException("Command not found"); + GuildContainer guildContainer = guildContainerOptional.get(); - SQLSession.getSqlConnector().getSqlWorker().deleteEntity(command); + return SQLSession.getSqlConnector().getSqlWorker().getEntityList(new CustomCommand(), + "FROM CustomCommand WHERE guildId = :gid", + Map.of("gid", guildId)) + .map(customCommands -> customCommands.stream().map(command -> new CustomCommandContainer(command, guildContainer)).toList()) + .block(); + }); } - public CustomCommandContainer addCustomCommand(String sessionIdentifier, long guildId, String commandName, String channelId, String response, String embedJson) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, true, false); - - CustomCommand command = SQLSession.getSqlConnector().getSqlWorker().getEntity(new CustomCommand(), - "FROM CustomCommand WHERE guildId = :gid AND command = :name", - Map.of("gid", guildId, "name", commandName)); + public Mono removeCustomCommand(String sessionIdentifier, long guildId, String commandId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, false, false) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return false; + } - if (command == null) { - command = new CustomCommand(); - command.setGuildId(guildId); - command.setName(commandName); - } + return SQLSession.getSqlConnector().getSqlWorker().getEntity(new CustomCommand(), + "FROM CustomCommand WHERE guildId = :gid AND id = :id", + Map.of("gid", guildId, "id", commandId)) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(customCommandOptional -> { + if (customCommandOptional.isEmpty()) { + return false; + } - if (response != null) { - command.setMessageResponse(response); - } + CustomCommand customCommand = customCommandOptional.get(); - if (embedJson != null) { - command.setEmbedResponse(JsonParser.parseString(embedJson)); - } + return SQLSession.getSqlConnector().getSqlWorker().deleteEntity(customCommand).thenReturn(true).block(); + }).block(); + }); + } - try { - long channelIdNumber = Long.parseLong(channelId); - command.setChannelId(channelIdNumber); - } catch (NumberFormatException e) { - throw new IllegalAccessException("Invalid channel id"); - } + public Mono> addCustomCommand(String sessionIdentifier, long guildId, String commandName, String channelId, String response, String embedJson) { + CustomCommandContainer errorReturnValue = null; + return sessionService.retrieveGuild(sessionIdentifier, guildId, true, false) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return Optional.ofNullable(errorReturnValue); + } - return new CustomCommandContainer(SQLSession.getSqlConnector().getSqlWorker().updateEntity(command), guildContainer); + return SQLSession.getSqlConnector().getSqlWorker().getEntity(new CustomCommand(), + "FROM CustomCommand WHERE guildId = :gid AND command = :name", + Map.of("gid", guildId, "name", commandName)) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(customCommandOptional -> { + CustomCommand customCommand = customCommandOptional.orElseGet(() -> { + CustomCommand command = new CustomCommand(); + command.setGuildId(guildId); + command.setName(commandName); + return command; + }); + + if (response != null) { + customCommand.setMessageResponse(response); + } + + if (embedJson != null) { + customCommand.setEmbedResponse(JsonParser.parseString(embedJson)); + } + + try { + long channelIdNumber = Long.parseLong(channelId); + customCommand.setChannelId(channelIdNumber); + } catch (NumberFormatException e) { + return Optional.ofNullable(errorReturnValue); + } + + return SQLSession.getSqlConnector().getSqlWorker().updateEntity(customCommand) + .map(updated -> Optional.of(new CustomCommandContainer(updated, guildContainerOptional.get()))) + .block(); + }) + .block(); + }); } - //endregion +//endregion //region Reaction role - public List retrieveReactionRoles(String sessionIdentifier, long guildId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, true, true); - - List roles = SQLSession.getSqlConnector().getSqlWorker().getEntityList(new ReactionRole(), - "FROM ReactionRole WHERE guildUserId.guildId = :gid", - Map.of("gid", guildId)); - - Map> map = roles.stream().collect(Collectors.groupingBy(ReactionRole::getMessageId)); + public Mono> retrieveReactionRoles(String sessionIdentifier, long guildId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, true, true) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return Collections.emptyList(); + } - List messageReactionRoleContainers = new ArrayList<>(); + GuildContainer guildContainer = guildContainerOptional.get(); - Guild guild = guildContainer.getGuild(); + Guild guild = guildContainer.getGuild(); - map.forEach((key, value) -> { - if (value.isEmpty()) return; + return SQLSession.getSqlConnector().getSqlWorker().getEntityList(new ReactionRole(), + "FROM ReactionRole WHERE guildUserId.guildId = :gid", + Map.of("gid", guildId)) + .map(roles -> { + Map> map = roles.stream().collect(Collectors.groupingBy(ReactionRole::getMessageId)); - StandardGuildMessageChannel channel = guild.getChannelById(StandardGuildMessageChannel.class, value.get(0).getChannelId()); + List messageReactionRoleContainers = new ArrayList<>(); + map.forEach((key, value) -> { + if (value.isEmpty()) return; - if (channel == null) return; + StandardGuildMessageChannel channel = guild.getChannelById(StandardGuildMessageChannel.class, value.get(0).getChannelId()); - Message message = channel.retrieveMessageById(key).complete(); + if (channel == null) return; - MessageReactionRoleContainer messageReactionRoleContainer = new MessageReactionRoleContainer(); - messageReactionRoleContainer.setRoleReactions(value.stream() - .map(role -> new ReactionRoleContainer(role, guildContainer)) - .toList()); - messageReactionRoleContainer.setMessage(new MessageContainer(message)); - messageReactionRoleContainers.add(messageReactionRoleContainer); - }); + Message message = channel.retrieveMessageById(key).complete(); - return messageReactionRoleContainers; + MessageReactionRoleContainer messageReactionRoleContainer = new MessageReactionRoleContainer(); + messageReactionRoleContainer.setRoleReactions(value.stream() + .map(role -> new ReactionRoleContainer(role, guildContainer)) + .toList()); + messageReactionRoleContainer.setMessage(new MessageContainer(message)); + messageReactionRoleContainers.add(messageReactionRoleContainer); + }); + return messageReactionRoleContainers; + }) + .block(); + }); } - public void addReactionRole(String sessionIdentifier, long guildId, String emojiId, String formattedEmoji, long channelId, String messageId, long roleId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, true, true); - - Guild guild = guildContainer.getGuild(); + public Mono addReactionRole(String sessionIdentifier, long guildId, String emojiId, String formattedEmoji, long channelId, String messageId, long roleId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, true, true) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return false; + } - RoleContainer role = guildContainer.getRoleById(roleId); + GuildContainer guildContainer = guildContainerOptional.get(); + Guild guild = guildContainer.getGuild(); - if (role == null) - throw new IllegalAccessException("Role not found"); + RoleContainer role = guildContainer.getRoleById(roleId); - try { - long messageIdNumber = Long.parseLong(messageId); - long emojiIdNumber = Long.parseLong(emojiId); + if (role == null) return false; - if (formattedEmoji == null || formattedEmoji.isBlank()) { - throw new IllegalAccessException("Invalid emoji"); - } + try { + long messageIdNumber = Long.parseLong(messageId); + long emojiIdNumber = Long.parseLong(emojiId); - Message message = guild.getTextChannelById(channelId).retrieveMessageById(messageIdNumber).complete(); + if (formattedEmoji == null || formattedEmoji.isBlank()) { + return false; + } - if (message == null) - throw new IllegalAccessException("Message not found"); + Message message = guild.getTextChannelById(channelId).retrieveMessageById(messageIdNumber).complete(); - //message.addReaction(Emoji.fromFormatted(emojiIdNumber)).queue(); + if (message == null) + return false; - ReactionRole reactionRole = new ReactionRole(); - reactionRole.setChannelId(channelId); - reactionRole.setEmoteId(emojiIdNumber); - reactionRole.setFormattedEmote(formattedEmoji); - reactionRole.setGuildId(guild.getIdLong()); - reactionRole.setMessageId(messageIdNumber); - reactionRole.getGuildRoleId().setRoleId(role.getId()); + //message.addReaction(Emoji.fromFormatted(emojiIdNumber)).queue(); - SQLSession.getSqlConnector().getSqlWorker().updateEntity(reactionRole); - } catch (NumberFormatException e) { - throw new IllegalAccessException("Invalid number format"); - } + ReactionRole reactionRole = new ReactionRole(); + reactionRole.setChannelId(channelId); + reactionRole.setEmoteId(emojiIdNumber); + reactionRole.setFormattedEmote(formattedEmoji); + reactionRole.setGuildId(guild.getIdLong()); + reactionRole.setMessageId(messageIdNumber); + reactionRole.getGuildRoleId().setRoleId(role.getId()); + return SQLSession.getSqlConnector().getSqlWorker().updateEntity(reactionRole).thenReturn(true).block(); + } catch (NumberFormatException e) { + return false; + } + }); } - public void removeReactionRole(String sessionIdentifier, long guildId, String emojiId, String messageId) throws IllegalAccessException { - GuildContainer guildContainer = sessionService.retrieveGuild(sessionIdentifier, guildId, true, true); - - Guild guild = guildContainer.getGuild(); - + public Mono removeReactionRole(String sessionIdentifier, long guildId, String emojiId, String messageId) { + return sessionService.retrieveGuild(sessionIdentifier, guildId, true, true) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(guildContainerOptional -> { + if (guildContainerOptional.isEmpty()) { + return false; + } - try { - long messageIdNumber = Long.parseLong(messageId); - long emojiIdNumber = Long.parseLong(emojiId); + GuildContainer guildContainer = guildContainerOptional.get(); - //message.removeReaction(Emoji.fromFormatted(emojiIdNumber)).queue(); + try { + long messageIdNumber = Long.parseLong(messageId); + long emojiIdNumber = Long.parseLong(emojiId); - ReactionRole reactionRole = SQLSession.getSqlConnector().getSqlWorker().getEntity(new ReactionRole(), - "FROM ReactionRole WHERE guildAndId.guildId = :gid AND messageId = :mid AND emoteId = :eid", - Map.of("gid", guildId, "mid", messageId, "eid", emojiId)); + //message.removeReaction(Emoji.fromFormatted(emojiIdNumber)).queue(); - if (reactionRole == null) - throw new IllegalAccessException("Reaction role not found"); + return SQLSession.getSqlConnector().getSqlWorker().getEntity(new ReactionRole(), + "FROM ReactionRole WHERE guildAndId.guildId = :gid AND messageId = :mid AND emoteId = :eid", + Map.of("gid", guildId, "mid", messageId, "eid", emojiId)) + .publishOn(Schedulers.boundedElastic()) + .mapNotNull(reactionRoleOptional -> { + if (reactionRoleOptional.isEmpty()) { + return false; + } - SQLSession.getSqlConnector().getSqlWorker().deleteEntity(reactionRole); - } catch (NumberFormatException e) { - throw new IllegalAccessException("Invalid number format"); - } + return SQLSession.getSqlConnector().getSqlWorker().deleteEntity(reactionRoleOptional.get()).thenReturn(true).block(); + }).block(); + } catch (NumberFormatException e) { + return false; + } + }); } - //endregion -} +//endregion +} \ No newline at end of file diff --git a/Backend/src/main/java/de/presti/ree6/backend/service/SessionService.java b/Backend/src/main/java/de/presti/ree6/backend/service/SessionService.java index 954f1b47..7d2c3218 100644 --- a/Backend/src/main/java/de/presti/ree6/backend/service/SessionService.java +++ b/Backend/src/main/java/de/presti/ree6/backend/service/SessionService.java @@ -9,17 +9,21 @@ import de.presti.ree6.backend.utils.RandomUtils; import de.presti.ree6.backend.utils.data.container.guild.GuildContainer; import de.presti.ree6.backend.utils.data.container.SessionContainer; +import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; import java.util.Collections; import java.util.List; +import java.util.Optional; /** * Service meant to handle Sessions. */ +@Slf4j @Service public class SessionService { @@ -28,28 +32,30 @@ public class SessionService { * * @param identifier Identifier to identify the Session. * @return Session Container with the Session. - * @throws IllegalAccessException If the Session could not be found. */ - public SessionContainer retrieveSession(String identifier) throws IllegalAccessException { - try { - // Try retrieving the Session from the Identifier. - Session session = Server.getInstance().getOAuth2Client().getSessionController().getSession(identifier); + public Mono> retrieveSession(String identifier) { + return Mono.fromSupplier(() -> { + try { + // Try retrieving the Session from the Identifier. + Session session = Server.getInstance().getOAuth2Client().getSessionController().getSession(identifier); + + if (session == null) { + throw new IllegalAccessException("Session not found!"); + } - if (session == null) { - throw new IllegalAccessException("Session not found!"); - } + // Try retrieving the User from the Session. + OAuth2User oAuth2User = Server.getInstance().getOAuth2Client().getUser(session).complete(); - // Try retrieving the User from the Session. - OAuth2User oAuth2User = Server.getInstance().getOAuth2Client().getUser(session).complete(); + if (oAuth2User == null) { + throw new IllegalAccessException("User not found!"); + } - if (oAuth2User == null) { - throw new IllegalAccessException("User not found!"); + return Optional.of(new SessionContainer("", session, oAuth2User)); + } catch (Exception ex) { + log.debug(ex.getMessage(), ex); + return Optional.empty(); } - - return new SessionContainer("", session, oAuth2User); - } catch (Exception ignore) { - throw new IllegalAccessException("Session not found!"); - } + }); } /** @@ -58,34 +64,36 @@ public SessionContainer retrieveSession(String identifier) throws IllegalAccessE * @param code Code to create the Session. * @param state State to create the Session. * @return Session Container with the Session. - * @throws IllegalAccessException If the Session could not be created. */ - public SessionContainer createSession(String code, String state) throws IllegalAccessException { - // Generate a secure Base64 String for the Identifier. - String identifier = RandomUtils.getRandomBase64String(128); + public Mono> createSession(String code, String state) { + return Mono.fromSupplier(() -> { + // Generate a secure Base64 String for the Identifier. + String identifier = RandomUtils.getRandomBase64String(128); - try { - // Try creating a Session. - Session session = Server.getInstance().getOAuth2Client().startSession(code, state, identifier, Scope.GUILDS, Scope.IDENTIFY, Scope.GUILDS_JOIN).complete(); + try { + // Try creating a Session. + Session session = Server.getInstance().getOAuth2Client().startSession(code, state, identifier, Scope.GUILDS, Scope.IDENTIFY, Scope.GUILDS_JOIN).complete(); - // If the given data was valid and a Session has been created redirect to the panel Site. If not redirect to error. - if (session != null) { + // If the given data was valid and a Session has been created redirect to the panel Site. If not redirect to error. + if (session != null) { - // Try retrieving the User from the Session. - OAuth2User oAuth2User = Server.getInstance().getOAuth2Client().getUser(session).complete(); + // Try retrieving the User from the Session. + OAuth2User oAuth2User = Server.getInstance().getOAuth2Client().getUser(session).complete(); - if (oAuth2User == null) { - throw new IllegalAccessException("User not found!"); + if (oAuth2User == null) { + throw new IllegalAccessException("User not found!"); + } + + return Optional.of(new SessionContainer(identifier, session, Server.getInstance().getOAuth2Client().getUser(session).complete())); + } else { + throw new IllegalStateException("Session creation failed!"); } - return new SessionContainer(identifier, session, Server.getInstance().getOAuth2Client().getUser(session).complete()); - } else { - throw new IllegalStateException("Session creation failed!"); + } catch (Exception ex) { + log.debug(ex.getMessage(), ex); + return Optional.empty(); } - - } catch (Exception exception) { - throw new IllegalStateException(exception.getMessage()); - } + }); } /** @@ -94,9 +102,8 @@ public SessionContainer createSession(String code, String state) throws IllegalA * @param identifier Identifier to identify the Session. * @param guildId Guild ID to identify the Guild. * @return Guild Container with the Guild. - * @throws IllegalAccessException If the Guild could not be found. */ - public GuildContainer retrieveGuild(String identifier, long guildId) throws IllegalAccessException { + public Mono> retrieveGuild(String identifier, long guildId) { return retrieveGuild(identifier, guildId, false); } @@ -107,9 +114,8 @@ public GuildContainer retrieveGuild(String identifier, long guildId) throws Ille * @param guildId Guild ID to identify the Guild. * @param retrieveChannels If the Channels should be retrieved. * @return Guild Container with the Guild. - * @throws IllegalAccessException If the Guild could not be found. */ - public GuildContainer retrieveGuild(String identifier, long guildId, boolean retrieveChannels) throws IllegalAccessException { + public Mono> retrieveGuild(String identifier, long guildId, boolean retrieveChannels) { return retrieveGuild(identifier, guildId, retrieveChannels, false); } @@ -121,9 +127,8 @@ public GuildContainer retrieveGuild(String identifier, long guildId, boolean ret * @param retrieveChannels If the Channels should be retrieved. * @param retrieveRoles If the Roles should be retrieved. * @return Guild Container with the Guild. - * @throws IllegalAccessException If the Guild could not be found. */ - public GuildContainer retrieveGuild(String identifier, long guildId, boolean retrieveChannels, boolean retrieveRoles) throws IllegalAccessException { + public Mono> retrieveGuild(String identifier, long guildId, boolean retrieveChannels, boolean retrieveRoles) { return retrieveGuild(identifier, guildId, retrieveChannels, retrieveRoles, true); } @@ -136,41 +141,47 @@ public GuildContainer retrieveGuild(String identifier, long guildId, boolean ret * @param retrieveRoles If the Roles should be retrieved. * @param permissionCheck If the Permission should be checked. * @return Guild Container with the Guild. - * @throws IllegalAccessException If the Guild could not be found. */ - public GuildContainer retrieveGuild(String identifier, long guildId, boolean retrieveChannels, boolean retrieveRoles, boolean permissionCheck) throws IllegalAccessException { - SessionContainer sessionContainer = retrieveSession(identifier); - - OAuth2Guild oAuth2Guild = null; - try { - oAuth2Guild = Server.getInstance().getOAuth2Client().getGuilds(sessionContainer.getSession()).complete() - .stream().filter(c -> c.getIdLong() == guildId && c.hasPermission(Permission.ADMINISTRATOR)).findFirst().orElse(null); - } catch (Exception ignore) { - } - - // Retrieve the Guild by its giving ID. - Guild guild = BotWorker.getShardManager().getGuildById(guildId); - - // If the Guild couldn't be loaded, redirect to Error page. - if (guild == null) { - if (oAuth2Guild != null) { - return new GuildContainer(oAuth2Guild); - } else { - throw new IllegalAccessException("Guild not found!"); + public Mono> retrieveGuild(String identifier, long guildId, boolean retrieveChannels, boolean retrieveRoles, boolean permissionCheck) { + return retrieveSession(identifier).map(sessionOptional -> { + if (sessionOptional.isEmpty()) { + return Optional.empty(); } - } - Member member = guild.retrieveMemberById(sessionContainer.getUser().getId()).complete(); - if (permissionCheck) { - if (member == null || !member.hasPermission(Permission.ADMINISTRATOR)) { - throw new IllegalAccessException("Not enough permissions!"); + SessionContainer sessionContainer = sessionOptional.get(); + + OAuth2Guild oAuth2Guild = null; + try { + oAuth2Guild = Server.getInstance().getOAuth2Client().getGuilds(sessionContainer.getSession()).complete() + .stream().filter(c -> c.getIdLong() == guildId && c.hasPermission(Permission.ADMINISTRATOR)).findFirst().orElse(null); + } catch (Exception ignore) { } - } - GuildContainer guildContainer = new GuildContainer(guild, retrieveChannels, retrieveRoles); - guildContainer.setAdmin(member.hasPermission(Permission.ADMINISTRATOR)); + // Retrieve the Guild by its giving ID. + Guild guild = BotWorker.getShardManager().getGuildById(guildId); + + // If the Guild couldn't be loaded, redirect to Error page. + if (guild == null) { + if (oAuth2Guild != null) { + return Optional.of(new GuildContainer(oAuth2Guild)); + } else { + log.warn("Could not find guild with id {}", guildId); + return Optional.empty(); + } + } + + Member member = guild.retrieveMemberById(sessionContainer.getUser().getId()).complete(); + if (permissionCheck) { + if (member == null || !member.hasPermission(Permission.ADMINISTRATOR)) { + log.warn("User {} has not enough permission for {}", sessionContainer.getUser().getId(), guildId); + return Optional.empty(); + } + } - return guildContainer; + GuildContainer guildContainer = new GuildContainer(guild, retrieveChannels, retrieveRoles); + guildContainer.setAdmin(member.hasPermission(Permission.ADMINISTRATOR)); + return Optional.of(guildContainer); + }); } /** @@ -178,9 +189,8 @@ public GuildContainer retrieveGuild(String identifier, long guildId, boolean ret * * @param guildId Guild ID to identify the Guild. * @return Guild Container with the Guild. - * @throws IllegalAccessException If the Guild could not be found. */ - public GuildContainer retrieveGuild(long guildId) throws IllegalAccessException { + public Mono> retrieveGuild(long guildId) { return retrieveGuild(guildId, false); } @@ -190,17 +200,20 @@ public GuildContainer retrieveGuild(long guildId) throws IllegalAccessException * @param guildId Guild ID to identify the Guild. * @param retrieveChannels If the Channels should be retrieved. * @return Guild Container with the Guild. - * @throws IllegalAccessException If the Guild could not be found. */ - public GuildContainer retrieveGuild(long guildId, boolean retrieveChannels) throws IllegalAccessException { - - // Retrieve the Guild by its giving ID. - Guild guild = BotWorker.getShardManager().getGuildById(guildId); - - // If the Guild couldn't be loaded, redirect to Error page. - if (guild == null) throw new IllegalAccessException("Guild not found!"); + public Mono> retrieveGuild(long guildId, boolean retrieveChannels) { + return Mono.fromSupplier(() -> { + // Retrieve the Guild by its giving ID. + Guild guild = BotWorker.getShardManager().getGuildById(guildId); + + // If the Guild couldn't be loaded, redirect to Error page. + if (guild == null) { + log.warn("Could not find guild with id {}", guildId); + return Optional.empty(); + } - return new GuildContainer(guild, retrieveChannels); + return Optional.of(new GuildContainer(guild, retrieveChannels)); + }); } /** @@ -208,9 +221,8 @@ public GuildContainer retrieveGuild(long guildId, boolean retrieveChannels) thro * * @param identifier Identifier to identify the Session. * @return List of Guild Containers with the Guilds. - * @throws IllegalAccessException If the Guilds could not be found. */ - public List retrieveGuilds(String identifier) throws IllegalAccessException { + public Mono>> retrieveGuilds(String identifier) { return retrieveGuilds(identifier, false); } @@ -220,20 +232,27 @@ public List retrieveGuilds(String identifier) throws IllegalAcce * @param identifier Identifier to identify the Session. * @param permissionFilter If the Guilds should be filtered by the Permission. * @return List of Guild Containers with the Guilds. - * @throws IllegalAccessException If the Guilds could not be found. */ - public List retrieveGuilds(String identifier, boolean permissionFilter) throws IllegalAccessException { - SessionContainer sessionContainer = retrieveSession(identifier); - List guilds = Collections.emptyList(); + public Mono>> retrieveGuilds(String identifier, boolean permissionFilter) { + return retrieveSession(identifier).map(sessionOptional -> { + if (sessionOptional.isEmpty()) { + return Optional.empty(); + } - try { - guilds = Server.getInstance().getOAuth2Client().getGuilds(sessionContainer.getSession()).complete(); + SessionContainer sessionContainer = sessionOptional.get(); + List guilds = Collections.emptyList(); + + try { + guilds = Server.getInstance().getOAuth2Client().getGuilds(sessionContainer.getSession()).complete(); + + if (permissionFilter) + guilds.removeIf(oAuth2Guild -> !oAuth2Guild.hasPermission(Permission.ADMINISTRATOR)); + } catch (Exception ignore) { + } - if (permissionFilter) - guilds.removeIf(oAuth2Guild -> !oAuth2Guild.hasPermission(Permission.ADMINISTRATOR)); - } catch (Exception ignore) { - } + if (guilds == null) return Optional.empty(); - return guilds.stream().map(GuildContainer::new).toList(); + return Optional.of(guilds.stream().map(GuildContainer::new).toList()); + }); } } diff --git a/Backend/src/main/java/de/presti/ree6/backend/utils/data/CustomOAuth2Util.java b/Backend/src/main/java/de/presti/ree6/backend/utils/data/CustomOAuth2Util.java index 29b2ce1e..e83ffa98 100644 --- a/Backend/src/main/java/de/presti/ree6/backend/utils/data/CustomOAuth2Util.java +++ b/Backend/src/main/java/de/presti/ree6/backend/utils/data/CustomOAuth2Util.java @@ -33,7 +33,7 @@ public static CustomOAuth2Credential convert(long discordId, OAuth2Credential oA // OAuth2 OAuth2IdentityProvider oAuth2IdentityProvider = Server.getInstance().getCredentialManager().getIdentityProviderByName("twitch") .filter(idp -> idp.getProviderType().equalsIgnoreCase("oauth2") && idp instanceof OAuth2IdentityProvider) - .map(idp -> (OAuth2IdentityProvider) idp) + .map(OAuth2IdentityProvider.class::cast) .orElseThrow(() -> new RuntimeException("Can't find a unique identity provider for the specified credential!")); Optional enrichedCredential = oAuth2IdentityProvider.getAdditionalCredentialInformation(oAuth2Credential); diff --git a/Backend/src/main/java/de/presti/ree6/backend/utils/data/DatabaseStorageBackend.java b/Backend/src/main/java/de/presti/ree6/backend/utils/data/DatabaseStorageBackend.java index a92c8f95..25a97476 100644 --- a/Backend/src/main/java/de/presti/ree6/backend/utils/data/DatabaseStorageBackend.java +++ b/Backend/src/main/java/de/presti/ree6/backend/utils/data/DatabaseStorageBackend.java @@ -21,11 +21,13 @@ public class DatabaseStorageBackend implements IStorageBackend { public List loadCredentials() { List twitchIntegrations = SQLSession.getSqlConnector().getSqlWorker().getEntityList(new TwitchIntegration(), - "FROM TwitchIntegration", null); + "FROM TwitchIntegration", null).block(); List credentials = new ArrayList<>(); - twitchIntegrations.forEach(twitchIntegration -> credentials.add(new CustomOAuth2Credential(twitchIntegration.getUserId(),"twitch", twitchIntegration.getToken(), + if (twitchIntegrations == null) return credentials; + + twitchIntegrations.forEach(twitchIntegration -> credentials.add(new CustomOAuth2Credential(twitchIntegration.getUserId(), "twitch", twitchIntegration.getToken(), twitchIntegration.getRefresh(), twitchIntegration.getChannelId(), twitchIntegration.getName(), twitchIntegration.getExpiresIn(), Collections.emptyList()))); return credentials; @@ -40,21 +42,21 @@ public List loadCredentials() { public void saveCredentials(List list) { list.forEach(credential -> { if (credential instanceof CustomOAuth2Credential oAuth2Credential) { - TwitchIntegration twitchIntegration = - SQLSession.getSqlConnector().getSqlWorker().getEntity(new TwitchIntegration(), - "FROM TwitchIntegration WHERE channelId = :userid", Map.of("userid",oAuth2Credential.getUserId())); - - if (twitchIntegration == null) { - twitchIntegration = new TwitchIntegration(); - twitchIntegration.setChannelId(oAuth2Credential.getUserId()); - twitchIntegration.setUserId(oAuth2Credential.getDiscordId()); - } + SQLSession.getSqlConnector().getSqlWorker().getEntity(new TwitchIntegration(), + "FROM TwitchIntegration WHERE channelId = :userid", Map.of("userid", oAuth2Credential.getUserId())).subscribe(twitchIntegrationOptional -> { + TwitchIntegration twitchIntegration = twitchIntegrationOptional.orElseGet(() -> { + TwitchIntegration newIntegration = new TwitchIntegration(); + newIntegration.setChannelId(oAuth2Credential.getUserId()); + newIntegration.setUserId(oAuth2Credential.getDiscordId()); + return newIntegration; + }); - twitchIntegration.setToken(oAuth2Credential.getAccessToken()); - twitchIntegration.setRefresh(oAuth2Credential.getRefreshToken()); - twitchIntegration.setName(oAuth2Credential.getUserName()); - twitchIntegration.setExpiresIn(oAuth2Credential.getExpiresIn()); - SQLSession.getSqlConnector().getSqlWorker().updateEntity(twitchIntegration); + twitchIntegration.setToken(oAuth2Credential.getAccessToken()); + twitchIntegration.setRefresh(oAuth2Credential.getRefreshToken()); + twitchIntegration.setName(oAuth2Credential.getUserName()); + twitchIntegration.setExpiresIn(oAuth2Credential.getExpiresIn()); + SQLSession.getSqlConnector().getSqlWorker().updateEntity(twitchIntegration).block(); + }); } }); } @@ -67,13 +69,13 @@ public void saveCredentials(List list) { */ @Override public Optional getCredentialByUserId(String userId) { - Optional twitchIntegration = Optional.ofNullable(SQLSession.getSqlConnector().getSqlWorker().getEntity(new TwitchIntegration(), - "FROM TwitchIntegration WHERE channelId = :userid", Map.of("userid", userId))); + Optional twitchIntegration = SQLSession.getSqlConnector().getSqlWorker().getEntity(new TwitchIntegration(), + "FROM TwitchIntegration WHERE channelId = :userid", Map.of("userid", userId)).block(); - if (twitchIntegration.isPresent()) { + if (twitchIntegration != null && twitchIntegration.isPresent()) { TwitchIntegration twitchIntegration1 = twitchIntegration.get(); CustomOAuth2Credential oAuth2Credential - = new CustomOAuth2Credential(twitchIntegration1.getUserId(),"twitch", twitchIntegration1.getToken(), + = new CustomOAuth2Credential(twitchIntegration1.getUserId(), "twitch", twitchIntegration1.getToken(), twitchIntegration1.getRefresh(), twitchIntegration1.getChannelId(), twitchIntegration1.getName(), twitchIntegration1.getExpiresIn(), Collections.emptyList()); return Optional.of(oAuth2Credential); diff --git a/Backend/src/main/java/de/presti/ree6/backend/utils/data/container/ChannelContainer.java b/Backend/src/main/java/de/presti/ree6/backend/utils/data/container/ChannelContainer.java index fedfc271..144f4f26 100644 --- a/Backend/src/main/java/de/presti/ree6/backend/utils/data/container/ChannelContainer.java +++ b/Backend/src/main/java/de/presti/ree6/backend/utils/data/container/ChannelContainer.java @@ -27,6 +27,8 @@ public class ChannelContainer { String name; ChannelType type; + public static ChannelContainer DEFAULT = new ChannelContainer(-1, -1, "None", ChannelType.TEXT); + public ChannelContainer(StandardGuildMessageChannel guildChannel) { this.id = guildChannel.getIdLong(); this.guildId = guildChannel.getGuild().getIdLong(); diff --git a/Backend/src/main/java/de/presti/ree6/backend/utils/data/container/TicketContainer.java b/Backend/src/main/java/de/presti/ree6/backend/utils/data/container/TicketContainer.java index ea147bbf..f8ab42ef 100644 --- a/Backend/src/main/java/de/presti/ree6/backend/utils/data/container/TicketContainer.java +++ b/Backend/src/main/java/de/presti/ree6/backend/utils/data/container/TicketContainer.java @@ -12,6 +12,8 @@ @AllArgsConstructor public class TicketContainer { + public static TicketContainer DEFAULT = new TicketContainer(null, null, 0, null, "", ""); + public ChannelContainer channel; public ChannelContainer category; diff --git a/Frontend/package-lock.json b/Frontend/package-lock.json index 1dd967f5..7984ec71 100644 --- a/Frontend/package-lock.json +++ b/Frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "frontend", - "version": "0.0.1", + "version": "2.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "frontend", - "version": "0.0.1", + "version": "2.0.0", "dependencies": { "sass": "^1.59.3" }, @@ -767,9 +767,9 @@ "license": "MIT" }, "node_modules/@rollup/rollup-android-arm-eabi": { - "version": "4.24.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.24.0.tgz", - "integrity": "sha512-Q6HJd7Y6xdB48x8ZNVDOqsbh2uByBhgK8PiQgPhwkIw/HC/YX5Ghq2mQY5sRMZWHb3VsFkWooUVOZHKr7DmDIA==", + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.24.3.tgz", + "integrity": "sha512-ufb2CH2KfBWPJok95frEZZ82LtDl0A6QKTa8MoM+cWwDZvVGl5/jNb79pIhRvAalUu+7LD91VYR0nwRD799HkQ==", "cpu": [ "arm" ], @@ -781,9 +781,9 @@ ] }, "node_modules/@rollup/rollup-android-arm64": { - "version": "4.24.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.24.0.tgz", - "integrity": "sha512-ijLnS1qFId8xhKjT81uBHuuJp2lU4x2yxa4ctFPtG+MqEE6+C5f/+X/bStmxapgmwLwiL3ih122xv8kVARNAZA==", + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.24.3.tgz", + "integrity": "sha512-iAHpft/eQk9vkWIV5t22V77d90CRofgR2006UiCjHcHJFVI1E0oBkQIAbz+pLtthFw3hWEmVB4ilxGyBf48i2Q==", "cpu": [ "arm64" ], @@ -795,9 +795,9 @@ ] }, "node_modules/@rollup/rollup-darwin-arm64": { - "version": "4.24.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.24.0.tgz", - "integrity": "sha512-bIv+X9xeSs1XCk6DVvkO+S/z8/2AMt/2lMqdQbMrmVpgFvXlmde9mLcbQpztXm1tajC3raFDqegsH18HQPMYtA==", + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.24.3.tgz", + "integrity": "sha512-QPW2YmkWLlvqmOa2OwrfqLJqkHm7kJCIMq9kOz40Zo9Ipi40kf9ONG5Sz76zszrmIZZ4hgRIkez69YnTHgEz1w==", "cpu": [ "arm64" ], @@ -809,9 +809,9 @@ ] }, "node_modules/@rollup/rollup-darwin-x64": { - "version": "4.24.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.24.0.tgz", - "integrity": "sha512-X6/nOwoFN7RT2svEQWUsW/5C/fYMBe4fnLK9DQk4SX4mgVBiTA9h64kjUYPvGQ0F/9xwJ5U5UfTbl6BEjaQdBQ==", + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.24.3.tgz", + "integrity": "sha512-KO0pN5x3+uZm1ZXeIfDqwcvnQ9UEGN8JX5ufhmgH5Lz4ujjZMAnxQygZAVGemFWn+ZZC0FQopruV4lqmGMshow==", "cpu": [ "x64" ], @@ -822,10 +822,38 @@ "darwin" ] }, + "node_modules/@rollup/rollup-freebsd-arm64": { + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.24.3.tgz", + "integrity": "sha512-CsC+ZdIiZCZbBI+aRlWpYJMSWvVssPuWqrDy/zi9YfnatKKSLFCe6fjna1grHuo/nVaHG+kiglpRhyBQYRTK4A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/@rollup/rollup-freebsd-x64": { + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.24.3.tgz", + "integrity": "sha512-F0nqiLThcfKvRQhZEzMIXOQG4EeX61im61VYL1jo4eBxv4aZRmpin6crnBJQ/nWnCsjH5F6J3W6Stdm0mBNqBg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, "node_modules/@rollup/rollup-linux-arm-gnueabihf": { - "version": "4.24.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.24.0.tgz", - "integrity": "sha512-0KXvIJQMOImLCVCz9uvvdPgfyWo93aHHp8ui3FrtOP57svqrF/roSSR5pjqL2hcMp0ljeGlU4q9o/rQaAQ3AYA==", + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.24.3.tgz", + "integrity": "sha512-KRSFHyE/RdxQ1CSeOIBVIAxStFC/hnBgVcaiCkQaVC+EYDtTe4X7z5tBkFyRoBgUGtB6Xg6t9t2kulnX6wJc6A==", "cpu": [ "arm" ], @@ -837,9 +865,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm-musleabihf": { - "version": "4.24.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.24.0.tgz", - "integrity": "sha512-it2BW6kKFVh8xk/BnHfakEeoLPv8STIISekpoF+nBgWM4d55CZKc7T4Dx1pEbTnYm/xEKMgy1MNtYuoA8RFIWw==", + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.24.3.tgz", + "integrity": "sha512-h6Q8MT+e05zP5BxEKz0vi0DhthLdrNEnspdLzkoFqGwnmOzakEHSlXfVyA4HJ322QtFy7biUAVFPvIDEDQa6rw==", "cpu": [ "arm" ], @@ -851,9 +879,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-gnu": { - "version": "4.24.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.24.0.tgz", - "integrity": "sha512-i0xTLXjqap2eRfulFVlSnM5dEbTVque/3Pi4g2y7cxrs7+a9De42z4XxKLYJ7+OhE3IgxvfQM7vQc43bwTgPwA==", + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.24.3.tgz", + "integrity": "sha512-fKElSyXhXIJ9pqiYRqisfirIo2Z5pTTve5K438URf08fsypXrEkVmShkSfM8GJ1aUyvjakT+fn2W7Czlpd/0FQ==", "cpu": [ "arm64" ], @@ -865,9 +893,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-musl": { - "version": "4.24.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.24.0.tgz", - "integrity": "sha512-9E6MKUJhDuDh604Qco5yP/3qn3y7SLXYuiC0Rpr89aMScS2UAmK1wHP2b7KAa1nSjWJc/f/Lc0Wl1L47qjiyQw==", + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.24.3.tgz", + "integrity": "sha512-YlddZSUk8G0px9/+V9PVilVDC6ydMz7WquxozToozSnfFK6wa6ne1ATUjUvjin09jp34p84milxlY5ikueoenw==", "cpu": [ "arm64" ], @@ -879,9 +907,9 @@ ] }, "node_modules/@rollup/rollup-linux-powerpc64le-gnu": { - "version": "4.24.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.24.0.tgz", - "integrity": "sha512-2XFFPJ2XMEiF5Zi2EBf4h73oR1V/lycirxZxHZNc93SqDN/IWhYYSYj8I9381ikUFXZrz2v7r2tOVk2NBwxrWw==", + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.24.3.tgz", + "integrity": "sha512-yNaWw+GAO8JjVx3s3cMeG5Esz1cKVzz8PkTJSfYzE5u7A+NvGmbVFEHP+BikTIyYWuz0+DX9kaA3pH9Sqxp69g==", "cpu": [ "ppc64" ], @@ -893,9 +921,9 @@ ] }, "node_modules/@rollup/rollup-linux-riscv64-gnu": { - "version": "4.24.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.24.0.tgz", - "integrity": "sha512-M3Dg4hlwuntUCdzU7KjYqbbd+BLq3JMAOhCKdBE3TcMGMZbKkDdJ5ivNdehOssMCIokNHFOsv7DO4rlEOfyKpg==", + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.24.3.tgz", + "integrity": "sha512-lWKNQfsbpv14ZCtM/HkjCTm4oWTKTfxPmr7iPfp3AHSqyoTz5AgLemYkWLwOBWc+XxBbrU9SCokZP0WlBZM9lA==", "cpu": [ "riscv64" ], @@ -907,9 +935,9 @@ ] }, "node_modules/@rollup/rollup-linux-s390x-gnu": { - "version": "4.24.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.24.0.tgz", - "integrity": "sha512-mjBaoo4ocxJppTorZVKWFpy1bfFj9FeCMJqzlMQGjpNPY9JwQi7OuS1axzNIk0nMX6jSgy6ZURDZ2w0QW6D56g==", + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.24.3.tgz", + "integrity": "sha512-HoojGXTC2CgCcq0Woc/dn12wQUlkNyfH0I1ABK4Ni9YXyFQa86Fkt2Q0nqgLfbhkyfQ6003i3qQk9pLh/SpAYw==", "cpu": [ "s390x" ], @@ -921,9 +949,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-gnu": { - "version": "4.24.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.24.0.tgz", - "integrity": "sha512-ZXFk7M72R0YYFN5q13niV0B7G8/5dcQ9JDp8keJSfr3GoZeXEoMHP/HlvqROA3OMbMdfr19IjCeNAnPUG93b6A==", + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.24.3.tgz", + "integrity": "sha512-mnEOh4iE4USSccBOtcrjF5nj+5/zm6NcNhbSEfR3Ot0pxBwvEn5QVUXcuOwwPkapDtGZ6pT02xLoPaNv06w7KQ==", "cpu": [ "x64" ], @@ -935,9 +963,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-musl": { - "version": "4.24.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.24.0.tgz", - "integrity": "sha512-w1i+L7kAXZNdYl+vFvzSZy8Y1arS7vMgIy8wusXJzRrPyof5LAb02KGr1PD2EkRcl73kHulIID0M501lN+vobQ==", + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.24.3.tgz", + "integrity": "sha512-rMTzawBPimBQkG9NKpNHvquIUTQPzrnPxPbCY1Xt+mFkW7pshvyIS5kYgcf74goxXOQk0CP3EoOC1zcEezKXhw==", "cpu": [ "x64" ], @@ -949,9 +977,9 @@ ] }, "node_modules/@rollup/rollup-win32-arm64-msvc": { - "version": "4.24.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.24.0.tgz", - "integrity": "sha512-VXBrnPWgBpVDCVY6XF3LEW0pOU51KbaHhccHw6AS6vBWIC60eqsH19DAeeObl+g8nKAz04QFdl/Cefta0xQtUQ==", + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.24.3.tgz", + "integrity": "sha512-2lg1CE305xNvnH3SyiKwPVsTVLCg4TmNCF1z7PSHX2uZY2VbUpdkgAllVoISD7JO7zu+YynpWNSKAtOrX3AiuA==", "cpu": [ "arm64" ], @@ -963,9 +991,9 @@ ] }, "node_modules/@rollup/rollup-win32-ia32-msvc": { - "version": "4.24.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.24.0.tgz", - "integrity": "sha512-xrNcGDU0OxVcPTH/8n/ShH4UevZxKIO6HJFK0e15XItZP2UcaiLFd5kiX7hJnqCbSztUF8Qot+JWBC/QXRPYWQ==", + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.24.3.tgz", + "integrity": "sha512-9SjYp1sPyxJsPWuhOCX6F4jUMXGbVVd5obVpoVEi8ClZqo52ViZewA6eFz85y8ezuOA+uJMP5A5zo6Oz4S5rVQ==", "cpu": [ "ia32" ], @@ -977,9 +1005,9 @@ ] }, "node_modules/@rollup/rollup-win32-x64-msvc": { - "version": "4.24.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.24.0.tgz", - "integrity": "sha512-fbMkAF7fufku0N2dE5TBXcNlg0pt0cJue4xBRE2Qc5Vqikxr4VCgKj/ht6SMdFcOacVA9rqF70APJ8RN/4vMJw==", + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.24.3.tgz", + "integrity": "sha512-HGZgRFFYrMrP3TJlq58nR1xy8zHKId25vhmm5S9jETEfDf6xybPxsavFTJaufe2zgOGYJBskGlj49CwtEuFhWQ==", "cpu": [ "x64" ], @@ -991,9 +1019,9 @@ ] }, "node_modules/@sveltejs/adapter-auto": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/@sveltejs/adapter-auto/-/adapter-auto-3.3.0.tgz", - "integrity": "sha512-EJZqY7eMM+bdbR898Xt9ufawUHLPJu7w3wPr4Cc+T1iIDf3fufVLWg4C71OluIqsdJqv85E4biKuHo3XXIY0PQ==", + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/@sveltejs/adapter-auto/-/adapter-auto-3.3.1.tgz", + "integrity": "sha512-5Sc7WAxYdL6q9j/+D0jJKjGREGlfIevDyHSQ2eNETHcB1TKlQWHcAo8AS8H1QdjNvSXpvOwNjykDUHPEAyGgdQ==", "dev": true, "license": "MIT", "dependencies": { @@ -1004,9 +1032,9 @@ } }, "node_modules/@sveltejs/adapter-netlify": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/@sveltejs/adapter-netlify/-/adapter-netlify-4.3.5.tgz", - "integrity": "sha512-3Gvk8WumDXw35xurzkUHw3fWoKlDXzcSpP76gNeHNx2AFuTtaOcv/utVLAtdmC1FyfpHk4YwAGzyEvFmmaJhwg==", + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/@sveltejs/adapter-netlify/-/adapter-netlify-4.3.6.tgz", + "integrity": "sha512-o1M8SlNeXiTD4X9T/q+WZaeStEzRlGZeMc/NHrgK5dhnrJhN3UFzMqFV4mnNAVyxqyvsQ87FYyjPlkDualSwRA==", "dev": true, "license": "MIT", "dependencies": { @@ -1019,9 +1047,9 @@ } }, "node_modules/@sveltejs/kit": { - "version": "2.7.2", - "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.7.2.tgz", - "integrity": "sha512-bFwrl+0bNr0/DHQZM0INwwSPNYqDjfsKRhUoa6rj9d8tDZzszBrJ3La6/HVFxWGONEigtG+SzHXa1BEa1BLdwA==", + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.7.3.tgz", + "integrity": "sha512-Vx7nq5MJ86I8qXYsVidC5PX6xm+uxt8DydvOdmJoyOK7LvGP18OFEG359yY+aa51t6pENvqZAMqAREQQx1OI2Q==", "dev": true, "hasInstallScript": true, "license": "MIT", @@ -1075,9 +1103,9 @@ } }, "node_modules/@sveltejs/vite-plugin-svelte-inspector": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@sveltejs/vite-plugin-svelte-inspector/-/vite-plugin-svelte-inspector-3.0.0.tgz", - "integrity": "sha512-hBxSYW/66989cq9dN248omD/ziskSdIV1NqfuueuAI1z6jGcg14k9Zd98pDIEnoA6wC9kWUGuQ6adzBbWwQyRg==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@sveltejs/vite-plugin-svelte-inspector/-/vite-plugin-svelte-inspector-3.0.1.tgz", + "integrity": "sha512-2CKypmj1sM4GE7HjllT7UKmo4Q6L5xFRd7VMGEWhYnZ+wc6AUVU01IBd7yUi6WnFndEwWoMNOd6e8UjoN0nbvQ==", "dev": true, "license": "MIT", "peer": true, @@ -1108,9 +1136,9 @@ "license": "MIT" }, "node_modules/acorn": { - "version": "8.13.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.13.0.tgz", - "integrity": "sha512-8zSiw54Oxrdym50NlZ9sUusyO1Z1ZchgRLWRaK6c86XJFClyCgFKetdowBg5bKxyp/u+CDBJG4Mpp0m3HLZl9w==", + "version": "8.14.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz", + "integrity": "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==", "dev": true, "license": "MIT", "bin": { @@ -1276,9 +1304,9 @@ } }, "node_modules/esm-env": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/esm-env/-/esm-env-1.0.0.tgz", - "integrity": "sha512-Cf6VksWPsTuW01vU9Mk/3vRue91Zevka5SjyNf3nEpokFRuqt/KjUQoGAwq9qMmhpLTHmXzSIrFRw8zxWzmFBA==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/esm-env/-/esm-env-1.1.4.tgz", + "integrity": "sha512-oO82nKPHKkzIj/hbtuDYy/JHqBHFlMIW36SDiPCVsj87ntDLcWN+sJ1erdVryd4NxODacFTsdrIE3b7IamqbOg==", "dev": true, "license": "MIT" }, @@ -1546,9 +1574,9 @@ } }, "node_modules/rollup": { - "version": "4.24.0", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.24.0.tgz", - "integrity": "sha512-DOmrlGSXNk1DM0ljiQA+i+o0rSLhtii1je5wgk60j49d1jHT5YYttBv1iWOnYSTG+fZZESUOSNiAl89SIet+Cg==", + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.24.3.tgz", + "integrity": "sha512-HBW896xR5HGmoksbi3JBDtmVzWiPAYqp7wip50hjQ67JbDz61nyoMPdqu1DvVW9asYb2M65Z20ZHsyJCMqMyDg==", "dev": true, "license": "MIT", "dependencies": { @@ -1562,22 +1590,24 @@ "npm": ">=8.0.0" }, "optionalDependencies": { - "@rollup/rollup-android-arm-eabi": "4.24.0", - "@rollup/rollup-android-arm64": "4.24.0", - "@rollup/rollup-darwin-arm64": "4.24.0", - "@rollup/rollup-darwin-x64": "4.24.0", - "@rollup/rollup-linux-arm-gnueabihf": "4.24.0", - "@rollup/rollup-linux-arm-musleabihf": "4.24.0", - "@rollup/rollup-linux-arm64-gnu": "4.24.0", - "@rollup/rollup-linux-arm64-musl": "4.24.0", - "@rollup/rollup-linux-powerpc64le-gnu": "4.24.0", - "@rollup/rollup-linux-riscv64-gnu": "4.24.0", - "@rollup/rollup-linux-s390x-gnu": "4.24.0", - "@rollup/rollup-linux-x64-gnu": "4.24.0", - "@rollup/rollup-linux-x64-musl": "4.24.0", - "@rollup/rollup-win32-arm64-msvc": "4.24.0", - "@rollup/rollup-win32-ia32-msvc": "4.24.0", - "@rollup/rollup-win32-x64-msvc": "4.24.0", + "@rollup/rollup-android-arm-eabi": "4.24.3", + "@rollup/rollup-android-arm64": "4.24.3", + "@rollup/rollup-darwin-arm64": "4.24.3", + "@rollup/rollup-darwin-x64": "4.24.3", + "@rollup/rollup-freebsd-arm64": "4.24.3", + "@rollup/rollup-freebsd-x64": "4.24.3", + "@rollup/rollup-linux-arm-gnueabihf": "4.24.3", + "@rollup/rollup-linux-arm-musleabihf": "4.24.3", + "@rollup/rollup-linux-arm64-gnu": "4.24.3", + "@rollup/rollup-linux-arm64-musl": "4.24.3", + "@rollup/rollup-linux-powerpc64le-gnu": "4.24.3", + "@rollup/rollup-linux-riscv64-gnu": "4.24.3", + "@rollup/rollup-linux-s390x-gnu": "4.24.3", + "@rollup/rollup-linux-x64-gnu": "4.24.3", + "@rollup/rollup-linux-x64-musl": "4.24.3", + "@rollup/rollup-win32-arm64-msvc": "4.24.3", + "@rollup/rollup-win32-ia32-msvc": "4.24.3", + "@rollup/rollup-win32-x64-msvc": "4.24.3", "fsevents": "~2.3.2" } }, @@ -1595,9 +1625,9 @@ } }, "node_modules/sass": { - "version": "1.80.3", - "resolved": "https://registry.npmjs.org/sass/-/sass-1.80.3.tgz", - "integrity": "sha512-ptDWyVmDMVielpz/oWy3YP3nfs7LpJTHIJZboMVs8GEC9eUmtZTZhMHlTW98wY4aEorDfjN38+Wr/XjskFWcfA==", + "version": "1.80.5", + "resolved": "https://registry.npmjs.org/sass/-/sass-1.80.5.tgz", + "integrity": "sha512-TQd2aoQl/+zsxRMEDSxVdpPIqeq9UFc6pr7PzkugiTx3VYCFPUaa3P4RrBQsqok4PO200Vkz0vXQBNlg7W907g==", "license": "MIT", "dependencies": { "@parcel/watcher": "^2.4.1", @@ -1644,9 +1674,9 @@ } }, "node_modules/svelte": { - "version": "5.0.5", - "resolved": "https://registry.npmjs.org/svelte/-/svelte-5.0.5.tgz", - "integrity": "sha512-f4WBlP5g8W6pEoDfx741lewMlemy+LIGpEqjGPWqnHVP92wqlQXl87U5O5Bi2tkSUrO95OxOoqwU8qlqiHmFKA==", + "version": "5.1.9", + "resolved": "https://registry.npmjs.org/svelte/-/svelte-5.1.9.tgz", + "integrity": "sha512-nzq+PPKGS2PoEWDjAcXSrKSbXmmmOAxd6dAz1IhRusUpVkFS6DMELWPyBPGwu6TpO/gsgtFXwX0M4+pAR5gzKw==", "dev": true, "license": "MIT", "dependencies": { @@ -1756,9 +1786,9 @@ } }, "node_modules/tslib": { - "version": "2.8.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.0.tgz", - "integrity": "sha512-jWVzBLplnCmoaTr13V9dYbiQ99wvZRd0vNWaDRg+aVYRcjDF3nDksxFDE/+fkXnKhpnUUkmx5pK/v8mCtLVqZA==", + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", + "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", "dev": true, "license": "0BSD" }, diff --git a/Frontend/package.json b/Frontend/package.json index 7549b669..c2be95b8 100644 --- a/Frontend/package.json +++ b/Frontend/package.json @@ -1,6 +1,6 @@ { "name": "frontend", - "version": "0.0.1", + "version": "2.0.0", "private": true, "scripts": { "dev": "vite dev",