diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/config/blacklist.ts | 4 | ||||
-rw-r--r-- | src/commands/dev/eval.ts | 16 | ||||
-rw-r--r-- | src/commands/info/help.ts | 6 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClientUtil.ts | 2 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushGuild.ts | 4 | ||||
-rw-r--r-- | src/lib/utils/BushCache.ts | 5 | ||||
-rw-r--r-- | src/tasks/updateCache.ts | 12 |
7 files changed, 33 insertions, 16 deletions
diff --git a/src/commands/config/blacklist.ts b/src/commands/config/blacklist.ts index 8e5d703..ae19d70 100644 --- a/src/commands/config/blacklist.ts +++ b/src/commands/config/blacklist.ts @@ -102,8 +102,8 @@ export default class BlacklistCommand extends BushCommand { }); // guild disable } else { - const blacklistedChannels = await message.guild.getSetting('blacklistedChannels'); - const blacklistedUsers = await message.guild.getSetting('blacklistedUsers'); + const blacklistedChannels = await message.guild.getSetting('blacklistedChannels')??[]; + const blacklistedUsers = await message.guild.getSetting('blacklistedUsers')??[]; if (action === 'toggle') { action = blacklistedChannels.includes(targetID) ?? blacklistedUsers.includes(targetID) ? 'unblacklist' : 'blacklist'; } diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts index 436268e..0de0aa1 100644 --- a/src/commands/dev/eval.ts +++ b/src/commands/dev/eval.ts @@ -1,5 +1,3 @@ -/* eslint-disable @typescript-eslint/no-var-requires */ -/* eslint-disable @typescript-eslint/no-unused-vars */ import { BushCommand, BushMessage, BushSlashMessage } from '@lib'; import { exec } from 'child_process'; import { Constants } from 'discord-akairo'; @@ -12,7 +10,6 @@ const clean = (text) => { return Util.cleanCodeBlockContent(text); } else return text; }; -const sh = promisify(exec); export default class EvalCommand extends BushCommand { public constructor() { @@ -173,7 +170,9 @@ export default class EvalCommand extends BushCommand { try { let output; - const me = message.member, + /* eslint-disable @typescript-eslint/no-unused-vars */ + const sh = promisify(exec), + me = message.member, member = message.member, bot = this.client, guild = message.guild, @@ -193,12 +192,15 @@ export default class EvalCommand extends BushCommand { MessageAttachment, MessageButton, MessageCollector, - MessageComponentInteractionCollector, + InteractionCollector, MessageEmbed, MessageSelectMenu, ReactionCollector, - Util - } = require('discord.js'); // I would use import here but esbuild doesn't like that + Util, + Collection + } = await import('discord.js'), + { Canvas } = await import('node-canvas'); + /* eslint-enable @typescript-eslint/no-unused-vars */ if (code[code.lang].replace(/ /g, '').includes('9+10' || '10+9')) { output = 21; } else { diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index e485d24..1786f8c 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -48,7 +48,7 @@ export default class HelpCommand extends BushCommand { ): Promise<unknown> { const prefix = this.client.config.isDevelopment ? 'dev ' : message.util.parsed.prefix; const components = - !this.client.config.isDevelopment || !this.client.guilds.cache.some((guild) => guild.ownerId === message.author.id) + !this.client.config.isDevelopment && !this.client.guilds.cache.some((guild) => guild.ownerId === message.author.id) ? [ new MessageActionRow().addComponents( new MessageButton({ @@ -60,6 +60,10 @@ export default class HelpCommand extends BushCommand { ] : undefined; + this.client.console.debug(!this.client.config.isDevelopment); + this.client.console.debug(!this.client.guilds.cache.some((guild) => guild.ownerId === message.author.id)); + this.client.console.debug(components); + const isOwner = this.client.isOwner(message.author); const isSuperUser = this.client.isSuperUser(message.author); const command = args.command diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index 1924de8..0e3a904 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -542,7 +542,7 @@ export class BushClientUtil extends ClientUtil { if (!array.includes(action)) array.push(value); newValue = array; } else { - newValue = array.filter((ae) => ae !== value); + newValue = Array.from(array).filter((ae) => ae !== value); } return newValue; } diff --git a/src/lib/extensions/discord.js/BushGuild.ts b/src/lib/extensions/discord.js/BushGuild.ts index f695f8b..e5eff21 100644 --- a/src/lib/extensions/discord.js/BushGuild.ts +++ b/src/lib/extensions/discord.js/BushGuild.ts @@ -12,12 +12,14 @@ export class BushGuild extends Guild { } public async getSetting<K extends keyof GuildModel>(setting: K): Promise<GuildModel[K]> { - return ((await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id }))[setting]; + return this.client.cache.guilds.get(this.id)?.[setting] ?? ((await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id }))[setting]; } public async setSetting<K extends keyof GuildModel>(setting: K, value: GuildDB[K]): Promise<GuildDB> { const row = (await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id }); row[setting] = value; + //@ts-ignore: idk why it thinks it doesn't exist + this.client.cache.guilds.set(this.id, row.dataValues) return await row.save(); } diff --git a/src/lib/utils/BushCache.ts b/src/lib/utils/BushCache.ts index ffef470..e4eaf55 100644 --- a/src/lib/utils/BushCache.ts +++ b/src/lib/utils/BushCache.ts @@ -1,4 +1,5 @@ -import { Snowflake } from 'discord.js'; +import { Collection, Snowflake } from 'discord.js'; +import { Guild } from '../models/Guild'; class GlobalCache { public static superUsers = new Array<Snowflake>(); @@ -8,6 +9,8 @@ class GlobalCache { public static blacklistedUsers = new Array<Snowflake>(); } + export class BushCache { public static global = GlobalCache; + public static guilds = new Collection<Snowflake, Guild>() } diff --git a/src/tasks/updateCache.ts b/src/tasks/updateCache.ts index 3f19091..cfadeb5 100644 --- a/src/tasks/updateCache.ts +++ b/src/tasks/updateCache.ts @@ -11,15 +11,17 @@ export class UpdateCacheTask extends BushTask { }); } public async exec(): Promise<void> { - await UpdateCacheTask.updateCache(this.client); + await UpdateCacheTask.updateGlobalCache(this.client); + // await UpdateCacheTask.updateGuildCache(this.client); await this.client.logger.verbose(`UpdateCache`, `Updated cache.`); } public static async init(client: BushClient): Promise<void> { - await UpdateCacheTask.updateCache(client); + await UpdateCacheTask.updateGlobalCache(client); + // await UpdateCacheTask.updateGuildCache(client); } - private static async updateCache(client: BushClient): Promise<void> { + private static async updateGlobalCache(client: BushClient): Promise<void> { const environment = config.environment; const row = (await Global.findByPk(environment)) || @@ -36,4 +38,8 @@ export class UpdateCacheTask extends BushTask { if (client.cache[option]) client.cache[option] = row[option]; } } + + private static async updateGuildCache(client: BushClient): Promise<void> { + // client.db.query(`SELECT * FROM 'Guilds'`) + } } |