diff --git a/assets/schemas.json b/assets/schemas.json index 84fc55ad..65a85c20 100755 Binary files a/assets/schemas.json and b/assets/schemas.json differ 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 { + await queryRunner.query(`ALTER TABLE "roles" ADD "colors" text`); + } + + public async down(queryRunner: QueryRunner): Promise { + 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 { + 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 { + 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; }