-
-
Notifications
You must be signed in to change notification settings - Fork 734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented phone verification (only get) and 50 MiB file limit for nitro accounts #445
Conversation
…evel and added support for sending 50 MiB files when having nitro
99608ee
to
c228a8d
Compare
While you're there, could you fix: |
new SelfUpdateEmailEvent( | ||
api, responseNumber, | ||
oldEmail)); | ||
api.getEventManager().handle(new SelfUpdateEmailEvent(api, responseNumber, oldEmail)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change these events here? They have a consistent setup...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ I wanna reiterate this comment, please don't change these as we have a consistent style for these event handling calls.
Does having a registered phone number outweigh the other verification level requirements? |
Yes Minn. However the current verification level of a guild outweights the lower verification levels. And yes i tested it :) |
If that is the case this swtich has to be changed. And when the phone number is not null it should not break but return true from what I can tell. |
@@ -661,19 +661,22 @@ public boolean checkVerification() | |||
return true; | |||
if(canSendVerification) | |||
return true; | |||
|
|||
if (api.getSelfUser().getPhoneNumber() != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MinnDevelopment @Sanduhr32 is this what you mean?
edit: I hate these snippets...
switch (verificationLevel) | ||
{ | ||
case VERY_HIGH: | ||
if(api.getSelfUser().getPhoneNumber() != null) | ||
break; | ||
return false; // we already checked for a verified phone number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be a break;
to be consistent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure whether you were done with this but it has been laying low for a bit now. There are several TODO comments I would like you to look into before we can merge this.
@@ -80,6 +80,9 @@ public SelfUser createSelfUser(JSONObject self) | |||
.setVerified(self.getBoolean("verified")) | |||
.setMfaEnabled(self.getBoolean("mfa_enabled")) | |||
.setEmail(!self.isNull("email") ? self.getString("email") : null) | |||
.setMobile(self.has("mobile") ? self.getBoolean("mobile") : false) | |||
.setPremium(self.has("premium") ? self.getBoolean("premium") : false) | |||
.setPhoneNumber(!self.isNull("phone") ? self.getString("phone") : null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be !self.isNull(x) && self.getBoolean(x)
for the boolean values.
@@ -507,8 +507,8 @@ protected void handleResponse(Response response, Request<Message> request) | |||
Checks.notNull(file, "file"); | |||
Checks.check(file.exists() && file.canRead(), | |||
"Provided file is either null, doesn't exist or is not readable!"); | |||
Checks.check(file.length() <= Message.MAX_FILE_SIZE,// TODO: deal with Discord Nitro allowing 50MB files. | |||
"File is to big! Max file-size is 8MB"); | |||
Checks.check(file.length() <= (getJDA().getAccountType() == AccountType.CLIENT && getJDA().getSelfUser().isPremium() ? Message.MAX_FILE_SIZE_NITRO : Message.MAX_FILE_SIZE), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ternary is pretty ugly, can we move this outside the check call?
Checks.notNull(fileName, "fileName"); | ||
|
||
Checks.check(data.length <= Message.MAX_FILE_SIZE, //8MB | ||
"Provided data is too large! Max file-size is 8MB (%d)", Message.MAX_FILE_SIZE); | ||
Checks.check(data.length <= (getJDA().getAccountType() == AccountType.CLIENT && getJDA().getSelfUser().isPremium() ? Message.MAX_FILE_SIZE_NITRO : Message.MAX_FILE_SIZE), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
* | ||
* @return The phone of the currently logged in account or null if there's no number associated | ||
*/ | ||
String getPhoneNumber() throws AccountTypeException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you specifically throw an AccountTypeException
for these methods? I would suggest to actually just return w/e we parsed and document that for bots the value will most likely be false or null. It might be possible that discord will make some of these available to bots in the future (unlikely) so we should just go with that, imo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose this because we already have the same be behavior for getEmail()
. I also highly doubt that any of these will be available for bots anytime in the future.
switch (verificationLevel) | ||
{ | ||
case VERY_HIGH: | ||
return false; // we already checked for a verified phone number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a break;
for consistency
new SelfUpdateEmailEvent( | ||
api, responseNumber, | ||
oldEmail)); | ||
api.getEventManager().handle(new SelfUpdateEmailEvent(api, responseNumber, oldEmail)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ I wanna reiterate this comment, please don't change these as we have a consistent style for these event handling calls.
JDAImpl.LOG.debug(""); | ||
String oldPhoneNumber = self.getPhoneNumber(); | ||
self.setPhoneNumber(phoneNumber); | ||
// api.getEventManager().handle(new SelfUpdatePhoneNumberEvent(api, responseNumber, oldPhoneNumber)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When do you intend to add these events?
I'd like to see some motion on this PR. |
Right... I completely forgot this still exists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it called premium and not just Nitro? I think people would search docs for Nitro rather than premium, i might be confusing for other people.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest renaming the constant to so it contains the same name as the Boolean which is currently named premium
.
/** | ||
* Useful constant for the max allowed file size for message attachments on nitro accounts. Value: {@value #MAX_FILE_SIZE_NITRO} Bytes (50 MiB) | ||
*/ | ||
int MAX_FILE_SIZE_NITRO = 50 << 20; // 50 MiB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really consistent you are calling your Boolean premium to check if user is a Nitro users but here you are calling you constant MAX_FILE_SIZE_NITRO instead of MAX_FILE_SIZE_PREMIUM. I'd say either rename the Boolean to nitro or rename this constant.
* | ||
* @return The Discord Nitro status of the currently logged in account. | ||
*/ | ||
boolean isPremium() throws AccountTypeException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should call this isNitro
to avoid unneeded confusion
@Almighty-Alpaca can you please update this PR |
c8a0e99
to
017dae7
Compare
|
||
import net.dv8tion.jda.core.JDA; | ||
|
||
public class SelfUpdateMobileEvent extends GenericSelfUpdateEvent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This event needs documentation on class-level and on its methods.
|
||
import net.dv8tion.jda.core.JDA; | ||
|
||
public class SelfUpdateNitroEvent extends GenericSelfUpdateEvent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This event needs documentation on class-level and on its methods.
|
||
import net.dv8tion.jda.core.JDA; | ||
|
||
public class SelfUpdatePhoneNumberEvent extends GenericSelfUpdateEvent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This event needs documentation on class-level and on its methods.
7026dad
to
a342114
Compare
a342114
to
5580542
Compare
|
||
if (api.getAccountType() == AccountType.CLIENT && !Objects.equals(phoneNumber, self.getPhoneNumber())) | ||
{ | ||
JDAImpl.LOG.debug(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh?
If anyone knows what the
mobile
is exactly used for let me know so that I can update the javadoc for it as it's currently a bit vague.