From edbf24664a45f8a6b83c57603bd469a36fd37b5f Mon Sep 17 00:00:00 2001 From: graphiteisaac Date: Tue, 3 Mar 2026 12:32:49 +1100 Subject: [PATCH] (bot/trakt) add entities and migrations for Trakt data --- .../src/data/entities/TraktMessageTarget.ts | 14 ++ backend/src/data/entities/TraktUser.ts | 16 ++ .../src/data/entities/TraktVoiceSession.ts | 12 ++ .../src/data/entities/TraktVoiceSummary.ts | 14 ++ .../migrations/1772497950752-CreateTrakt.ts | 142 ++++++++++++++++++ backend/src/plugins/Trakt/TraktPlugin.ts | 0 6 files changed, 198 insertions(+) create mode 100644 backend/src/data/entities/TraktMessageTarget.ts create mode 100644 backend/src/data/entities/TraktUser.ts create mode 100644 backend/src/data/entities/TraktVoiceSession.ts create mode 100644 backend/src/data/entities/TraktVoiceSummary.ts create mode 100644 backend/src/migrations/1772497950752-CreateTrakt.ts create mode 100644 backend/src/plugins/Trakt/TraktPlugin.ts diff --git a/backend/src/data/entities/TraktMessageTarget.ts b/backend/src/data/entities/TraktMessageTarget.ts new file mode 100644 index 00000000..f0a9d29e --- /dev/null +++ b/backend/src/data/entities/TraktMessageTarget.ts @@ -0,0 +1,14 @@ +import { Column, Entity, Index, PrimaryColumn } from "typeorm"; + +@Entity("trakt_message_targets") +export class TraktMessageTarget { + @Column() + @PrimaryColumn() + owner: number; + + @Column() + @Index() + target: number; + + @Column() timeout: number; +} diff --git a/backend/src/data/entities/TraktUser.ts b/backend/src/data/entities/TraktUser.ts new file mode 100644 index 00000000..c3a6b8b0 --- /dev/null +++ b/backend/src/data/entities/TraktUser.ts @@ -0,0 +1,16 @@ +import { Column, Entity, PrimaryColumn } from "typeorm"; + +@Entity("trakt_users") +export class TraktUser { + @Column() + @PrimaryColumn() + snowflake: number; + + @Column() message_score: number; + + @Column() time_score: number; + + @Column() has_regular: boolean; + + @Column() sanction_time: number; +} diff --git a/backend/src/data/entities/TraktVoiceSession.ts b/backend/src/data/entities/TraktVoiceSession.ts new file mode 100644 index 00000000..d7d688ae --- /dev/null +++ b/backend/src/data/entities/TraktVoiceSession.ts @@ -0,0 +1,12 @@ +import { Column, Entity, PrimaryColumn } from "typeorm"; + +@Entity("trakt_voice_sessions") +export class TraktVoiceSession { + @Column() + @PrimaryColumn() + snowflake: number; + + @Column() session_date: Date; + + @Column() session_duration: number; +} diff --git a/backend/src/data/entities/TraktVoiceSummary.ts b/backend/src/data/entities/TraktVoiceSummary.ts new file mode 100644 index 00000000..9e4e9633 --- /dev/null +++ b/backend/src/data/entities/TraktVoiceSummary.ts @@ -0,0 +1,14 @@ +import { Column, Entity, PrimaryColumn } from "typeorm"; + +@Entity("trakt_voice_summaries") +export class TraktVoiceSummary { + @Column() + @PrimaryColumn() + snowflake: number; + + @Column() week_total: number; + + @Column() month_total: number; + + @Column() has_regular: boolean; +} diff --git a/backend/src/migrations/1772497950752-CreateTrakt.ts b/backend/src/migrations/1772497950752-CreateTrakt.ts new file mode 100644 index 00000000..b3d80da0 --- /dev/null +++ b/backend/src/migrations/1772497950752-CreateTrakt.ts @@ -0,0 +1,142 @@ +import { MigrationInterface, QueryRunner, Table, TableIndex } from "typeorm"; + +export class CreateTrakt1772497950752 implements MigrationInterface { + name = "CreateTrakt1772497950752"; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.createTable( + new Table({ + name: "trakt_users", + columns: [ + { + name: "snowflake", + type: "bigint", + unsigned: true, + isNullable: false, + isPrimary: true, + }, + { + name: "message_score", + type: "smallint", + isNullable: false, + default: 1, + }, + { + name: "time_score", + type: "smallint", + isNullable: false, + default: 0, + }, + { + name: "has_regular", + type: "boolean", + default: false, + isNullable: false, + }, + { + name: "sanction_time", + type: "int", + isNullable: true, + default: null, + }, + ], + }), + ); + + await queryRunner.createTable( + new Table({ + name: "trakt_voice_sessions", + columns: [ + { + name: "snowflake", + type: "bigint", + unsigned: true, + isNullable: false, + isPrimary: true, + }, + { + name: "session_date", + type: "date", + isNullable: false, + }, + { + name: "session_duration", + type: "int", + isNullable: false, + }, + ], + }), + ); + + await queryRunner.createTable( + new Table({ + name: "trakt_voice_summaries", + columns: [ + { + name: "snowflake", + type: "bigint", + unsigned: true, + isNullable: false, + isPrimary: true, + }, + { + name: "week_total", + type: "int", + isNullable: false, + }, + { + name: "month_total", + type: "int", + isNullable: false, + }, + { + name: "has_regular", + type: "bool", + isNullable: false, + default: false, + }, + ], + }), + ); + + await queryRunner.createTable( + new Table({ + name: "trakt_message_targets", + columns: [ + { + name: "owner", + type: "bigint", + unsigned: true, + isNullable: false, + isPrimary: true, + }, + { + name: "target", + type: "bigint", + unsigned: true, + isNullable: false, + }, + { + name: "timeout", + type: "int", + isNullable: false, + }, + ], + }), + ); + + await queryRunner.createIndex( + "trakt_message_targets", + new TableIndex({ + columnNames: ["target"], + }), + ); + } + + public async down(queryRunner: QueryRunner): Promise { + queryRunner.dropTable("trakt_users"); + queryRunner.dropTable("trakt_voice_session"); + queryRunner.dropTable("trakt_voice_summary"); + queryRunner.dropTable("trakt_message_targets"); + } +} diff --git a/backend/src/plugins/Trakt/TraktPlugin.ts b/backend/src/plugins/Trakt/TraktPlugin.ts new file mode 100644 index 00000000..e69de29b