Skip to content

Commit

Permalink
Ensure status is checked before sending messages
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasCdry committed Sep 9, 2024
1 parent 14adf47 commit 9ed52b4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/net/clementraynaud/skoice/bot/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class Bot {
private final MenuFactory menuFactory;
private JDA jda;
private BotStatus status = BotStatus.NOT_CONNECTED;
private boolean isStatusChecked = false;
private String tokenManagerId;
private String guildId;
private String inviteUrl;
Expand All @@ -89,6 +90,7 @@ public void connect() {

public void connect(CommandSender sender) {
if (!this.plugin.getConfigYamlFile().contains(ConfigField.TOKEN.toString())) {
this.isStatusChecked = true;
this.plugin.getLogger().warning(this.plugin.getLang().getMessage("logger.warning.no-token"));
return;
}
Expand Down Expand Up @@ -121,6 +123,7 @@ public void connect(CommandSender sender) {
.addEventListeners(new ReadyListener(this.plugin))
.build();
} catch (InvalidTokenException | IllegalArgumentException | ErrorResponseException e) {
this.isStatusChecked = true;
this.plugin.getLogger().warning(this.plugin.getLang().getMessage("logger.error.bot-could-not-connect"));
this.plugin.getConfigYamlFile().remove(ConfigField.TOKEN.toString());
if (tokenManager != null) {
Expand Down Expand Up @@ -262,6 +265,7 @@ public void updateStatus() {
}
}

this.isStatusChecked = true;
this.updateActivity();
}
}
Expand All @@ -276,6 +280,10 @@ public void updateActivity() {
}

public void sendIncompleteConfigurationAlert(Player player, boolean sendIfPermissionMissing, boolean force) {
if (!this.isStatusChecked) {
return;
}

if (player.hasPermission(Argument.MANAGE_PERMISSION) || force) {
if (this.status == BotStatus.NOT_CONNECTED) {
if (this.plugin.getConfigYamlFile().getBoolean(ConfigField.TOOLTIPS.toString())) {
Expand Down

0 comments on commit 9ed52b4

Please sign in to comment.