Switch to TypeORM's DataSource API #299

Merged
Vylpes merged 5 commits from feature/297-stage-deployment into develop 2023-05-26 17:59:22 +01:00
27 changed files with 51 additions and 51 deletions
Showing only changes of commit e6d3c3e3cd - Show all commits

View file

@ -8,7 +8,7 @@ import { Command } from "../type/command";
import { Events } from "./events"; import { Events } from "./events";
import { Util } from "./util"; import { Util } from "./util";
import AppDataSource from "../database/appDataSource"; import AppDataSource from "../database/dataSources/appDataSource";
export class CoreClient extends Client { export class CoreClient extends Client {
private static _commandItems: ICommandItem[]; private static _commandItems: ICommandItem[];

View file

@ -1,6 +1,6 @@
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js"; import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import { Command } from "../../../type/command"; 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 { export default class AddRole extends Command {
constructor() { constructor() {

View file

@ -1,6 +1,6 @@
import { CacheType, CommandInteraction, EmbedBuilder, GuildBasedChannel, PermissionsBitField, SlashCommandBuilder } from "discord.js"; import { CacheType, CommandInteraction, EmbedBuilder, GuildBasedChannel, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import { Command } from "../../../type/command"; 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"; import EmbedColours from "../../../constants/EmbedColours";
export default class ListLobby extends Command { export default class ListLobby extends Command {

View file

@ -1,6 +1,6 @@
import { CommandInteraction, SlashCommandBuilder } from "discord.js"; import { CommandInteraction, SlashCommandBuilder } from "discord.js";
import { Command } from "../../../type/command"; 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 { export default class Lobby extends Command {
constructor() { constructor() {
@ -13,7 +13,7 @@ export default class Lobby extends Command {
public override async execute(interaction: CommandInteraction) { public override async execute(interaction: CommandInteraction) {
if (!interaction.channelId) return; if (!interaction.channelId) return;
const lobby = await eLobby.FetchOneByChannelId(interaction.channelId); const lobby = await eLobby.FetchOneByChannelId(interaction.channelId);
if (!lobby) { if (!lobby) {

View file

@ -1,6 +1,6 @@
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js"; import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import { Command } from "../../../type/command"; 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"; import BaseEntity from "../../../contracts/BaseEntity";
export default class RemoveLobby extends Command { export default class RemoveLobby extends Command {
@ -32,7 +32,7 @@ export default class RemoveLobby extends Command {
await interaction.reply('Channel not found.'); await interaction.reply('Channel not found.');
return; return;
} }
await BaseEntity.Remove<eLobby>(eLobby, entity); await BaseEntity.Remove<eLobby>(eLobby, entity);
await interaction.reply(`Removed <#${channel.channel.id}> from the list of lobby channels`); await interaction.reply(`Removed <#${channel.channel.id}> from the list of lobby channels`);

View file

@ -1,7 +1,7 @@
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js"; import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import { Command } from "../../type/command"; import { Command } from "../../type/command";
import { default as eRole } from "../../entity/Role"; import { default as eRole } from "../../database/entities/Role";
import Server from "../../entity/Server"; import Server from "../../database/entities/Server";
export default class ConfigRole extends Command { export default class ConfigRole extends Command {
constructor() { constructor() {
@ -33,7 +33,7 @@ export default class ConfigRole extends Command {
if (existingRole) { if (existingRole) {
await eRole.Remove(eRole, existingRole); await eRole.Remove(eRole, existingRole);
await interaction.reply('Removed role from configuration.'); await interaction.reply('Removed role from configuration.');
} else { } else {
const server = await Server.FetchOneById(Server, interaction.guildId); 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); const newRole = new eRole(role.role.id);
newRole.SetServer(server); newRole.SetServer(server);
await newRole.Save(eRole, newRole); await newRole.Save(eRole, newRole);
await interaction.reply('Added role to configuration.'); await interaction.reply('Added role to configuration.');

View file

@ -1,6 +1,6 @@
import { CommandInteraction, EmbedBuilder, GuildMemberRoleManager, SlashCommandBuilder } from "discord.js"; import { CommandInteraction, EmbedBuilder, GuildMemberRoleManager, SlashCommandBuilder } from "discord.js";
import { Command } from "../../type/command"; 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"; import EmbedColours from "../../constants/EmbedColours";
export default class Role extends Command { export default class Role extends Command {
@ -47,7 +47,7 @@ export default class Role extends Command {
.setColor(EmbedColours.Ok) .setColor(EmbedColours.Ok)
.setTitle("Roles") .setTitle("Roles")
.setDescription(`Roles: ${roles.length}\n\n${roles.join("\n")}`); .setDescription(`Roles: ${roles.length}\n\n${roles.join("\n")}`);
await interaction.reply({ embeds: [ embed ]}); await interaction.reply({ embeds: [ embed ]});
} }

View file

@ -1,4 +1,4 @@
import Audit from "../entity/Audit"; import Audit from "../database/entities/Audit";
import AuditTools from "../helpers/AuditTools"; import AuditTools from "../helpers/AuditTools";
import { Command } from "../type/command"; import { Command } from "../type/command";
import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js"; import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js";
@ -13,7 +13,7 @@ export default class Audits extends Command {
.setName("audits") .setName("audits")
.setDescription("View audits of a particular user in the server") .setDescription("View audits of a particular user in the server")
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers) .setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
.addSubcommand(subcommand => .addSubcommand(subcommand =>
subcommand subcommand
.setName('user') .setName('user')
.setDescription('View all audits done against a user') .setDescription('View all audits done against a user')
@ -66,7 +66,7 @@ export default class Audits extends Command {
option option
.setName('reason') .setName('reason')
.setDescription('The reason'))); .setDescription('The reason')));
} }
public override async execute(interaction: CommandInteraction) { public override async execute(interaction: CommandInteraction) {
@ -188,13 +188,13 @@ export default class Audits extends Command {
await interaction.reply("Audit cleared."); await interaction.reply("Audit cleared.");
} }
private async AddAudit(interaction: CommandInteraction) { private async AddAudit(interaction: CommandInteraction) {
if (!interaction.guildId) return; if (!interaction.guildId) return;
const user = interaction.options.getUser('target'); const user = interaction.options.getUser('target');
const auditType = interaction.options.get('type'); const auditType = interaction.options.get('type');
const reasonInput = interaction.options.get('reason'); const reasonInput = interaction.options.get('reason');
if (!user || !auditType || !auditType.value) { if (!user || !auditType || !auditType.value) {
await interaction.reply("Invalid input."); await interaction.reply("Invalid input.");
return; return;
@ -206,7 +206,7 @@ export default class Audits extends Command {
const audit = new Audit(user.id, type, reason, interaction.user.id, interaction.guildId); const audit = new Audit(user.id, type, reason, interaction.user.id, interaction.guildId);
await audit.Save(Audit, audit); await audit.Save(Audit, audit);
await interaction.reply(`Created new audit with ID \`${audit.AuditId}\``); await interaction.reply(`Created new audit with ID \`${audit.AuditId}\``);
} }
} }

View file

@ -1,5 +1,5 @@
import { Command } from "../type/command"; import { Command } from "../type/command";
import Audit from "../entity/Audit"; import Audit from "../database/entities/Audit";
import { AuditType } from "../constants/AuditType"; import { AuditType } from "../constants/AuditType";
import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js"; import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
import EmbedColours from "../constants/EmbedColours"; import EmbedColours from "../constants/EmbedColours";

View file

@ -2,8 +2,8 @@ import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuil
import { readFileSync } from "fs"; import { readFileSync } from "fs";
import DefaultValues from "../constants/DefaultValues"; import DefaultValues from "../constants/DefaultValues";
import EmbedColours from "../constants/EmbedColours"; import EmbedColours from "../constants/EmbedColours";
import Server from "../entity/Server"; import Server from "../database/entities/Server";
import Setting from "../entity/Setting"; import Setting from "../database/entities/Setting";
import { Command } from "../type/command"; import { Command } from "../type/command";
export default class Config extends Command { export default class Config extends Command {
@ -124,7 +124,7 @@ export default class Config extends Command {
private async ResetValue(interaction: CommandInteraction) { private async ResetValue(interaction: CommandInteraction) {
if (!interaction.guildId) return; if (!interaction.guildId) return;
const key = interaction.options.get('key'); const key = interaction.options.get('key');
if (!key || !key.value) { if (!key || !key.value) {

View file

@ -1,5 +1,5 @@
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js"; import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import IgnoredChannel from "../entity/IgnoredChannel"; import IgnoredChannel from "../database/entities/IgnoredChannel";
import { Command } from "../type/command"; import { Command } from "../type/command";
export default class Ignore extends Command { export default class Ignore extends Command {

View file

@ -1,5 +1,5 @@
import { Command } from "../type/command"; import { Command } from "../type/command";
import Audit from "../entity/Audit"; import Audit from "../database/entities/Audit";
import { AuditType } from "../constants/AuditType"; import { AuditType } from "../constants/AuditType";
import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js"; import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
import EmbedColours from "../constants/EmbedColours"; import EmbedColours from "../constants/EmbedColours";
@ -54,7 +54,7 @@ export default class Kick extends Command {
value: reason, value: reason,
}, },
]); ]);
if (!member.kickable) { if (!member.kickable) {
await interaction.reply('Insufficient permissions. Please contact a moderator.'); await interaction.reply('Insufficient permissions. Please contact a moderator.');
return; return;

View file

@ -1,7 +1,7 @@
import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js"; import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
import { AuditType } from "../constants/AuditType"; import { AuditType } from "../constants/AuditType";
import EmbedColours from "../constants/EmbedColours"; import EmbedColours from "../constants/EmbedColours";
import Audit from "../entity/Audit"; import Audit from "../database/entities/Audit";
import SettingsHelper from "../helpers/SettingsHelper"; import SettingsHelper from "../helpers/SettingsHelper";
import { Command } from "../type/command"; import { Command } from "../type/command";

View file

@ -1,5 +1,5 @@
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js"; import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import Server from "../entity/Server"; import Server from "../database/entities/Server";
import { Command } from "../type/command"; import { Command } from "../type/command";
export default class Setup extends Command { export default class Setup extends Command {

View file

@ -1,7 +1,7 @@
import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js"; import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
import { AuditType } from "../constants/AuditType"; import { AuditType } from "../constants/AuditType";
import EmbedColours from "../constants/EmbedColours"; import EmbedColours from "../constants/EmbedColours";
import Audit from "../entity/Audit"; import Audit from "../database/entities/Audit";
import SettingsHelper from "../helpers/SettingsHelper"; import SettingsHelper from "../helpers/SettingsHelper";
import { Command } from "../type/command"; import { Command } from "../type/command";

View file

@ -1,6 +1,6 @@
import { Column, DeepPartial, EntityTarget, PrimaryColumn, ObjectLiteral, FindOptionsWhere } from "typeorm"; import { Column, DeepPartial, EntityTarget, PrimaryColumn, ObjectLiteral, FindOptionsWhere } from "typeorm";
import { v4 } from "uuid"; import { v4 } from "uuid";
import AppDataSource from "../database/appDataSource"; import AppDataSource from "../database/dataSources/appDataSource";
export default class BaseEntity { export default class BaseEntity {
constructor() { constructor() {

View file

@ -13,13 +13,13 @@ const AppDataSource = new DataSource({
synchronize: process.env.DB_SYNC == "true", synchronize: process.env.DB_SYNC == "true",
logging: process.env.DB_LOGGING == "true", logging: process.env.DB_LOGGING == "true",
entities: [ entities: [
"dist/entity/**/*.js", "dist/database/entities/**/*.js",
], ],
migrations: [ migrations: [
"dist/mirgration/**/*.js", "dist/database/migrations/**/*.js",
], ],
subscribers: [ subscribers: [
"dist/subscriber/**/*.js", "dist/database/subscribers/**/*.js",
], ],
}); });

View file

@ -1,6 +1,6 @@
import { Column, Entity } from "typeorm"; import { Column, Entity } from "typeorm";
import BaseEntity from "../../contracts/BaseEntity"; import BaseEntity from "../../../contracts/BaseEntity";
import AppDataSource from "../../database/appDataSource"; import AppDataSource from "../../dataSources/appDataSource";
@Entity() @Entity()
export default class Lobby extends BaseEntity { export default class Lobby extends BaseEntity {

View file

@ -1,8 +1,8 @@
import { Column, Entity } from "typeorm"; import { Column, Entity } from "typeorm";
import { AuditType } from "../constants/AuditType"; import { AuditType } from "../../constants/AuditType";
import BaseEntity from "../contracts/BaseEntity"; import BaseEntity from "../../contracts/BaseEntity";
import StringTools from "../helpers/StringTools"; import StringTools from "../../helpers/StringTools";
import AppDataSource from "../database/appDataSource"; import AppDataSource from "../dataSources/appDataSource";
@Entity() @Entity()
export default class Audit extends BaseEntity { export default class Audit extends BaseEntity {

View file

@ -1,6 +1,6 @@
import { Entity } from "typeorm"; import { Entity } from "typeorm";
import BaseEntity from "../contracts/BaseEntity"; import BaseEntity from "../../contracts/BaseEntity";
import AppDataSource from "../database/appDataSource"; import AppDataSource from "../dataSources/appDataSource";
@Entity() @Entity()
export default class IgnoredChannel extends BaseEntity { export default class IgnoredChannel extends BaseEntity {

View file

@ -1,7 +1,7 @@
import { Column, Entity, ManyToOne } from "typeorm"; import { Column, Entity, ManyToOne } from "typeorm";
import BaseEntity from "../contracts/BaseEntity" import BaseEntity from "../../contracts/BaseEntity"
import Server from "./Server"; import Server from "./Server";
import AppDataSource from "../database/appDataSource"; import AppDataSource from "../dataSources/appDataSource";
@Entity() @Entity()
export default class Role extends BaseEntity { export default class Role extends BaseEntity {

View file

@ -1,5 +1,5 @@
import { Entity, OneToMany } from "typeorm"; import { Entity, OneToMany } from "typeorm";
import BaseEntity from "../contracts/BaseEntity"; import BaseEntity from "../../contracts/BaseEntity";
import Role from "./Role"; import Role from "./Role";
import Setting from "./Setting"; import Setting from "./Setting";

View file

@ -1,7 +1,7 @@
import { Column, Entity, ManyToOne } from "typeorm"; import { Column, Entity, ManyToOne } from "typeorm";
import BaseEntity from "../contracts/BaseEntity"; import BaseEntity from "../../contracts/BaseEntity";
import Server from "./Server"; import Server from "./Server";
import AppDataSource from "../database/appDataSource"; import AppDataSource from "../dataSources/appDataSource";
@Entity() @Entity()
export default class Setting extends BaseEntity { export default class Setting extends BaseEntity {

View file

@ -1,5 +1,5 @@
import { MigrationInterface, QueryRunner } from "typeorm" import { MigrationInterface, QueryRunner } from "typeorm"
import MigrationHelper from "../../helpers/MigrationHelper" import MigrationHelper from "../../../helpers/MigrationHelper"
export class vylbot1662399171315 implements MigrationInterface { export class vylbot1662399171315 implements MigrationInterface {

View file

@ -1,6 +1,6 @@
import { EmbedBuilder, Message, TextChannel } from "discord.js"; import { EmbedBuilder, Message, TextChannel } from "discord.js";
import EmbedColours from "../../constants/EmbedColours"; import EmbedColours from "../../constants/EmbedColours";
import IgnoredChannel from "../../entity/IgnoredChannel"; import IgnoredChannel from "../../database/entities/IgnoredChannel";
import SettingsHelper from "../../helpers/SettingsHelper"; import SettingsHelper from "../../helpers/SettingsHelper";
export default async function MessageDelete(message: Message) { export default async function MessageDelete(message: Message) {

View file

@ -1,6 +1,6 @@
import { EmbedBuilder, Message, TextChannel } from "discord.js"; import { EmbedBuilder, Message, TextChannel } from "discord.js";
import EmbedColours from "../../constants/EmbedColours"; import EmbedColours from "../../constants/EmbedColours";
import IgnoredChannel from "../../entity/IgnoredChannel"; import IgnoredChannel from "../../database/entities/IgnoredChannel";
import SettingsHelper from "../../helpers/SettingsHelper"; import SettingsHelper from "../../helpers/SettingsHelper";
export default async function MessageUpdate(oldMessage: Message, newMessage: Message) { export default async function MessageUpdate(oldMessage: Message, newMessage: Message) {

View file

@ -1,6 +1,6 @@
import DefaultValues from "../constants/DefaultValues"; import DefaultValues from "../constants/DefaultValues";
import Server from "../entity/Server"; import Server from "../database/entities/Server";
import Setting from "../entity/Setting"; import Setting from "../database/entities/Setting";
export default class SettingsHelper { export default class SettingsHelper {
public static async GetSetting(key: string, serverId: string): Promise<string | undefined> { public static async GetSetting(key: string, serverId: string): Promise<string | undefined> {