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') 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 ++--- src/lib/models/Guild.ts | 4 +- src/lib/utils/Logger.ts | 6 +- 13 files changed, 224 insertions(+), 224 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') 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}` : '' }}` ); diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts index 1cb3abb..c224bf5 100644 --- a/src/lib/models/Guild.ts +++ b/src/lib/models/Guild.ts @@ -1,5 +1,5 @@ import { DataTypes, Optional, Sequelize } from 'sequelize'; -import { BotClient } from '../extensions/BotClient'; +import { BushClient } from '../extensions/BushClient'; import { BaseModel } from './BaseModel'; export interface GuildModel { @@ -14,7 +14,7 @@ export class Guild { id: string; prefix: string; - static initModel(seqeulize: Sequelize, client: BotClient): void { + static initModel(seqeulize: Sequelize, client: BushClient): void { Guild.init( { id: { diff --git a/src/lib/utils/Logger.ts b/src/lib/utils/Logger.ts index f38365e..604b45e 100644 --- a/src/lib/utils/Logger.ts +++ b/src/lib/utils/Logger.ts @@ -1,10 +1,10 @@ import { TextChannel } from 'discord.js'; -import { BotClient } from '../extensions/BotClient'; +import { BushClient } from '../extensions/BushClient'; import chalk from 'chalk'; export class Logger { - private client: BotClient; - public constructor(client: BotClient) { + private client: BushClient; + public constructor(client: BushClient) { this.client = client; } private stripColor(text: string): string { -- 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 +++++++-------------------- src/lib/models/Ban.ts | 5 +---- src/lib/models/Modlog.ts | 9 +-------- src/lib/utils/Logger.ts | 4 +--- 5 files changed, 12 insertions(+), 41 deletions(-) (limited to 'src/lib') 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) { diff --git a/src/lib/models/Ban.ts b/src/lib/models/Ban.ts index 3ce9c06..75e38ab 100644 --- a/src/lib/models/Ban.ts +++ b/src/lib/models/Ban.ts @@ -20,10 +20,7 @@ export interface BanModelCreationAttributes { modlog: string; } -export class Ban - extends BaseModel - implements BanModel -{ +export class Ban extends BaseModel implements BanModel { /** * The ID of this ban (no real use just for a primary key) */ diff --git a/src/lib/models/Modlog.ts b/src/lib/models/Modlog.ts index 7efeeed..52a13b2 100644 --- a/src/lib/models/Modlog.ts +++ b/src/lib/models/Modlog.ts @@ -54,14 +54,7 @@ export class Modlog defaultValue: uuidv4 }, type: { - type: new DataTypes.ENUM( - 'BAN', - 'TEMPBAN', - 'MUTE', - 'TEMPMUTE', - 'KICK', - 'WARN' - ), + type: new DataTypes.ENUM('BAN', 'TEMPBAN', 'MUTE', 'TEMPMUTE', 'KICK', 'WARN'), allowNull: false }, user: { diff --git a/src/lib/utils/Logger.ts b/src/lib/utils/Logger.ts index 604b45e..b0f7da5 100644 --- a/src/lib/utils/Logger.ts +++ b/src/lib/utils/Logger.ts @@ -15,9 +15,7 @@ export class Logger { ); } public getChannel(channel: 'log' | 'error' | 'dm'): Promise { - return this.client.channels.fetch( - this.client.config.channels[channel] - ) as Promise; + return this.client.channels.fetch(this.client.config.channels[channel]) as Promise; } public async log(message: string, sendChannel = false): Promise { console.log(chalk`{bgCyan LOG} ` + message); -- 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 ++++++------------------------ src/lib/models/Guild.ts | 5 +-- src/lib/models/Modlog.ts | 5 +-- src/lib/utils/AllowedMentions.ts | 6 +-- src/lib/utils/Console.ts | 94 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 118 insertions(+), 92 deletions(-) create mode 100644 src/lib/utils/Console.ts (limited to 'src/lib') 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.}`); } } diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts index c224bf5..7902461 100644 --- a/src/lib/models/Guild.ts +++ b/src/lib/models/Guild.ts @@ -8,10 +8,7 @@ export interface GuildModel { } export type GuildModelCreationAttributes = Optional; -export class Guild - extends BaseModel - implements GuildModel -{ +export class Guild extends BaseModel implements GuildModel { id: string; prefix: string; static initModel(seqeulize: Sequelize, client: BushClient): void { diff --git a/src/lib/models/Modlog.ts b/src/lib/models/Modlog.ts index 52a13b2..2b2050a 100644 --- a/src/lib/models/Modlog.ts +++ b/src/lib/models/Modlog.ts @@ -32,10 +32,7 @@ export interface ModlogModelCreationAttributes { guild: string; } -export class Modlog - extends BaseModel - implements ModlogModel -{ +export class Modlog extends BaseModel implements ModlogModel { id: string; type: ModlogType; user: string; diff --git a/src/lib/utils/AllowedMentions.ts b/src/lib/utils/AllowedMentions.ts index 47e440b..68c44d7 100644 --- a/src/lib/utils/AllowedMentions.ts +++ b/src/lib/utils/AllowedMentions.ts @@ -34,11 +34,7 @@ export default class AllowedMentions { } public toObject(): MessageMentionOptions { return { - parse: [ - ...(this.users ? ['users'] : []), - ...(this.roles ? ['roles'] : []), - ...(this.everyone ? ['everyone'] : []) - ] as MessageMentionTypes[] + parse: [...(this.users ? ['users'] : []), ...(this.roles ? ['roles'] : []), ...(this.everyone ? ['everyone'] : [])] as MessageMentionTypes[] }; } } diff --git a/src/lib/utils/Console.ts b/src/lib/utils/Console.ts new file mode 100644 index 0000000..36c078c --- /dev/null +++ b/src/lib/utils/Console.ts @@ -0,0 +1,94 @@ +import chalk from 'chalk'; +import { BushClient } from '../extensions/BushClient'; + +export class CustomConsole { + private client: BushClient; + public constructor(client: BushClient) { + this.client = client; + } + + private parseColors(content: any, color: 'blueBright' | 'blackBright' | 'redBright' | 'yellowBright' | 'greenBright'): string|any { + if (typeof content === 'string') { + const newContent: Array = content.split(/<<|>>/); + const tempParsedArray: Array = []; + newContent.forEach((value, index) => { + if (index % 2 !== 0) { + tempParsedArray.push(chalk[color](value)); + } else { + tempParsedArray.push(value); + } + }); + return tempParsedArray.join(''); + } else { + return content + } + + } + + private timeStamp(): string { + const now = new Date(); + const hours = now.getHours(); + const minute = now.getMinutes(); + let hour = hours; + let amOrPm: 'AM' | 'PM' = 'AM'; + if (hour > 12) { + amOrPm = 'PM'; + hour = hour - 12; + } + + return `${hour >= 10 ? hour : `0${hour}`}:${minute >= 10 ? minute : `0${minute}`} ${amOrPm}`; + } + + /** + * Logs debug information. + * @param content - The content to log. + */ + public debug(content: any): void { + console.log(`${chalk.bgGrey(this.timeStamp())} ${chalk.grey('[Debug]')}`, content); + } + + /** + * Logs verbose information. Highlight information by surrounding it in `<<>>`. + * @param header - The header displayed before the content, displayed in grey. + * @param content - The content to log, highlights displayed in bright black. + */ + public verbose(header: string, content: string): void { + return console.info(`${chalk.bgGrey(this.timeStamp())} ${chalk.grey(`[${header}]`)} `+this.parseColors(content, 'blackBright')); + } + + /** + * Logs information. Highlight information by surrounding it in `<<>>`. + * @param header - The header displayed before the content, displayed in cyan. + * @param content - The content to log, highlights displayed in bright blue. + */ + public info(header: string, content: string): void { + return console.info(`${chalk.bgCyan(this.timeStamp())} ${chalk.cyan(`[${header}]`)} `+this.parseColors(content, 'blueBright')); + } + + /** + * Logs warnings. Highlight information by surrounding it in `<<>>`. + * @param header - The header displayed before the content, displayed in yellow. + * @param content - The content to log, highlights displayed in bright yellow. + */ + public warn(header: string, content: string): void { + return console.warn(`${chalk.bgYellow(this.timeStamp())} ${chalk.yellow(`[${header}]`)} `+this.parseColors(content, 'yellowBright')); + } + + /** + * Logs errors. Highlight information by surrounding it in `<<>>`. + * @param header - The header displayed before the content, displayed in bright red. + * @param content - The content to log, highlights displayed in bright red. + */ + public error(header: string, content: string): void { + return console.error(`${chalk.bgRedBright(this.timeStamp())} ${chalk.redBright(`[${header}]`)} `+ this.parseColors(content, 'redBright')); + } + + /** + * Logs successes. Highlight information by surrounding it in `<<>>`. + * @param header - The header displayed before the content, displayed in green. + * @param content - The content to log, highlights displayed in bright green. + */ + public success(header: string, content: string): void { + return console.log(`${chalk.bgGreen(this.timeStamp())} ${chalk.greenBright(`[${header}]`)} `+this.parseColors(content, 'greenBright')); + } +} -- cgit From fbce619ff39521bdd30ab6598c83d0c94e5ae6b8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 29 May 2021 00:14:24 +0000 Subject: Automatically format code --- src/lib/utils/Console.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/lib') diff --git a/src/lib/utils/Console.ts b/src/lib/utils/Console.ts index 36c078c..5b61094 100644 --- a/src/lib/utils/Console.ts +++ b/src/lib/utils/Console.ts @@ -7,7 +7,7 @@ export class CustomConsole { this.client = client; } - private parseColors(content: any, color: 'blueBright' | 'blackBright' | 'redBright' | 'yellowBright' | 'greenBright'): string|any { + private parseColors(content: any, color: 'blueBright' | 'blackBright' | 'redBright' | 'yellowBright' | 'greenBright'): string | any { if (typeof content === 'string') { const newContent: Array = content.split(/<<|>>/); const tempParsedArray: Array = []; @@ -20,9 +20,8 @@ export class CustomConsole { }); return tempParsedArray.join(''); } else { - return content + return content; } - } private timeStamp(): string { @@ -53,7 +52,7 @@ export class CustomConsole { * @param content - The content to log, highlights displayed in bright black. */ public verbose(header: string, content: string): void { - return console.info(`${chalk.bgGrey(this.timeStamp())} ${chalk.grey(`[${header}]`)} `+this.parseColors(content, 'blackBright')); + return console.info(`${chalk.bgGrey(this.timeStamp())} ${chalk.grey(`[${header}]`)} ` + this.parseColors(content, 'blackBright')); } /** @@ -62,7 +61,7 @@ export class CustomConsole { * @param content - The content to log, highlights displayed in bright blue. */ public info(header: string, content: string): void { - return console.info(`${chalk.bgCyan(this.timeStamp())} ${chalk.cyan(`[${header}]`)} `+this.parseColors(content, 'blueBright')); + return console.info(`${chalk.bgCyan(this.timeStamp())} ${chalk.cyan(`[${header}]`)} ` + this.parseColors(content, 'blueBright')); } /** @@ -71,7 +70,7 @@ export class CustomConsole { * @param content - The content to log, highlights displayed in bright yellow. */ public warn(header: string, content: string): void { - return console.warn(`${chalk.bgYellow(this.timeStamp())} ${chalk.yellow(`[${header}]`)} `+this.parseColors(content, 'yellowBright')); + return console.warn(`${chalk.bgYellow(this.timeStamp())} ${chalk.yellow(`[${header}]`)} ` + this.parseColors(content, 'yellowBright')); } /** @@ -80,7 +79,7 @@ export class CustomConsole { * @param content - The content to log, highlights displayed in bright red. */ public error(header: string, content: string): void { - return console.error(`${chalk.bgRedBright(this.timeStamp())} ${chalk.redBright(`[${header}]`)} `+ this.parseColors(content, 'redBright')); + return console.error(`${chalk.bgRedBright(this.timeStamp())} ${chalk.redBright(`[${header}]`)} ` + this.parseColors(content, 'redBright')); } /** @@ -89,6 +88,6 @@ export class CustomConsole { * @param content - The content to log, highlights displayed in bright green. */ public success(header: string, content: string): void { - return console.log(`${chalk.bgGreen(this.timeStamp())} ${chalk.greenBright(`[${header}]`)} `+this.parseColors(content, 'greenBright')); + return console.log(`${chalk.bgGreen(this.timeStamp())} ${chalk.greenBright(`[${header}]`)} ` + this.parseColors(content, 'greenBright')); } } -- cgit From a57f343e92c4f13b26e4c5b79541547d816e7264 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Fri, 28 May 2021 20:15:45 -0400 Subject: commet out, not finished yet --- src/lib/utils/Logger.ts | 82 ++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) (limited to 'src/lib') diff --git a/src/lib/utils/Logger.ts b/src/lib/utils/Logger.ts index b0f7da5..95f32ad 100644 --- a/src/lib/utils/Logger.ts +++ b/src/lib/utils/Logger.ts @@ -1,43 +1,43 @@ -import { TextChannel } from 'discord.js'; -import { BushClient } from '../extensions/BushClient'; -import chalk from 'chalk'; +// import { TextChannel } from 'discord.js'; +// import { BushClient } from '../extensions/BushClient'; +// import chalk from 'chalk'; -export class Logger { - private client: BushClient; - public constructor(client: BushClient) { - this.client = client; - } - private stripColor(text: string): string { - return text.replace( - // eslint-disable-next-line no-control-regex - /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, - '' - ); - } - public getChannel(channel: 'log' | 'error' | 'dm'): Promise { - return this.client.channels.fetch(this.client.config.channels[channel]) as Promise; - } - public async log(message: string, sendChannel = false): Promise { - console.log(chalk`{bgCyan LOG} ` + message); - if (sendChannel) { - const channel = await this.getChannel('log'); - await channel.send('[LOG] ' + this.stripColor(message)); - } - } +// export class Logger { +// private client: BushClient; +// public constructor(client: BushClient) { +// this.client = client; +// } +// private stripColor(text: string): string { +// return text.replace( +// // eslint-disable-next-line no-control-regex +// /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, +// '' +// ); +// } +// public getChannel(channel: 'log' | 'error' | 'dm'): Promise { +// return this.client.channels.fetch(this.client.config.channels[channel]) as Promise; +// } +// public async log(message: string, sendChannel = false): Promise { +// console.log(chalk`{bgCyan LOG} ` + message); +// if (sendChannel) { +// const channel = await this.getChannel('log'); +// await channel.send('[LOG] ' + this.stripColor(message)); +// } +// } - public async verbose(message: string, sendChannel = false): Promise { - if (!this.client.config.verbose) return; - console.log(chalk`{bgMagenta VERBOSE} ` + message); - if (sendChannel) { - const channel = await this.getChannel('log'); - await channel.send('[VERBOSE] ' + this.stripColor(message)); - } - } - public async error(message: string, sendChannel = false): Promise { - console.log(chalk`{bgRed ERROR} ` + message); - if (sendChannel) { - const channel = await this.getChannel('error'); - await channel.send('[ERROR] ' + this.stripColor(message)); - } - } -} +// public async verbose(message: string, sendChannel = false): Promise { +// if (!this.client.config.verbose) return; +// console.log(chalk`{bgMagenta VERBOSE} ` + message); +// if (sendChannel) { +// const channel = await this.getChannel('log'); +// await channel.send('[VERBOSE] ' + this.stripColor(message)); +// } +// } +// public async error(message: string, sendChannel = false): Promise { +// console.log(chalk`{bgRed ERROR} ` + message); +// if (sendChannel) { +// const channel = await this.getChannel('error'); +// await channel.send('[ERROR] ' + this.stripColor(message)); +// } +// } +// } -- cgit From 6bb93ad27fbc39dc8cf6c8adb5e88e7c39e6c788 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Fri, 28 May 2021 20:17:31 -0400 Subject: I am dumb --- src/lib/utils/Console.ts | 166 +++++++++++++++++++++++------------------------ src/lib/utils/Logger.ts | 82 +++++++++++------------ 2 files changed, 124 insertions(+), 124 deletions(-) (limited to 'src/lib') diff --git a/src/lib/utils/Console.ts b/src/lib/utils/Console.ts index 5b61094..b74ea07 100644 --- a/src/lib/utils/Console.ts +++ b/src/lib/utils/Console.ts @@ -1,93 +1,93 @@ -import chalk from 'chalk'; -import { BushClient } from '../extensions/BushClient'; +// import chalk from 'chalk'; +// import { BushClient } from '../extensions/BushClient'; -export class CustomConsole { - private client: BushClient; - public constructor(client: BushClient) { - this.client = client; - } +// export class CustomConsole { +// private client: BushClient; +// public constructor(client: BushClient) { +// this.client = client; +// } - private parseColors(content: any, color: 'blueBright' | 'blackBright' | 'redBright' | 'yellowBright' | 'greenBright'): string | any { - if (typeof content === 'string') { - const newContent: Array = content.split(/<<|>>/); - const tempParsedArray: Array = []; - newContent.forEach((value, index) => { - if (index % 2 !== 0) { - tempParsedArray.push(chalk[color](value)); - } else { - tempParsedArray.push(value); - } - }); - return tempParsedArray.join(''); - } else { - return content; - } - } +// private parseColors(content: any, color: 'blueBright' | 'blackBright' | 'redBright' | 'yellowBright' | 'greenBright'): string | any { +// if (typeof content === 'string') { +// const newContent: Array = content.split(/<<|>>/); +// const tempParsedArray: Array = []; +// newContent.forEach((value, index) => { +// if (index % 2 !== 0) { +// tempParsedArray.push(chalk[color](value)); +// } else { +// tempParsedArray.push(value); +// } +// }); +// return tempParsedArray.join(''); +// } else { +// return content; +// } +// } - private timeStamp(): string { - const now = new Date(); - const hours = now.getHours(); - const minute = now.getMinutes(); - let hour = hours; - let amOrPm: 'AM' | 'PM' = 'AM'; - if (hour > 12) { - amOrPm = 'PM'; - hour = hour - 12; - } +// private timeStamp(): string { +// const now = new Date(); +// const hours = now.getHours(); +// const minute = now.getMinutes(); +// let hour = hours; +// let amOrPm: 'AM' | 'PM' = 'AM'; +// if (hour > 12) { +// amOrPm = 'PM'; +// hour = hour - 12; +// } - return `${hour >= 10 ? hour : `0${hour}`}:${minute >= 10 ? minute : `0${minute}`} ${amOrPm}`; - } +// return `${hour >= 10 ? hour : `0${hour}`}:${minute >= 10 ? minute : `0${minute}`} ${amOrPm}`; +// } - /** - * Logs debug information. - * @param content - The content to log. - */ - public debug(content: any): void { - console.log(`${chalk.bgGrey(this.timeStamp())} ${chalk.grey('[Debug]')}`, content); - } +// /** +// * Logs debug information. +// * @param content - The content to log. +// */ +// public debug(content: any): void { +// console.log(`${chalk.bgGrey(this.timeStamp())} ${chalk.grey('[Debug]')}`, content); +// } - /** - * Logs verbose information. Highlight information by surrounding it in `<<>>`. - * @param header - The header displayed before the content, displayed in grey. - * @param content - The content to log, highlights displayed in bright black. - */ - public verbose(header: string, content: string): void { - return console.info(`${chalk.bgGrey(this.timeStamp())} ${chalk.grey(`[${header}]`)} ` + this.parseColors(content, 'blackBright')); - } +// /** +// * Logs verbose information. Highlight information by surrounding it in `<<>>`. +// * @param header - The header displayed before the content, displayed in grey. +// * @param content - The content to log, highlights displayed in bright black. +// */ +// public verbose(header: string, content: string): void { +// return console.info(`${chalk.bgGrey(this.timeStamp())} ${chalk.grey(`[${header}]`)} ` + this.parseColors(content, 'blackBright')); +// } - /** - * Logs information. Highlight information by surrounding it in `<<>>`. - * @param header - The header displayed before the content, displayed in cyan. - * @param content - The content to log, highlights displayed in bright blue. - */ - public info(header: string, content: string): void { - return console.info(`${chalk.bgCyan(this.timeStamp())} ${chalk.cyan(`[${header}]`)} ` + this.parseColors(content, 'blueBright')); - } +// /** +// * Logs information. Highlight information by surrounding it in `<<>>`. +// * @param header - The header displayed before the content, displayed in cyan. +// * @param content - The content to log, highlights displayed in bright blue. +// */ +// public info(header: string, content: string): void { +// return console.info(`${chalk.bgCyan(this.timeStamp())} ${chalk.cyan(`[${header}]`)} ` + this.parseColors(content, 'blueBright')); +// } - /** - * Logs warnings. Highlight information by surrounding it in `<<>>`. - * @param header - The header displayed before the content, displayed in yellow. - * @param content - The content to log, highlights displayed in bright yellow. - */ - public warn(header: string, content: string): void { - return console.warn(`${chalk.bgYellow(this.timeStamp())} ${chalk.yellow(`[${header}]`)} ` + this.parseColors(content, 'yellowBright')); - } +// /** +// * Logs warnings. Highlight information by surrounding it in `<<>>`. +// * @param header - The header displayed before the content, displayed in yellow. +// * @param content - The content to log, highlights displayed in bright yellow. +// */ +// public warn(header: string, content: string): void { +// return console.warn(`${chalk.bgYellow(this.timeStamp())} ${chalk.yellow(`[${header}]`)} ` + this.parseColors(content, 'yellowBright')); +// } - /** - * Logs errors. Highlight information by surrounding it in `<<>>`. - * @param header - The header displayed before the content, displayed in bright red. - * @param content - The content to log, highlights displayed in bright red. - */ - public error(header: string, content: string): void { - return console.error(`${chalk.bgRedBright(this.timeStamp())} ${chalk.redBright(`[${header}]`)} ` + this.parseColors(content, 'redBright')); - } +// /** +// * Logs errors. Highlight information by surrounding it in `<<>>`. +// * @param header - The header displayed before the content, displayed in bright red. +// * @param content - The content to log, highlights displayed in bright red. +// */ +// public error(header: string, content: string): void { +// return console.error(`${chalk.bgRedBright(this.timeStamp())} ${chalk.redBright(`[${header}]`)} ` + this.parseColors(content, 'redBright')); +// } - /** - * Logs successes. Highlight information by surrounding it in `<<>>`. - * @param header - The header displayed before the content, displayed in green. - * @param content - The content to log, highlights displayed in bright green. - */ - public success(header: string, content: string): void { - return console.log(`${chalk.bgGreen(this.timeStamp())} ${chalk.greenBright(`[${header}]`)} ` + this.parseColors(content, 'greenBright')); - } -} +// /** +// * Logs successes. Highlight information by surrounding it in `<<>>`. +// * @param header - The header displayed before the content, displayed in green. +// * @param content - The content to log, highlights displayed in bright green. +// */ +// public success(header: string, content: string): void { +// return console.log(`${chalk.bgGreen(this.timeStamp())} ${chalk.greenBright(`[${header}]`)} ` + this.parseColors(content, 'greenBright')); +// } +// } diff --git a/src/lib/utils/Logger.ts b/src/lib/utils/Logger.ts index 95f32ad..b0f7da5 100644 --- a/src/lib/utils/Logger.ts +++ b/src/lib/utils/Logger.ts @@ -1,43 +1,43 @@ -// import { TextChannel } from 'discord.js'; -// import { BushClient } from '../extensions/BushClient'; -// import chalk from 'chalk'; +import { TextChannel } from 'discord.js'; +import { BushClient } from '../extensions/BushClient'; +import chalk from 'chalk'; -// export class Logger { -// private client: BushClient; -// public constructor(client: BushClient) { -// this.client = client; -// } -// private stripColor(text: string): string { -// return text.replace( -// // eslint-disable-next-line no-control-regex -// /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, -// '' -// ); -// } -// public getChannel(channel: 'log' | 'error' | 'dm'): Promise { -// return this.client.channels.fetch(this.client.config.channels[channel]) as Promise; -// } -// public async log(message: string, sendChannel = false): Promise { -// console.log(chalk`{bgCyan LOG} ` + message); -// if (sendChannel) { -// const channel = await this.getChannel('log'); -// await channel.send('[LOG] ' + this.stripColor(message)); -// } -// } +export class Logger { + private client: BushClient; + public constructor(client: BushClient) { + this.client = client; + } + private stripColor(text: string): string { + return text.replace( + // eslint-disable-next-line no-control-regex + /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, + '' + ); + } + public getChannel(channel: 'log' | 'error' | 'dm'): Promise { + return this.client.channels.fetch(this.client.config.channels[channel]) as Promise; + } + public async log(message: string, sendChannel = false): Promise { + console.log(chalk`{bgCyan LOG} ` + message); + if (sendChannel) { + const channel = await this.getChannel('log'); + await channel.send('[LOG] ' + this.stripColor(message)); + } + } -// public async verbose(message: string, sendChannel = false): Promise { -// if (!this.client.config.verbose) return; -// console.log(chalk`{bgMagenta VERBOSE} ` + message); -// if (sendChannel) { -// const channel = await this.getChannel('log'); -// await channel.send('[VERBOSE] ' + this.stripColor(message)); -// } -// } -// public async error(message: string, sendChannel = false): Promise { -// console.log(chalk`{bgRed ERROR} ` + message); -// if (sendChannel) { -// const channel = await this.getChannel('error'); -// await channel.send('[ERROR] ' + this.stripColor(message)); -// } -// } -// } + public async verbose(message: string, sendChannel = false): Promise { + if (!this.client.config.verbose) return; + console.log(chalk`{bgMagenta VERBOSE} ` + message); + if (sendChannel) { + const channel = await this.getChannel('log'); + await channel.send('[VERBOSE] ' + this.stripColor(message)); + } + } + public async error(message: string, sendChannel = false): Promise { + console.log(chalk`{bgRed ERROR} ` + message); + if (sendChannel) { + const channel = await this.getChannel('error'); + await channel.send('[ERROR] ' + this.stripColor(message)); + } + } +} -- cgit From 5b5f0bf5667b922037508dfa88e40a1f8a2671ec Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Fri, 28 May 2021 20:20:07 -0400 Subject: bruh --- src/lib/utils/Logger.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/utils/Logger.ts b/src/lib/utils/Logger.ts index b0f7da5..96837b6 100644 --- a/src/lib/utils/Logger.ts +++ b/src/lib/utils/Logger.ts @@ -26,7 +26,7 @@ export class Logger { } public async verbose(message: string, sendChannel = false): Promise { - if (!this.client.config.verbose) return; + if (!this.client.config.logging.verbose) return; console.log(chalk`{bgMagenta VERBOSE} ` + message); if (sendChannel) { const channel = await this.getChannel('log'); -- cgit