aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/extensions')
-rw-r--r--src/lib/extensions/BushClient.ts29
-rw-r--r--src/lib/extensions/Util.ts71
2 files changed, 21 insertions, 79 deletions
diff --git a/src/lib/extensions/BushClient.ts b/src/lib/extensions/BushClient.ts
index 99d0dd3..2b674b1 100644
--- a/src/lib/extensions/BushClient.ts
+++ b/src/lib/extensions/BushClient.ts
@@ -1,10 +1,4 @@
-import {
- AkairoClient,
- CommandHandler,
- InhibitorHandler,
- ListenerHandler,
- TaskHandler
-} from 'discord-akairo';
+import { AkairoClient, CommandHandler, InhibitorHandler, ListenerHandler, TaskHandler } from 'discord-akairo';
import { Guild } from 'discord.js';
import * as path from 'path';
import { Sequelize } from 'sequelize';
@@ -89,17 +83,12 @@ export class BushClient extends AkairoClient {
});
this.util = new Util(this);
- this.db = new Sequelize(
- this.config.dev ? 'bushbot-dev' : 'bushbot',
- this.config.db.username,
- this.config.db.password,
- {
- dialect: 'postgres',
- host: this.config.db.host,
- port: this.config.db.port,
- logging: false
- }
- );
+ this.db = new Sequelize(this.config.dev ? 'bushbot-dev' : 'bushbot', this.config.db.username, this.config.db.password, {
+ dialect: 'postgres',
+ host: this.config.db.host,
+ port: this.config.db.port,
+ logging: false
+ });
this.logger = new Logger(this);
}
@@ -124,9 +113,7 @@ export class BushClient extends AkairoClient {
loaders[loader].loadAll();
this.logger.log(chalk.green('Successfully loaded ' + chalk.cyan(loader) + '.'));
} catch (e) {
- console.error(
- chalk.red('Unable to load loader ' + chalk.cyan(loader) + ' with error ' + e)
- );
+ console.error(chalk.red('Unable to load loader ' + chalk.cyan(loader) + ' with error ' + e));
}
}
this.taskHandler.startAll();
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.}`);
}
}