-
Notifications
You must be signed in to change notification settings - Fork 145
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 support for Badges #412
base: master
Are you sure you want to change the base?
Conversation
This looks great except I would prefer to use the API term "flag" everywhere instead of using the product term "badge". So, |
I'm not sure I like the |
@@ -202,4 +219,18 @@ function get.mutualGuilds(self) | |||
return self._mutual_guilds | |||
end | |||
|
|||
--[=[@p badges Array An array of all badges the user has, represented by the badge's name.]=] |
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 either say table
or it should return an ArrayIterable
instead of a table (I recommend this), Array
on its own is not a valid type.
]=] | ||
function User:hasBadge(badge) | ||
badge = Resolver.userFlag(badge) | ||
return band(self._public_flags or 0, badge) == badge |
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.
Note that this method works differently compared to something like Message:hasFlag()
, which checks for the presence of any of the provided flags. Might want to change it to how Message does it, or vise versa.
This pull request creates a new Enum,
enum.userFlag
, creates a new Resolver,Resolver.userFlag()
, a new User getter,get.badges()
, and a new User method,User:hasBadge(User-Flag-Resolvable)
. These all allow for Badges support.get.badges()
returns an array of strings which represent the badge's name (which matches up with the Enum).User:hasBadge()
returns a boolean indicating whether or not the user has the specified User-Flag-Resolvable.Most of this was derived from Message Flags to maintain consistency.
Both the getter and the method have been tested.
One thing to note it that the
staff
badge does not seem to be able to be read due to its bit. I wasn't entirely sure what to do with the enum so I ended up keeping it. Another thing I wasnt so sure about was whether User:hasBadge() should return the flag value, or the badge name. It was agreed upon in the Discordia server that the badge name would be easier to handle.The raw property of a User that provides the functionality of Badges is
User._public_flags
. The documentation can be found here.