Skip to content

Add colors and collectibles #241

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

Draft
wants to merge 6 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/structures/Role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Base from "./Base";
import Permission from "./Permission";
import type Guild from "./Guild";
import type Client from "../Client";
import type { RawRole, RoleTags, EditRoleOptions } from "../types/guilds";
import type { RawRole, RoleTags, EditRoleOptions, RoleColors } from "../types/guilds";
import type { JSONRole } from "../types/json";
import { UncachedError } from "../util/Errors";

Expand All @@ -12,6 +12,8 @@ export default class Role extends Base {
private _cachedGuild?: Guild;
/** The color of this role. */
color: number;
/** The colors of this role. */
colors: RoleColors;
/** The {@link Constants~RoleFlags | flags } for this role. */
flags: number;
/** The id of the guild this role is in. */
Expand All @@ -37,6 +39,11 @@ export default class Role extends Base {
constructor(data: RawRole, client: Client, guildID: string) {
super(data.id, client);
this.color = data.color;
this.colors = {
primaryColor: data.colors.primary_color,
secondaryColor: data.colors.secondary_color,
tertiaryColor: data.colors.tertiary_color
};
this.flags = data.flags;
this.guildID = guildID;
this.hoist = !!data.hoist;
Expand All @@ -57,6 +64,13 @@ export default class Role extends Base {
if (data.color !== undefined) {
this.color = data.color;
}
if (data.colors !== undefined) {
this.colors = {
primaryColor: data.colors.primary_color,
secondaryColor: data.colors.secondary_color,
tertiaryColor: data.colors.tertiary_color
};
}
if (data.hoist !== undefined) {
this.hoist = data.hoist;
}
Expand Down Expand Up @@ -132,6 +146,7 @@ export default class Role extends Base {
return {
...super.toJSON(),
color: this.color,
colors: this.colors,
guildID: this.guildID,
hoist: this.hoist,
icon: this.icon,
Expand Down
16 changes: 15 additions & 1 deletion lib/structures/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Clan from "./Clan";
import { EntitlementOwnerTypes, type ImageFormat } from "../Constants";
import * as Routes from "../util/Routes";
import type Client from "../Client";
import type { AvatarDecorationData, RawUser } from "../types/users";
import type { AvatarDecorationData, Collectibles, RawUser } from "../types/users";
import type { JSONUser } from "../types/json";
import type { SearchEntitlementsOptions } from "../types/applications";
import { UncachedError } from "../util/Errors";
Expand All @@ -26,6 +26,8 @@ export default class User extends Base {
bot: boolean;
/** The primary clan this user is in. */
clan: Clan | null;
/** The user's collectibles. */
collectibles: Collectibles | null;
/** The 4 digits after this user's username, if they have not been migrated. If migrated, this will be a single "0". */
discriminator: string;
/** The user's display name, if set. */
Expand All @@ -42,6 +44,7 @@ export default class User extends Base {
this.avatarDecorationData = null;
this.bot = !!data.bot;
this.clan = null;
this.collectibles = null;
this.discriminator = data.discriminator;
this.globalName = data.global_name;
this.publicFlags = 0;
Expand All @@ -66,6 +69,16 @@ export default class User extends Base {
if (data.banner !== undefined) {
this.banner = data.banner;
}
if (data.collectibles !== undefined) {
this.collectibles = data.collectibles ? {
nameplate: data.collectibles.nameplate ? {
asset: data.collectibles.nameplate.asset,
label: data.collectibles.nameplate.label,
palette: data.collectibles.nameplate.palette,
skuID: data.collectibles.nameplate.sku_id
} : undefined
} : null;
}
if (data.discriminator !== undefined) {
this.discriminator = data.discriminator;
}
Expand Down Expand Up @@ -185,6 +198,7 @@ export default class User extends Base {
avatarDecorationData: this.avatarDecorationData,
banner: this.banner,
bot: this.bot,
collectibles: this.collectibles,
discriminator: this.discriminator,
globalName: this.globalName,
publicFlags: this.publicFlags,
Expand Down
14 changes: 14 additions & 0 deletions lib/types/guilds.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export interface RawInviteGuild extends Pick<RawGuild, "id" | "name" | "splash"

export interface RawRole {
color: number;
colors: RawRoleColors;
flags: number;
hoist: boolean;
icon?: string | null;
Expand Down Expand Up @@ -137,6 +138,19 @@ export interface RoleTags {
premiumSubscriber: boolean;
subscriptionListingID?: string;
}

export interface RawRoleColors {
primary_color: number;
secondary_color: number | null;
tertiary_color: number | null;
}

export interface RoleColors {
primaryColor: number;
secondaryColor: number | null;
tertiaryColor: number | null;
}

export interface RawGuildEmoji extends Required<Omit<Emoji, "user" | "id">> { id: string; user?: RawUser; }
export interface GuildEmoji extends Omit<RawGuildEmoji, "user" | "id" | "require_colons"> { id: string; requireColons?: boolean; user?: User; }
export interface RawWelcomeScreen {
Expand Down
7 changes: 5 additions & 2 deletions lib/types/json.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import type {
WelcomeScreen,
Sticker,
Presence,
IncidentActions
IncidentActions,
RoleColors
} from "./guilds";
import type {
ChannelMention,
Expand All @@ -46,7 +47,7 @@ import type {
MessageComponent
} from "./channels";
import type { ScheduledEventEntityMetadata } from "./scheduled-events";
import type { AvatarDecorationData } from "./users";
import type { AvatarDecorationData, Collectibles } from "./users";
import type {
ApplicationCommandTypes,
AutoModerationEventTypes,
Expand Down Expand Up @@ -635,6 +636,7 @@ export interface JSONPublicThreadChannel extends JSONThreadChannel {
}
export interface JSONRole extends JSONBase {
color: number;
colors: RoleColors;
guildID: string;
hoist: boolean;
icon: string | null;
Expand Down Expand Up @@ -755,6 +757,7 @@ export interface JSONUser extends JSONBase {
avatarDecorationData: AvatarDecorationData | null;
banner?: string | null;
bot: boolean;
collectibles: Collectibles | null;
discriminator: string;
globalName: string | null;
publicFlags: number;
Expand Down
25 changes: 24 additions & 1 deletion lib/types/users.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface RESTUser {
banner?: string | null;
bot?: boolean;
clan?: RawClan | null;
collectibles?: RawCollectibles | null;
discriminator: string;
email?: string | null;
flags?: number;
Expand All @@ -23,7 +24,7 @@ export interface RESTUser {
username: string;
verified?: boolean;
}
export interface RawUser extends Pick<RESTUser, "id" | "username" | "discriminator" | "avatar" | "avatar_decoration_data" | "bot" | "system" | "banner" | "accent_color" | "clan">, Required<Pick<RESTUser, "public_flags" | "global_name">> {}
export interface RawUser extends Pick<RESTUser, "id" | "username" | "discriminator" | "avatar" | "avatar_decoration_data" | "bot" | "system" | "banner" | "accent_color" | "clan" | "collectibles">, Required<Pick<RESTUser, "public_flags" | "global_name">> {}
export interface RawUserWithMember extends RawUser, Pick<RESTUser, "member"> {}
export interface RawOAuthUser extends Pick<RESTUser, "id" | "username" | "discriminator" | "avatar" | "avatar_decoration_data" | "bot" | "system" | "global_name">, Required<Pick<RESTUser, "banner" | "accent_color" | "locale" | "mfa_enabled" | "email" | "verified" | "flags" | "public_flags" | "clan">> {}
export interface RawExtendedUser extends Pick<RawOAuthUser, "avatar" | "avatar_decoration_data" | "bot" | "discriminator" | "email" | "flags" | "id" | "mfa_enabled" | "username" | "verified" | "global_name" | "clan"> {}
Expand Down Expand Up @@ -60,3 +61,25 @@ export interface AvatarDecorationData {
asset: string;
skuID: string;
}

export interface RawCollectibles {
nameplate?: RawNameplate;
}

export interface Collectibles {
nameplate?: Nameplate;
}

export interface RawNameplate {
asset: string;
label: string;
palette: string;
sku_id: string;
}

export interface Nameplate {
asset: string;
label: string;
palette: string;
skuID: string;
}