-
-
Notifications
You must be signed in to change notification settings - Fork 0
GH-75 Add Discord Integration #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jakubk15
wants to merge
48
commits into
master
Choose a base branch
from
discord
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,541
−7
Open
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
c5a6d1e
Begin working on Discord integration
Jakubk15 6307b0e
Finish implementing Discord integration
Jakubk15 9e4a998
Add `@Async` annotation to command executors to ensure that the serve…
Jakubk15 1109f11
Remove `@Async` annotations
Jakubk15 67ac9a2
Refactor Discord integration to use reactive programming for login an…
Jakubk15 e98e263
Remove redundant check for bot admin role ID in Discord configuration…
Jakubk15 8751030
Update src/main/java/com/eternalcode/parcellockers/discord/repository…
Jakubk15 031d466
Update src/main/java/com/eternalcode/parcellockers/discord/repository…
Jakubk15 fc95d79
Merge branch 'master' into discord
Jakubk15 ed98f10
Add service layer
Jakubk15 14ae198
Add DiscordSRV hook integration
Jakubk15 7de214f
feat: Update DiscordSRV integration and add parcel delivery notificat…
Jakubk15 143d8a1
feat: Implement abstract DiscordNotificationService with Discord4J an…
Jakubk15 161cec0
fix: declare appropriate events as async
Jakubk15 f2b470a
fix: avoid DiscordClientManager#getClient race conditions by using bl…
Jakubk15 9342e82
Remove redundant discord properties
Jakubk15 a271e9f
Update src/main/java/com/eternalcode/parcellockers/discord/command/Di…
Jakubk15 8809808
fix: initialize DiscordLinkRepository only when fallback Discord inte…
Jakubk15 457490b
Update src/main/java/com/eternalcode/parcellockers/discord/command/Di…
Jakubk15 dee0d6c
Update src/main/java/com/eternalcode/parcellockers/discord/command/Di…
Jakubk15 73477f6
Update src/main/java/com/eternalcode/parcellockers/configuration/impl…
Jakubk15 152dc6f
Merge remote-tracking branch 'origin/discord' into discord
Jakubk15 b8d54bf
Update src/main/java/com/eternalcode/parcellockers/discord/command/Di…
Jakubk15 a7f2a35
fix: add logging to DiscordSrvLinkService for better error handling
Jakubk15 2ddcf51
Merge remote-tracking branch 'origin/discord' into discord
Jakubk15 6d1c84e
Update PluginConfig.java
Jakubk15 5cbffe7
Update ParcelDeliverNotificationController.java
Jakubk15 77b19aa
Update ParcelDeliverNotificationController.java
Jakubk15 d0ed324
Add missing import
Jakubk15 3555651
WIP - Adjust to DMK suggestions
Jakubk15 8df0ed9
Use OfflinePlayer instead of String
Jakubk15 a31f0c2
Use OfflinePlayer in unlinkPlayer executor too
Jakubk15 e4070c3
Align with single-responsibility-principle
Jakubk15 7dd0cc7
Ensure proper encapsulation
Jakubk15 055acc2
Refactor sendPrivateMessage method to return void and improve message…
Jakubk15 57ac290
Improve error logging in DiscordClientManager during login failure
Jakubk15 00cf84d
Merge branch 'master' into discord
Jakubk15 201c382
Refactor Discord ID handling to use long, add NoticeHandler, remove r…
Jakubk15 5d50f24
Delete random javadocs
Jakubk15 cfd7509
Refactor Discord notification handling, introduce Formatter for messa…
Jakubk15 bc63ada
Refactor notification handling to use thenAcceptBoth for improved mes…
Jakubk15 c48268b
Refactor Discord link/unlink to use result enums
Jakubk15 d2cabe2
Use FutureHandler
Jakubk15 8eccb8a
Subscribe to the DiscordClient logout rather than blocking the thread.
Jakubk15 be5d0f7
Refactor Discord verification handling to utilize configurable link c…
Jakubk15 52dd98c
Adjust to Gemini suggestions
Jakubk15 a3f16f4
Merge branch 'master' into discord
Jakubk15 d2a5deb
Merge branch 'master' into discord
Jakubk15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,11 @@ | |
| import com.eternalcode.commons.adventure.AdventureLegacyColorPreProcessor; | ||
| import com.eternalcode.commons.bukkit.scheduler.BukkitSchedulerImpl; | ||
| import com.eternalcode.commons.scheduler.Scheduler; | ||
| import com.eternalcode.multification.notice.Notice; | ||
| import com.eternalcode.parcellockers.command.debug.DebugCommand; | ||
| import com.eternalcode.parcellockers.command.handler.InvalidUsageHandlerImpl; | ||
| import com.eternalcode.parcellockers.command.handler.MissingPermissionsHandlerImpl; | ||
| import com.eternalcode.parcellockers.command.handler.NoticeHandler; | ||
| import com.eternalcode.parcellockers.configuration.ConfigService; | ||
| import com.eternalcode.parcellockers.configuration.implementation.MessageConfig; | ||
| import com.eternalcode.parcellockers.configuration.implementation.PluginConfig; | ||
|
|
@@ -16,6 +18,9 @@ | |
| import com.eternalcode.parcellockers.database.DatabaseManager; | ||
| import com.eternalcode.parcellockers.delivery.DeliveryManager; | ||
| import com.eternalcode.parcellockers.delivery.repository.DeliveryRepositoryOrmLite; | ||
| import com.eternalcode.parcellockers.discord.DiscordClientManager; | ||
| import com.eternalcode.parcellockers.discord.DiscordProviderPicker; | ||
| import com.eternalcode.parcellockers.discord.argument.SnowflakeArgument; | ||
| import com.eternalcode.parcellockers.gui.GuiManager; | ||
| import com.eternalcode.parcellockers.gui.implementation.locker.LockerGui; | ||
| import com.eternalcode.parcellockers.gui.implementation.remote.MainGui; | ||
|
|
@@ -47,13 +52,16 @@ | |
| import com.eternalcode.parcellockers.user.validation.UserValidationService; | ||
| import com.eternalcode.parcellockers.user.validation.UserValidator; | ||
| import dev.rollczi.litecommands.LiteCommands; | ||
| import dev.rollczi.litecommands.LiteCommandsBuilder; | ||
| import dev.rollczi.litecommands.adventure.LiteAdventureExtension; | ||
| import dev.rollczi.litecommands.annotations.LiteCommandsAnnotations; | ||
| import dev.rollczi.litecommands.bukkit.LiteBukkitFactory; | ||
| import dev.rollczi.litecommands.bukkit.LiteBukkitMessages; | ||
| import dev.rollczi.litecommands.bukkit.LiteBukkitSettings; | ||
| import dev.rollczi.liteskullapi.LiteSkullFactory; | ||
| import dev.rollczi.liteskullapi.SkullAPI; | ||
| import dev.triumphteam.gui.TriumphGui; | ||
| import discord4j.common.util.Snowflake; | ||
| import java.io.File; | ||
| import java.sql.SQLException; | ||
| import java.time.Duration; | ||
|
|
@@ -72,6 +80,7 @@ public final class ParcelLockers extends JavaPlugin { | |
| private SkullAPI skullAPI; | ||
| private DatabaseManager databaseManager; | ||
| private Economy economy; | ||
| private DiscordClientManager discordClientManager; | ||
|
|
||
| @Override | ||
| public void onEnable() { | ||
|
|
@@ -175,19 +184,30 @@ public void onEnable() { | |
| this.skullAPI | ||
| ); | ||
|
|
||
| this.liteCommands = LiteBukkitFactory.builder(this.getName(), this) | ||
| LiteCommandsBuilder<CommandSender, LiteBukkitSettings, ?> liteCommandsBuilder = LiteBukkitFactory.builder(this.getName(), this) | ||
| .extension(new LiteAdventureExtension<>()) | ||
| .argument(Snowflake.class, new SnowflakeArgument(messageConfig)) | ||
| .message(LiteBukkitMessages.PLAYER_ONLY, messageConfig.playerOnlyCommand) | ||
| .message(LiteBukkitMessages.PLAYER_NOT_FOUND, messageConfig.playerNotFound) | ||
| .commands(LiteCommandsAnnotations.of( | ||
| new ParcelCommand(mainGUI), | ||
| new ParcelLockersCommand(configService, config, noticeService), | ||
| new DebugCommand(parcelService, lockerManager, itemStorageManager, parcelContentManager, | ||
| new DebugCommand( | ||
| parcelService, lockerManager, itemStorageManager, parcelContentManager, | ||
| noticeService, deliveryManager) | ||
| )) | ||
| .invalidUsage(new InvalidUsageHandlerImpl(noticeService)) | ||
| .missingPermission(new MissingPermissionsHandlerImpl(noticeService)) | ||
| .build(); | ||
| .result(Notice.class, new NoticeHandler(noticeService)); | ||
|
|
||
| DiscordProviderPicker discordProviderPicker = new DiscordProviderPicker( | ||
| config, messageConfig, server, noticeService, scheduler, databaseManager, | ||
| this.getLogger(), userManager, this, miniMessage | ||
| ); | ||
|
|
||
| this.discordClientManager = discordProviderPicker.pick(liteCommandsBuilder); | ||
|
|
||
| this.liteCommands = liteCommandsBuilder.build(); | ||
|
|
||
| Stream.of( | ||
| new LockerInteractionController(lockerManager, lockerGUI, scheduler), | ||
|
|
@@ -197,16 +217,18 @@ public void onEnable() { | |
| new LoadUserController(userManager, server) | ||
| ).forEach(controller -> server.getPluginManager().registerEvents(controller, this)); | ||
|
|
||
| new Metrics(this, 17677); | ||
| new UpdaterService(this.getPluginMeta().getVersion()); | ||
| Metrics metrics = new Metrics(this, 17677); | ||
| UpdaterService updaterService = new UpdaterService(this.getPluginMeta().getVersion()); | ||
Jakubk15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| parcelRepository.findAll().thenAccept(optionalParcels -> optionalParcels | ||
| .stream() | ||
| .filter(parcel -> parcel.status() != ParcelStatus.DELIVERED) | ||
| .forEach(parcel -> deliveryRepository.find(parcel.uuid()).thenAccept(optionalDelivery -> | ||
| optionalDelivery.ifPresent(delivery -> { | ||
| long delay = Math.max(0, delivery.deliveryTimestamp().toEpochMilli() - System.currentTimeMillis()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be did like this: long delay = Math.max(
0,
Duration.between(Instant.now(clock), delivery.deliveryTimestamp()).toMillis()
); |
||
| scheduler.runLaterAsync(new ParcelSendTask(parcel, parcelService, deliveryManager), Duration.ofMillis(delay)); | ||
| scheduler.runLaterAsync( | ||
| new ParcelSendTask(parcel, parcelService, deliveryManager), | ||
| Duration.ofMillis(delay)); | ||
| }) | ||
| ))); | ||
| } | ||
|
|
@@ -224,6 +246,10 @@ public void onDisable() { | |
| if (this.skullAPI != null) { | ||
| this.skullAPI.shutdown(); | ||
| } | ||
|
|
||
| if (this.discordClientManager != null) { | ||
| this.discordClientManager.shutdown(); | ||
| } | ||
| } | ||
|
|
||
| private boolean setupEconomy() { | ||
|
|
||
26 changes: 26 additions & 0 deletions
26
src/main/java/com/eternalcode/parcellockers/command/handler/NoticeHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.eternalcode.parcellockers.command.handler; | ||
|
|
||
| import com.eternalcode.multification.notice.Notice; | ||
| import com.eternalcode.parcellockers.notification.NoticeService; | ||
| import dev.rollczi.litecommands.handler.result.ResultHandler; | ||
| import dev.rollczi.litecommands.handler.result.ResultHandlerChain; | ||
| import dev.rollczi.litecommands.invocation.Invocation; | ||
| import org.bukkit.command.CommandSender; | ||
|
|
||
| public class NoticeHandler implements ResultHandler<CommandSender, Notice> { | ||
|
|
||
| private final NoticeService noticeService; | ||
|
|
||
| public NoticeHandler(NoticeService noticeService) { | ||
| this.noticeService = noticeService; | ||
| } | ||
|
|
||
| @Override | ||
| public void handle(Invocation<CommandSender> invocation, Notice result, ResultHandlerChain<CommandSender> chain) { | ||
| this.noticeService.create() | ||
| .viewer(invocation.sender()) | ||
| .notice(result) | ||
| .send(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/com/eternalcode/parcellockers/discord/DiscordClientManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package com.eternalcode.parcellockers.discord; | ||
|
|
||
| import discord4j.core.DiscordClient; | ||
| import discord4j.core.GatewayDiscordClient; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
| public class DiscordClientManager { | ||
|
|
||
| private final String token; | ||
| private final Logger logger; | ||
|
|
||
| private GatewayDiscordClient client; | ||
|
|
||
| public DiscordClientManager(String token, Logger logger) { | ||
| this.token = token; | ||
| this.logger = logger; | ||
| } | ||
|
|
||
| public boolean initialize() { | ||
| this.logger.info("Discord integration is enabled. Logging in to Discord..."); | ||
| try { | ||
| GatewayDiscordClient discordClient = DiscordClient.create(this.token) | ||
| .login() | ||
| .block(); | ||
|
|
||
| if (discordClient == null) { | ||
| this.logger.severe("Failed to log in to Discord: login returned null client."); | ||
| return false; | ||
| } | ||
|
|
||
| this.client = discordClient; | ||
| this.logger.info("Successfully logged in to Discord."); | ||
| return true; | ||
| } catch (Exception exception) { | ||
| this.logger.log(Level.SEVERE, "Failed to log in to Discord", exception); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| public void shutdown() { | ||
| this.logger.info("Shutting down Discord client..."); | ||
| if (this.client != null) { | ||
| this.client.logout().subscribe(); | ||
| } | ||
| } | ||
|
|
||
| public GatewayDiscordClient getClient() { | ||
| return this.client; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.