mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
feat: role gradient colors (#4239)
* sort GuildFeatures * feat: role gradient colors * Use deprecated jsdoc tag --------- Co-authored-by: Awesome Stickz <awesome@stickz.dev>
This commit is contained in:
@@ -41,6 +41,7 @@ import type {
|
||||
PollMedia,
|
||||
PollResult,
|
||||
Role,
|
||||
RoleColors,
|
||||
ScheduledEvent,
|
||||
ScheduledEventRecurrenceRule,
|
||||
Sku,
|
||||
@@ -99,6 +100,7 @@ export interface TransformersObjects {
|
||||
pollMedia: PollMedia
|
||||
pollResult: PollResult
|
||||
role: Role
|
||||
roleColors: RoleColors
|
||||
scheduledEvent: ScheduledEvent
|
||||
scheduledEventRecurrenceRule: ScheduledEventRecurrenceRule
|
||||
sku: Sku
|
||||
@@ -571,6 +573,7 @@ export function createDesiredPropertiesObject<T extends RecursivePartial<Transfo
|
||||
guildId: defaultValue,
|
||||
position: defaultValue,
|
||||
color: defaultValue,
|
||||
colors: defaultValue,
|
||||
id: defaultValue,
|
||||
permissions: defaultValue,
|
||||
icon: defaultValue,
|
||||
@@ -580,6 +583,12 @@ export function createDesiredPropertiesObject<T extends RecursivePartial<Transfo
|
||||
toggles: defaultValue,
|
||||
...desiredProperties.role,
|
||||
},
|
||||
roleColors: {
|
||||
primaryColor: defaultValue,
|
||||
secondaryColor: defaultValue,
|
||||
tertiaryColor: defaultValue,
|
||||
...desiredProperties.roleColors,
|
||||
},
|
||||
scheduledEvent: {
|
||||
id: defaultValue,
|
||||
guildId: defaultValue,
|
||||
|
||||
@@ -56,6 +56,7 @@ import type {
|
||||
DiscordPollMedia,
|
||||
DiscordPresenceUpdate,
|
||||
DiscordRole,
|
||||
DiscordRoleColors,
|
||||
DiscordScheduledEvent,
|
||||
DiscordScheduledEventRecurrenceRule,
|
||||
DiscordSku,
|
||||
@@ -136,6 +137,7 @@ import {
|
||||
type PollMedia,
|
||||
type PresenceUpdate,
|
||||
type Role,
|
||||
type RoleColors,
|
||||
type ScheduledEvent,
|
||||
type ScheduledEventRecurrenceRule,
|
||||
type Sku,
|
||||
@@ -211,6 +213,7 @@ import {
|
||||
transformPollMedia,
|
||||
transformPresence,
|
||||
transformRole,
|
||||
transformRoleColors,
|
||||
transformScheduledEvent,
|
||||
transformScheduledEventRecurrenceRule,
|
||||
transformSku,
|
||||
@@ -373,6 +376,7 @@ export type Transformers<TProps extends TransformersDesiredProperties, TBehavior
|
||||
pollMedia: (bot: Bot<TProps, TBehavior>, payload: DiscordPollMedia, pollMedia: SetupDesiredProps<PollMedia, TProps, TBehavior>) => any
|
||||
presence: (bot: Bot<TProps, TBehavior>, payload: DiscordPresenceUpdate, presence: PresenceUpdate) => any
|
||||
role: (bot: Bot<TProps, TBehavior>, payload: DiscordRole, role: SetupDesiredProps<Role, TProps, TBehavior>) => any
|
||||
roleColors: (bot: Bot<TProps, TBehavior>, payload: DiscordRoleColors, roleColors: SetupDesiredProps<RoleColors, TProps, TBehavior>) => any
|
||||
scheduledEvent: (
|
||||
bot: Bot<TProps, TBehavior>,
|
||||
payload: DiscordScheduledEvent,
|
||||
@@ -523,6 +527,7 @@ export type Transformers<TProps extends TransformersDesiredProperties, TBehavior
|
||||
pollMedia: (bot: Bot<TProps, TBehavior>, payload: DiscordPollMedia) => SetupDesiredProps<PollMedia, TProps, TBehavior>
|
||||
presence: (bot: Bot<TProps, TBehavior>, payload: DiscordPresenceUpdate) => PresenceUpdate
|
||||
role: (bot: Bot<TProps, TBehavior>, payload: { role: DiscordRole; guildId: BigString }) => SetupDesiredProps<Role, TProps, TBehavior>
|
||||
roleColors: (bot: Bot<TProps, TBehavior>, payload: DiscordRoleColors) => SetupDesiredProps<RoleColors, TProps, TBehavior>
|
||||
scheduledEvent: (bot: Bot<TProps, TBehavior>, payload: DiscordScheduledEvent) => SetupDesiredProps<ScheduledEvent, TProps, TBehavior>
|
||||
scheduledEventRecurrenceRule: (
|
||||
bot: Bot<TProps, TBehavior>,
|
||||
@@ -608,6 +613,7 @@ export function createTransformers<TProps extends TransformersDesiredProperties,
|
||||
pollMedia: options.customizers?.pollMedia ?? defaultCustomizer,
|
||||
presence: options.customizers?.presence ?? defaultCustomizer,
|
||||
role: options.customizers?.role ?? defaultCustomizer,
|
||||
roleColors: options.customizers?.roleColors ?? defaultCustomizer,
|
||||
scheduledEvent: options.customizers?.scheduledEvent ?? defaultCustomizer,
|
||||
scheduledEventRecurrenceRule: options.customizers?.scheduledEventRecurrenceRule ?? defaultCustomizer,
|
||||
sku: options.customizers?.sku ?? defaultCustomizer,
|
||||
@@ -698,6 +704,7 @@ export function createTransformers<TProps extends TransformersDesiredProperties,
|
||||
pollMedia: options.pollMedia ?? transformPollMedia,
|
||||
presence: options.presence ?? transformPresence,
|
||||
role: options.role ?? transformRole,
|
||||
roleColors: options.roleColors ?? transformRoleColors,
|
||||
scheduledEvent: options.scheduledEvent ?? transformScheduledEvent,
|
||||
scheduledEventRecurrenceRule: options.scheduledEventRecurrenceRule ?? transformScheduledEventRecurrenceRule,
|
||||
sku: options.sku ?? transformSku,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { BigString, DiscordRole } from '@discordeno/types'
|
||||
import { type InternalBot, type Role, iconHashToBigInt } from '../index.js'
|
||||
import type { BigString, DiscordRole, DiscordRoleColors } from '@discordeno/types'
|
||||
import { type InternalBot, type Role, type RoleColors, iconHashToBigInt } from '../index.js'
|
||||
import { Permissions } from './toggles/Permissions.js'
|
||||
import { RoleToggles } from './toggles/role.js'
|
||||
|
||||
@@ -69,3 +69,16 @@ export function transformRole(bot: InternalBot, payload: { role: DiscordRole; gu
|
||||
|
||||
return bot.transformers.customizers.role(bot, payload.role, role)
|
||||
}
|
||||
|
||||
export function transformRoleColors(bot: InternalBot, payload: DiscordRoleColors): RoleColors {
|
||||
const roleColors = {} as RoleColors
|
||||
const props = bot.transformers.desiredProperties.roleColors
|
||||
|
||||
if (props.primaryColor && payload.primary_color !== undefined) roleColors.primaryColor = payload.primary_color
|
||||
if (props.secondaryColor && payload.secondary_color !== undefined && payload.secondary_color !== null)
|
||||
roleColors.secondaryColor = payload.secondary_color
|
||||
if (props.tertiaryColor && payload.tertiary_color !== undefined && payload.tertiary_color !== null)
|
||||
roleColors.tertiaryColor = payload.tertiary_color
|
||||
|
||||
return bot.transformers.customizers.roleColors(bot, payload, roleColors)
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ const featureNames = [
|
||||
'verified',
|
||||
'vipRegions',
|
||||
'welcomeScreenEnabled',
|
||||
'enhancedRoleColors',
|
||||
] as const
|
||||
|
||||
export const GuildToggle = {
|
||||
@@ -45,7 +46,7 @@ export const GuildToggle = {
|
||||
premiumProgressBarEnabled: 1n << 4n,
|
||||
|
||||
// GUILD FEATURES ARE BELOW THIS
|
||||
// MISSING VALUES IN THE BITFIELD: 26, 35+
|
||||
// MISSING VALUES IN THE BITFIELD: 36+
|
||||
|
||||
/** Whether the guild has access to set an animated guild banner image */
|
||||
animatedBanner: 1n << 11n,
|
||||
@@ -105,6 +106,8 @@ export const GuildToggle = {
|
||||
vipRegions: 1n << 6n,
|
||||
/** Whether the guild has enabled the welcome screen */
|
||||
welcomeScreenEnabled: 1n << 18n,
|
||||
/** Whether the guild is able to set gradient colors to roles */
|
||||
enhancedRoleColors: 1n << 35n,
|
||||
}
|
||||
|
||||
export class GuildToggles extends ToggleBitfieldBigint {
|
||||
@@ -152,6 +155,7 @@ export class GuildToggles extends ToggleBitfieldBigint {
|
||||
if (guild.features.includes(GuildFeatures.Verified)) this.add(GuildToggle.verified)
|
||||
if (guild.features.includes(GuildFeatures.VipRegions)) this.add(GuildToggle.vipRegions)
|
||||
if (guild.features.includes(GuildFeatures.WelcomeScreenEnabled)) this.add(GuildToggle.welcomeScreenEnabled)
|
||||
if (guild.features.includes(GuildFeatures.EnhancedRoleColors)) this.add(GuildToggle.enhancedRoleColors)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,6 +341,11 @@ export class GuildToggles extends ToggleBitfieldBigint {
|
||||
return this.has('soundboard')
|
||||
}
|
||||
|
||||
/** Whether the guild is able to set gradient colors to roles */
|
||||
get enhancedRoleColors(): boolean {
|
||||
return this.has('enhancedRoleColors')
|
||||
}
|
||||
|
||||
/** Checks whether or not the permissions exist in this */
|
||||
has(permissions: GuildToggleKeys | GuildToggleKeys[]): boolean {
|
||||
if (!Array.isArray(permissions)) return super.contains(GuildToggle[permissions])
|
||||
|
||||
@@ -1502,8 +1502,13 @@ export interface Role {
|
||||
icon?: bigint
|
||||
/** Role name */
|
||||
name: string
|
||||
/** Integer representation of hexadecimal color code */
|
||||
/**
|
||||
* Integer representation of hexadecimal color code
|
||||
* @deprecated the {@link colors} field is recommended for use instead of this field
|
||||
*/
|
||||
color: number
|
||||
/** The role's color */
|
||||
colors: RoleColors
|
||||
/** Position of this role */
|
||||
position: number
|
||||
/** role unicode emoji */
|
||||
@@ -1547,6 +1552,15 @@ export interface RoleTags {
|
||||
premiumSubscriber?: boolean
|
||||
}
|
||||
|
||||
export interface RoleColors {
|
||||
/** The primary color for the role */
|
||||
primaryColor: number
|
||||
/** The secondary color for the role, this will make the role a gradient between the other provided colors */
|
||||
secondaryColor?: number
|
||||
/** The tertiary color for the role, this will turn the gradient into a holographic style */
|
||||
tertiaryColor?: number
|
||||
}
|
||||
|
||||
export interface ScheduledEvent {
|
||||
/** the id of the scheduled event */
|
||||
id: bigint
|
||||
|
||||
Reference in New Issue
Block a user