diff --git a/.dev.env b/.dev.env index bb123f5..964667c 100644 --- a/.dev.env +++ b/.dev.env @@ -15,11 +15,3 @@ BOT_CLIENTID=682942374040961060 ABOUT_FUNDING=https://ko-fi.com/vylpes ABOUT_REPO=https://gitea.vylpes.xyz/RabbitLabs/vylbot-app - -DB_HOST=127.0.0.1 -DB_PORT=3101 -DB_NAME=vylbot -DB_AUTH_USER=dev -DB_AUTH_PASS=dev -DB_SYNC=true -DB_LOGGING=true \ No newline at end of file diff --git a/.prod.env b/.prod.env index 25cac3d..f0c75d5 100644 --- a/.prod.env +++ b/.prod.env @@ -14,11 +14,3 @@ BOT_CLIENTID=680083120896081954 ABOUT_FUNDING=https://ko-fi.com/vylpes ABOUT_REPO=https://gitea.vylpes.xyz/RabbitLabs/vylbot-app - -DB_HOST=127.0.0.1 -DB_PORT=3121 -DB_NAME=vylbot -DB_AUTH_USER=prod -DB_AUTH_PASS=prod -DB_SYNC=false -DB_LOGGING=false \ No newline at end of file diff --git a/.stage.env b/.stage.env index 383569a..9b90831 100644 --- a/.stage.env +++ b/.stage.env @@ -14,11 +14,3 @@ BOT_CLIENTID=1016767908740857949 ABOUT_FUNDING=https://ko-fi.com/vylpes ABOUT_REPO=https://gitea.vylpes.xyz/RabbitLabs/vylbot-app - -DB_HOST=127.0.0.1 -DB_PORT=3111 -DB_NAME=vylbot -DB_AUTH_USER=stage -DB_AUTH_PASS=stage -DB_SYNC=false -DB_LOGGING=false \ No newline at end of file diff --git a/ormconfig.dev.json b/ormconfig.dev.json new file mode 100644 index 0000000..f6f80c1 --- /dev/null +++ b/ormconfig.dev.json @@ -0,0 +1,24 @@ +{ + "type": "mysql", + "host": "localhost", + "port": 3101, + "username": "dev", + "password": "dev", + "database": "vylbot", + "synchronize": false, + "logging": false, + "entities": [ + "dist/entity/**/*.js" + ], + "migrations": [ + "dist/migration/**/*.js" + ], + "subscribers": [ + "dist/subscriber/**/*.js" + ], + "cli": { + "entitiesDir": "dist/entity", + "migrationsDir": "dist/migration", + "subscribersDir": "dist/subscriber" + } +} \ No newline at end of file diff --git a/ormconfig.prod.json b/ormconfig.prod.json new file mode 100644 index 0000000..300cfe2 --- /dev/null +++ b/ormconfig.prod.json @@ -0,0 +1,24 @@ +{ + "type": "mysql", + "host": "localhost", + "port": 3121, + "username": "prod", + "password": "prod", + "database": "vylbot", + "synchronize": false, + "logging": false, + "entities": [ + "dist/entity/**/*.js" + ], + "migrations": [ + "dist/migration/**/*.js" + ], + "subscribers": [ + "dist/subscriber/**/*.js" + ], + "cli": { + "entitiesDir": "dist/entity", + "migrationsDir": "dist/migration", + "subscribersDir": "dist/subscriber" + } +} \ No newline at end of file diff --git a/ormconfig.stage.json b/ormconfig.stage.json new file mode 100644 index 0000000..a038f64 --- /dev/null +++ b/ormconfig.stage.json @@ -0,0 +1,24 @@ +{ + "type": "mysql", + "host": "localhost", + "port": 3111, + "username": "stage", + "password": "stage", + "database": "vylbot", + "synchronize": false, + "logging": false, + "entities": [ + "dist/entity/**/*.js" + ], + "migrations": [ + "dist/migration/**/*.js" + ], + "subscribers": [ + "dist/subscriber/**/*.js" + ], + "cli": { + "entitiesDir": "dist/entity", + "migrationsDir": "dist/migration", + "subscribersDir": "dist/subscriber" + } +} \ No newline at end of file diff --git a/package.json b/package.json index 988a97d..9372a44 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ "build": "tsc", "start": "node ./dist/vylbot", "test": "jest", - "db:up": "typeorm migration:run -d dist/database/dataSources/appDataSource.js", - "db:down": "typeorm migration:revert -d dist/database/dataSources/appDataSource.js" + "db:up": "typeorm migration:run", + "db:down": "typeorm migration:revert" }, "repository": { "type": "git", @@ -33,7 +33,7 @@ "emoji-regex": "^10.0.0", "jest": "^29.0.0", "jest-mock-extended": "^3.0.0", - "minimatch": "9.0.1", + "minimatch": "7.4.6", "mysql": "^2.18.1", "random-bunny": "^2.0.5", "ts-jest": "^29.0.0", diff --git a/scripts/deploy_prod.sh b/scripts/deploy_prod.sh index 7adef0a..d9d5296 100644 --- a/scripts/deploy_prod.sh +++ b/scripts/deploy_prod.sh @@ -13,6 +13,7 @@ cd ~/apps/vylbot/vylbot_prod \ && (pm2 stop vylbot_prod || true) \ && (pm2 delete vylbot_prod || true) \ && cp .prod.env .env \ +&& cp ormconfig.prod.json ormconfig.json \ && yarn clean \ && yarn install --frozen-lockfile \ && yarn build \ diff --git a/scripts/deploy_stage.sh b/scripts/deploy_stage.sh index d12a421..a6c8c92 100644 --- a/scripts/deploy_stage.sh +++ b/scripts/deploy_stage.sh @@ -13,6 +13,7 @@ cd ~/apps/vylbot/vylbot_stage \ && (pm2 stop vylbot_stage || true) \ && (pm2 delete vylbot_stage || true) \ && cp .stage.env .env \ +&& cp ormconfig.stage.json ormconfig.json \ && yarn clean \ && yarn install --frozen-lockfile \ && yarn build \ diff --git a/src/client/client.ts b/src/client/client.ts index d544ec7..75e06fb 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -8,12 +8,11 @@ import { Command } from "../type/command"; import { Events } from "./events"; import { Util } from "./util"; -import AppDataSource from "../database/dataSources/appDataSource"; export class CoreClient extends Client { private static _commandItems: ICommandItem[]; private static _eventItems: IEventItem[]; - + private _events: Events; private _util: Util; @@ -42,9 +41,10 @@ export class CoreClient extends Client { return; } - await AppDataSource.initialize() - .then(() => console.log("Data Source Initialized")) - .catch((err) => console.error("Error Initialising Data Source", err)); + await createConnection().catch(e => { + console.error(e); + return; + }); super.on("interactionCreate", this._events.onInteractionCreate); super.on("ready", this._events.onReady); diff --git a/src/commands/501231711271780357/Lobby/add.ts b/src/commands/501231711271780357/Lobby/add.ts index 0bc3ca0..16a38d2 100644 --- a/src/commands/501231711271780357/Lobby/add.ts +++ b/src/commands/501231711271780357/Lobby/add.ts @@ -1,6 +1,6 @@ import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js"; import { Command } from "../../../type/command"; -import { default as eLobby } from "../../../database/entities/501231711271780357/Lobby"; +import { default as eLobby } from "../../../entity/501231711271780357/Lobby"; export default class AddRole extends Command { constructor() { diff --git a/src/commands/501231711271780357/Lobby/list.ts b/src/commands/501231711271780357/Lobby/list.ts index 41bc4a3..ccf0766 100644 --- a/src/commands/501231711271780357/Lobby/list.ts +++ b/src/commands/501231711271780357/Lobby/list.ts @@ -1,6 +1,6 @@ import { CacheType, CommandInteraction, EmbedBuilder, GuildBasedChannel, PermissionsBitField, SlashCommandBuilder } from "discord.js"; import { Command } from "../../../type/command"; -import { default as eLobby } from "../../../database/entities/501231711271780357/Lobby"; +import { default as eLobby } from "../../../entity/501231711271780357/Lobby"; import EmbedColours from "../../../constants/EmbedColours"; export default class ListLobby extends Command { diff --git a/src/commands/501231711271780357/Lobby/lobby.ts b/src/commands/501231711271780357/Lobby/lobby.ts index 83849a6..d7f0d42 100644 --- a/src/commands/501231711271780357/Lobby/lobby.ts +++ b/src/commands/501231711271780357/Lobby/lobby.ts @@ -1,6 +1,6 @@ import { CommandInteraction, SlashCommandBuilder } from "discord.js"; import { Command } from "../../../type/command"; -import { default as eLobby } from "../../../database/entities/501231711271780357/Lobby"; +import { default as eLobby } from "../../../entity/501231711271780357/Lobby"; export default class Lobby extends Command { constructor() { @@ -13,7 +13,7 @@ export default class Lobby extends Command { public override async execute(interaction: CommandInteraction) { if (!interaction.channelId) return; - + const lobby = await eLobby.FetchOneByChannelId(interaction.channelId); if (!lobby) { diff --git a/src/commands/501231711271780357/Lobby/remove.ts b/src/commands/501231711271780357/Lobby/remove.ts index 2f241d2..b350316 100644 --- a/src/commands/501231711271780357/Lobby/remove.ts +++ b/src/commands/501231711271780357/Lobby/remove.ts @@ -1,6 +1,6 @@ import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js"; import { Command } from "../../../type/command"; -import { default as eLobby } from "../../../database/entities/501231711271780357/Lobby"; +import { default as eLobby } from "../../../entity/501231711271780357/Lobby"; import BaseEntity from "../../../contracts/BaseEntity"; export default class RemoveLobby extends Command { @@ -32,7 +32,7 @@ export default class RemoveLobby extends Command { await interaction.reply('Channel not found.'); return; } - + await BaseEntity.Remove(eLobby, entity); await interaction.reply(`Removed <#${channel.channel.id}> from the list of lobby channels`); diff --git a/src/commands/Role/config.ts b/src/commands/Role/config.ts index aeb5c67..93d6891 100644 --- a/src/commands/Role/config.ts +++ b/src/commands/Role/config.ts @@ -1,7 +1,7 @@ import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js"; import { Command } from "../../type/command"; -import { default as eRole } from "../../database/entities/Role"; -import Server from "../../database/entities/Server"; +import { default as eRole } from "../../entity/Role"; +import Server from "../../entity/Server"; export default class ConfigRole extends Command { constructor() { @@ -33,7 +33,7 @@ export default class ConfigRole extends Command { if (existingRole) { await eRole.Remove(eRole, existingRole); - + await interaction.reply('Removed role from configuration.'); } else { const server = await Server.FetchOneById(Server, interaction.guildId); @@ -45,7 +45,7 @@ export default class ConfigRole extends Command { const newRole = new eRole(role.role.id); newRole.SetServer(server); - + await newRole.Save(eRole, newRole); await interaction.reply('Added role to configuration.'); diff --git a/src/commands/Role/role.ts b/src/commands/Role/role.ts index 296b98f..85b0abf 100644 --- a/src/commands/Role/role.ts +++ b/src/commands/Role/role.ts @@ -1,6 +1,6 @@ import { CommandInteraction, EmbedBuilder, GuildMemberRoleManager, SlashCommandBuilder } from "discord.js"; import { Command } from "../../type/command"; -import { default as eRole } from "../../database/entities/Role"; +import { default as eRole } from "../../entity/Role"; import EmbedColours from "../../constants/EmbedColours"; export default class Role extends Command { @@ -47,7 +47,7 @@ export default class Role extends Command { .setColor(EmbedColours.Ok) .setTitle("Roles") .setDescription(`Roles: ${roles.length}\n\n${roles.join("\n")}`); - + await interaction.reply({ embeds: [ embed ]}); } diff --git a/src/commands/audits.ts b/src/commands/audits.ts index c6c2366..3dabe26 100644 --- a/src/commands/audits.ts +++ b/src/commands/audits.ts @@ -1,4 +1,4 @@ -import Audit from "../database/entities/Audit"; +import Audit from "../entity/Audit"; import AuditTools from "../helpers/AuditTools"; import { Command } from "../type/command"; import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js"; @@ -13,7 +13,7 @@ export default class Audits extends Command { .setName("audits") .setDescription("View audits of a particular user in the server") .setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers) - .addSubcommand(subcommand => + .addSubcommand(subcommand => subcommand .setName('user') .setDescription('View all audits done against a user') @@ -66,7 +66,7 @@ export default class Audits extends Command { option .setName('reason') .setDescription('The reason'))); - + } public override async execute(interaction: CommandInteraction) { @@ -188,13 +188,13 @@ export default class Audits extends Command { await interaction.reply("Audit cleared."); } - private async AddAudit(interaction: CommandInteraction) { + private async AddAudit(interaction: CommandInteraction) { if (!interaction.guildId) return; const user = interaction.options.getUser('target'); const auditType = interaction.options.get('type'); const reasonInput = interaction.options.get('reason'); - + if (!user || !auditType || !auditType.value) { await interaction.reply("Invalid input."); return; @@ -206,7 +206,7 @@ export default class Audits extends Command { const audit = new Audit(user.id, type, reason, interaction.user.id, interaction.guildId); await audit.Save(Audit, audit); - + await interaction.reply(`Created new audit with ID \`${audit.AuditId}\``); } } \ No newline at end of file diff --git a/src/commands/ban.ts b/src/commands/ban.ts index 219a078..a7f2d99 100644 --- a/src/commands/ban.ts +++ b/src/commands/ban.ts @@ -1,5 +1,5 @@ import { Command } from "../type/command"; -import Audit from "../database/entities/Audit"; +import Audit from "../entity/Audit"; import { AuditType } from "../constants/AuditType"; import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js"; import EmbedColours from "../constants/EmbedColours"; diff --git a/src/commands/config.ts b/src/commands/config.ts index d86c7e3..a370f27 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -2,8 +2,8 @@ import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuil import { readFileSync } from "fs"; import DefaultValues from "../constants/DefaultValues"; import EmbedColours from "../constants/EmbedColours"; -import Server from "../database/entities/Server"; -import Setting from "../database/entities/Setting"; +import Server from "../entity/Server"; +import Setting from "../entity/Setting"; import { Command } from "../type/command"; export default class Config extends Command { @@ -124,7 +124,7 @@ export default class Config extends Command { private async ResetValue(interaction: CommandInteraction) { if (!interaction.guildId) return; - + const key = interaction.options.get('key'); if (!key || !key.value) { diff --git a/src/commands/ignore.ts b/src/commands/ignore.ts index a93e801..4a57d83 100644 --- a/src/commands/ignore.ts +++ b/src/commands/ignore.ts @@ -1,5 +1,5 @@ import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js"; -import IgnoredChannel from "../database/entities/IgnoredChannel"; +import IgnoredChannel from "../entity/IgnoredChannel"; import { Command } from "../type/command"; export default class Ignore extends Command { diff --git a/src/commands/kick.ts b/src/commands/kick.ts index 0008589..6ddee0c 100644 --- a/src/commands/kick.ts +++ b/src/commands/kick.ts @@ -1,5 +1,5 @@ import { Command } from "../type/command"; -import Audit from "../database/entities/Audit"; +import Audit from "../entity/Audit"; import { AuditType } from "../constants/AuditType"; import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js"; import EmbedColours from "../constants/EmbedColours"; @@ -54,7 +54,7 @@ export default class Kick extends Command { value: reason, }, ]); - + if (!member.kickable) { await interaction.reply('Insufficient permissions. Please contact a moderator.'); return; diff --git a/src/commands/mute.ts b/src/commands/mute.ts index 137aace..d3b1493 100644 --- a/src/commands/mute.ts +++ b/src/commands/mute.ts @@ -1,7 +1,7 @@ import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js"; import { AuditType } from "../constants/AuditType"; import EmbedColours from "../constants/EmbedColours"; -import Audit from "../database/entities/Audit"; +import Audit from "../entity/Audit"; import SettingsHelper from "../helpers/SettingsHelper"; import { Command } from "../type/command"; diff --git a/src/commands/setup.ts b/src/commands/setup.ts index 5b1e3fc..6676ef8 100644 --- a/src/commands/setup.ts +++ b/src/commands/setup.ts @@ -1,5 +1,5 @@ import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js"; -import Server from "../database/entities/Server"; +import Server from "../entity/Server"; import { Command } from "../type/command"; export default class Setup extends Command { diff --git a/src/commands/warn.ts b/src/commands/warn.ts index 5044912..5a41985 100644 --- a/src/commands/warn.ts +++ b/src/commands/warn.ts @@ -1,7 +1,7 @@ import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js"; import { AuditType } from "../constants/AuditType"; import EmbedColours from "../constants/EmbedColours"; -import Audit from "../database/entities/Audit"; +import Audit from "../entity/Audit"; import SettingsHelper from "../helpers/SettingsHelper"; import { Command } from "../type/command"; diff --git a/src/contracts/BaseEntity.ts b/src/contracts/BaseEntity.ts index 941ba6f..bb4d550 100644 --- a/src/contracts/BaseEntity.ts +++ b/src/contracts/BaseEntity.ts @@ -1,6 +1,5 @@ -import { Column, DeepPartial, EntityTarget, PrimaryColumn, ObjectLiteral, FindOptionsWhere } from "typeorm"; +import { Column, DeepPartial, EntityTarget, getConnection, PrimaryColumn, ObjectLiteral, FindOptionsWhere } from "typeorm"; import { v4 } from "uuid"; -import AppDataSource from "../database/dataSources/appDataSource"; export default class BaseEntity { constructor() { @@ -22,19 +21,25 @@ export default class BaseEntity { public async Save(target: EntityTarget, entity: DeepPartial): Promise { this.WhenUpdated = new Date(); - const repository = AppDataSource.getRepository(target); + const connection = getConnection(); + + const repository = connection.getRepository(target); await repository.save(entity); } public static async Remove(target: EntityTarget, entity: T): Promise { - const repository = AppDataSource.getRepository(target); + const connection = getConnection(); + + const repository = connection.getRepository(target); await repository.remove(entity); } public static async FetchAll(target: EntityTarget, relations?: string[]): Promise { - const repository = AppDataSource.getRepository(target); + const connection = getConnection(); + + const repository = connection.getRepository(target); const all = await repository.find({ relations: relations || [] }); @@ -42,7 +47,9 @@ export default class BaseEntity { } public static async FetchOneById(target: EntityTarget, id: string, relations?: string[]): Promise { - const repository = AppDataSource.getRepository(target); + const connection = getConnection(); + + const repository = connection.getRepository(target); const single = await repository.findOne({ where: ({ Id: id } as FindOptionsWhere), relations: relations || {} }); @@ -50,7 +57,9 @@ export default class BaseEntity { } public static async Any(target: EntityTarget): Promise { - const repository = AppDataSource.getRepository(target); + const connection = getConnection(); + + const repository = connection.getRepository(target); const any = await repository.find(); diff --git a/src/database/dataSources/appDataSource.ts b/src/database/dataSources/appDataSource.ts deleted file mode 100644 index 89cd27f..0000000 --- a/src/database/dataSources/appDataSource.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { DataSource } from "typeorm"; -import * as dotenv from "dotenv"; - -dotenv.config(); - -const AppDataSource = new DataSource({ - type: "mysql", - host: process.env.DB_HOST, - port: Number(process.env.DB_PORT), - username: process.env.DB_AUTH_USER, - password: process.env.DB_AUTH_PASS, - database: process.env.DB_NAME, - synchronize: process.env.DB_SYNC == "true", - logging: process.env.DB_LOGGING == "true", - entities: [ - "dist/database/entities/**/*.js", - ], - migrations: [ - "dist/database/migrations/**/*.js", - ], - subscribers: [ - "dist/database/subscribers/**/*.js", - ], -}); - -export default AppDataSource; \ No newline at end of file diff --git a/src/database/entities/501231711271780357/Lobby.ts b/src/entity/501231711271780357/Lobby.ts similarity index 79% rename from src/database/entities/501231711271780357/Lobby.ts rename to src/entity/501231711271780357/Lobby.ts index 95eafc8..b9f588b 100644 --- a/src/database/entities/501231711271780357/Lobby.ts +++ b/src/entity/501231711271780357/Lobby.ts @@ -1,6 +1,5 @@ -import { Column, Entity } from "typeorm"; -import BaseEntity from "../../../contracts/BaseEntity"; -import AppDataSource from "../../dataSources/appDataSource"; +import { Column, Entity, getConnection } from "typeorm"; +import BaseEntity from "../../contracts/BaseEntity"; @Entity() export default class Lobby extends BaseEntity { @@ -35,7 +34,9 @@ export default class Lobby extends BaseEntity { } public static async FetchOneByChannelId(channelId: string, relations?: string[]): Promise { - const repository = AppDataSource.getRepository(Lobby); + const connection = getConnection(); + + const repository = connection.getRepository(Lobby); const single = await repository.findOne({ where: { ChannelId: channelId }, relations: relations || [] }); diff --git a/src/database/entities/Audit.ts b/src/entity/Audit.ts similarity index 72% rename from src/database/entities/Audit.ts rename to src/entity/Audit.ts index af4b1a5..8577f0f 100644 --- a/src/database/entities/Audit.ts +++ b/src/entity/Audit.ts @@ -1,8 +1,7 @@ -import { Column, Entity } from "typeorm"; -import { AuditType } from "../../constants/AuditType"; -import BaseEntity from "../../contracts/BaseEntity"; -import StringTools from "../../helpers/StringTools"; -import AppDataSource from "../dataSources/appDataSource"; +import { Column, Entity, getConnection } from "typeorm"; +import { AuditType } from "../constants/AuditType"; +import BaseEntity from "../contracts/BaseEntity"; +import StringTools from "../helpers/StringTools"; @Entity() export default class Audit extends BaseEntity { @@ -36,7 +35,9 @@ export default class Audit extends BaseEntity { ServerId: string; public static async FetchAuditsByUserId(userId: string, serverId: string): Promise { - const repository = AppDataSource.getRepository(Audit); + const connection = getConnection(); + + const repository = connection.getRepository(Audit); const all = await repository.find({ where: { UserId: userId, ServerId: serverId } }); @@ -44,7 +45,9 @@ export default class Audit extends BaseEntity { } public static async FetchAuditByAuditId(auditId: string, serverId: string): Promise { - const repository = AppDataSource.getRepository(Audit); + const connection = getConnection(); + + const repository = connection.getRepository(Audit); const single = await repository.findOne({ where: { AuditId: auditId, ServerId: serverId } }); diff --git a/src/database/entities/IgnoredChannel.ts b/src/entity/IgnoredChannel.ts similarity index 62% rename from src/database/entities/IgnoredChannel.ts rename to src/entity/IgnoredChannel.ts index 7b40be7..ccb573c 100644 --- a/src/database/entities/IgnoredChannel.ts +++ b/src/entity/IgnoredChannel.ts @@ -1,6 +1,5 @@ -import { Entity } from "typeorm"; -import BaseEntity from "../../contracts/BaseEntity"; -import AppDataSource from "../dataSources/appDataSource"; +import { Entity, getConnection } from "typeorm"; +import BaseEntity from "../contracts/BaseEntity"; @Entity() export default class IgnoredChannel extends BaseEntity { @@ -11,7 +10,9 @@ export default class IgnoredChannel extends BaseEntity { } public static async IsChannelIgnored(channelId: string): Promise { - const repository = AppDataSource.getRepository(IgnoredChannel); + const connection = getConnection(); + + const repository = connection.getRepository(IgnoredChannel); const single = await repository.findOne({ where: { Id: channelId } }); diff --git a/src/database/entities/Role.ts b/src/entity/Role.ts similarity index 72% rename from src/database/entities/Role.ts rename to src/entity/Role.ts index 6f83bf5..8bbd0d2 100644 --- a/src/database/entities/Role.ts +++ b/src/entity/Role.ts @@ -1,7 +1,6 @@ -import { Column, Entity, ManyToOne } from "typeorm"; -import BaseEntity from "../../contracts/BaseEntity" +import { Column, Entity, getConnection, ManyToOne } from "typeorm"; +import BaseEntity from "../contracts/BaseEntity" import Server from "./Server"; -import AppDataSource from "../dataSources/appDataSource"; @Entity() export default class Role extends BaseEntity { @@ -22,7 +21,9 @@ export default class Role extends BaseEntity { } public static async FetchOneByRoleId(roleId: string, relations?: string[]): Promise { - const repository = AppDataSource.getRepository(Role); + const connection = getConnection(); + + const repository = connection.getRepository(Role); const single = await repository.findOne({ where: { RoleId: roleId }, relations: relations || []}); @@ -30,7 +31,9 @@ export default class Role extends BaseEntity { } public static async FetchAllByServerId(serverId: string): Promise { - const repository = AppDataSource.getRepository(Server); + const connection = getConnection(); + + const repository = connection.getRepository(Server); const all = await repository.findOne({ where: { Id: serverId }, relations: [ "Roles", diff --git a/src/database/entities/Server.ts b/src/entity/Server.ts similarity index 91% rename from src/database/entities/Server.ts rename to src/entity/Server.ts index 211ea9c..f669e58 100644 --- a/src/database/entities/Server.ts +++ b/src/entity/Server.ts @@ -1,5 +1,5 @@ import { Entity, OneToMany } from "typeorm"; -import BaseEntity from "../../contracts/BaseEntity"; +import BaseEntity from "../contracts/BaseEntity"; import Role from "./Role"; import Setting from "./Setting"; diff --git a/src/database/entities/Setting.ts b/src/entity/Setting.ts similarity index 75% rename from src/database/entities/Setting.ts rename to src/entity/Setting.ts index e7b27d1..813accf 100644 --- a/src/database/entities/Setting.ts +++ b/src/entity/Setting.ts @@ -1,7 +1,6 @@ -import { Column, Entity, ManyToOne } from "typeorm"; -import BaseEntity from "../../contracts/BaseEntity"; +import { Column, Entity, getConnection, ManyToOne } from "typeorm"; +import BaseEntity from "../contracts/BaseEntity"; import Server from "./Server"; -import AppDataSource from "../dataSources/appDataSource"; @Entity() export default class Setting extends BaseEntity { @@ -27,7 +26,9 @@ export default class Setting extends BaseEntity { } public static async FetchOneByKey(key: string, relations?: string[]): Promise { - const repository = AppDataSource.getRepository(Setting); + const connection = getConnection(); + + const repository = connection.getRepository(Setting); const single = await repository.findOne({ where: { Key: key }, relations: relations || {} }); diff --git a/src/events/MessageEvents/MessageDelete.ts b/src/events/MessageEvents/MessageDelete.ts index 4bb9199..8d0d40e 100644 --- a/src/events/MessageEvents/MessageDelete.ts +++ b/src/events/MessageEvents/MessageDelete.ts @@ -1,6 +1,6 @@ import { EmbedBuilder, Message, TextChannel } from "discord.js"; import EmbedColours from "../../constants/EmbedColours"; -import IgnoredChannel from "../../database/entities/IgnoredChannel"; +import IgnoredChannel from "../../entity/IgnoredChannel"; import SettingsHelper from "../../helpers/SettingsHelper"; export default async function MessageDelete(message: Message) { diff --git a/src/events/MessageEvents/MessageUpdate.ts b/src/events/MessageEvents/MessageUpdate.ts index 7564a2f..2ccd737 100644 --- a/src/events/MessageEvents/MessageUpdate.ts +++ b/src/events/MessageEvents/MessageUpdate.ts @@ -1,6 +1,6 @@ import { EmbedBuilder, Message, TextChannel } from "discord.js"; import EmbedColours from "../../constants/EmbedColours"; -import IgnoredChannel from "../../database/entities/IgnoredChannel"; +import IgnoredChannel from "../../entity/IgnoredChannel"; import SettingsHelper from "../../helpers/SettingsHelper"; export default async function MessageUpdate(oldMessage: Message, newMessage: Message) { diff --git a/src/helpers/SettingsHelper.ts b/src/helpers/SettingsHelper.ts index 66c92a8..1c6fd6a 100644 --- a/src/helpers/SettingsHelper.ts +++ b/src/helpers/SettingsHelper.ts @@ -1,6 +1,6 @@ import DefaultValues from "../constants/DefaultValues"; -import Server from "../database/entities/Server"; -import Setting from "../database/entities/Setting"; +import Server from "../entity/Server"; +import Setting from "../entity/Setting"; export default class SettingsHelper { public static async GetSetting(key: string, serverId: string): Promise { diff --git a/src/database/migrations/3.1/1662399171315-CreateBase.ts b/src/migration/3.1/1662399171315-CreateBase.ts similarity index 92% rename from src/database/migrations/3.1/1662399171315-CreateBase.ts rename to src/migration/3.1/1662399171315-CreateBase.ts index b05aee7..cd4e696 100644 --- a/src/database/migrations/3.1/1662399171315-CreateBase.ts +++ b/src/migration/3.1/1662399171315-CreateBase.ts @@ -1,5 +1,5 @@ import { MigrationInterface, QueryRunner } from "typeorm" -import MigrationHelper from "../../../helpers/MigrationHelper" +import MigrationHelper from "../../helpers/MigrationHelper" export class vylbot1662399171315 implements MigrationInterface { diff --git a/src/vylbot.ts b/src/vylbot.ts index c1d2997..16589c2 100644 --- a/src/vylbot.ts +++ b/src/vylbot.ts @@ -11,12 +11,6 @@ const requiredConfigs: string[] = [ "BOT_AUTHOR", "BOT_OWNERID", "BOT_CLIENTID", - "DB_HOST", - "DB_PORT", - "DB_AUTH_USER", - "DB_AUTH_PASS", - "DB_SYNC", - "DB_LOGGING", ]; requiredConfigs.forEach(config => { diff --git a/yarn.lock b/yarn.lock index 617ce5d..9f5f87b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2154,10 +2154,10 @@ mimic-response@^3.1.0: resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-3.1.0.tgz#2d1d59af9c1b129815accc2c46a022a5ce1fa3c9" integrity sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ== -minimatch@9.0.1: - version "9.0.1" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.1.tgz#8a555f541cf976c622daf078bb28f29fb927c253" - integrity sha512-0jWhJpD/MdhPXwPuiRkCbfYfSKp2qnn2eOc279qI7f+osl/l+prKSrvhg157zSYvx/1nmgn2NqdT6k2Z7zSH9w== +minimatch@7.4.6: + version "7.4.6" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-7.4.6.tgz#845d6f254d8f4a5e4fd6baf44d5f10c8448365fb" + integrity sha512-sBz8G/YjVniEz6lKPNpKxXwazJe4c19fEfV2GDMX6AjFz+MX9uDWIZW8XreVhkFW3fkIdTv/gxWr/Kks5FFAVw== dependencies: brace-expansion "^2.0.1"