Skip to content

Commit f74269a

Browse files
Merge pull request #117 from Cyborger1/verify-discord-error-message
Add toggle to hide discord verification errors and show the actual error in chat
2 parents b193388 + 3b5b5b9 commit f74269a

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

src/main/java/com/botdetector/BotDetectorConfig.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public interface BotDetectorConfig extends Config
4646
String PANEL_FONT_TYPE_KEY = "panelFontType";
4747
String AUTH_FULL_TOKEN_KEY = "authToken";
4848
String SHOW_FEEDBACK_TEXTBOX = "showFeedbackTextbox";
49+
String SHOW_DISCORD_VERIFICATION_ERRORS = "showDiscordVerificationErrors";
4950

5051
int AUTO_SEND_MINIMUM_MINUTES = 5;
5152
int AUTO_SEND_MAXIMUM_MINUTES = 360;
@@ -202,5 +203,24 @@ default String authFullToken()
202203
description = "",
203204
hidden = true
204205
)
205-
String setAuthFullToken(String fullToken);
206+
void setAuthFullToken(String fullToken);
207+
208+
@ConfigItem(
209+
keyName = SHOW_DISCORD_VERIFICATION_ERRORS,
210+
name = "",
211+
description = "",
212+
hidden = true
213+
)
214+
default boolean showDiscordVerificationErrors()
215+
{
216+
return true;
217+
}
218+
219+
@ConfigItem(
220+
keyName = SHOW_DISCORD_VERIFICATION_ERRORS,
221+
name = "",
222+
description = "",
223+
hidden = true
224+
)
225+
void setShowDiscordVerificationErrors(boolean show);
206226
}

src/main/java/com/botdetector/BotDetectorPlugin.java

+23-2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ public class BotDetectorPlugin extends Plugin
156156
private static final String GET_AUTH_TOKEN_COMMAND = COMMAND_PREFIX + "GetToken";
157157
private static final String SET_AUTH_TOKEN_COMMAND = COMMAND_PREFIX + "SetToken";
158158
private static final String CLEAR_AUTH_TOKEN_COMMAND = COMMAND_PREFIX + "ClearToken";
159+
private static final String TOGGLE_SHOW_DISCORD_VERIFICATION_ERRORS_COMMAND = COMMAND_PREFIX + "ToggleShowDiscordVerificationErrors";
160+
private static final String TOGGLE_SHOW_DISCORD_VERIFICATION_ERRORS_COMMAND_ALIAS = COMMAND_PREFIX + "ToggleDVE";
159161

160162
/** Command to method map to be used in {@link #onCommandExecuted(CommandExecuted)}. **/
161163
private final ImmutableMap<CaseInsensitiveString, Consumer<String[]>> commandConsumerMap =
@@ -167,6 +169,8 @@ public class BotDetectorPlugin extends Plugin
167169
.put(wrap(GET_AUTH_TOKEN_COMMAND), s -> putAuthTokenIntoClipboardCommand())
168170
.put(wrap(SET_AUTH_TOKEN_COMMAND), s -> setAuthTokenFromClipboardCommand())
169171
.put(wrap(CLEAR_AUTH_TOKEN_COMMAND), s -> clearAuthTokenCommand())
172+
.put(wrap(TOGGLE_SHOW_DISCORD_VERIFICATION_ERRORS_COMMAND), s -> toggleShowDiscordVerificationErrors())
173+
.put(wrap(TOGGLE_SHOW_DISCORD_VERIFICATION_ERRORS_COMMAND_ALIAS), s -> toggleShowDiscordVerificationErrors())
170174
.build();
171175

172176
private static final int MANUAL_FLUSH_COOLDOWN_SECONDS = 60;
@@ -759,9 +763,9 @@ else if (ex instanceof UnauthorizedTokenException)
759763
{
760764
sendChatStatusMessage("Invalid token for Discord verification, cannot verify '" + author + "'.", true);
761765
}
762-
else
766+
else if (config.showDiscordVerificationErrors())
763767
{
764-
sendChatStatusMessage("Could not verify Discord for '" + author + "'.", true);
768+
sendChatStatusMessage("Could not verify Discord for '" + author + "'" + (ex != null ? ": " + ex.getMessage() : "."), true);
765769
}
766770
});
767771
}
@@ -1161,6 +1165,23 @@ private void clearAuthTokenCommand()
11611165
sendChatStatusMessage("Auth token cleared.", true);
11621166
}
11631167

1168+
/**
1169+
* Toggles the config value in {@link BotDetectorConfig#showDiscordVerificationErrors()} and notifies the user of the change.
1170+
*/
1171+
private void toggleShowDiscordVerificationErrors()
1172+
{
1173+
boolean newVal = !config.showDiscordVerificationErrors();
1174+
config.setShowDiscordVerificationErrors(newVal);
1175+
if (newVal)
1176+
{
1177+
sendChatStatusMessage("Discord verification errors will now be shown in the chat", true);
1178+
}
1179+
else
1180+
{
1181+
sendChatStatusMessage("Discord verification errors will no longer be shown in the chat", true);
1182+
}
1183+
}
1184+
11641185
//endregion
11651186

11661187

0 commit comments

Comments
 (0)