aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/extensions/discord-akairo/BushClient.ts28
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts3
-rw-r--r--src/lib/models/Global.ts6
-rw-r--r--src/lib/utils/BushLogger.ts4
-rw-r--r--src/lib/utils/Config.ts49
5 files changed, 71 insertions, 19 deletions
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<Global | void> {
- 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<GlobalModel, GlobalModelCreationAttributes
/**
* The bot's environment.
*/
- environment: 'production' | 'development';
+ environment: 'production' | 'development'|'beta';
/**
* Trusted users.
*/
diff --git a/src/lib/utils/BushLogger.ts b/src/lib/utils/BushLogger.ts
index 915d8f1..98c3c04 100644
--- a/src/lib/utils/BushLogger.ts
+++ b/src/lib/utils/BushLogger.ts
@@ -86,7 +86,7 @@ export class BushLogger {
* @param depth - The depth the content will inspected. Defaults to 0.
*/
public debug(content: any, depth = 0): void {
- if (!this.client.config.dev) return;
+ if (!this.client.config.isDevelopment) return;
const newContent = this.inspectContent(content, depth, true);
console.log(`${chalk.bgMagenta(this.getTimeStamp())} ${chalk.magenta('[Debug]')}`, newContent);
}
@@ -96,7 +96,7 @@ export class BushLogger {
* @param content - The content to log.
*/
public debugRaw(...content: any): void {
- if (!this.client.config.dev) return;
+ if (!this.client.config.isDevelopment) return;
console.log(`${chalk.bgMagenta(this.getTimeStamp())} ${chalk.magenta('[Debug]')}`, ...content);
}
diff --git a/src/lib/utils/Config.ts b/src/lib/utils/Config.ts
new file mode 100644
index 0000000..d6b5802
--- /dev/null
+++ b/src/lib/utils/Config.ts
@@ -0,0 +1,49 @@
+import { Snowflake } from 'discord.js';
+
+export interface ConfigOptions {
+ credentials: { token: string; betaToken: string; devToken: string; hypixelApiKey: string };
+ environment: 'production' | 'beta' | 'development';
+ owners: Snowflake[];
+ prefix: string;
+ channels: { log: Snowflake; error: Snowflake; dm: Snowflake };
+ db: { host: string; port: number; username: string; password: string };
+ logging: { db: boolean; verbose: boolean; info: boolean };
+}
+
+export class Config {
+ public credentials: { token: string; betaToken: string; devToken: string; hypixelApiKey: string };
+ public environment: 'production' | 'beta' | 'development';
+ public owners: Snowflake[];
+ public prefix: string;
+ public channels: { log: Snowflake; error: Snowflake; dm: Snowflake };
+ public db: { host: string; port: number; username: string; password: string };
+ public logging: { db: boolean; verbose: boolean; info: boolean };
+
+ public constructor(options: ConfigOptions) {
+ this.credentials = options.credentials;
+ this.environment = options.environment;
+ this.owners = options.owners;
+ this.prefix = options.prefix;
+ this.channels = options.channels;
+ this.db = options.db;
+ this.logging = options.logging;
+ }
+
+ public get token(): string {
+ return this.environment === 'production'
+ ? this.credentials.token
+ : this.environment === 'beta'
+ ? this.credentials.betaToken
+ : this.credentials.devToken;
+ }
+
+ public get isProduction(): boolean {
+ return this.environment === 'production';
+ }
+ public get isBeta(): boolean {
+ return this.environment === 'beta';
+ }
+ public get isDevelopment(): boolean {
+ return this.environment === 'development';
+ }
+}