From 8f4ec1c48d8b7b295fce7413bf3e5facacab1f56 Mon Sep 17 00:00:00 2001 From: Troptop <87533146+NickIsADev@users.noreply.github.com> Date: Wed, 24 Jul 2024 13:00:40 -0400 Subject: [PATCH 1/4] Add new getter: get.badges() --- libs/containers/User.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libs/containers/User.lua b/libs/containers/User.lua index a0ba9795..aa50469c 100644 --- a/libs/containers/User.lua +++ b/libs/containers/User.lua @@ -7,8 +7,13 @@ specific guild's context. local Snowflake = require('containers/abstract/Snowflake') local FilteredIterable = require('iterables/FilteredIterable') local constants = require('constants') +local enums = require('enums') +local bit = require('bit') +local band = bit.band local format = string.format +local insert = table.insert + local DEFAULT_AVATARS = constants.DEFAULT_AVATARS local User, get = require('class')('User', Snowflake) @@ -202,4 +207,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.]=] +function get.badges(self) + local badges = {} + local publicflags = self._public_flags + + for badge, flag in pairs(enums.userFlag) do + if band(publicflags, flag) == flag then + insert(badges, badge) + end + end + + return badges +end + return User From e4a77ca0d0d61de36d53baa5616197d60643da81 Mon Sep 17 00:00:00 2001 From: Troptop <87533146+NickIsADev@users.noreply.github.com> Date: Wed, 24 Jul 2024 13:05:30 -0400 Subject: [PATCH 2/4] Add enums.userFlag enum --- libs/enums.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/libs/enums.lua b/libs/enums.lua index b148b561..3b2c6dd2 100644 --- a/libs/enums.lua +++ b/libs/enums.lua @@ -235,6 +235,32 @@ enums.messageFlag = enum { isVoiceMessage = flag(13), } +enums.userFlag = enum { + staff = flag(0), + partner = flag(1), + hypesquad = flag(2), + bugHunterLevel1 = flag(3), + -- unused = flag(4), + -- unused = flag(5), + houseBravery = flag(6), + houseBrilliance = flag(7), + houseBalance = flag(8), + earlyNitroSupporter = flag(9), + teamPseudoUser = flag(10), + -- unused = flag(11), + -- unused = flag(12), + -- unused = flag(13), + bugHunterLevel2 = flag(14), + -- unused = flag(15), + verifiedBot = flag(16), + verifiedDeveloper = flag(17), + certifiedModerator = flag(18), + botHttpInteractions = flag(19), + -- unused = flag(20), + -- unused = flag(21), + activeDeveloper = flag(22) +} + enums.gatewayIntent = enum { guilds = flag(0), guildMembers = flag(1), -- privileged From f02b813ba536fbe65baf860fe4e4a7007ee57193 Mon Sep 17 00:00:00 2001 From: Troptop <87533146+NickIsADev@users.noreply.github.com> Date: Wed, 24 Jul 2024 13:11:01 -0400 Subject: [PATCH 3/4] Add User:hasBadge(dia.enums.userFlag) --- libs/containers/User.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/containers/User.lua b/libs/containers/User.lua index aa50469c..617f158e 100644 --- a/libs/containers/User.lua +++ b/libs/containers/User.lua @@ -62,6 +62,18 @@ function User:getDefaultAvatarURL(size) end end +--[=[ +@m hasBadge +@t mem +@p badge User-Flag-Resolvable +@r boolean +@d Indicates whether the user has the badge given. +]=] +function User:hasBadge(badge) + badge = Resolver.userFlag(badge) + return band(self._public_flags or 0, badge) == badge +end + --[=[ @m getPrivateChannel @t http From 4209ebdce40f99b6173ac3914d9b78e1cc3c3073 Mon Sep 17 00:00:00 2001 From: Troptop <87533146+NickIsADev@users.noreply.github.com> Date: Wed, 24 Jul 2024 13:12:54 -0400 Subject: [PATCH 4/4] Added Resolver.userFlag() --- libs/client/Resolver.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/client/Resolver.lua b/libs/client/Resolver.lua index efe9544e..a17d9204 100644 --- a/libs/client/Resolver.lua +++ b/libs/client/Resolver.lua @@ -8,6 +8,7 @@ local permission = assert(enums.permission) local gatewayIntent = assert(enums.gatewayIntent) local actionType = assert(enums.actionType) local messageFlag = assert(enums.messageFlag) +local userFlag = assert(enums.userFlag) local base64 = ssl.base64 local readFileSync = fs.readFileSync local classes = class.classes @@ -211,6 +212,17 @@ function Resolver.messageFlag(obj) return n end +function Resolver.userFlag(obj) + local t = type(obj) + local n = nil + if t == 'string' then + n = userFlag[obj] + elseif t == 'number' then + n = userFlag(obj) and obj + end + return n +end + function Resolver.base64(obj) if type(obj) == 'string' then if obj:find('data:.*;base64,') == 1 then