DB Storage Re-engineering #1
@ -1,5 +1,5 @@
|
|||||||
import "reflect-metadata"
|
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 { config } from "./config"
|
||||||
import { DataSource } from "typeorm"
|
import { DataSource } from "typeorm"
|
||||||
import { DBServer } from "./utilties/storage/entities/DBServer"
|
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 { DBMessageContentChanges } from "./utilties/storage/entities/DBMessageContentChanges"
|
||||||
import { DBMessageAttachments } from "./utilties/storage/entities/DBMessageAttachment"
|
import { DBMessageAttachments } from "./utilties/storage/entities/DBMessageAttachment"
|
||||||
import { setupMessageCapture } from "./utilties/events/messages"
|
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")
|
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,
|
DBUser,
|
||||||
DBMessage,
|
DBMessage,
|
||||||
DBMessageContentChanges,
|
DBMessageContentChanges,
|
||||||
DBMessageAttachments
|
DBMessageAttachments,
|
||||||
|
DBCall,
|
||||||
|
DBCallTranscriptions,
|
||||||
|
DBCallUsers
|
||||||
],
|
],
|
||||||
synchronize: true,
|
synchronize: true,
|
||||||
logging: true
|
logging: true
|
||||||
@ -69,67 +77,25 @@ client.once(Events.ClientReady, async () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
setupRoleCapture(client, serverRepo, roleRepo)
|
client.on(Events.GuildCreate, async (guild : Guild) => {
|
||||||
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)
|
await utilities.commands.deployCommands(guild.id)
|
||||||
|
await utilities.guilds.insertGuild(serverRepo, guild)
|
||||||
// TODO handle failures?
|
|
||||||
await utilities.guilds.insertGuild(db, guild)
|
|
||||||
|
|
||||||
guild.channels.cache.forEach(async (channel: GuildBasedChannel) => {
|
guild.channels.cache.forEach(async (channel: GuildBasedChannel) => {
|
||||||
await utilities.channels.insertChannel(db, channel)
|
await utilities.channels.insertChannel(channelRepo, channel)
|
||||||
})
|
})
|
||||||
|
|
||||||
guild.roles.cache.forEach(async (role: Role) => {
|
guild.roles.cache.forEach(async (role: Role) => {
|
||||||
await utilities.roles.insertRole(db, role)
|
await insertRole(roleRepo, 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) => {
|
client.on(Events.ChannelCreate, async (channel) => {
|
||||||
console.log("CHANNEL CREATE CALLED")
|
await utilities.channels.insertChannel(channelRepo, channel)
|
||||||
await utilities.channels.insertChannel(db, channel)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
client.on(Events.ThreadCreate, async (channel) => {
|
client.on(Events.ThreadCreate, async (channel) => {
|
||||||
console.log("THREAD CREATE CALLED")
|
await utilities.channels.insertChannel(channelRepo, channel)
|
||||||
console.log(channel.toString())
|
|
||||||
await utilities.channels.insertChannel(db, channel)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
client.on(Events.InteractionCreate, async (interaction: Interaction) => {
|
client.on(Events.InteractionCreate, async (interaction: Interaction) => {
|
||||||
@ -142,8 +108,10 @@ client.on(Events.InteractionCreate, async (interaction: Interaction) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
setInterval(async () => {
|
setupRoleCapture(client, serverRepo, roleRepo)
|
||||||
await utilities.breadthread.breadthreadProcessLocks(db, client)
|
setupMessageCapture(client, channelRepo, userRepo, messageRepo, mccRepo, maRepo)
|
||||||
}, 5000)
|
|
||||||
|
|
||||||
client.login(config.DISCORD_TOKEN)*/
|
console.log("Breadbot is Ready")
|
||||||
|
})
|
||||||
|
|
||||||
|
client.login(config.DISCORD_TOKEN)
|
||||||
34
src/utilties/storage/entities/DBCall.ts
Normal file
34
src/utilties/storage/entities/DBCall.ts
Normal file
@ -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
|
||||||
|
}
|
||||||
21
src/utilties/storage/entities/DBCallTranscriptions.ts
Normal file
21
src/utilties/storage/entities/DBCallTranscriptions.ts
Normal file
@ -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
|
||||||
|
}
|
||||||
21
src/utilties/storage/entities/DBCallUsers.ts
Normal file
21
src/utilties/storage/entities/DBCallUsers.ts
Normal file
@ -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
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
import { Column, Entity, ManyToOne, OneToMany, PrimaryColumn } from "typeorm";
|
import { Column, Entity, ManyToOne, OneToMany, PrimaryColumn } from "typeorm";
|
||||||
import { DBServer } from "./DBServer";
|
import { DBServer } from "./DBServer";
|
||||||
import { DBMessage } from "./DBMessage";
|
import { DBMessage } from "./DBMessage";
|
||||||
|
import { DBCall } from "./DBCall";
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class DBChannel {
|
export class DBChannel {
|
||||||
@ -23,5 +24,8 @@ export class DBChannel {
|
|||||||
is_voice: boolean
|
is_voice: boolean
|
||||||
|
|
||||||
@OneToMany(() => DBMessage, (message: DBMessage) => message.channel)
|
@OneToMany(() => DBMessage, (message: DBMessage) => message.channel)
|
||||||
messages: DBMessage[]
|
messages: DBMessage[] | null
|
||||||
|
|
||||||
|
@OneToMany(() => DBCall, (call: DBCall) => call.channel)
|
||||||
|
calls: DBCall[] | null
|
||||||
}
|
}
|
||||||
@ -1,5 +1,7 @@
|
|||||||
import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm";
|
import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm";
|
||||||
import { DBMessage } from "./DBMessage";
|
import { DBMessage } from "./DBMessage";
|
||||||
|
import { DBCallTranscriptions } from "./DBCallTranscriptions";
|
||||||
|
import { DBCallUsers } from "./DBCallUsers";
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class DBUser {
|
export class DBUser {
|
||||||
@ -14,4 +16,10 @@ export class DBUser {
|
|||||||
|
|
||||||
@OneToMany(() => DBMessage, (message: DBMessage) => message.user)
|
@OneToMany(() => DBMessage, (message: DBMessage) => message.user)
|
||||||
messages: DBMessage[]
|
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
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user