Skip to content
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

Merged
merged 10 commits into from
Oct 29, 2017

Conversation

Almighty-Alpaca
Copy link
Collaborator

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.

@randomnetcat
Copy link
Contributor

randomnetcat commented Aug 26, 2017

While you're there, could you fix: File is to big! (MessageChannel:511)

new SelfUpdateEmailEvent(
api, responseNumber,
oldEmail));
api.getEventManager().handle(new SelfUpdateEmailEvent(api, responseNumber, oldEmail));
Copy link
Member

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...

Copy link
Member

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.

@MinnDevelopment MinnDevelopment added bug client type: discord issue seems to be an issue on discord's end labels Aug 26, 2017
@MinnDevelopment
Copy link
Member

Does having a registered phone number outweigh the other verification level requirements?

@Sanduhr32
Copy link
Contributor

Yes Minn. However the current verification level of a guild outweights the lower verification levels. And yes i tested it :)

@MinnDevelopment
Copy link
Member

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)
Copy link
Collaborator Author

@Almighty-Alpaca Almighty-Alpaca Aug 26, 2017

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

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?

@MinnDevelopment MinnDevelopment modified the milestone: Upcoming Release Sep 6, 2017
Copy link
Member

@MinnDevelopment MinnDevelopment left a 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)
Copy link
Member

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),
Copy link
Member

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),
Copy link
Member

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;
Copy link
Member

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.

Copy link
Collaborator Author

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
Copy link
Member

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));
Copy link
Member

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));
Copy link
Member

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?

@DV8FromTheWorld
Copy link
Member

I'd like to see some motion on this PR.

@Almighty-Alpaca
Copy link
Collaborator Author

Right... I completely forgot this still exists.

Copy link

@DuncanCasteleyn DuncanCasteleyn left a 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.

Copy link

@DuncanCasteleyn DuncanCasteleyn left a 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
Copy link

@DuncanCasteleyn DuncanCasteleyn Oct 8, 2017

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;
Copy link
Member

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

@MinnDevelopment
Copy link
Member

@Almighty-Alpaca can you please update this PR


import net.dv8tion.jda.core.JDA;

public class SelfUpdateMobileEvent extends GenericSelfUpdateEvent
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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.

@MinnDevelopment MinnDevelopment modified the milestones: Upcoming Release, Release 3.4 Oct 26, 2017
@Almighty-Alpaca Almighty-Alpaca force-pushed the fix/phone-verification branch 2 times, most recently from 7026dad to a342114 Compare October 27, 2017 17:46

if (api.getAccountType() == AccountType.CLIENT && !Objects.equals(phoneNumber, self.getPhoneNumber()))
{
JDAImpl.LOG.debug("");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh?

@Almighty-Alpaca Almighty-Alpaca merged commit d6fc0bc into master Oct 29, 2017
@MinnDevelopment MinnDevelopment deleted the fix/phone-verification branch October 29, 2017 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug type: discord issue seems to be an issue on discord's end
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants