aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/extensions')
-rw-r--r--src/lib/extensions/BushClient.ts3
-rw-r--r--src/lib/extensions/BushClientUtil.ts20
-rw-r--r--src/lib/extensions/BushCommand.ts4
-rw-r--r--src/lib/extensions/BushInteractionMessage.ts2
4 files changed, 24 insertions, 5 deletions
diff --git a/src/lib/extensions/BushClient.ts b/src/lib/extensions/BushClient.ts
index ad22cfe..d0758d4 100644
--- a/src/lib/extensions/BushClient.ts
+++ b/src/lib/extensions/BushClient.ts
@@ -36,6 +36,7 @@ export class BushClient extends AkairoClient {
public db: Sequelize;
public logger: BushLogger;
public constants = BushConstants;
+ public cache = BushCache;
constructor(config: BotConfig) {
super(
{
@@ -164,7 +165,7 @@ export class BushClient extends AkairoClient {
Models.Ban.initModel(this.db);
Models.Level.initModel(this.db);
Models.StickyRole.initModel(this.db);
- await this.db.sync(); // Sync all tables to fix everything if updated
+ await this.db.sync({ alter: true }); // Sync all tables to fix everything if updated
this.console.success('Startup', `Successfully connected to <<database>>.`, false);
} catch (error) {
this.console.error('Startup', `Failed to connect to <<database>> with error:\n` + error?.stack, false);
diff --git a/src/lib/extensions/BushClientUtil.ts b/src/lib/extensions/BushClientUtil.ts
index 6687cb0..4d428ee 100644
--- a/src/lib/extensions/BushClientUtil.ts
+++ b/src/lib/extensions/BushClientUtil.ts
@@ -31,6 +31,8 @@ import {
} from 'discord.js';
import got from 'got';
import { promisify } from 'util';
+import { Global } from '../models/Global';
+import { BushCache } from '../utils/BushCache';
import { BushClient } from './BushClient';
import { BushMessage } from './BushMessage';
@@ -233,7 +235,7 @@ export class BushClientUtil extends ClientUtil {
/** Commonly Used Emojis */
public emojis = {
success: '<:checkmark:837109864101707807>',
- warn: '<:warn:848726900876247050> ',
+ warn: '<:warn:848726900876247050>',
error: '<:error:837123021016924261>',
successFull: '<:checkmark_full:850118767576088646>',
warnFull: '<:warn_full:850118767391539312>',
@@ -481,4 +483,20 @@ export class BushClientUtil extends ClientUtil {
array[l - 1] = `${conjunction} ${array[l - 1]}`;
return array.join(', ');
}
+
+ public async insertOrRemoveFromGlobal(action: 'add' | 'remove', key: keyof typeof BushCache, value: any) {
+ const environment = this.client.config.dev ? 'development' : 'production';
+ let row = await Global.findByPk(environment);
+ const oldValue: any[] = row[key];
+ let newValue: any[];
+ if (action === 'add') {
+ if (!oldValue.includes(action)) oldValue.push(value);
+ newValue = oldValue;
+ } else {
+ newValue = oldValue.filter((ae) => ae !== value);
+ }
+ row[key] = newValue;
+ this.client.cache[key] = newValue;
+ return await row.save().catch((e) => this.client.logger.error('insertOrRemoveFromGlobal', e));
+ }
}
diff --git a/src/lib/extensions/BushCommand.ts b/src/lib/extensions/BushCommand.ts
index 8358c46..bc6ff68 100644
--- a/src/lib/extensions/BushCommand.ts
+++ b/src/lib/extensions/BushCommand.ts
@@ -4,7 +4,7 @@ import { Command, CommandOptions } from 'discord-akairo';
import { Snowflake } from 'discord.js';
import { BushClient } from './BushClient';
import { BushCommandHandler } from './BushCommandHandler';
-import { BushInteractionMessage } from './BushInteractionMessage';
+import { BushSlashMessage } from './BushInteractionMessage';
import { BushMessage } from './BushMessage';
export interface BushCommandOptions extends CommandOptions {
@@ -37,7 +37,7 @@ export class BushCommand extends Command {
}
public exec(message: BushMessage, args: any): any;
- public exec(message: BushMessage | BushInteractionMessage, args: any): any {
+ public exec(message: BushMessage | BushSlashMessage, args: any): any {
super.exec(message, args);
}
}
diff --git a/src/lib/extensions/BushInteractionMessage.ts b/src/lib/extensions/BushInteractionMessage.ts
index 9bdc291..ade11ea 100644
--- a/src/lib/extensions/BushInteractionMessage.ts
+++ b/src/lib/extensions/BushInteractionMessage.ts
@@ -2,7 +2,7 @@ import { AkairoMessage } from 'discord-akairo';
import { CommandInteraction } from 'discord.js';
import { BushClient } from './BushClient';
-export class BushInteractionMessage extends AkairoMessage {
+export class BushSlashMessage extends AkairoMessage {
public constructor(
client: BushClient,
interaction: CommandInteraction,