summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-07-12 20:12:37 +0200
committerRory& <root@rory.gay>2025-09-29 18:38:06 +0200
commit528662446c3377032190c117f5a3fe2fa8f3b88e (patch)
tree4d58bc6e22e74be7e47e1a8f52d1a13bf894b53b /src
parentA little bit of formatting cleanup (diff)
downloadserver-ts-528662446c3377032190c117f5a3fe2fa8f3b88e.tar.xz
Colorful roles
Diffstat (limited to 'src')
-rw-r--r--src/api/routes/guilds/#guild_id/roles/index.ts7
-rw-r--r--src/util/entities/Role.ts17
-rw-r--r--src/util/migration/postgres/1752321571508-RoleColors.ts14
-rw-r--r--src/util/migration/postgres/1752342900886-RoleColorsSolidColor.ts15
-rw-r--r--src/util/schemas/RoleModifySchema.ts5
5 files changed, 57 insertions, 1 deletions
diff --git a/src/api/routes/guilds/#guild_id/roles/index.ts b/src/api/routes/guilds/#guild_id/roles/index.ts

index e2c34e7f..bd944324 100644 --- a/src/api/routes/guilds/#guild_id/roles/index.ts +++ b/src/api/routes/guilds/#guild_id/roles/index.ts
@@ -72,7 +72,7 @@ router.post( throw DiscordApiErrors.MAXIMUM_ROLES.withParams(maxRoles); const role = Role.create({ - // values before ...body are default and can be overriden + // values before ...body are default and can be overridden position: 1, hoist: false, color: 0, @@ -88,6 +88,11 @@ router.post( icon: undefined, unicode_emoji: undefined, id: Snowflake.generate(), + colors: { + primary_color: body.colors?.primary_color || body.color || 0, + secondary_color: body.colors?.secondary_color || undefined, // gradient + tertiary_color: body.colors?.tertiary_color || undefined, // "holographic" + }, }); await Promise.all([ diff --git a/src/util/entities/Role.ts b/src/util/entities/Role.ts
index c5df6068..a58742ad 100644 --- a/src/util/entities/Role.ts +++ b/src/util/entities/Role.ts
@@ -22,6 +22,20 @@ import { BaseClass } from "./BaseClass"; import { Guild } from "./Guild"; import { dbEngine } from "../util/Database"; +export class RoleColors { + primary_color: number; + secondary_color: number | undefined; // only used for "holographic" and "gradient" styles + tertiary_color?: number | undefined; // only used for "holographic" style + + toJSON(): RoleColors { + return { + ...this, + secondary_color: this.secondary_color ?? undefined, + tertiary_color: this.tertiary_color ?? undefined, + }; + } +} + @Entity({ name: "roles", engine: dbEngine, @@ -74,6 +88,9 @@ export class Role extends BaseClass { @Column({ default: 0 }) flags: number; + @Column({ nullable: false, type: "simple-json" }) + colors: RoleColors; + toJSON(): Role { return { ...this, diff --git a/src/util/migration/postgres/1752321571508-RoleColors.ts b/src/util/migration/postgres/1752321571508-RoleColors.ts new file mode 100644
index 00000000..687142e3 --- /dev/null +++ b/src/util/migration/postgres/1752321571508-RoleColors.ts
@@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class RoleColors1752321571508 implements MigrationInterface { + name = 'RoleColors1752321571508' + + public async up(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(`ALTER TABLE "roles" ADD "colors" text`); + } + + public async down(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(`ALTER TABLE "roles" DROP COLUMN "colors"`); + } + +} diff --git a/src/util/migration/postgres/1752342900886-RoleColorsSolidColor.ts b/src/util/migration/postgres/1752342900886-RoleColorsSolidColor.ts new file mode 100644
index 00000000..36c24a37 --- /dev/null +++ b/src/util/migration/postgres/1752342900886-RoleColorsSolidColor.ts
@@ -0,0 +1,15 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class RoleColorsSolidColor1752342900886 implements MigrationInterface { + name = 'RoleColorsSolidColor1752342900886' + + public async up(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(`UPDATE "roles" SET "colors" = jsonb_build_object('primary_color', "color") WHERE "colors" IS NULL`); + await queryRunner.query(`ALTER TABLE "roles" ALTER COLUMN "colors" SET NOT NULL`); + } + + public async down(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(`ALTER TABLE "roles" ALTER COLUMN "colors" DROP NOT NULL`); + } + +} diff --git a/src/util/schemas/RoleModifySchema.ts b/src/util/schemas/RoleModifySchema.ts
index 1466953c..a6d18931 100644 --- a/src/util/schemas/RoleModifySchema.ts +++ b/src/util/schemas/RoleModifySchema.ts
@@ -25,4 +25,9 @@ export interface RoleModifySchema { position?: number; icon?: string; unicode_emoji?: string; + colors?: { + primary_color: number; + secondary_color: number | null | undefined; // only used for "holographic" and "gradient" styles + tertiary_color?: number | null | undefined; // only used for "holographic" style + } | undefined; }