diff options
Diffstat (limited to 'src/lib/extensions/Util.ts')
-rw-r--r-- | src/lib/extensions/Util.ts | 71 |
1 files changed, 13 insertions, 58 deletions
diff --git a/src/lib/extensions/Util.ts b/src/lib/extensions/Util.ts index 7bedfc1..431410c 100644 --- a/src/lib/extensions/Util.ts +++ b/src/lib/extensions/Util.ts @@ -5,12 +5,7 @@ import { exec } from 'child_process'; import got from 'got'; import { MessageEmbed, GuildMember, User } from 'discord.js'; import { CommandInteractionOption } from 'discord.js'; -import { - ApplicationCommandOptionType, - APIInteractionDataResolvedGuildMember, - APIInteractionDataResolvedChannel, - APIRole -} from 'discord-api-types'; +import { ApplicationCommandOptionType, APIInteractionDataResolvedGuildMember, APIInteractionDataResolvedChannel, APIRole } from 'discord-api-types'; import { GuildChannel } from 'discord.js'; import { Role } from 'discord.js'; import chalk from 'chalk'; @@ -223,20 +218,13 @@ export class Util extends ClientUtil { author = author.user; // Convert to User if GuildMember } let embed = new MessageEmbed().setTimestamp(); - if (author) - embed = embed.setAuthor( - author.username, - author.displayAvatarURL({ dynamic: true }), - `https://discord.com/users/${author.id}` - ); + if (author) embed = embed.setAuthor(author.username, author.displayAvatarURL({ dynamic: true }), `https://discord.com/users/${author.id}`); if (color) embed = embed.setColor(color); return embed; } public async mcUUID(username: string): Promise<string> { - const apiRes = (await got - .get(`https://api.ashcon.app/mojang/v2/user/${username}`) - .json()) as uuidRes; + const apiRes = (await got.get(`https://api.ashcon.app/mojang/v2/user/${username}`).json()) as uuidRes; return apiRes.uuid.replace(/-/g, ''); } @@ -244,24 +232,11 @@ export class Util extends ClientUtil { let fetchedGuild: Guild; if (guild) fetchedGuild = this.client.guilds.cache.get(guild); try { - const registered = - guild === undefined - ? await this.client.application.commands.fetch() - : await fetchedGuild.commands.fetch(); + const registered = guild === undefined ? await this.client.application.commands.fetch() : await fetchedGuild.commands.fetch(); for (const [, registeredCommand] of registered) { - if ( - !this.client.commandHandler.modules.find((cmd) => cmd.id == registeredCommand.name) - ?.execSlash || - force - ) { - guild === undefined - ? await this.client.application.commands.delete(registeredCommand.id) - : await fetchedGuild.commands.delete(registeredCommand.id); - this.client.logger.verbose( - chalk`{red Deleted slash command ${registeredCommand.name}${ - guild !== undefined ? ` in guild ${fetchedGuild.name}` : '' - }}` - ); + if (!this.client.commandHandler.modules.find((cmd) => cmd.id == registeredCommand.name)?.execSlash || force) { + guild === undefined ? await this.client.application.commands.delete(registeredCommand.id) : await fetchedGuild.commands.delete(registeredCommand.id); + this.client.logger.verbose(chalk`{red Deleted slash command ${registeredCommand.name}${guild !== undefined ? ` in guild ${fetchedGuild.name}` : ''}}`); } } @@ -277,40 +252,20 @@ export class Util extends ClientUtil { if (found?.id && !force) { if (slashdata.description !== found.description) { - guild === undefined - ? await this.client.application.commands.edit(found.id, slashdata) - : fetchedGuild.commands.edit(found.id, slashdata); - this.client.logger.verbose( - chalk`{yellow Edited slash command ${BushCommand.id}${ - guild !== undefined ? ` in guild ${fetchedGuild.name}` : '' - }}` - ); + guild === undefined ? await this.client.application.commands.edit(found.id, slashdata) : fetchedGuild.commands.edit(found.id, slashdata); + this.client.logger.verbose(chalk`{yellow Edited slash command ${BushCommand.id}${guild !== undefined ? ` in guild ${fetchedGuild.name}` : ''}}`); } } else { - guild === undefined - ? await this.client.application.commands.create(slashdata) - : fetchedGuild.commands.create(slashdata); - this.client.logger.verbose( - chalk`{green Created slash command ${BushCommand.id}${ - guild !== undefined ? ` in guild ${fetchedGuild.name}` : '' - }}` - ); + guild === undefined ? await this.client.application.commands.create(slashdata) : fetchedGuild.commands.create(slashdata); + this.client.logger.verbose(chalk`{green Created slash command ${BushCommand.id}${guild !== undefined ? ` in guild ${fetchedGuild.name}` : ''}}`); } } } - return this.client.logger.log( - chalk.green( - `Slash commands registered${guild !== undefined ? ` in guild ${fetchedGuild.name}` : ''}` - ) - ); + return this.client.logger.log(chalk.green(`Slash commands registered${guild !== undefined ? ` in guild ${fetchedGuild.name}` : ''}`)); } catch (e) { console.log(chalk.red(e.stack)); - return this.client.logger.error( - chalk`{red Slash commands not registered${ - guild !== undefined ? ` in guild ${fetchedGuild.name}` : '' - }, see above error.}` - ); + return this.client.logger.error(chalk`{red Slash commands not registered${guild !== undefined ? ` in guild ${fetchedGuild.name}` : ''}, see above error.}`); } } |