From da70ed6f4ad82c58adf7dc6120aa8b6b255238e9 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Sat, 17 Jul 2021 14:11:37 -0400 Subject: rewrote config for absolutly no reason :troll: --- src/lib/extensions/discord-akairo/BushClient.ts | 28 +++++++------ .../extensions/discord-akairo/BushClientUtil.ts | 3 +- src/lib/models/Global.ts | 6 +-- src/lib/utils/BushLogger.ts | 4 +- src/lib/utils/Config.ts | 49 ++++++++++++++++++++++ 5 files changed, 71 insertions(+), 19 deletions(-) create mode 100644 src/lib/utils/Config.ts (limited to 'src/lib') diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index 3b14200..b8e9d00 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -17,7 +17,6 @@ import readline from 'readline'; import { Sequelize } from 'sequelize'; import { contentWithDurationTypeCaster } from '../../../arguments/contentWithDuration'; import { durationTypeCaster } from '../../../arguments/duration'; -import * as config from '../../../config/options'; import { UpdateCacheTask } from '../../../tasks/updateCache'; import { Ban } from '../../models/Ban'; import { Global } from '../../models/Global'; @@ -31,6 +30,7 @@ import { AllowedMentions } from '../../utils/AllowedMentions'; import { BushCache } from '../../utils/BushCache'; import { BushConstants } from '../../utils/BushConstants'; import { BushLogger } from '../../utils/BushLogger'; +import { Config } from '../../utils/Config'; import { BushButtonInteraction } from '../discord.js/BushButtonInteraction'; import { BushCategoryChannel } from '../discord.js/BushCategoryChannel'; import { BushCommandInteraction } from '../discord.js/BushCommandInteraction'; @@ -57,7 +57,6 @@ import { BushInhibitorHandler } from './BushInhibitorHandler'; import { BushListenerHandler } from './BushListenerHandler'; import { BushTaskHandler } from './BushTaskHandler'; -export type BotConfig = typeof config; export type BushReplyMessageType = string | MessagePayload | ReplyMessageOptions; export type BushEditMessageType = string | MessageEditOptions | MessagePayload; export type BushSendMessageType = string | MessagePayload | MessageOptions; @@ -96,7 +95,7 @@ export class BushClient extends AkairoClient { Structures.extend('SelectMenuInteraction', () => BushSelectMenuInteraction); } - public config: BotConfig; + public config: Config; public listenerHandler: BushListenerHandler; public inhibitorHandler: BushInhibitorHandler; public commandHandler: BushCommandHandler; @@ -107,7 +106,7 @@ export class BushClient extends AkairoClient { public logger: BushLogger; public constants = BushConstants; public cache = BushCache; - public constructor(config: BotConfig) { + public constructor(config: Config) { super( { ownerID: config.owners, @@ -164,9 +163,9 @@ export class BushClient extends AkairoClient { this.commandHandler = new BushCommandHandler(this, { directory: path.join(__dirname, '..', '..', '..', 'commands'), prefix: async ({ guild }: { guild: Guild }) => { - if (this.config.dev) return 'dev '; + if (this.config.isDevelopment) return 'dev '; const row = await GuildModel.findByPk(guild.id); - return (row?.prefix || this.config.prefix) as string; + return (row?.prefix || this.config.isBeta ? 'bush ' : this.config.prefix) as string; }, allowMention: true, handleEdits: true, @@ -193,12 +192,17 @@ export class BushClient extends AkairoClient { }); this.util = new BushClientUtil(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: this.config.logging.db ? (sql) => this.logger.debug(sql) : false - }); + this.db = new Sequelize( + this.config.isDevelopment ? 'bushbot-dev' : 'bushbot', + this.config.db.username, + this.config.db.password, + { + dialect: 'postgres', + host: this.config.db.host, + port: this.config.db.port, + logging: this.config.logging.db ? (sql) => this.logger.debug(sql) : false + } + ); this.logger = new BushLogger(this); } diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index 6a08c54..46e81df 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -527,8 +527,7 @@ export class BushClientUtil extends ClientUtil { key: keyof typeof BushCache['global'], value: any ): Promise { - const environment = this.client.config.dev ? 'development' : 'production'; - const row = await Global.findByPk(environment); + const row = await Global.findByPk(this.client.config.environment); const oldValue: any[] = row[key]; const newValue = this.addOrRemoveFromArray(action, oldValue, value); row[key] = newValue; diff --git a/src/lib/models/Global.ts b/src/lib/models/Global.ts index 8664365..08392c5 100644 --- a/src/lib/models/Global.ts +++ b/src/lib/models/Global.ts @@ -3,7 +3,7 @@ import { DataTypes, Sequelize } from 'sequelize'; import { BaseModel } from './BaseModel'; export interface GlobalModel { - environment: 'production' | 'development'; + environment: 'production' | 'development'|'beta'; superUsers: Snowflake[]; disabledCommands: string[]; blacklistedUsers: Snowflake[]; @@ -12,7 +12,7 @@ export interface GlobalModel { } export interface GlobalModelCreationAttributes { - environment: 'production' | 'development'; + environment: 'production' | 'development'|'beta'; superUsers?: Snowflake[]; disabledCommands?: string[]; blacklistedUsers?: Snowflake[]; @@ -24,7 +24,7 @@ export class Global extends BaseModel