From e6d3c3e3cd15bef5823990c3d47bd6081b93cfe0 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Wed, 17 May 2023 18:45:27 +0100 Subject: [PATCH] Create database folder in source --- src/client/client.ts | 2 +- src/commands/501231711271780357/Lobby/add.ts | 2 +- src/commands/501231711271780357/Lobby/list.ts | 2 +- src/commands/501231711271780357/Lobby/lobby.ts | 4 ++-- src/commands/501231711271780357/Lobby/remove.ts | 4 ++-- src/commands/Role/config.ts | 8 ++++---- src/commands/Role/role.ts | 4 ++-- src/commands/audits.ts | 12 ++++++------ src/commands/ban.ts | 2 +- src/commands/config.ts | 6 +++--- src/commands/ignore.ts | 2 +- src/commands/kick.ts | 4 ++-- src/commands/mute.ts | 2 +- src/commands/setup.ts | 2 +- src/commands/warn.ts | 2 +- src/contracts/BaseEntity.ts | 2 +- src/database/{ => dataSources}/appDataSource.ts | 6 +++--- .../entities}/501231711271780357/Lobby.ts | 4 ++-- src/{entity => database/entities}/Audit.ts | 8 ++++---- src/{entity => database/entities}/IgnoredChannel.ts | 4 ++-- src/{entity => database/entities}/Role.ts | 4 ++-- src/{entity => database/entities}/Server.ts | 2 +- src/{entity => database/entities}/Setting.ts | 4 ++-- .../migrations}/3.1/1662399171315-CreateBase.ts | 2 +- src/events/MessageEvents/MessageDelete.ts | 2 +- src/events/MessageEvents/MessageUpdate.ts | 2 +- src/helpers/SettingsHelper.ts | 4 ++-- 27 files changed, 51 insertions(+), 51 deletions(-) rename src/database/{ => dataSources}/appDataSource.ts (80%) rename src/{entity => database/entities}/501231711271780357/Lobby.ts (89%) rename src/{entity => database/entities}/Audit.ts (85%) rename src/{entity => database/entities}/IgnoredChannel.ts (80%) rename src/{entity => database/entities}/Role.ts (90%) rename src/{entity => database/entities}/Server.ts (91%) rename src/{entity => database/entities}/Setting.ts (88%) rename src/{migration => database/migrations}/3.1/1662399171315-CreateBase.ts (92%) diff --git a/src/client/client.ts b/src/client/client.ts index f9ffc89..2833ab3 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -8,7 +8,7 @@ import { Command } from "../type/command"; import { Events } from "./events"; import { Util } from "./util"; -import AppDataSource from "../database/appDataSource"; +import AppDataSource from "../database/dataSources/appDataSource"; export class CoreClient extends Client { private static _commandItems: ICommandItem[]; diff --git a/src/commands/501231711271780357/Lobby/add.ts b/src/commands/501231711271780357/Lobby/add.ts index 16a38d2..0bc3ca0 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 "../../../entity/501231711271780357/Lobby"; +import { default as eLobby } from "../../../database/entities/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 ccf0766..41bc4a3 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 "../../../entity/501231711271780357/Lobby"; +import { default as eLobby } from "../../../database/entities/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 d7f0d42..83849a6 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 "../../../entity/501231711271780357/Lobby"; +import { default as eLobby } from "../../../database/entities/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 b350316..2f241d2 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 "../../../entity/501231711271780357/Lobby"; +import { default as eLobby } from "../../../database/entities/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 93d6891..aeb5c67 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 "../../entity/Role"; -import Server from "../../entity/Server"; +import { default as eRole } from "../../database/entities/Role"; +import Server from "../../database/entities/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 85b0abf..296b98f 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 "../../entity/Role"; +import { default as eRole } from "../../database/entities/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 3dabe26..c6c2366 100644 --- a/src/commands/audits.ts +++ b/src/commands/audits.ts @@ -1,4 +1,4 @@ -import Audit from "../entity/Audit"; +import Audit from "../database/entities/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 a7f2d99..219a078 100644 --- a/src/commands/ban.ts +++ b/src/commands/ban.ts @@ -1,5 +1,5 @@ import { Command } from "../type/command"; -import Audit from "../entity/Audit"; +import Audit from "../database/entities/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 a370f27..d86c7e3 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 "../entity/Server"; -import Setting from "../entity/Setting"; +import Server from "../database/entities/Server"; +import Setting from "../database/entities/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 4a57d83..a93e801 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 "../entity/IgnoredChannel"; +import IgnoredChannel from "../database/entities/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 6ddee0c..0008589 100644 --- a/src/commands/kick.ts +++ b/src/commands/kick.ts @@ -1,5 +1,5 @@ import { Command } from "../type/command"; -import Audit from "../entity/Audit"; +import Audit from "../database/entities/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 d3b1493..137aace 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 "../entity/Audit"; +import Audit from "../database/entities/Audit"; import SettingsHelper from "../helpers/SettingsHelper"; import { Command } from "../type/command"; diff --git a/src/commands/setup.ts b/src/commands/setup.ts index 6676ef8..5b1e3fc 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 "../entity/Server"; +import Server from "../database/entities/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 5a41985..5044912 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 "../entity/Audit"; +import Audit from "../database/entities/Audit"; import SettingsHelper from "../helpers/SettingsHelper"; import { Command } from "../type/command"; diff --git a/src/contracts/BaseEntity.ts b/src/contracts/BaseEntity.ts index dfed28c..941ba6f 100644 --- a/src/contracts/BaseEntity.ts +++ b/src/contracts/BaseEntity.ts @@ -1,6 +1,6 @@ import { Column, DeepPartial, EntityTarget, PrimaryColumn, ObjectLiteral, FindOptionsWhere } from "typeorm"; import { v4 } from "uuid"; -import AppDataSource from "../database/appDataSource"; +import AppDataSource from "../database/dataSources/appDataSource"; export default class BaseEntity { constructor() { diff --git a/src/database/appDataSource.ts b/src/database/dataSources/appDataSource.ts similarity index 80% rename from src/database/appDataSource.ts rename to src/database/dataSources/appDataSource.ts index 2f9fef2..89cd27f 100644 --- a/src/database/appDataSource.ts +++ b/src/database/dataSources/appDataSource.ts @@ -13,13 +13,13 @@ const AppDataSource = new DataSource({ synchronize: process.env.DB_SYNC == "true", logging: process.env.DB_LOGGING == "true", entities: [ - "dist/entity/**/*.js", + "dist/database/entities/**/*.js", ], migrations: [ - "dist/mirgration/**/*.js", + "dist/database/migrations/**/*.js", ], subscribers: [ - "dist/subscriber/**/*.js", + "dist/database/subscribers/**/*.js", ], }); diff --git a/src/entity/501231711271780357/Lobby.ts b/src/database/entities/501231711271780357/Lobby.ts similarity index 89% rename from src/entity/501231711271780357/Lobby.ts rename to src/database/entities/501231711271780357/Lobby.ts index d0ca25c..95eafc8 100644 --- a/src/entity/501231711271780357/Lobby.ts +++ b/src/database/entities/501231711271780357/Lobby.ts @@ -1,6 +1,6 @@ import { Column, Entity } from "typeorm"; -import BaseEntity from "../../contracts/BaseEntity"; -import AppDataSource from "../../database/appDataSource"; +import BaseEntity from "../../../contracts/BaseEntity"; +import AppDataSource from "../../dataSources/appDataSource"; @Entity() export default class Lobby extends BaseEntity { diff --git a/src/entity/Audit.ts b/src/database/entities/Audit.ts similarity index 85% rename from src/entity/Audit.ts rename to src/database/entities/Audit.ts index dddcc8e..af4b1a5 100644 --- a/src/entity/Audit.ts +++ b/src/database/entities/Audit.ts @@ -1,8 +1,8 @@ import { Column, Entity } from "typeorm"; -import { AuditType } from "../constants/AuditType"; -import BaseEntity from "../contracts/BaseEntity"; -import StringTools from "../helpers/StringTools"; -import AppDataSource from "../database/appDataSource"; +import { AuditType } from "../../constants/AuditType"; +import BaseEntity from "../../contracts/BaseEntity"; +import StringTools from "../../helpers/StringTools"; +import AppDataSource from "../dataSources/appDataSource"; @Entity() export default class Audit extends BaseEntity { diff --git a/src/entity/IgnoredChannel.ts b/src/database/entities/IgnoredChannel.ts similarity index 80% rename from src/entity/IgnoredChannel.ts rename to src/database/entities/IgnoredChannel.ts index dae34ad..7b40be7 100644 --- a/src/entity/IgnoredChannel.ts +++ b/src/database/entities/IgnoredChannel.ts @@ -1,6 +1,6 @@ import { Entity } from "typeorm"; -import BaseEntity from "../contracts/BaseEntity"; -import AppDataSource from "../database/appDataSource"; +import BaseEntity from "../../contracts/BaseEntity"; +import AppDataSource from "../dataSources/appDataSource"; @Entity() export default class IgnoredChannel extends BaseEntity { diff --git a/src/entity/Role.ts b/src/database/entities/Role.ts similarity index 90% rename from src/entity/Role.ts rename to src/database/entities/Role.ts index 4c51372..6f83bf5 100644 --- a/src/entity/Role.ts +++ b/src/database/entities/Role.ts @@ -1,7 +1,7 @@ import { Column, Entity, ManyToOne } from "typeorm"; -import BaseEntity from "../contracts/BaseEntity" +import BaseEntity from "../../contracts/BaseEntity" import Server from "./Server"; -import AppDataSource from "../database/appDataSource"; +import AppDataSource from "../dataSources/appDataSource"; @Entity() export default class Role extends BaseEntity { diff --git a/src/entity/Server.ts b/src/database/entities/Server.ts similarity index 91% rename from src/entity/Server.ts rename to src/database/entities/Server.ts index f669e58..211ea9c 100644 --- a/src/entity/Server.ts +++ b/src/database/entities/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/entity/Setting.ts b/src/database/entities/Setting.ts similarity index 88% rename from src/entity/Setting.ts rename to src/database/entities/Setting.ts index fe43ec6..e7b27d1 100644 --- a/src/entity/Setting.ts +++ b/src/database/entities/Setting.ts @@ -1,7 +1,7 @@ import { Column, Entity, ManyToOne } from "typeorm"; -import BaseEntity from "../contracts/BaseEntity"; +import BaseEntity from "../../contracts/BaseEntity"; import Server from "./Server"; -import AppDataSource from "../database/appDataSource"; +import AppDataSource from "../dataSources/appDataSource"; @Entity() export default class Setting extends BaseEntity { diff --git a/src/migration/3.1/1662399171315-CreateBase.ts b/src/database/migrations/3.1/1662399171315-CreateBase.ts similarity index 92% rename from src/migration/3.1/1662399171315-CreateBase.ts rename to src/database/migrations/3.1/1662399171315-CreateBase.ts index cd4e696..b05aee7 100644 --- a/src/migration/3.1/1662399171315-CreateBase.ts +++ b/src/database/migrations/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/events/MessageEvents/MessageDelete.ts b/src/events/MessageEvents/MessageDelete.ts index 8d0d40e..4bb9199 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 "../../entity/IgnoredChannel"; +import IgnoredChannel from "../../database/entities/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 2ccd737..7564a2f 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 "../../entity/IgnoredChannel"; +import IgnoredChannel from "../../database/entities/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 1c6fd6a..66c92a8 100644 --- a/src/helpers/SettingsHelper.ts +++ b/src/helpers/SettingsHelper.ts @@ -1,6 +1,6 @@ import DefaultValues from "../constants/DefaultValues"; -import Server from "../entity/Server"; -import Setting from "../entity/Setting"; +import Server from "../database/entities/Server"; +import Setting from "../database/entities/Setting"; export default class SettingsHelper { public static async GetSetting(key: string, serverId: string): Promise {