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

Add User#getFlags #1271

Merged

Conversation

Andre601
Copy link
Contributor

@Andre601 Andre601 commented Apr 21, 2020

Pull Request Etiquette

Changes

  • Internal code
  • Library interface (affecting end-user code)
  • Documentation
  • Other: _____

Closes Issue: NaN

Description

This implements the public_flags value for the User object, which essentially contains all user flags with some exceptions like what type of nitro (or if they even have nitro) the user has and some other hidden flags.

@duncte123
Copy link
Contributor

Why didn't you add the early supporter one?

@Andre601
Copy link
Contributor Author

Why didn't you add the early supporter one?

I'm not sure if all flags are available, because people said that some aren't insider the public_flags, and my assumption is, that any kind of nitro indicator (including ea) are not in this...
There's sadly no proper documentation (yet) about which flags aren't included, because if public_flags = flags, then why not just use flags?

@Andre601
Copy link
Contributor Author

@duncte123 I now added all flags that are considered "public" (based on this file)

I also renamed some flags to make them match the internal names Discord uses, although I think having the names of the HypeSquad houses would be better.

Change the naming of the flags to match the upcoming changes to the Discord Documentation discord/discord-api-docs#1493 
The offsets and raw values will now be correct as well
@Andre601
Copy link
Contributor Author

@MinnDevelopment How should we treat NONE then when using the offset?
Because NONE is a flag in Discord, using the value 0 and I think using -1 should be reserved for a UNKNOWN flag.

I suggested here that we perhaps should have both the offset and the raw value? Would kind of make sense considering Discord provides the flags as their raw (total) value.

@MinnDevelopment
Copy link
Member

@MinnDevelopment How should we treat NONE then when using the offset?
Because NONE is a flag in Discord, using the value 0 and I think using -1 should be reserved for a UNKNOWN flag.

NONE isn't a flag, it's a bitmask representing no flags being set. If we have something like getFlags(): EnumSet<UserFlag> then it makes no sense to return a EnumSet.of(NONE) rather than just an empty set. There is no reasonable way to use this. UNKNOWN is a placeholder constant used when we can't resolve the flag to an enum constant.

I suggested here that we perhaps should have both the offset and the raw value? Would kind of make sense considering Discord provides the flags as their raw (total) value.

The offset gives a good and understandable code. Using raw values is confusing and can lead to bugs. You should simply use the offset to do 1 << offset in a getRaw(). See Permission. The documentation also uses offsets for the same reason.

@Andre601
Copy link
Contributor Author

I merged the suggested changes from @boomboompower in Andre601#3 which also covered most, if not all requested changes by Minn

Co-Authored-By: Florian Spieß <business@minnced.club>
@Andre601
Copy link
Contributor Author

I think now should I implement this into the User object somehow?
I never done this before, so I'm unsure where I should alter stuff to implement this. A helping hand on this (i.e. guiding me into the right direction) would be appreciated.

@MinnDevelopment
Copy link
Member

The user objects are created in the EntityBuilder and the flags should be stored as an int in the UserImpl class. The getter is declared in the User interface and should return an EnumSet. The implementation will need the same getter plus one for the int itself, used to compare against in the updateUser method in EntityBuilder to fire an update event.

@Andre601
Copy link
Contributor Author

Would the Permission enum be a good example for the Getter?

@Andre601

This comment has been minimized.

@MinnDevelopment
Copy link
Member

Permissions are a good example for flags, yes.

@Andre601
Copy link
Contributor Author

I now implemented a getFlags() of type EnumSet<Flag> to the User Object and updated the UserImpl accordingly.

Right now am I stuck with the following things:

  • Not sure how I should set the flags (int) and enum set of it for UserImpl
  • Not sure how to best return the flags (int)
  • Best way to compare values in the EntityBuilder... Similar as the one used in updateUser? (!Objects.equasls(Object, Object))?

Andre601 and others added 2 commits April 26, 2020 19:00
Co-Authored-By: Florian Spieß <business@minnced.club>
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.

Only a few small issues with the docs

