From d75d45748601a317111d823351bbed1b47492cae Mon Sep 17 00:00:00 2001 From: March 7th <71698422+aiko-chan-ai@users.noreply.github.com> Date: Thu, 22 Dec 2022 19:37:05 +0700 Subject: [PATCH] feat: premiumUsageFlags --- src/client/websocket/handlers/READY.js | 2 -- src/structures/ClientUser.js | 8 +++++++ src/util/PremiumUsageFlags.js | 30 ++++++++++++++++++++++++++ typings/index.d.ts | 9 ++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/util/PremiumUsageFlags.js diff --git a/src/client/websocket/handlers/READY.js b/src/client/websocket/handlers/READY.js index 80f1b72..bc34ad4 100644 --- a/src/client/websocket/handlers/READY.js +++ b/src/client/websocket/handlers/READY.js @@ -109,8 +109,6 @@ module.exports = async (client, { d: data }, shard) => { client.users.cache.set(client.user.id, client.user); } - client.user.setAFK(false); - client.settings._patch(data.user_settings); client.user.connectedAccounts = data.connected_accounts ?? []; diff --git a/src/structures/ClientUser.js b/src/structures/ClientUser.js index 39e2e7e..85b711c 100644 --- a/src/structures/ClientUser.js +++ b/src/structures/ClientUser.js @@ -8,6 +8,7 @@ const { Util } = require('..'); const { Error: Error_ } = require('../errors'); const { Opcodes, NitroType, HypeSquadType } = require('../util/Constants'); const DataResolver = require('../util/DataResolver'); +const PremiumUsageFlags = require('../util/PremiumUsageFlags'); const PurchasedFlags = require('../util/PurchasedFlags'); /** * Represents the logged in client's Discord user. @@ -53,6 +54,13 @@ class ClientUser extends User { */ this.purchasedFlags = new PurchasedFlags(data.purchased_flags || 0); } + if ('premium_usage_flags' in data) { + /** + * Premium usage state of the client user. + * @type {?PremiumUsageFlags} + */ + this.premiumUsageFlags = new PremiumUsageFlags(data.premium_usage_flags || 0); + } // Key: premium = boolean; if ('phone' in data) { /** diff --git a/src/util/PremiumUsageFlags.js b/src/util/PremiumUsageFlags.js new file mode 100644 index 00000000..7b71ebb --- /dev/null +++ b/src/util/PremiumUsageFlags.js @@ -0,0 +1,30 @@ +'use strict'; + +const BitField = require('./BitField'); + +/** + * Data structure that makes it easy to interact with an {@link PremiumUsageFlags#flags} bitfield. + * @extends {BitField} + */ +class PremiumUsageFlags extends BitField {} + +/** + * @name PremiumUsageFlags + * @kind constructor + * @memberof PremiumUsageFlags + * @param {BitFieldResolvable} [bits=0] Bit(s) to read from + */ + +/** + * Numeric the Discord premium usage flags. All available properties: + * * `ANIMATED_AVATAR` + * * `BANNER` + * * `CUSTOM_DISCRIMINATOR` + * @type {Object} + */ +PremiumUsageFlags.FLAGS = { + ANIMATED_AVATAR: 1 << 1, + BANNER: 1 << 2, +}; + +module.exports = PremiumUsageFlags; diff --git a/typings/index.d.ts b/typings/index.d.ts index e46d256..70adde0 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -360,6 +360,11 @@ export class PurchasedFlags extends BitField { public static resolve(bit?: BitFieldResolvable): number; } +export class PremiumUsageFlags extends BitField { + public static FLAGS: Record; + public static resolve(bit?: BitFieldResolvable): number; +} + export abstract class AnonymousGuild extends BaseGuild { protected constructor(client: Client, data: RawAnonymousGuildData, immediatePatch?: boolean); public banner: string | null; @@ -951,6 +956,8 @@ export class ClientUser extends User { public verified: boolean; public notes: Collection; public friendNicknames: Collection; + public purchasedFlags: PurchasedFlags; + public premiumUsageFlags: PremiumUsageFlags; public setThemeColors(primary?: ColorResolvable, accent?: ColorResolvable): ClientUser; public edit(data: ClientUserEditData): Promise; public setActivity(options?: ActivityOptions): ClientPresence; @@ -4240,6 +4247,8 @@ export interface WebhookFields extends PartialWebhookFields { //#region Typedefs export type PurchasedFlagsString = 'NITRO_CLASSIC' | 'NITRO' | 'GUILD_BOOST'; +export type PremiumUsageFlagsString = 'ANIMATED_AVATAR' | 'BANNER' | 'CUSTOM_DISCRIMINATOR'; + export type ActivityFlagsString = | 'INSTANCE' | 'JOIN'