From 481a157a177e60f023b59e4e9acffc549760db40 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 26 May 2021 16:53:45 +0000 Subject: Automatically format code --- src/lib/extensions/Util.ts | 48 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) (limited to 'src/lib/extensions') diff --git a/src/lib/extensions/Util.ts b/src/lib/extensions/Util.ts index bd6823f..54df670 100644 --- a/src/lib/extensions/Util.ts +++ b/src/lib/extensions/Util.ts @@ -246,10 +246,13 @@ export class Util extends ClientUtil { } public async syncSlashCommands(force = false, guild?: string): Promise { - let fetchedGuild: Guild + 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( @@ -257,9 +260,15 @@ export class Util extends ClientUtil { )?.execSlash || force ) { - guild === undefined ? await this.client.application.commands.delete(registeredCommand.id) : await fetchedGuild.commands.delete(registeredCommand.id); + 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}`:''}}` + chalk`{red Deleted slash command ${registeredCommand.name}${ + guild !== undefined ? ` in guild ${fetchedGuild.name}` : '' + }}` ); } } @@ -276,25 +285,44 @@ 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); + 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 ${botCommand.id}${guild !== undefined ? ` in guild ${fetchedGuild.name}`:''}}` + chalk`{yellow Edited slash command ${botCommand.id}${ + guild !== undefined ? ` in guild ${fetchedGuild.name}` : '' + }}` ); } } else { - guild === undefined ? await this.client.application.commands.create(slashdata) : fetchedGuild.commands.create(slashdata); + guild === undefined + ? await this.client.application.commands.create(slashdata) + : fetchedGuild.commands.create(slashdata); this.client.logger.verbose( - chalk`{green Created slash command ${botCommand.id}${guild !== undefined ? ` in guild ${fetchedGuild.name}`:''}}` + chalk`{green Created slash command ${botCommand.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.}` + chalk`{red Slash commands not registered${ + guild !== undefined ? ` in guild ${fetchedGuild.name}` : '' + }, see above error.}` ); } } -- cgit From 0caccda67d97dd74405aa4ece5d3f07e7c7dfc66 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Wed, 26 May 2021 21:36:50 -0400 Subject: some rebranding --- src/lib/extensions/BotClient.ts | 169 ------------------------------------ src/lib/extensions/BotCommand.ts | 20 ----- src/lib/extensions/BotInhibitor.ts | 6 -- src/lib/extensions/BotListener.ts | 6 -- src/lib/extensions/BotTask.ts | 6 -- src/lib/extensions/BushClient.ts | 169 ++++++++++++++++++++++++++++++++++++ src/lib/extensions/BushCommand.ts | 20 +++++ src/lib/extensions/BushInhibitor.ts | 6 ++ src/lib/extensions/BushListener.ts | 6 ++ src/lib/extensions/BushTask.ts | 6 ++ src/lib/extensions/Util.ts | 24 ++--- 11 files changed, 219 insertions(+), 219 deletions(-) delete mode 100644 src/lib/extensions/BotClient.ts delete mode 100644 src/lib/extensions/BotCommand.ts delete mode 100644 src/lib/extensions/BotInhibitor.ts delete mode 100644 src/lib/extensions/BotListener.ts delete mode 100644 src/lib/extensions/BotTask.ts create mode 100644 src/lib/extensions/BushClient.ts create mode 100644 src/lib/extensions/BushCommand.ts create mode 100644 src/lib/extensions/BushInhibitor.ts create mode 100644 src/lib/extensions/BushListener.ts create mode 100644 src/lib/extensions/BushTask.ts (limited to 'src/lib/extensions') diff --git a/src/lib/extensions/BotClient.ts b/src/lib/extensions/BotClient.ts deleted file mode 100644 index c98f50d..0000000 --- a/src/lib/extensions/BotClient.ts +++ /dev/null @@ -1,169 +0,0 @@ -import { - AkairoClient, - CommandHandler, - InhibitorHandler, - ListenerHandler, - TaskHandler -} from 'discord-akairo'; -import { Guild } from 'discord.js'; -import * as path from 'path'; -import { Sequelize } from 'sequelize'; -import * as Models from '../models'; -import { Util } from './Util'; -import { exit } from 'process'; -import { Intents } from 'discord.js'; -import * as config from '../../config/options'; -import { Logger } from '../utils/Logger'; -import chalk from 'chalk'; - -export type BotConfig = typeof config; - -export class BotClient extends AkairoClient { - public config: BotConfig; - public listenerHandler: ListenerHandler; - public inhibitorHandler: InhibitorHandler; - public commandHandler: CommandHandler; - public taskHandler: TaskHandler; - public util: Util; - public ownerID: string[]; - public db: Sequelize; - public logger: Logger; - constructor(config: BotConfig) { - super( - { - ownerID: config.owners, - intents: Intents.NON_PRIVILEGED - }, - { - allowedMentions: { parse: ['users'] }, // No everyone or role mentions by default - intents: Intents.NON_PRIVILEGED - } - ); - - // Set token - this.token = config.credentials.botToken; - - // Set config - this.config = config; - - // Create listener handler - this.listenerHandler = new ListenerHandler(this, { - directory: path.join(__dirname, '..', '..', 'listeners'), - automateCategories: true - }); - - // Create inhibitor handler - this.inhibitorHandler = new InhibitorHandler(this, { - directory: path.join(__dirname, '..', '..', 'inhibitors'), - automateCategories: true - }); - - // Create task handler - this.taskHandler = new TaskHandler(this, { - directory: path.join(__dirname, '..', '..', 'tasks') - }); - - // Create command handler - this.commandHandler = new CommandHandler(this, { - directory: path.join(__dirname, '..', '..', 'commands'), - prefix: async ({ guild }: { guild: Guild }) => { - const row = await Models.Guild.findByPk(guild.id); - if (!row) return this.config.prefix; - return row.prefix as string; - }, - allowMention: true, - handleEdits: true, - commandUtil: true, - commandUtilLifetime: 3e5, - argumentDefaults: { - prompt: { - timeout: 'Timed out.', - ended: 'Too many tries.', - cancel: 'Canceled.', - time: 3e4 - } - }, - ignorePermissions: this.config.owners, - ignoreCooldown: this.config.owners, - automateCategories: true - }); - - 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.logger = new Logger(this); - } - - // Initialize everything - private async _init(): Promise { - this.commandHandler.useListenerHandler(this.listenerHandler); - this.commandHandler.useInhibitorHandler(this.inhibitorHandler); - this.listenerHandler.setEmitters({ - commandHandler: this.commandHandler, - listenerHandler: this.listenerHandler, - process - }); - // loads all the handlers - const loaders = { - commands: this.commandHandler, - listeners: this.listenerHandler, - inhibitors: this.inhibitorHandler, - tasks: this.taskHandler - }; - for (const loader of Object.keys(loaders)) { - try { - 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 - ) - ); - } - } - this.taskHandler.startAll(); - await this.dbPreInit(); - } - - public async dbPreInit(): Promise { - await this.db.authenticate(); - Models.Guild.initModel(this.db, this); - Models.Modlog.initModel(this.db); - Models.Ban.initModel(this.db); - Models.Level.initModel(this.db); - try { - await this.db.sync(); // Sync all tables to fix everything if updated - } catch { - // Ignore error - } - } - - public async start(): Promise { - try { - await this._init(); - await this.login(this.token); - } catch (e) { - console.error(chalk.red(e.stack)); - exit(2); - } - } - - public destroy(relogin = true): void | Promise { - super.destroy(); - if (relogin) { - return this.login(this.token); - } - } -} diff --git a/src/lib/extensions/BotCommand.ts b/src/lib/extensions/BotCommand.ts deleted file mode 100644 index c5d31e9..0000000 --- a/src/lib/extensions/BotCommand.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Command, CommandOptions } from 'discord-akairo'; -import { APIApplicationCommandOption } from 'discord-api-types'; -import { BotClient } from './BotClient'; - -export interface BotCommandOptions extends CommandOptions { - slashCommandOptions?: APIApplicationCommandOption[]; - description: { - content: string; - usage: string; - examples: string[]; - }; -} - -export class BotCommand extends Command { - public client: BotClient; - constructor(id: string, options?: BotCommandOptions) { - super(id, options); - this.options = options; - } -} diff --git a/src/lib/extensions/BotInhibitor.ts b/src/lib/extensions/BotInhibitor.ts deleted file mode 100644 index 960aade..0000000 --- a/src/lib/extensions/BotInhibitor.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Inhibitor } from 'discord-akairo'; -import { BotClient } from './BotClient'; - -export class BotInhibitor extends Inhibitor { - public client: BotClient; -} diff --git a/src/lib/extensions/BotListener.ts b/src/lib/extensions/BotListener.ts deleted file mode 100644 index 9ec17b2..0000000 --- a/src/lib/extensions/BotListener.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Listener } from 'discord-akairo'; -import { BotClient } from './BotClient'; - -export class BotListener extends Listener { - public client: BotClient; -} diff --git a/src/lib/extensions/BotTask.ts b/src/lib/extensions/BotTask.ts deleted file mode 100644 index 4d5cdcd..0000000 --- a/src/lib/extensions/BotTask.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Task } from 'discord-akairo'; -import { BotClient } from './BotClient'; - -export class BotTask extends Task { - public client: BotClient; -} diff --git a/src/lib/extensions/BushClient.ts b/src/lib/extensions/BushClient.ts new file mode 100644 index 0000000..8a8ae91 --- /dev/null +++ b/src/lib/extensions/BushClient.ts @@ -0,0 +1,169 @@ +import { + AkairoClient, + CommandHandler, + InhibitorHandler, + ListenerHandler, + TaskHandler +} from 'discord-akairo'; +import { Guild } from 'discord.js'; +import * as path from 'path'; +import { Sequelize } from 'sequelize'; +import * as Models from '../models'; +import { Util } from './Util'; +import { exit } from 'process'; +import { Intents } from 'discord.js'; +import * as config from '../../config/options'; +import { Logger } from '../utils/Logger'; +import chalk from 'chalk'; + +export type BotConfig = typeof config; + +export class BushClient extends AkairoClient { + public config: BotConfig; + public listenerHandler: ListenerHandler; + public inhibitorHandler: InhibitorHandler; + public commandHandler: CommandHandler; + public taskHandler: TaskHandler; + public util: Util; + public ownerID: string[]; + public db: Sequelize; + public logger: Logger; + constructor(config: BotConfig) { + super( + { + ownerID: config.owners, + intents: Intents.NON_PRIVILEGED + }, + { + allowedMentions: { parse: ['users'] }, // No everyone or role mentions by default + intents: Intents.NON_PRIVILEGED + } + ); + + // Set token + this.token = config.credentials.botToken; + + // Set config + this.config = config; + + // Create listener handler + this.listenerHandler = new ListenerHandler(this, { + directory: path.join(__dirname, '..', '..', 'listeners'), + automateCategories: true + }); + + // Create inhibitor handler + this.inhibitorHandler = new InhibitorHandler(this, { + directory: path.join(__dirname, '..', '..', 'inhibitors'), + automateCategories: true + }); + + // Create task handler + this.taskHandler = new TaskHandler(this, { + directory: path.join(__dirname, '..', '..', 'tasks') + }); + + // Create command handler + this.commandHandler = new CommandHandler(this, { + directory: path.join(__dirname, '..', '..', 'commands'), + prefix: async ({ guild }: { guild: Guild }) => { + const row = await Models.Guild.findByPk(guild.id); + if (!row) return this.config.prefix; + return row.prefix as string; + }, + allowMention: true, + handleEdits: true, + commandUtil: true, + commandUtilLifetime: 3e5, + argumentDefaults: { + prompt: { + timeout: 'Timed out.', + ended: 'Too many tries.', + cancel: 'Canceled.', + time: 3e4 + } + }, + ignorePermissions: this.config.owners, + ignoreCooldown: this.config.owners, + automateCategories: true + }); + + 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.logger = new Logger(this); + } + + // Initialize everything + private async _init(): Promise { + this.commandHandler.useListenerHandler(this.listenerHandler); + this.commandHandler.useInhibitorHandler(this.inhibitorHandler); + this.listenerHandler.setEmitters({ + commandHandler: this.commandHandler, + listenerHandler: this.listenerHandler, + process + }); + // loads all the handlers + const loaders = { + commands: this.commandHandler, + listeners: this.listenerHandler, + inhibitors: this.inhibitorHandler, + tasks: this.taskHandler + }; + for (const loader of Object.keys(loaders)) { + try { + 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 + ) + ); + } + } + this.taskHandler.startAll(); + await this.dbPreInit(); + } + + public async dbPreInit(): Promise { + await this.db.authenticate(); + Models.Guild.initModel(this.db, this); + Models.Modlog.initModel(this.db); + Models.Ban.initModel(this.db); + Models.Level.initModel(this.db); + try { + await this.db.sync(); // Sync all tables to fix everything if updated + } catch { + // Ignore error + } + } + + public async start(): Promise { + try { + await this._init(); + await this.login(this.token); + } catch (e) { + console.error(chalk.red(e.stack)); + exit(2); + } + } + + public destroy(relogin = true): void | Promise { + super.destroy(); + if (relogin) { + return this.login(this.token); + } + } +} diff --git a/src/lib/extensions/BushCommand.ts b/src/lib/extensions/BushCommand.ts new file mode 100644 index 0000000..4f9dc6e --- /dev/null +++ b/src/lib/extensions/BushCommand.ts @@ -0,0 +1,20 @@ +import { Command, CommandOptions } from 'discord-akairo'; +import { APIApplicationCommandOption } from 'discord-api-types'; +import { BushClient } from './BushClient'; + +export interface BushCommandOptions extends CommandOptions { + slashCommandOptions?: APIApplicationCommandOption[]; + description: { + content: string; + usage: string; + examples: string[]; + }; +} + +export class BushCommand extends Command { + public client: BushClient; + constructor(id: string, options?: BushCommandOptions) { + super(id, options); + this.options = options; + } +} diff --git a/src/lib/extensions/BushInhibitor.ts b/src/lib/extensions/BushInhibitor.ts new file mode 100644 index 0000000..d9a9b68 --- /dev/null +++ b/src/lib/extensions/BushInhibitor.ts @@ -0,0 +1,6 @@ +import { Inhibitor } from 'discord-akairo'; +import { BushClient } from './BushClient'; + +export class BushInhibitor extends Inhibitor { + public client: BushClient; +} diff --git a/src/lib/extensions/BushListener.ts b/src/lib/extensions/BushListener.ts new file mode 100644 index 0000000..6a13210 --- /dev/null +++ b/src/lib/extensions/BushListener.ts @@ -0,0 +1,6 @@ +import { Listener } from 'discord-akairo'; +import { BushClient } from './BushClient'; + +export class BushListener extends Listener { + public client: BushClient; +} diff --git a/src/lib/extensions/BushTask.ts b/src/lib/extensions/BushTask.ts new file mode 100644 index 0000000..21655e9 --- /dev/null +++ b/src/lib/extensions/BushTask.ts @@ -0,0 +1,6 @@ +import { Task } from 'discord-akairo'; +import { BushClient } from './BushClient'; + +export class BushTask extends Task { + public client: BushClient; +} diff --git a/src/lib/extensions/Util.ts b/src/lib/extensions/Util.ts index 54df670..7c1d4b2 100644 --- a/src/lib/extensions/Util.ts +++ b/src/lib/extensions/Util.ts @@ -1,5 +1,5 @@ import { ClientUtil } from 'discord-akairo'; -import { BotClient } from './BotClient'; +import { BushClient } from './BushClient'; import { promisify } from 'util'; import { exec } from 'child_process'; import got from 'got'; @@ -57,9 +57,9 @@ export interface SlashCommandOption { export class Util extends ClientUtil { /** * The client of this ClientUtil - * @type {BotClient} + * @type {BushClient} */ - public client: BotClient; + public client: BushClient; /** * The hastebin urls used to post to hastebin, attempts to post in order * @type {string[]} @@ -83,7 +83,7 @@ export class Util extends ClientUtil { * Creates this client util * @param client The client to initialize with */ - constructor(client: BotClient) { + constructor(client: BushClient) { super(client); } @@ -273,14 +273,14 @@ export class Util extends ClientUtil { } } - for (const [, botCommand] of this.client.commandHandler.modules) { - if (botCommand.execSlash) { - const found = registered.find((i) => i.name == botCommand.id); + for (const [, BushCommand] of this.client.commandHandler.modules) { + if (BushCommand.execSlash) { + const found = registered.find((i) => i.name == BushCommand.id); const slashdata = { - name: botCommand.id, - description: botCommand.description.content, - options: botCommand.options.slashCommandOptions + name: BushCommand.id, + description: BushCommand.description.content, + options: BushCommand.options.slashCommandOptions }; if (found?.id && !force) { @@ -292,7 +292,7 @@ export class Util extends ClientUtil { ) : fetchedGuild.commands.edit(found.id, slashdata); this.client.logger.verbose( - chalk`{yellow Edited slash command ${botCommand.id}${ + chalk`{yellow Edited slash command ${BushCommand.id}${ guild !== undefined ? ` in guild ${fetchedGuild.name}` : '' }}` ); @@ -302,7 +302,7 @@ export class Util extends ClientUtil { ? await this.client.application.commands.create(slashdata) : fetchedGuild.commands.create(slashdata); this.client.logger.verbose( - chalk`{green Created slash command ${botCommand.id}${ + chalk`{green Created slash command ${BushCommand.id}${ guild !== undefined ? ` in guild ${fetchedGuild.name}` : '' }}` ); -- cgit From f1cdbd260c6c2249fc0d765949d44d889bcaedc8 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Fri, 28 May 2021 17:37:04 -0400 Subject: I can't read anything --- src/lib/extensions/BushClient.ts | 8 ++------ src/lib/extensions/Util.ts | 27 +++++++-------------------- 2 files changed, 9 insertions(+), 26 deletions(-) (limited to 'src/lib/extensions') diff --git a/src/lib/extensions/BushClient.ts b/src/lib/extensions/BushClient.ts index 8a8ae91..99d0dd3 100644 --- a/src/lib/extensions/BushClient.ts +++ b/src/lib/extensions/BushClient.ts @@ -122,14 +122,10 @@ export class BushClient extends AkairoClient { for (const loader of Object.keys(loaders)) { try { loaders[loader].loadAll(); - this.logger.log( - chalk.green('Successfully loaded ' + chalk.cyan(loader) + '.') - ); + 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 - ) + chalk.red('Unable to load loader ' + chalk.cyan(loader) + ' with error ' + e) ); } } diff --git a/src/lib/extensions/Util.ts b/src/lib/extensions/Util.ts index 7c1d4b2..7bedfc1 100644 --- a/src/lib/extensions/Util.ts +++ b/src/lib/extensions/Util.ts @@ -125,9 +125,7 @@ export class Util extends ClientUtil { public async haste(content: string): Promise { for (const url of this.hasteURLs) { try { - const res: hastebinRes = await got - .post(`${url}/documents`, { body: content }) - .json(); + const res: hastebinRes = await got.post(`${url}/documents`, { body: content }).json(); return `${url}/${res.key}`; } catch (e) { // pass @@ -220,10 +218,7 @@ export class Util extends ClientUtil { /** * A simple utility to create and embed with the needed style for the bot */ - public createEmbed( - color?: string, - author?: User | GuildMember - ): MessageEmbed { + public createEmbed(color?: string, author?: User | GuildMember): MessageEmbed { if (author instanceof GuildMember) { author = author.user; // Convert to User if GuildMember } @@ -255,15 +250,12 @@ export class Util extends ClientUtil { : await fetchedGuild.commands.fetch(); for (const [, registeredCommand] of registered) { if ( - !this.client.commandHandler.modules.find( - (cmd) => cmd.id == registeredCommand.name - )?.execSlash || + !this.client.commandHandler.modules.find((cmd) => cmd.id == registeredCommand.name) + ?.execSlash || force ) { guild === undefined - ? await this.client.application.commands.delete( - registeredCommand.id - ) + ? 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}${ @@ -286,10 +278,7 @@ 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 - ) + ? 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}${ @@ -312,9 +301,7 @@ export class Util extends ClientUtil { return this.client.logger.log( chalk.green( - `Slash commands registered${ - guild !== undefined ? ` in guild ${fetchedGuild.name}` : '' - }` + `Slash commands registered${guild !== undefined ? ` in guild ${fetchedGuild.name}` : ''}` ) ); } catch (e) { -- cgit From 25cf269e2e793de5fefb9aa3f19fb167168e06c6 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Fri, 28 May 2021 20:13:49 -0400 Subject: stuff --- src/lib/extensions/BushClient.ts | 29 +++++----------- src/lib/extensions/Util.ts | 71 ++++++++-------------------------------- 2 files changed, 21 insertions(+), 79 deletions(-) (limited to 'src/lib/extensions') 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 { - 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.}`); } } -- cgit