Skip to content

Commit

Permalink
修复不填channel时更新通知发送失败
Browse files Browse the repository at this point in the history
  • Loading branch information
Xujiayao committed Jun 28, 2024
1 parent e5bfae7 commit 406055d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/main/java/com/xujiayao/discord_mc_chat/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,16 @@ public void onInitializeServer() {
if (!CONFIG.generic.updateNotificationChannelId.isEmpty()) {
UPDATE_NOTIFICATION_CHANNEL = JDA.getTextChannelById(CONFIG.generic.updateNotificationChannelId);
if (UPDATE_NOTIFICATION_CHANNEL == null) {
UPDATE_NOTIFICATION_CHANNEL = CHANNEL;
throw new NullPointerException("Invalid Update Notification Channel ID");
}
// TODO This (including other messages, /reload) should be checked every time before sending!
if (!UPDATE_NOTIFICATION_CHANNEL.canTalk()) {
LOGGER.warn("Unable to send messages in the Update Notification Channel; Using the default channel instead.");
UPDATE_NOTIFICATION_CHANNEL = CHANNEL;
LOGGER.warn("Unable to send messages in the Update Notification Channel; Using the default channel instead.");
}
} else {
UPDATE_NOTIFICATION_CHANNEL = CHANNEL;
}

String webhookName = "DMCC Webhook" + " (" + JDA.getSelfUser().getApplicationId() + ")";
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/xujiayao/discord_mc_chat/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,15 @@ public static String reload() {
if (!CONFIG.generic.updateNotificationChannelId.isEmpty()) {
UPDATE_NOTIFICATION_CHANNEL = JDA.getTextChannelById(CONFIG.generic.updateNotificationChannelId);
if (UPDATE_NOTIFICATION_CHANNEL == null) {
UPDATE_NOTIFICATION_CHANNEL = CHANNEL;
throw new NullPointerException("Invalid Update Notification Channel ID");
}
if (!UPDATE_NOTIFICATION_CHANNEL.canTalk()) {
LOGGER.warn("Unable to send messages in the Update Notification Channel; Using the default channel instead.");
UPDATE_NOTIFICATION_CHANNEL = CHANNEL;
LOGGER.warn("Unable to send messages in the Update Notification Channel; Using the default channel instead.");
}
} else {
UPDATE_NOTIFICATION_CHANNEL = CHANNEL;
}

String webhookName = "DMCC Webhook" + " (" + JDA.getSelfUser().getApplicationId() + ")";
Expand Down

0 comments on commit 406055d

Please sign in to comment.