️ remove redundant plugin loading

This commit is contained in:
Axel Olausson Holtenäs 2022-04-17 18:09:46 +02:00
parent 61ae59847d
commit 49c8350054
No known key found for this signature in database
GPG key ID: 7BF6826B76382CBA

View file

@ -3,52 +3,51 @@ import { token, clientId } from "@config/discord";
import { devMode, guildId } from "@config/other"; import { devMode, guildId } from "@config/other";
import logger from "../logger"; import logger from "../logger";
import fs from "fs"; import { Client } from "@root/types/common/discord";
import { REST } from "@discordjs/rest"; import { REST } from "@discordjs/rest";
import { Routes } from "discord-api-types/v9"; import { Routes } from "discord-api-types/v9";
export default async () => { export default async (client: Client) => {
fs.readdir("./src/plugins", async (error: any, plugins: any) => { const pluginList = [] as string[];
if (error) {
return logger?.error(new Error(error));
}
const pluginList = [] as any; await Promise.all(
client.commands.map(async (pluginData: any) => {
pluginList.push(pluginData.data.toJSON());
logger.verbose(
`${pluginData.data.name} successfully pushed to plugin list.`
);
})
)
.then(async () => {
logger.debug("Successfully pushed all plugins to plugin list.");
})
.catch(async (error) => {
logger.error(error);
});
await Promise.all( const rest = new REST({ version: "9" }).setToken(token);
plugins?.map(async (pluginName: any) => {
const plugin = await import(`../plugins/${pluginName}`);
pluginList.push(plugin.default.data.toJSON()); await rest
.put(Routes.applicationCommands(clientId), {
logger?.verbose(`Loaded plugin: ${pluginName} for deployment`); body: pluginList,
}) })
); .then(async () => {
logger.debug(`Successfully deployed plugins to Discord`);
const rest = new REST({ version: "9" }).setToken(token); })
.catch(async (error) => {
logger.error(error);
});
if (devMode) {
await rest await rest
.put(Routes.applicationCommands(clientId), { .put(Routes.applicationGuildCommands(clientId, guildId), {
body: pluginList, body: pluginList,
}) })
.then(async () => { .then(async () =>
logger?.info(`Successfully deployed plugins to Discord`); logger.debug(`Successfully deployed guild plugins to Discord`)
}) )
.catch(async (err: any) => { .catch(async (error) => {
logger.error(err); logger.error(error);
}); });
}
if (devMode) {
await rest
.put(Routes.applicationGuildCommands(clientId, guildId), {
body: pluginList,
})
.then(async () =>
logger?.info(`Successfully deployed guild plugins to Discord`)
)
.catch(async (err: any) => {
logger.error(err);
});
}
});
}; };