-
-
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
base: master
Are you sure you want to change the base?
Changes from all commits
c5a6d1e
6307b0e
9e4a998
1109f11
67ac9a2
e98e263
8751030
031d466
fc95d79
ed98f10
14ae198
7de214f
143d8a1
161cec0
f2b470a
9342e82
a271e9f
8809808
457490b
dee0d6c
73477f6
152dc6f
b8d54bf
a7f2a35
2ddcf51
6d1c84e
5cbffe7
77b19aa
d0ed324
3555651
8df0ed9
a31f0c2
e4070c3
7dd0cc7
055acc2
57ac290
00cf84d
201c382
5d50f24
cfd7509
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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(); | ||
| } | ||
|
|
||
| } |
| 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().block(); | ||
|
Contributor
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. Blocking main thread?
Member
Author
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. It's not a problem on shutdown. We don't have to block, but then the discord bot will be shown as online for few minutes despite server shutdown
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. Blocking the main thread is generally a bad idea, even during shutdown. The main thread handles all server ticks, events, and scheduled tasks. Using A better approach is to use a non-blocking call, like |
||
| } | ||
|
Comment on lines
+43
to
+45
Contributor
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. |
||
| } | ||
|
|
||
| public GatewayDiscordClient getClient() { | ||
| return this.client; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?