Andre601 and others added 3 commits May 10, 2020 11:45
Co-authored-by: Florian Spieß <business@minnced.club>
Co-authored-by: Florian Spieß <business@minnced.club>
@MinnDevelopment MinnDevelopment added this to the v4.2.0 milestone May 10, 2020
@Artuto
Copy link
Contributor

Artuto commented May 13, 2020

update on this?

@Andre601
Copy link
Contributor Author

update on this?

Uhm..... It's ready?
I mean considering that Minn approved it, and that it has a set Milestone can we consider this done and the merge is the only thing waiting. So no need to hurry now.

@HydroPage
Copy link
Contributor

This is probably the largest conversation I'll have ever contributed to, lmao. Glad this seems to be done, and glad to have helped out a bit

@Andre601
Copy link
Contributor Author

I would say it's kind of small if you remove all the review stuff.

@MinnDevelopment MinnDevelopment merged commit e5b8c6a into discord-jda:development May 20, 2020
Andre601 added a commit to Andre601/JDA that referenced this pull request May 21, 2020
* Fix description for RestAction#flatMap

* Remove invalid NSFW info

* Fix bug in buffer allocation for ZlibDecompressor

* Don't insert null into override cache

* Keep a strong reference to user from members

Fake members will use fake users that are not cached

* Add functionality to set/get state of embed suppression (discord-jda#1117)

* Add functionality to set/get state of embed suppression

* Provide Enum for MessageFlags

* Improve handling of events for unavailable guilds (discord-jda#1184)

* Improve handling of events for unavailable guilds
* Add UnavailableGuildLeaveEvent
* Update docs for Guild#isAvailable

* Improve ratelimit bucket handling (discord-jda#1103)

* Let ChannelUpdateHandler add overrides to cache

This is a bug since the override shouldn't be in the interface
if the member is not actually in the cache. With the current
implementation we have a cache inconsistency that could NPE.

* Change handling of GuildDeleteHandler to avoid deadlock

There really is no point in holding a write-lock here

* Bump version

* Add South Korea Region

* Add getPermissionHolder method to PermissionOverride (discord-jda#1183)

* Make ignored events for unavailable guilds a debug log

* Add ErrorHandler utility class (discord-jda#1200)

* Add ErrorHandler utility class
* Improve logging of 429 warnings

* Add clearReactions(String) (discord-jda#1192)

* Add clearReactions(String)
* Add MessageReactionRemoveEmoteEvent
* Fix some outdated documentation
* Log and rethrow errors in BotRateLimiter workers

* Properly encode reaction emoji for clearReactionsById(...)

* Updated all copyright headers for 2020 (discord-jda#1198)

* Add (Guild) Invite Events (discord-jda#1196)

Adds GuildInviteCreateEvent and GuildInviteDeleteEvent

* Allow queued requests to finish

* Support gateway intents and configurable member caching (discord-jda#1190)

* First pass on member cache policy
* Add INVALID_INTENTS to close code enum
* Deprecate AccountType.CLIENT
* Add Guild#unloadMembers
* Update README with better examples
* Improve handling of channel overrides
* Add documentation for intents and member cache policy
* Remove references to guild subscriptions
* Add GuildMemberRemoveEvent
* Improve retrieveMemberById and retrieveUserById
* Changes to the builders, we use factory methods now :)
* Disable presence cache by default
* Add JDA#getGatewayIntents

* Fix NPE for GUILD_UPDATE handling

* Fix GuildChannel#createCopy for uncached members (discord-jda#1229)

* Deprecate GuildUpdateBannerEvent#getNewBannerIdUrl (discord-jda#1217)

* Allow to open private channel with user id (discord-jda#1224)

* Change defaults for requester to be non-daemon and have a shorter timeout (discord-jda#1215)

* Added Server Insights permission (discord-jda#1221)

* Add RestAction#timeout and RestAction#deadline (discord-jda#1220)

* Fix NPE in PermissionOverrideAction constructor

* Fix another NPE in success handler

* Documentation updates (discord-jda#1222)

* Swapped manage server and manage channel in Invite#isExpanded docs (discord-jda#1210)
* Document another possible null return case of Message#getMember (discord-jda#1204)
* Fix EmbedBuilder constructor javadocs (discord-jda#1214)
* Update example for jda-nas
* Add more details to modifyMemberRoles docs
* Fix typo

* Added getGuildChannelById methods to ShardManager (discord-jda#1234)

* Add better configuration methods to the builders (discord-jda#1240)

* Update README
* Add enableCache and disableCache
* Add enableIntents and disableIntents
* Update docs for events to mention required intents when necessary.
* Deprecate the old setters for cache flags

* Include voice server endpoint in connection failure logs

* Initialize SelfUser for all shards before logging them in

* Fix bug with new channel overrides having incorrect permissions

* Add the close code to the disconnect warn

* Adding a check in reaction methods before calling getTextChannel() (discord-jda#1216)

* Add JDA#cancelRequests (discord-jda#1223)

* Fix boost time not being handled in guild create

* Add GuildVoiceStreamEvent

* Fix IllegalStateException in Requester

Closes discord-jda#1254

* Change reconnect code to 4900 to avoid confusion (discord-jda#1250)

* Change reconnect code to 4900 to avoid confusion
* And update the disconnect handling to better log things
* Make resume reconnect log on debug
* Log server error on error level
* Add catch in gateway worker

* Add Guild#getMaxFileSize and Guild.BoostTier#getMaxFileSize (discord-jda#1244)

Fixes discord-jda#1243

* Add fallback operators onErrorMap and onErrorFlatMap to RestAction (discord-jda#1219)

* Fix incorrect file size check

* Documentation updates (discord-jda#1241)

* Add note about presence update and member intents
* Fix typo in readme
* Add MessageChannel#retrieveReactionUsersById and update reaction related docs (discord-jda#1236)
* Add requirements section to member/user events

* Json Parsing Optimizations (discord-jda#1267)

* Remove initial reconnect delay for resumes

* Add prune overload to disable wait parameter

* Add Guild#retrieveMetaData (discord-jda#1171)

* Lazy load member limits for guilds
* Improve implementation of update handler
* Add Guild#retrieveMetaData

* Add check for heartbeats in WebSocketClient (discord-jda#1282)

* Add retrieveMembersByPrefix (discord-jda#1276)

* Add retrieveMemberByPrefix
* Add event pool configuration
* Fix javadoc errors
* Rename chunkSyncQueue -> chunkQueue

* Create file if it doesn't exist in downloadToFile

* Add members to cache from retrieveMember methods

* Improve handling of join times for members

* Add Message.JUMP_URL_PATTERN

* Replace disconnect handling to recover from strange thread states (discord-jda#1295)

* Shutdown the WebSocket connection after everything else

* Use executor to shutdown in DefaultShardManager

* Add methods to bulk retrieve members (discord-jda#1292)

* Add methods to bulk retrieve members
* Add documentation
* Add missing annotations to Task interface
* Use random number as nonce

* Improvements to handling of Error (discord-jda#1285)

* Remove usage of AssertionError
* Improve handling of Errors

* Change domain to discord.com (discord-jda#1288)

* Fix NPE in ChannelManager#sync

* Add User#getFlags (discord-jda#1271)

* Add Emote#isAvailable() method

Co-authored-by: Florian Spieß <business@minnced.club>
Co-authored-by: Michael Ritter <ritter.michael92@gmail.com>
Co-authored-by: horyu1234 <horyu1234@naver.com>
Co-authored-by: DMan <DManstrator@users.noreply.github.com>
Co-authored-by: Austin Keener <keeneraustin@yahoo.com>
Co-authored-by: averen <31487840+averen@users.noreply.github.com>
Co-authored-by: Mathéo CIMBARO <25774021+DiscowZombie@users.noreply.github.com>
Co-authored-by: Artuto <artutogamer@gmail.com>
Co-authored-by: Nik <nik@monsterlyrics.co>
Co-authored-by: Sebo Molnár <git@mlnr.dev>
Co-authored-by: gpluscb <20143778+gpluscb@users.noreply.github.com>
Co-authored-by: Napster <napster@npstr.space>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants