diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-06-21 15:33:36 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-06-21 15:33:36 -0400 |
commit | 6eb42974bdd4da4f9a6d77c8fde4c19f9f0a351b (patch) | |
tree | 6b0490f7f17d5d663f0f764589328e8acb79dd22 /src/lib/extensions/BushClientUtil.ts | |
parent | 5c3da90f441c321f55ae735d6002f4da91f2481e (diff) | |
download | tanzanite-6eb42974bdd4da4f9a6d77c8fde4c19f9f0a351b.tar.gz tanzanite-6eb42974bdd4da4f9a6d77c8fde4c19f9f0a351b.tar.bz2 tanzanite-6eb42974bdd4da4f9a6d77c8fde4c19f9f0a351b.zip |
fix(db): made it work now
Diffstat (limited to 'src/lib/extensions/BushClientUtil.ts')
-rw-r--r-- | src/lib/extensions/BushClientUtil.ts | 20 |
1 files changed, 19 insertions, 1 deletions
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)); + } } |