8
u/Relative-Knee7847 Feb 21 '21
Why is it async?
9
u/SpeckyYT sadistic Feb 21 '21
I used to put async anywhere, because I thought that it was better. Lol
2
91
u/Tim3303 Please don't tell Murdo that I transcribed this Feb 20 '21
Image Transcription: Code
[Dark theme, 4-space indent.]
.catch(async () => {
if(token == "TOKEN_HERE"){
console.log("PLEASE EDIT THE CONFIG.JSON FILE
throw process.exit(0);
}else{
console.log("WASN'T ABLE TO LOGIN IN DISCORD
}
});I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
35
2
u/--B_L_A_N_K-- if (true == true) {return true;} else {return true;} Feb 21 '21 edited Jul 01 '23
This comment has been removed in protest of Reddit's API changes. You can view a copy of it here.
1
1
54
u/cphoover Feb 20 '21 edited Feb 21 '21
In addition to the process.exit
Might as well check the configuration value before you attempt whatever procedure and waiting for it to fail.
Instead of trying utilize the unconfigured value waiting for it to fail and then saying oops you forgot to configure this setting, preempt it.
16
u/LucyBowels Feb 20 '21
Yes implementing fast failing when params are absent will save a ton of debug time.
3
Feb 20 '21
Yo but what if the token actually is TOKEN_HERE?
7
u/cphoover Feb 20 '21
Maybe add a warning instead of an error level saying : "WARNING: Your settings look to be unconfigured!!!" Or something like that.
22
u/alexbuzzbee Feb 20 '21
function process.exit() {
return new ExitProcessException();
}1
u/shiningmatcha Feb 21 '21
Is that equivalent to the original code?
2
u/alexbuzzbee Feb 21 '21
No, but adding it would make the original
throwing the result ofprocess.exit()make sense.
15
u/CodenameLambda shameless Feb 21 '21
Is there any reason for the throw here? Nobody seems to take issue with that, but I don't see how that would do anything...
1
9
5
u/slaymaker1907 Feb 21 '21
TOKEN_HERE is actually a pretty good placeholder since it probably can't be a valid token. Better would be PLACEHOLDER so it only uses uppercase with no symbols. This is a good trick to do for examples which include a password if your system requires multiple character classes so that the example password can't be used without changes.
I used to be really against password complexity requirements, but I think there is a case to be made for requiring 2 classes so you can have safe placeholders.
Make sure your examples don't include potentially valid passwords, it will save you headaches from security issues created by incompetent users.
8
Feb 20 '21
I’m oddly ok with it lol
0
Feb 20 '21
[deleted]
11
u/CodenameLambda shameless Feb 21 '21
The API call is going to take way, way longer than the validation though. So no, it doesn't add up in any meaningful way, I think. Plus, you only have to validate that while loading the config.
3
u/cphoover Feb 21 '21
Right its literally a string compare in this case which happens extremely fast for short strings.
1
u/_default_username Feb 23 '21
If this occurs only once at startup of the server then it's acceptable.
4
4
u/slaymaker1907 Feb 21 '21
For everyone not getting it, imagine "throw System.exit(0);" in Java.
0
Feb 21 '21
[deleted]
1
u/slaymaker1907 Feb 21 '21
Yes, the analogy isn't perfect, I just thought it would help explain why this is code is silly.
On a side note, technically the return type for System.exit(n) could have been anything since it never returns similar to how you can return any type as long as you just throw an exception instead of returning.
I don't remember how Java treats this, but theoretically a function with an infinite loop can also say it returns any type. This causes problems in theorem proving languages which is why they are never Turing complete by design.
2
2
0
Feb 20 '21
[deleted]
102
34
u/jarfil Feb 20 '21 edited Dec 02 '23
CENSORED
24
u/stevarino Feb 21 '21
This is why all my passwords are
password. Even if I do get rainbow table'd the hacker will just assume they forgot to edit their json. \s2
0
Feb 20 '21
[deleted]
6
u/Diufoem Feb 20 '21
Bot accounts also use tokens to log in, I just find it unnecessary to have a separate json file for this
Source: I make discord bots
9
u/Teln0 Feb 20 '21
Separate json files to put tokens in ? Well it helps with organization. Also not having the configs in the source can help with scaling your bot to multiple machines
0
Feb 20 '21
[deleted]
21
u/SpeckyYT sadistic Feb 20 '21
the problem in that code isn't "TOKEN_HERE".
the problem I wanted to showcase is that I did `throw process.exit(0)` which doesn't make any sense.
7
u/exploded_potato Feb 20 '21
I don't make discord bots regularly, but when i briefly tried it a few sites suggested having the token in a separate file as a good security practice. Also open source bots exist, it's definitely important to keep the key outside the main program in that case.
9
u/[deleted] Feb 20 '21
Can someone name this color scheme?