diff --git a/src/breadbot.ts b/src/breadbot.ts index f80ead5..b2e9fc6 100644 --- a/src/breadbot.ts +++ b/src/breadbot.ts @@ -1,5 +1,5 @@ import "reflect-metadata" -import { Client, Events, GatewayIntentBits, Guild, GuildBasedChannel, Role } from "discord.js" +import { ChatInputCommandInteraction, Client, Events, GatewayIntentBits, Guild, GuildBasedChannel, Interaction, Role } from "discord.js" import { config } from "./config" import { DataSource } from "typeorm" import { DBServer } from "./utilties/storage/entities/DBServer" @@ -15,6 +15,11 @@ import { DBMessage } from "./utilties/storage/entities/DBMessage" import { DBMessageContentChanges } from "./utilties/storage/entities/DBMessageContentChanges" import { DBMessageAttachments } from "./utilties/storage/entities/DBMessageAttachment" import { setupMessageCapture } from "./utilties/events/messages" +import { utilities } from "./utilties" +import { commands } from "./commands" +import { DBCall } from "./utilties/storage/entities/DBCall" +import { DBCallTranscriptions } from "./utilties/storage/entities/DBCallTranscriptions" +import { DBCallUsers } from "./utilties/storage/entities/DBCallUsers" console.log(__dirname + path.sep + "utilities" + path.sep + "storage" + path.sep + "entities" + path.sep + "*.ts") @@ -28,7 +33,10 @@ export const dataSource = new DataSource({ DBUser, DBMessage, DBMessageContentChanges, - DBMessageAttachments + DBMessageAttachments, + DBCall, + DBCallTranscriptions, + DBCallUsers ], synchronize: true, logging: true @@ -69,81 +77,41 @@ client.once(Events.ClientReady, async () => { } }) + client.on(Events.GuildCreate, async (guild : Guild) => { + await utilities.commands.deployCommands(guild.id) + await utilities.guilds.insertGuild(serverRepo, guild) + + guild.channels.cache.forEach(async (channel: GuildBasedChannel) => { + await utilities.channels.insertChannel(channelRepo, channel) + }) + + guild.roles.cache.forEach(async (role: Role) => { + await insertRole(roleRepo, role) + }) + }) + + client.on(Events.ChannelCreate, async (channel) => { + await utilities.channels.insertChannel(channelRepo, channel) + }) + + client.on(Events.ThreadCreate, async (channel) => { + await utilities.channels.insertChannel(channelRepo, channel) + }) + + client.on(Events.InteractionCreate, async (interaction: Interaction) => { + if (!interaction.isCommand()) { + return + } + + if (commands[interaction.commandName as keyof typeof commands]) { + commands[interaction.commandName as keyof typeof commands].execute(interaction as ChatInputCommandInteraction) + } + }) + setupRoleCapture(client, serverRepo, roleRepo) setupMessageCapture(client, channelRepo, userRepo, messageRepo, mccRepo, maRepo) console.log("Breadbot is Ready") }) -client.login(config.DISCORD_TOKEN) - -/* -export let db: SQLCommon - -if (config.DB_MODE == "sqlite") { - db = new utilities.sqlite.SqliteDB("breadbot_test.db") - - db.run("PRAGMA foreign_keys = ON") - - utilities.tables.makeTables(db) - - //TODO I really don't want this to be here. - utilities.events.messages.setupMessageCapture(client, db) - utilities.events.roles.setupRoleCapture(client, db) -} - -client.once(Events.ClientReady, () => { - // TODO Winston should handle this - console.log("Breadbot is ready") - - client.guilds.cache.forEach(async (guild: Guild) => { - await utilities.commands.deployCommands(guild.id) - - // TODO handle failures? - await utilities.guilds.insertGuild(db, guild) - - guild.channels.cache.forEach(async (channel: GuildBasedChannel) => { - await utilities.channels.insertChannel(db, channel) - }) - - guild.roles.cache.forEach(async (role: Role) => { - await utilities.roles.insertRole(db, role) - }) - }) -}) - -client.on(Events.GuildCreate, async (guild : Guild) => { - await utilities.commands.deployCommands(guild.id) - await utilities.guilds.insertGuild(db, guild) - - guild.channels.cache.forEach(async (channel: GuildBasedChannel) => { - await utilities.channels.insertChannel(db, channel) - }) -}) - -client.on(Events.ChannelCreate, async (channel) => { - console.log("CHANNEL CREATE CALLED") - await utilities.channels.insertChannel(db, channel) -}) - -client.on(Events.ThreadCreate, async (channel) => { - console.log("THREAD CREATE CALLED") - console.log(channel.toString()) - await utilities.channels.insertChannel(db, channel) -}) - -client.on(Events.InteractionCreate, async (interaction: Interaction) => { - if (!interaction.isCommand()) { - return - } - - if (commands[interaction.commandName as keyof typeof commands]) { - commands[interaction.commandName as keyof typeof commands].execute(interaction as ChatInputCommandInteraction) - } -}) - -setInterval(async () => { - await utilities.breadthread.breadthreadProcessLocks(db, client) -}, 5000) - -client.login(config.DISCORD_TOKEN)*/ \ No newline at end of file +client.login(config.DISCORD_TOKEN) \ No newline at end of file diff --git a/src/utilties/storage/entities/DBCall.ts b/src/utilties/storage/entities/DBCall.ts new file mode 100644 index 0000000..1424f5b --- /dev/null +++ b/src/utilties/storage/entities/DBCall.ts @@ -0,0 +1,34 @@ +import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm"; +import { DBChannel } from "./DBChannel"; +import { DBCallTranscriptions } from "./DBCallTranscriptions"; +import { DBCallUsers } from "./DBCallUsers"; + +@Entity() +export class DBCall { + @PrimaryGeneratedColumn() + call_id: number + + @ManyToOne(() => DBChannel, (channel: DBChannel) => channel.calls) + channel: DBChannel + + @Column({type: "datetime"}) + call_start_time: Date + + @Column({type: "datetime", nullable: true, default: null}) + call_end_time: Date | null + + @Column({default: false}) + call_consolidated: boolean + + @Column({default: false}) + call_transcribed: boolean + + @Column({default: false}) + call_data_cleaned_up: boolean + + @OneToMany(() => DBCallTranscriptions, (transcription: DBCallTranscriptions) => transcription.call, {nullable: true}) + transcriptions: DBCallTranscriptions[] | null + + @OneToMany(() => DBCallUsers, (callUser: DBCallUsers) => callUser.call, {nullable: true}) + participants: DBCallUsers | null +} \ No newline at end of file diff --git a/src/utilties/storage/entities/DBCallTranscriptions.ts b/src/utilties/storage/entities/DBCallTranscriptions.ts new file mode 100644 index 0000000..04520ac --- /dev/null +++ b/src/utilties/storage/entities/DBCallTranscriptions.ts @@ -0,0 +1,21 @@ +import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm"; +import { DBCall } from "./DBCall"; +import { DBUser } from "./DBUser"; + +@Entity() +export class DBCallTranscriptions { + @PrimaryGeneratedColumn() + transcription_id: number + + @ManyToOne(() => DBCall, (call: DBCall) => call.transcriptions) + call: DBCall + + @ManyToOne(() => DBUser, (user: DBUser) => user.transcriptions) + user: DBUser + + @Column({type: "datetime"}) + speaking_start_time: Date + + @Column() + text: string +} \ No newline at end of file diff --git a/src/utilties/storage/entities/DBCallUsers.ts b/src/utilties/storage/entities/DBCallUsers.ts new file mode 100644 index 0000000..1a36d2b --- /dev/null +++ b/src/utilties/storage/entities/DBCallUsers.ts @@ -0,0 +1,21 @@ +import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm"; +import { DBCall } from "./DBCall"; +import { DBUser } from "./DBUser"; + +@Entity() +export class DBCallUsers { + @PrimaryGeneratedColumn() + call_users_id: number + + @ManyToOne(() => DBCall, (call: DBCall) => call.participants) + call: DBCall + + @ManyToOne(() => DBUser, (user: DBUser) => user.call_history) + user: DBUser + + @Column({type: "datetime"}) + call_join_time: Date + + @Column({type: "datetime", nullable: true, default: null}) + call_leave_time: Date | null +} \ No newline at end of file diff --git a/src/utilties/storage/entities/DBChannel.ts b/src/utilties/storage/entities/DBChannel.ts index 63c7e35..f2fdf02 100644 --- a/src/utilties/storage/entities/DBChannel.ts +++ b/src/utilties/storage/entities/DBChannel.ts @@ -1,6 +1,7 @@ import { Column, Entity, ManyToOne, OneToMany, PrimaryColumn } from "typeorm"; import { DBServer } from "./DBServer"; import { DBMessage } from "./DBMessage"; +import { DBCall } from "./DBCall"; @Entity() export class DBChannel { @@ -23,5 +24,8 @@ export class DBChannel { is_voice: boolean @OneToMany(() => DBMessage, (message: DBMessage) => message.channel) - messages: DBMessage[] + messages: DBMessage[] | null + + @OneToMany(() => DBCall, (call: DBCall) => call.channel) + calls: DBCall[] | null } \ No newline at end of file diff --git a/src/utilties/storage/entities/DBUser.ts b/src/utilties/storage/entities/DBUser.ts index bf11254..bce4cc3 100644 --- a/src/utilties/storage/entities/DBUser.ts +++ b/src/utilties/storage/entities/DBUser.ts @@ -1,5 +1,7 @@ import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm"; import { DBMessage } from "./DBMessage"; +import { DBCallTranscriptions } from "./DBCallTranscriptions"; +import { DBCallUsers } from "./DBCallUsers"; @Entity() export class DBUser { @@ -14,4 +16,10 @@ export class DBUser { @OneToMany(() => DBMessage, (message: DBMessage) => message.user) messages: DBMessage[] + + @OneToMany(() => DBCallTranscriptions, (transcription: DBCallTranscriptions) => transcription.user, {nullable: true}) + transcriptions: DBCallTranscriptions[] | null + + @OneToMany(() => DBCallUsers, (call_user: DBCallUsers) => call_user.user) + call_history: DBCallUsers[] | null } \ No newline at end of file