🚑 plugins now loading

This commit is contained in:
Axel Olausson Holtenäs 2022-05-29 19:35:42 +02:00
parent 2d3d7fe7aa
commit 880ad789c9
No known key found for this signature in database
GPG key ID: 7BF6826B76382CBA
18 changed files with 267 additions and 331 deletions

View file

@ -6,7 +6,7 @@ import { ICommand } from "../interfaces/Command";
export default async (client: Client) => { export default async (client: Client) => {
client.commands = new Collection(); client.commands = new Collection();
fs.readdir("./src/plugins", async (error, plugins) => { fs.readdir("plugins", async (error, plugins) => {
if (error) { if (error) {
return logger.error(`Error reading plugins: ${error}`); return logger.error(`Error reading plugins: ${error}`);
} }

View file

@ -9,6 +9,6 @@ export default async (
const subcommandGroup = interaction.options.getSubcommandGroup(false); const subcommandGroup = interaction.options.getSubcommandGroup(false);
return subcommandGroup return subcommandGroup
? currentCommand.modules[subcommandGroup].modules[subcommand].metadata ? currentCommand.moduleData[subcommandGroup].moduleData[subcommand].metadata
: currentCommand.modules[subcommand].metadata; : currentCommand.moduleData[subcommand].metadata;
}; };

View file

@ -1,7 +1,7 @@
import { SlashCommandBuilder } from "@discordjs/builders"; import { SlashCommandBuilder } from "@discordjs/builders";
export interface ICommand { export interface ICommand {
modules: any;
builder: SlashCommandBuilder; builder: SlashCommandBuilder;
moduleData: any;
execute: Promise<void>; execute: Promise<void>;
} }

View file

@ -3,7 +3,7 @@ import { Client } from "discord.js";
import listDir from "../../helpers/listDir"; import listDir from "../../helpers/listDir";
export const register = async (client: Client) => { export const register = async (client: Client) => {
const eventNames = await listDir("src/events"); const eventNames = await listDir("events");
if (!eventNames) return; if (!eventNames) return;
for await (const eventName of eventNames) { for await (const eventName of eventNames) {

View file

@ -8,11 +8,7 @@ import modules from "./modules";
// Handlers // Handlers
import logger from "../../logger"; import logger from "../../logger";
// Function export const builder = new SlashCommandBuilder()
export default {
modules,
builder: new SlashCommandBuilder()
.setName("config") .setName("config")
.setDescription("Manage guild configurations.") .setDescription("Manage guild configurations.")
@ -22,43 +18,26 @@ export default {
.addSubcommand(modules.welcome.builder) .addSubcommand(modules.welcome.builder)
.addSubcommand(modules.audits.builder) .addSubcommand(modules.audits.builder)
.addSubcommand(modules.shop.builder) .addSubcommand(modules.shop.builder)
.addSubcommand(modules.embeds.builder), .addSubcommand(modules.embeds.builder);
async execute(interaction: CommandInteraction) { export const moduleData = modules;
// Destructure member
const { options } = interaction;
switch (options?.getSubcommand()) { // Function
export const execute = async (interaction: CommandInteraction) => {
switch (interaction.options?.getSubcommand()) {
case "pterodactyl": case "pterodactyl":
logger?.silly(`Subcommand is pterodactyl`);
return modules.pterodactyl.execute(interaction); return modules.pterodactyl.execute(interaction);
case "credits": case "credits":
logger?.silly(`Subcommand is credits`);
return modules.credits.execute(interaction); return modules.credits.execute(interaction);
case "points": case "points":
logger?.silly(`Subcommand is points`);
return modules.points.execute(interaction); return modules.points.execute(interaction);
case "welcome": case "welcome":
logger?.silly(`Subcommand is welcome`);
return modules.welcome.execute(interaction); return modules.welcome.execute(interaction);
case "audits": case "audits":
logger?.silly(`Subcommand is audits`);
return modules.audits.execute(interaction); return modules.audits.execute(interaction);
case "shop": case "shop":
logger?.silly(`Subcommand is shop`);
return modules.shop.execute(interaction); return modules.shop.execute(interaction);
case "embeds": case "embeds":
logger?.silly(`Subcommand is shop`);
return modules.embeds.execute(interaction); return modules.embeds.execute(interaction);
default:
logger?.silly(`Subcommand is not found`);
} }
},
}; };

View file

@ -4,23 +4,16 @@ import logger from "../../logger";
import modules from "../../plugins/counters/modules"; import modules from "../../plugins/counters/modules";
export default { export const builder = new SlashCommandBuilder()
modules,
builder: new SlashCommandBuilder()
.setName("counters") .setName("counters")
.setDescription("View guild counters") .setDescription("View guild counters")
.addSubcommand(modules.view.builder), .addSubcommand(modules.view.builder);
async execute(interaction: CommandInteraction) { export const moduleData = modules;
const { options } = interaction;
if (options.getSubcommand() === "view") { export const execute = async (interaction: CommandInteraction) => {
logger.silly(`Executing view subcommand`); if (interaction.options.getSubcommand() === "view") {
return modules.view.execute(interaction); await modules.view.execute(interaction);
} }
logger.silly(`Unknown subcommand ${options.getSubcommand()}`);
},
}; };

View file

@ -2,21 +2,20 @@ import { SlashCommandBuilder } from "@discordjs/builders";
import { CommandInteraction } from "discord.js"; import { CommandInteraction } from "discord.js";
import logger from "../../logger"; import logger from "../../logger";
import modules from "../../plugins/credits/modules"; import modules from "./modules";
export default { export const builder = new SlashCommandBuilder()
modules,
builder: new SlashCommandBuilder()
.setName("credits") .setName("credits")
.setDescription("Manage your credits.") .setDescription("Manage your credits.")
.addSubcommand(modules.balance.builder) .addSubcommand(modules.balance.builder)
.addSubcommand(modules.gift.builder) .addSubcommand(modules.gift.builder)
.addSubcommand(modules.top.builder) .addSubcommand(modules.top.builder)
.addSubcommand(modules.work.builder), .addSubcommand(modules.work.builder);
async execute(interaction: CommandInteraction) { export const moduleData = modules;
export const execute = async (interaction: CommandInteraction) => {
const { options } = interaction; const { options } = interaction;
switch (options.getSubcommand()) { switch (options.getSubcommand()) {
@ -35,5 +34,4 @@ export default {
default: default:
logger.silly(`Unknown subcommand ${options.getSubcommand()}`); logger.silly(`Unknown subcommand ${options.getSubcommand()}`);
} }
},
}; };

View file

@ -4,16 +4,15 @@ import logger from "../../logger";
import modules from "../../plugins/fun/modules"; import modules from "../../plugins/fun/modules";
export default { export const builder = new SlashCommandBuilder()
modules,
builder: new SlashCommandBuilder()
.setName("fun") .setName("fun")
.setDescription("Fun commands.") .setDescription("Fun commands.")
.addSubcommand(modules.meme.builder), .addSubcommand(modules.meme.builder);
async execute(interaction: CommandInteraction) { export const moduleData = modules;
export const execute = async (interaction: CommandInteraction) => {
const { options } = interaction; const { options } = interaction;
if (options.getSubcommand() === "meme") { if (options.getSubcommand() === "meme") {
@ -21,5 +20,4 @@ export default {
} else { } else {
logger.silly(`Unknown subcommand ${options.getSubcommand()}`); logger.silly(`Unknown subcommand ${options.getSubcommand()}`);
} }
},
}; };

View file

@ -6,32 +6,24 @@ import { CommandInteraction } from "discord.js";
import modules from "../../plugins/manage/modules"; import modules from "../../plugins/manage/modules";
import logger from "../../logger"; import logger from "../../logger";
// Function export const moduleData = modules;
export default {
modules,
builder: new SlashCommandBuilder() // Function
export const builder = new SlashCommandBuilder()
.setName("manage") .setName("manage")
.setDescription("Manage the bot.") .setDescription("Manage the bot.")
.addSubcommandGroup(modules.counters.builder) .addSubcommandGroup(modules.counters.builder)
.addSubcommandGroup(modules.credits.builder), .addSubcommandGroup(modules.credits.builder);
async execute(interaction: CommandInteraction) { export const execute = async (interaction: CommandInteraction) => {
// Destructure // Destructure
const { options } = interaction; const { options } = interaction;
if (options?.getSubcommandGroup() === "credits") { if (options?.getSubcommandGroup() === "credits") {
logger?.silly(`Subcommand group is credits`);
return modules.credits.execute(interaction); return modules.credits.execute(interaction);
} }
if (options?.getSubcommandGroup() === "counters") { if (options?.getSubcommandGroup() === "counters") {
logger?.silly(`Subcommand group is counters`);
return modules.counters.execute(interaction); return modules.counters.execute(interaction);
} }
logger?.silly(`Subcommand group is not credits or counters`);
},
}; };

View file

@ -8,18 +8,17 @@ import logger from "../../../../logger";
import modules from "./modules"; import modules from "./modules";
// Function // Function
export default { export const moduleData = modules;
modules,
builder: (group: SlashCommandSubcommandGroupBuilder) => { export const builder = (group: SlashCommandSubcommandGroupBuilder) => {
return group return group
.setName("counters") .setName("counters")
.setDescription("Manage guild counters.") .setDescription("Manage guild counters.")
.addSubcommand(modules.add.builder) .addSubcommand(modules.add.builder)
.addSubcommand(modules.remove.builder); .addSubcommand(modules.remove.builder);
}, };
execute: async (interaction: CommandInteraction) => { export const execute = async (interaction: CommandInteraction) => {
const { options } = interaction; const { options } = interaction;
if (options?.getSubcommand() === "add") { if (options?.getSubcommand() === "add") {
@ -35,5 +34,4 @@ export default {
} }
logger?.silly(`Unknown subcommand ${options?.getSubcommand()}`); logger?.silly(`Unknown subcommand ${options?.getSubcommand()}`);
},
}; };

View file

@ -4,10 +4,9 @@ import logger from "../../../../logger";
import modules from "./modules"; import modules from "./modules";
export default { export const moduleData = modules;
modules,
builder: (group: SlashCommandSubcommandGroupBuilder) => { export const builder = (group: SlashCommandSubcommandGroupBuilder) => {
return group return group
.setName("credits") .setName("credits")
.setDescription("Manage the credits of a user.") .setDescription("Manage the credits of a user.")
@ -15,29 +14,17 @@ export default {
.addSubcommand(modules.set.builder) .addSubcommand(modules.set.builder)
.addSubcommand(modules.take.builder) .addSubcommand(modules.take.builder)
.addSubcommand(modules.transfer.builder); .addSubcommand(modules.transfer.builder);
}, };
execute: async (interaction: CommandInteraction) => {
const { options } = interaction;
switch (options.getSubcommand()) { export const execute = async (interaction: CommandInteraction) => {
switch (interaction.options.getSubcommand()) {
case "give": case "give":
logger.silly(`Executing give subcommand`);
return modules.give.execute(interaction); return modules.give.execute(interaction);
case "set": case "set":
logger.silly(`Executing set subcommand`);
return modules.set.execute(interaction); return modules.set.execute(interaction);
case "take": case "take":
logger.silly(`Executing take subcommand`);
return modules.take.execute(interaction); return modules.take.execute(interaction);
case "transfer": case "transfer":
logger.silly(`Executing transfer subcommand`);
return modules.transfer.execute(interaction); return modules.transfer.execute(interaction);
default:
logger.silly(`Unknown subcommand ${options.getSubcommand()}`);
} }
},
}; };

View file

@ -1,4 +1,4 @@
import counters from "./counters"; import * as counters from "./counters";
import credits from "./credits"; import * as credits from "./credits";
export default { counters, credits }; export default { counters, credits };

View file

@ -8,15 +8,15 @@ import modules from "../../plugins/profile/modules";
// Handlers // Handlers
import logger from "../../logger"; import logger from "../../logger";
// Function export const moduleData = modules;
export default {
modules,
builder: new SlashCommandBuilder() // Function
export const builder = new SlashCommandBuilder()
.setName("profile") .setName("profile")
.setDescription("Check a profile.") .setDescription("Check a profile.")
.addSubcommand(modules.view.builder), .addSubcommand(modules.view.builder);
async execute(interaction: CommandInteraction) {
export const execute = async (interaction: CommandInteraction) => {
const { options } = interaction; const { options } = interaction;
if (options?.getSubcommand() === "view") { if (options?.getSubcommand() === "view") {
@ -26,5 +26,4 @@ export default {
} }
logger?.silly(`No subcommand found`); logger?.silly(`No subcommand found`);
},
}; };

View file

@ -8,14 +8,15 @@ import modules from "./modules";
// Handlers // Handlers
import logger from "../../logger"; import logger from "../../logger";
export const moduleData = modules;
// Function // Function
export default { export const builder = new SlashCommandBuilder()
modules,
builder: new SlashCommandBuilder()
.setName("reputation") .setName("reputation")
.setDescription("Manage reputation.") .setDescription("Manage reputation.")
.addSubcommand(modules.give.builder), .addSubcommand(modules.give.builder);
async execute(interaction: CommandInteraction) {
export const execute = async (interaction: CommandInteraction) => {
const { options } = interaction; const { options } = interaction;
if (options?.getSubcommand() === "give") { if (options?.getSubcommand() === "give") {
@ -25,5 +26,4 @@ export default {
} }
logger?.silly(`No subcommand found`); logger?.silly(`No subcommand found`);
},
}; };

View file

@ -8,16 +8,16 @@ import modules from "./modules";
// Handlers // Handlers
import logger from "../../logger"; import logger from "../../logger";
// Function export const moduleData = modules;
export default {
modules,
builder: new SlashCommandBuilder() // Function
export const builder = new SlashCommandBuilder()
.setName("shop") .setName("shop")
.setDescription("Shop for credits and custom roles.") .setDescription("Shop for credits and custom roles.")
.addSubcommand(modules.pterodactyl.builder) .addSubcommand(modules.pterodactyl.builder)
.addSubcommandGroup(modules.roles.builder), .addSubcommandGroup(modules.roles.builder);
async execute(interaction: CommandInteraction) {
export const execute = async (interaction: CommandInteraction) => {
const { options } = interaction; const { options } = interaction;
if (options?.getSubcommand() === "pterodactyl") { if (options?.getSubcommand() === "pterodactyl") {
@ -33,5 +33,4 @@ export default {
} }
logger?.silly(`No subcommand found.`); logger?.silly(`No subcommand found.`);
},
}; };

View file

@ -1,4 +1,4 @@
import pterodactyl from "./pterodactyl"; import pterodactyl from "./pterodactyl";
import roles from "./roles"; import * as roles from "./roles";
export default { pterodactyl, roles }; export default { pterodactyl, roles };

View file

@ -12,18 +12,18 @@ import modules from "./modules";
import guildSchema from "../../../../database/schemas/guild"; import guildSchema from "../../../../database/schemas/guild";
// Function export const moduleData = modules;
export default {
modules,
builder: (group: SlashCommandSubcommandGroupBuilder) => { // Function
export const builder = (group: SlashCommandSubcommandGroupBuilder) => {
return group return group
.setName("roles") .setName("roles")
.setDescription("Shop for custom roles.") .setDescription("Shop for custom roles.")
.addSubcommand(modules.buy.builder) .addSubcommand(modules.buy.builder)
.addSubcommand(modules.cancel.builder); .addSubcommand(modules.cancel.builder);
}, };
execute: async (interaction: CommandInteraction) => {
export const execute = async (interaction: CommandInteraction) => {
if (interaction.guild == null) return; if (interaction.guild == null) return;
const { errorColor, footerText, footerIcon } = await getEmbedConfig( const { errorColor, footerText, footerIcon } = await getEmbedConfig(
interaction.guild interaction.guild
@ -56,15 +56,10 @@ export default {
} }
if (options?.getSubcommand() === "buy") { if (options?.getSubcommand() === "buy") {
logger.silly(`Executing buy subcommand`);
await modules.buy.execute(interaction); await modules.buy.execute(interaction);
} }
if (options?.getSubcommand() === "cancel") { if (options?.getSubcommand() === "cancel") {
logger.silly(`Executing cancel subcommand`);
await modules.cancel.execute(interaction); await modules.cancel.execute(interaction);
} }
},
}; };

View file

@ -8,20 +8,19 @@ import modules from "../../plugins/utility/modules";
// Handlers // Handlers
import logger from "../../logger"; import logger from "../../logger";
// Function export const moduleData = modules;
export default {
modules,
builder: new SlashCommandBuilder() // Function
export const builder = new SlashCommandBuilder()
.setName("utility") .setName("utility")
.setDescription("Common utility.") .setDescription("Common utility.")
.addSubcommand(modules.lookup.builder) .addSubcommand(modules.lookup.builder)
.addSubcommand(modules.about.builder) .addSubcommand(modules.about.builder)
.addSubcommand(modules.stats.builder) .addSubcommand(modules.stats.builder)
.addSubcommand(modules.avatar.builder), .addSubcommand(modules.avatar.builder);
async execute(interaction: CommandInteraction) { export const execute = async (interaction: CommandInteraction) => {
const { options } = interaction; const { options } = interaction;
switch (options.getSubcommand()) { switch (options.getSubcommand()) {
@ -36,5 +35,4 @@ export default {
default: default:
logger.error(`Unknown subcommand ${options.getSubcommand()}`); logger.error(`Unknown subcommand ${options.getSubcommand()}`);
} }
},
}; };