🎨 reorganized files

This commit is contained in:
Axel Olausson Holtenäs 2022-10-19 21:21:19 +02:00
parent 7281a4e53b
commit 9536478730
51 changed files with 48 additions and 252 deletions

View file

@ -2,7 +2,7 @@
import { ButtonInteraction, CommandInteraction, Message } from "discord.js";
import addSeconds from "../../helpers/addSeconds";
import logger from "../../middlewares/logger";
import prisma from "../../prisma";
import prisma from "../database";
export const command = async (i: CommandInteraction, cooldown: number) => {
const { guild, user, commandId } = i;

View file

@ -1,5 +1,5 @@
import { BaseInteraction, EmbedBuilder } from "discord.js";
import getEmbedConfig from "../getEmbedData";
import getEmbedConfig from "../../helpers/getEmbedData";
export default async (interaction: BaseInteraction, ephemeral: boolean) => {
if (!interaction.isRepliable())

View file

@ -1,18 +1,18 @@
import { Client } from "discord.js";
import schedule from "node-schedule";
import listDir from "../../helpers/checkDirectory";
import checkDirectory from "../../helpers/checkDirectory";
import { IJob } from "../../interfaces/Job";
import logger from "../../middlewares/logger";
export const start = async (client: Client) => {
logger.info("⏰ Started job management");
const jobNames = await listDir("jobs");
const jobNames = await checkDirectory("schedules");
if (!jobNames) return logger.warn("No available jobs found");
await Promise.all(
jobNames.map(async (jobName) => {
const job: IJob = await import(`../../jobs/${jobName}`);
const job: IJob = await import(`../../schedules/${jobName}`);
schedule.scheduleJob(job.options.schedule, async () => {
logger.verbose(`⏰ Performed the job "${jobName}"`);

View file

@ -1,8 +0,0 @@
import { EmbedBuilder } from "discord.js";
export default new EmbedBuilder()
.setFooter({
text: process.env.EMBED_FOOTER_TEXT,
iconURL: process.env.EMBED_FOOTER_ICON,
})
.setTimestamp(new Date());

View file

@ -1,43 +0,0 @@
/* eslint-disable no-loops/no-loops */
import { SlashCommandBuilder } from "discord.js";
import logger from "../../middlewares/logger";
import getPluginCommands from "../getPluginCommands";
import getPlugins from "../getPlugins";
export default async () => {
logger.debug("Processing complete builder for plugins");
const plugins = await getPlugins("plugins");
const pluginBuilders = [];
for await (const plugin of plugins) {
logger.debug(`Processing builder for plugin: ${plugin}`);
const commands = await getPluginCommands(plugin);
const builderStructure = new SlashCommandBuilder()
.setName(plugin)
.setDescription("Get info about a user or a server!");
for await (const command of commands) {
logger.debug(`Processing builder of command: ${command.name}`);
if (command?.options?.group) {
logger.debug(`Processing subcommand group: ${command.builder.name}`);
builderStructure.addSubcommandGroup(command.builder);
logger.verbose(`Processed subcommand group: ${command.builder.name}!`);
} else {
logger.debug(`Processing subcommand: ${command.builder.name}`);
builderStructure.addSubcommand(command.builder);
logger.verbose(`Processed subcommand: ${command.builder.name}!`);
}
logger.verbose(`Processed builder of command: ${command.name}!`);
}
pluginBuilders.push(builderStructure);
logger.verbose(`Processed builder for plugin: ${plugin}!`);
}
logger.verbose("Processed complete builder for plugins!");
return pluginBuilders;
};

View file

@ -1,6 +1,6 @@
import { ColorResolvable, Guild } from "discord.js";
import prisma from "../../handlers/database";
import logger from "../../middlewares/logger";
import prisma from "../../prisma";
export default async (guild?: Guild | null) => {
const {

View file

@ -1,11 +0,0 @@
import logger from "../../middlewares/logger";
export default async (plugin: string, command: string) => {
logger.debug(`Processing builder for command: ${command}`);
const { builder } = await import(
`../../plugins/${plugin}/commands/${command}`
);
logger.verbose(`Processed builder for command: ${command}!`);
return builder;
};

View file

@ -1,10 +0,0 @@
import logger from "../../middlewares/logger";
export default async (plugin: string, command: string) => {
logger.debug(`Processing options for command: ${command}`);
const { options } =
(await import(`../../plugins/${plugin}/commands/${command}`)) || [];
logger.verbose(`Processed options for command: ${command}!`);
return options;
};

View file

@ -1,24 +0,0 @@
/* eslint-disable no-loops/no-loops */
import logger from "../../middlewares/logger";
import listDir from "../checkDirectory";
import getPluginCommandBuilder from "../getPluginCommandBuilder";
import getPluginCommandOptions from "../getPluginCommandOptions";
export default async (plugin: string) => {
logger.debug(`Processing commands for plugin: ${plugin}`);
const commands = (await listDir(`plugins/${plugin}/commands`)) || [];
const commandStructure = [];
for await (const command of commands) {
logger.debug(`Processing command: ${command}`);
const builder = await getPluginCommandBuilder(plugin, command);
const options = await getPluginCommandOptions(plugin, command);
commandStructure.push({ name: command, builder, options });
logger.verbose(`Processed command: ${command}!`);
}
logger.verbose(`Processed commands for plugin: ${plugin}!`);
return commandStructure;
};

View file

@ -1,8 +0,0 @@
import logger from "../../middlewares/logger";
export default async (plugin: string) => {
logger.debug(`Processing metadata for plugin: ${plugin}`);
const metadata = await import(`../../plugins/${plugin}/metadata`);
logger.verbose(`Processed metadata for plugin: ${plugin}!`);
return metadata.default;
};

View file

@ -1,34 +0,0 @@
/* eslint-disable no-loops/no-loops */
import { Client } from "discord.js";
import logger from "../../middlewares/logger";
import getPluginCommands from "../getPluginCommands";
import getPluginMetadata from "../getPluginMetadata";
import getPlugins from "../getPlugins";
export default async (client: Client, dir: string) => {
const plugins = await getPlugins(dir);
const pluginStructure = [];
logger.debug("Processing structure of plugins...");
for await (const plugin of plugins) {
logger.debug(`Processing structure of plugin: ${plugin}`);
const commands = await getPluginCommands(plugin);
const metadata = await getPluginMetadata(plugin);
pluginStructure.push({
plugin,
commands,
metadata,
});
client.commands.set(plugin, commands);
logger.verbose(`Processed structure of plugin: ${plugin}!`);
}
logger.verbose("Processed structure of plugins!");
return pluginStructure;
};

View file

@ -1,10 +0,0 @@
import logger from "../../middlewares/logger";
import listDir from "../checkDirectory";
export default async (dir: string) => {
logger.debug("Processing list of plugins...");
const plugins = await listDir(dir);
logger.verbose("Processed list of plugins!");
return plugins || [];
};

View file

@ -1,22 +0,0 @@
import { REST } from "@discordjs/rest";
import { Routes, SlashCommandBuilder } from "discord.js";
import logger from "../../middlewares/logger";
export default async (builder: SlashCommandBuilder) => {
const rest = new REST({ version: "10" }).setToken(process.env.DISCORD_TOKEN);
await rest.put(
Routes.applicationGuildCommands(
process.env.DISCORD_CLIENT_ID,
process.env.DISCORD_GUILD_ID
),
{ body: builder }
);
await rest
.put(Routes.applicationCommands(process.env.DISCORD_CLIENT_ID as string), {
body: builder,
})
.then(() => logger.info("Successfully deployed to Discord"))
.catch(() => logger.error("Failed to deployed to Discord"));
};

View file

@ -1,5 +1,5 @@
import { Guild, User } from "discord.js";
import prisma from "../prisma";
import prisma from "../../handlers/database";
export default async (guild: Guild, from: User, to: User, amount: number) => {
return await prisma.$transaction(async (tx) => {

View file

@ -1,7 +1,8 @@
import { Client, Collection, GatewayIntentBits } from "discord.js"; // discord.js
import "dotenv/config";
import * as managers from "./managers";
import * as command from "./handlers/command";
import * as event from "./handlers/event";
import * as schedule from "./handlers/schedule";
// Main process that starts all other sub processes
const main = async () => {
@ -18,7 +19,9 @@ const main = async () => {
// Create command collection
client.commands = new Collection();
await managers.start(client);
await schedule.start(client);
await event.register(client);
await command.register(client);
// Authorize with Discord's API
await client.login(process.env.DISCORD_TOKEN);

View file

@ -1,22 +0,0 @@
import mongoose from "mongoose";
import logger from "../../middlewares/logger";
// Function to connect to MongoDB server
export const connect = async () => {
await mongoose
.connect(process.env.MONGO_URL)
.then((connection) => {
logger.info(`💾 Connected to database: ${connection.connection.name}`);
})
.catch(() => {
throw new Error("Error connecting to database.");
});
mongoose.connection.on("error", () => {
throw new Error("Failed to connect to database.");
});
mongoose.connection.on("warn", (warning) => {
logger.warn(`💾 ${warning}`);
});
};

View file

@ -1,12 +0,0 @@
import { Client } from "discord.js";
import * as command from "./command";
import * as event from "./event";
import * as schedule from "./schedule";
export const start = async (client: Client) => {
// await database.connect();
await schedule.start(client);
await command.register(client);
await event.register(client);
};

View file

@ -1,7 +1,7 @@
import { ChatInputCommandInteraction, ColorResolvable } from "discord.js";
import prisma from "../../../../../../../handlers/database";
import getEmbedConfig from "../../../../../../../helpers/getEmbedData";
import logger from "../../../../../../../middlewares/logger";
import prisma from "../../../../../../../prisma";
export default async (interaction: ChatInputCommandInteraction) => {
const { options, guild } = interaction;

View file

@ -1,8 +1,8 @@
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { ChannelType } from "discord-api-types/v10";
import { ChatInputCommandInteraction, EmbedBuilder } from "discord.js";
import prisma from "../../../../../handlers/database";
import getEmbedConfig from "../../../../../helpers/getEmbedData";
import prisma from "../../../../../prisma";
export default {
metadata: { guildOnly: true, ephemeral: false },

View file

@ -1,8 +1,8 @@
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { CommandInteraction, EmbedBuilder } from "discord.js";
import prisma from "../../../../../handlers/database";
import getEmbedConfig from "../../../../../helpers/getEmbedData";
import logger from "../../../../../middlewares/logger";
import prisma from "../../../../../prisma";
export default {
metadata: { guildOnly: true, ephemeral: true },

View file

@ -1,9 +1,9 @@
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { GuildMember } from "@prisma/client";
import { CommandInteraction, EmbedBuilder } from "discord.js";
import prisma from "../../../../../handlers/database";
import getEmbedConfig from "../../../../../helpers/getEmbedData";
import logger from "../../../../../middlewares/logger";
import prisma from "../../../../../prisma";
export default {
metadata: { guildOnly: true, ephemeral: false },

View file

@ -3,13 +3,13 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import Chance from "chance";
import { CommandInteraction, EmbedBuilder } from "discord.js";
// Models
import * as cooldown from "../../../../../helpers/cooldown";
import * as cooldown from "../../../../../handlers/cooldown";
// Configurations
import getEmbedConfig from "../../../../../helpers/getEmbedData";
// Helpers
// Handlers
import prisma from "../../../../../handlers/database";
import logger from "../../../../../middlewares/logger";
import prisma from "../../../../../prisma";
export default {
metadata: { guildOnly: true, ephemeral: true },

View file

@ -7,9 +7,9 @@ import {
PermissionsBitField,
} from "discord.js";
// Configurations
import prisma from "../../../../../../../handlers/database";
import getEmbedConfig from "../../../../../../../helpers/getEmbedData";
import logger from "../../../../../../../middlewares/logger";
import prisma from "../../../../../../../prisma";
// Function
export default {

View file

@ -8,8 +8,8 @@ import {
PermissionsBitField,
} from "discord.js";
// Configurations
import prisma from "../../../../../../../handlers/database";
import getEmbedConfig from "../../../../../../../helpers/getEmbedData";
import prisma from "../../../../../../../prisma";
// Function
export default {

View file

@ -12,7 +12,7 @@ import getEmbedConfig from "../../../../../../../helpers/getEmbedData";
import pluralize from "../../../../../../../helpers/pluralize";
// Models
// Handlers
import prisma from "../../../../../../../prisma";
import prisma from "../../../../../../../handlers/database";
// Function
export default {
metadata: {

View file

@ -10,8 +10,8 @@ import {
// Configurations
import getEmbedConfig from "../../../../../../../helpers/getEmbedData";
// Handlers
import prisma from "../../../../../../../handlers/database";
import logger from "../../../../../../../middlewares/logger";
import prisma from "../../../../../../../prisma";
// Function
export default {

View file

@ -11,8 +11,8 @@ import getEmbedConfig from "../../../../../../../helpers/getEmbedData";
// Helpers../../../../../../../helpers/userData
import pluralize from "../../../../../../../helpers/pluralize";
// Handlers
import prisma from "../../../../../../../handlers/database";
import logger from "../../../../../../../middlewares/logger";
import prisma from "../../../../../../../prisma";
// Function
export default {

View file

@ -1,11 +1,11 @@
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { ChatInputCommandInteraction, EmbedBuilder } from "discord.js";
import { command as CooldownCommand } from "../../../../../helpers/cooldown";
import { command as CooldownCommand } from "../../../../../handlers/cooldown";
import getEmbedConfig from "../../../../../helpers/getEmbedData";
import logger from "../../../../../middlewares/logger";
import noSelfReputation from "./components/noSelfReputation";
import prisma from "../../../../../prisma";
import prisma from "../../../../../handlers/database";
export default {
metadata: { guildOnly: true, ephemeral: true },

View file

@ -1,8 +1,8 @@
import { Guild } from "discord.js";
import updatePresence from "../../../helpers/updatePresence";
import prisma from "../../../handlers/database";
import updatePresence from "../../../handlers/updatePresence";
import { IEventOptions } from "../../../interfaces/EventOptions";
import logger from "../../../middlewares/logger";
import prisma from "../../../prisma";
export const options: IEventOptions = {
type: "on",

View file

@ -1,9 +1,9 @@
// 3rd party dependencies
import { Guild } from "discord.js";
import updatePresence from "../../../helpers/updatePresence";
import prisma from "../../../handlers/database";
import updatePresence from "../../../handlers/updatePresence";
import { IEventOptions } from "../../../interfaces/EventOptions";
import logger from "../../../middlewares/logger";
import prisma from "../../../prisma";
export const options: IEventOptions = {
type: "on",

View file

@ -1,9 +1,9 @@
// 3rd party dependencies
import { GuildMember } from "discord.js";
import updatePresence from "../../../helpers/updatePresence";
import prisma from "../../../handlers/database";
import updatePresence from "../../../handlers/updatePresence";
import { IEventOptions } from "../../../interfaces/EventOptions";
import logger from "../../../middlewares/logger";
import prisma from "../../../prisma";
import audits from "./audits";
import joinMessage from "./joinMessage";

View file

@ -1,9 +1,9 @@
// 3rd party dependencies
import { GuildMember } from "discord.js";
import updatePresence from "../../../helpers/updatePresence";
import prisma from "../../../handlers/database";
import updatePresence from "../../../handlers/updatePresence";
import { IEventOptions } from "../../../interfaces/EventOptions";
import logger from "../../../middlewares/logger";
import prisma from "../../../prisma";
import audits from "./audits";
import leaveMessage from "./leaveMessage";

View file

@ -1,7 +1,7 @@
// Dependencies
import { BaseInteraction } from "discord.js";
import { button as CooldownButton } from "../../../../../helpers/cooldown";
import deferReply from "../../../../../helpers/deferReply";
import { button as CooldownButton } from "../../../../../handlers/cooldown";
import deferReply from "../../../../../handlers/deferReply";
export default async (interaction: BaseInteraction) => {
if (!interaction.isButton()) return;

View file

@ -1,7 +1,7 @@
// Dependencies
import { ChatInputCommandInteraction } from "discord.js";
import { command as CooldownCommand } from "../../../../../helpers/cooldown";
import deferReply from "../../../../../helpers/deferReply";
import { command as CooldownCommand } from "../../../../../handlers/cooldown";
import deferReply from "../../../../../handlers/deferReply";
import getCommandMetadata from "../../../../../helpers/getCommandMetadata";
export default async (interaction: ChatInputCommandInteraction) => {

View file

@ -1,6 +1,6 @@
import { ChannelType, Message } from "discord.js";
import prisma from "../../../../../handlers/database";
import logger from "../../../../../middlewares/logger";
import prisma from "../../../../../prisma";
export default {
execute: async (message: Message) => {

View file

@ -1,7 +1,7 @@
import { ChannelType, Message } from "discord.js";
import { message as CooldownMessage } from "../../../../../helpers/cooldown";
import { message as CooldownMessage } from "../../../../../handlers/cooldown";
import prisma from "../../../../../handlers/database";
import logger from "../../../../../middlewares/logger";
import prisma from "../../../../../prisma";
export default {
execute: async (message: Message) => {

View file

@ -1,7 +1,7 @@
import { ChannelType, Message } from "discord.js";
import { message as CooldownMessage } from "../../../../../helpers/cooldown";
import { message as CooldownMessage } from "../../../../../handlers/cooldown";
import prisma from "../../../../../handlers/database";
import logger from "../../../../../middlewares/logger";
import prisma from "../../../../../prisma";
export default {
execute: async (message: Message) => {

View file

@ -1,8 +1,8 @@
// Dependencies
import { Message } from "discord.js";
// Models
import prisma from "../../../../handlers/database";
import logger from "../../../../middlewares/logger";
import prisma from "../../../../prisma";
export default async (message: Message) => {
const { guild, channel, author, content } = message;

View file

@ -1,8 +1,8 @@
// Dependencies
import { Message } from "discord.js";
// Models
import prisma from "../../../../handlers/database";
import logger from "../../../../middlewares/logger";
import prisma from "../../../../prisma";
export default async (message: Message) => {
const { guild, channel, author, content } = message;

View file

@ -1,9 +1,9 @@
// Dependencies
import { Client } from "discord.js";
// Helpers
import deployCommands from "../../../helpers/deployCommands";
import devMode from "../../../helpers/devMode";
import updatePresence from "../../../helpers/updatePresence";
import deployCommands from "../../../handlers/deployCommands";
import devMode from "../../../handlers/devMode";
import updatePresence from "../../../handlers/updatePresence";
import { IEventOptions } from "../../../interfaces/EventOptions";
import logger from "../../../middlewares/logger";

View file

@ -1,3 +0,0 @@
import { PrismaClient } from "@prisma/client";
export default new PrismaClient();