Skip to content

Commit

Permalink
Discord connect id case sensitivity fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Apr 20, 2022
1 parent 928f863 commit 1c706a5
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,23 +203,24 @@ public static String flagFilePathFor(String bot) {

@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag id = scriptEntry.requiredArgForPrefixAsElement("id");
ElementTag idElement = scriptEntry.requiredArgForPrefixAsElement("id");
ElementTag tokenFile = scriptEntry.argForPrefixAsElement("tokenfile", null);
SecretTag token = scriptEntry.argForPrefix("token", SecretTag.class, true);
ListTag intents = scriptEntry.argForPrefix("intents", ListTag.class, true);
if (tokenFile == null && token == null) {
throw new InvalidArgumentsRuntimeException("Missing token SecretTag object!");
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), id, token, tokenFile, intents);
Debug.report(scriptEntry, getName(), idElement, token, tokenFile, intents);
}
if (DenizenDiscordBot.instance.connections.containsKey(id.asString())) {
String id = CoreUtilities.toLowerCase(idElement.asString());
if (DenizenDiscordBot.instance.connections.containsKey(id)) {
Debug.echoError("Failed to connect: duplicate ID!");
return;
}
DiscordConnection dc = new DiscordConnection();
dc.botID = id.asString();
DenizenDiscordBot.instance.connections.put(id.asString(), dc);
dc.botID = id;
DenizenDiscordBot.instance.connections.put(id, dc);
Bukkit.getScheduler().runTaskAsynchronously(DenizenDiscordBot.instance, () -> {
String codeRaw;
if (tokenFile != null) {
Expand All @@ -228,20 +229,20 @@ public void execute(ScriptEntry scriptEntry) {
if (!Utilities.canReadFile(f)) {
handleError(scriptEntry, "Cannot read from that token file path due to security settings in Denizen/config.yml.");
scriptEntry.setFinished(true);
DenizenDiscordBot.instance.connections.remove(id.asString());
DenizenDiscordBot.instance.connections.remove(id);
return;
}
if (!f.exists()) {
handleError(scriptEntry, "Invalid tokenfile specified. File does not exist.");
scriptEntry.setFinished(true);
DenizenDiscordBot.instance.connections.remove(id.asString());
DenizenDiscordBot.instance.connections.remove(id);
return;
}
codeRaw = CoreUtilities.journallingLoadFile(f.getAbsolutePath());
if (codeRaw == null || codeRaw.length() < 5 || codeRaw.length() > 200) {
handleError(scriptEntry, "Invalid tokenfile specified. File content doesn't look like a bot token.");
scriptEntry.setFinished(true);
DenizenDiscordBot.instance.connections.remove(id.asString());
DenizenDiscordBot.instance.connections.remove(id);
return;
}
}
Expand All @@ -263,7 +264,7 @@ public void execute(ScriptEntry scriptEntry) {
catch (IllegalArgumentException ex) {
Debug.echoError("Invalid 'intents' input - " + ex.getMessage());
scriptEntry.setFinished(true);
DenizenDiscordBot.instance.connections.remove(id.asString());
DenizenDiscordBot.instance.connections.remove(id);
return;
}
}
Expand Down

0 comments on commit 1c706a5

Please sign in to comment.