diff options
88 files changed, 513 insertions, 381 deletions
diff --git a/package.json b/package.json index 413889d..3e35241 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "@types/node-fetch": "^2", "@types/tinycolor2": "^1", "@types/uuid": "^8.3.0", + "@types/validator": "^13.6.3", "@typescript-eslint/eslint-plugin": "^4.14.1", "@typescript-eslint/parser": "^4.14.1", "esbuild": "^0.12.11", @@ -122,7 +123,8 @@ "no-throw-literal": "off", "@typescript-eslint/no-throw-literal": "warn", "@typescript-eslint/prefer-nullish-coalescing": "warn", - "@typescript-eslint/no-explicit-any": "off" + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-non-null-assertion": "off" } }, "prettier": { diff --git a/src/arguments/contentWithDuration.ts b/src/arguments/contentWithDuration.ts index 99b251f..314b761 100644 --- a/src/arguments/contentWithDuration.ts +++ b/src/arguments/contentWithDuration.ts @@ -3,6 +3,6 @@ import { BushArgumentTypeCaster, BushMessage } from '@lib'; export const contentWithDurationTypeCaster: BushArgumentTypeCaster = async ( _message: BushMessage, phrase: string -): Promise<{ duration: number; contentWithoutTime: string }> => { +): Promise<{ duration: number; contentWithoutTime: string | null }> => { return client.util.parseDuration(phrase); }; diff --git a/src/arguments/permission.ts b/src/arguments/permission.ts index dc90f3a..8ad0102 100644 --- a/src/arguments/permission.ts +++ b/src/arguments/permission.ts @@ -4,7 +4,7 @@ import { BushArgumentTypeCaster } from '../lib/extensions/discord-akairo/BushArg export const permissionTypeCaster: BushArgumentTypeCaster = (_, phrase) => { if (!phrase) return null; phrase = phrase.toUpperCase().replace(/ /g, '_'); - if (!Permissions.FLAGS[phrase]) { + if (!Permissions.FLAGS[phrase as keyof typeof Permissions.FLAGS]) { return null; } else { return phrase; diff --git a/src/commands/admin/channelPermissions.ts b/src/commands/admin/channelPermissions.ts index a13f07a..83230f7 100644 --- a/src/commands/admin/channelPermissions.ts +++ b/src/commands/admin/channelPermissions.ts @@ -1,4 +1,4 @@ -import { GuildChannel, GuildMember, MessageEmbed, Role } from 'discord.js'; +import { GuildMember, MessageEmbed, Role } from 'discord.js'; import { BushCommand, BushMessage } from '../../lib'; export default class ChannelPermissionsCommand extends BushCommand { @@ -63,7 +63,7 @@ export default class ChannelPermissionsCommand extends BushCommand { } ): Promise<unknown> { const failedChannels = []; - for (const channel of message.guild.channels.cache.values()) { + for (const channel of message.guild!.channels.cache.values()) { try { if (channel.isThread()) return; if (channel.permissionsLocked) return; @@ -78,7 +78,7 @@ export default class ChannelPermissionsCommand extends BushCommand { failedChannels.push(channel); } } - const failure = failedChannels.map((e: GuildChannel) => `<#${e.id}>`).join(' '); + const failure = failedChannels.map((e) => `<#${e.id}>`).join(' '); if (failure.length > 2000) { const paginate: MessageEmbed[] = []; for (let i = 0; i < failure.length; i += 2000) { diff --git a/src/commands/config/autoPublishChannel.ts b/src/commands/config/autoPublishChannel.ts index 3381dc2..f058402 100644 --- a/src/commands/config/autoPublishChannel.ts +++ b/src/commands/config/autoPublishChannel.ts @@ -29,7 +29,7 @@ export default class AutoPublishChannelCommand extends BushCommand { name: 'channel', description: 'What channel would you like me to send welcome messages in?', type: 'CHANNEL', - required: false + required: true } ], channel: 'guild', @@ -39,13 +39,13 @@ export default class AutoPublishChannelCommand extends BushCommand { } public override async exec(message: BushMessage, { channel }: { channel: Channel }): Promise<unknown> { - const autoPublishChannels = await message.guild.getSetting('autoPublishChannels'); + const autoPublishChannels = await message.guild!.getSetting('autoPublishChannels'); const newValue = util.addOrRemoveFromArray( autoPublishChannels.includes(channel.id) ? 'remove' : 'add', autoPublishChannels, channel.id ); - await message.guild.setSetting('autoPublishChannels', newValue); + await message.guild!.setSetting('autoPublishChannels', newValue); return await message.util.reply({ content: `${util.emojis.success} Successfully ${ autoPublishChannels.includes(channel.id) ? 'disabled' : 'enabled' diff --git a/src/commands/config/blacklist.ts b/src/commands/config/blacklist.ts index 864081c..57c3015 100644 --- a/src/commands/config/blacklist.ts +++ b/src/commands/config/blacklist.ts @@ -75,9 +75,12 @@ export default class BlacklistCommand extends BushCommand { const targetID = target.id; if (global) { - if (action === 'toggle') { - const blacklistedUsers = (await Global.findByPk(client.config.environment)).blacklistedUsers; - const blacklistedChannels = (await Global.findByPk(client.config.environment)).blacklistedChannels; + if ((action as 'blacklist' | 'unblacklist' | 'toggle') === 'toggle') { + const globalDB = + (await Global.findByPk(client.config.environment)) ?? + (await Global.create({ environment: client.config.environment })); + const blacklistedUsers = globalDB.blacklistedUsers; + const blacklistedChannels = globalDB.blacklistedChannels; action = blacklistedUsers.includes(targetID) || blacklistedChannels.includes(targetID) ? 'unblacklist' : 'blacklist'; } const success = await util @@ -99,9 +102,11 @@ export default class BlacklistCommand extends BushCommand { }); // guild disable } else { + if (!message.guild) + return await message.util.reply(`${util.emojis.error} You have to be in a guild to disable commands.`); const blacklistedChannels = (await message.guild.getSetting('blacklistedChannels')) ?? []; const blacklistedUsers = (await message.guild.getSetting('blacklistedUsers')) ?? []; - if (action === 'toggle') { + if ((action as 'blacklist' | 'unblacklist' | 'toggle') === 'toggle') { action = blacklistedChannels.includes(targetID) ?? blacklistedUsers.includes(targetID) ? 'unblacklist' : 'blacklist'; } const newValue = util.addOrRemoveFromArray( diff --git a/src/commands/config/disable.ts b/src/commands/config/disable.ts index a9318a5..bc6ed47 100644 --- a/src/commands/config/disable.ts +++ b/src/commands/config/disable.ts @@ -69,8 +69,11 @@ export default class DisableCommand extends BushCommand { const commandID = (args.command as BushCommand).id; if (global) { - if (action === 'toggle') { - const disabledCommands = (await Global.findByPk(client.config.environment)).disabledCommands; + if ((action as 'disable' | 'enable' | 'toggle') === 'toggle') { + const disabledCommands = ( + (await Global.findByPk(client.config.environment)) ?? + (await Global.create({ environment: client.config.environment })) + ).disabledCommands; action = disabledCommands.includes(commandID) ? 'disable' : 'enable'; } const success = await util @@ -95,12 +98,12 @@ export default class DisableCommand extends BushCommand { // guild disable } else { - const disabledCommands = await message.guild.getSetting('disabledCommands'); - if (action === 'toggle') { + const disabledCommands = await message.guild!.getSetting('disabledCommands'); + if ((action as 'disable' | 'enable' | 'toggle') === 'toggle') { action = disabledCommands.includes(commandID) ? 'disable' : 'enable'; } const newValue = util.addOrRemoveFromArray(action === 'disable' ? 'remove' : 'add', disabledCommands, commandID); - const success = await message.guild.setSetting('disabledCommands', newValue).catch(() => false); + const success = await message.guild!.setSetting('disabledCommands', newValue).catch(() => false); if (!success) return await message.util.reply({ content: `${util.emojis.error} There was an error **${action.substr( diff --git a/src/commands/config/muteRole.ts b/src/commands/config/muteRole.ts index dee5322..c7a6e75 100644 --- a/src/commands/config/muteRole.ts +++ b/src/commands/config/muteRole.ts @@ -38,7 +38,7 @@ export default class MuteRoleCommand extends BushCommand { } override async exec(message: BushMessage | BushSlashMessage, args: { role: Role }): Promise<void> { - await message.guild.setSetting('muteRole', args.role.id); + await message.guild!.setSetting('muteRole', args.role.id); await message.util.send({ content: `${util.emojis.success} Changed the server's mute role to <@&${args.role.id}>.`, allowedMentions: AllowedMentions.none() diff --git a/src/commands/config/prefix.ts b/src/commands/config/prefix.ts index 9f80633..9d707e0 100644 --- a/src/commands/config/prefix.ts +++ b/src/commands/config/prefix.ts @@ -37,8 +37,8 @@ export default class PrefixCommand extends BushCommand { } override async exec(message: BushMessage | BushSlashMessage, args: { prefix?: string }): Promise<unknown> { - const oldPrefix = await message.guild.getSetting('prefix'); - await message.guild.setSetting('prefix', args.prefix ?? client.config.prefix); + const oldPrefix = await message.guild!.getSetting('prefix'); + await message.guild!.setSetting('prefix', args.prefix ?? client.config.prefix); if (args.prefix) { return await message.util.send({ content: `${util.emojis.success} changed the server's prefix ${oldPrefix ? `from \`${oldPrefix}\`` : ''} to \`${ diff --git a/src/commands/config/punishmentFooter.ts b/src/commands/config/punishmentFooter.ts index d8daf77..d07ce4f 100644 --- a/src/commands/config/punishmentFooter.ts +++ b/src/commands/config/punishmentFooter.ts @@ -39,7 +39,7 @@ export default class PunishmentFooterCommand extends BushCommand { } override async exec(message: BushMessage | BushSlashMessage, args: { ending: string }): Promise<unknown> { - await message.guild.setSetting('punishmentEnding', args.ending || null); + await message.guild!.setSetting('punishmentEnding', args.ending || ''); if (args.ending) return await message.util.send({ content: `${util.emojis.success} Changed the server's punishment footer to \n\`\`\`${Util.cleanCodeBlockContent( diff --git a/src/commands/config/welcomeChannel.ts b/src/commands/config/welcomeChannel.ts index a662802..fc56607 100644 --- a/src/commands/config/welcomeChannel.ts +++ b/src/commands/config/welcomeChannel.ts @@ -37,8 +37,8 @@ export default class WelcomeChannelCommand extends BushCommand { }); } public override async exec(message: BushMessage | BushSlashMessage, args: { channel: Channel }): Promise<unknown> { - const oldChannel = await message.guild.getSetting('welcomeChannel'); - await message.guild.setSetting('welcomeChannel', args.channel.id ?? undefined); + const oldChannel = await message.guild!.getSetting('welcomeChannel'); + await message.guild!.setSetting('welcomeChannel', args.channel.id ?? undefined); if (args.channel) { return await message.util.send( `${util.emojis.success} changed the server's welcome channel ${oldChannel ? `from <#${oldChannel}>` : ''} to <#${ diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts index 5b44db2..10360cf 100644 --- a/src/commands/dev/eval.ts +++ b/src/commands/dev/eval.ts @@ -70,7 +70,7 @@ export default class EvalCommand extends BushCommand { } args.code = args.code.replace(/[“”]/g, '"').replace(/```*(?:js|ts)?/g, ''); - const code = { + const code: { ts: string | null; js: string; lang: 'ts' | 'js' } = { ts: args.typescript ? args.code : null, js: args.typescript ? transpile(args.code) : args.code, lang: args.typescript ? 'ts' : 'js' @@ -79,7 +79,7 @@ export default class EvalCommand extends BushCommand { const embed = new _MessageEmbed(); const badPhrases = ['delete', 'destroy']; - if (badPhrases.some((p) => code[code.lang].includes(p)) && !args.sudo) { + if (badPhrases.some((p) => code[code.lang]!.includes(p)) && !args.sudo) { return await message.util.send(`${util.emojis.error} This eval was blocked by smooth brain protection™.`); } @@ -119,7 +119,7 @@ export default class EvalCommand extends BushCommand { const inputJS = await util.inspectCleanRedactCodeblock(code.js, 'js'); const inputTS = code.lang === 'ts' ? await util.inspectCleanRedactCodeblock(code.ts, 'ts') : undefined; try { - const rawOutput = code[code.lang].replace(/ /g, '').includes('9+10' || '10+9') ? '21' : await eval(code.js); + const rawOutput = code[code.lang]!.replace(/ /g, '').includes('9+10' || '10+9') ? '21' : await eval(code.js); const output = await util.inspectCleanRedactCodeblock(rawOutput, 'js', { depth: args.sel_depth ?? 0, showHidden: args.hidden, @@ -148,7 +148,7 @@ export default class EvalCommand extends BushCommand { embed.addField('📤 Output', await util.inspectCleanRedactCodeblock(e?.stack || e, 'js')); } - embed.setTimestamp().setFooter(message.author.tag, message.author.displayAvatarURL({ dynamic: true })); + embed.setTimestamp().setFooter(message.author.tag, message.author.displayAvatarURL({ dynamic: true }) ?? undefined); if (!args.silent || message.util.isSlash) { await message.util.reply({ embeds: [embed] }); diff --git a/src/commands/dev/reload.ts b/src/commands/dev/reload.ts index 4f11a81..91cabfb 100644 --- a/src/commands/dev/reload.ts +++ b/src/commands/dev/reload.ts @@ -44,7 +44,7 @@ export default class ReloadCommand extends BushCommand { client.inhibitorHandler.reloadAll(); return message.util.send(`🔁 Successfully reloaded! (${new Date().getTime() - s.getTime()}ms)`); } catch (e) { - if (output) void client.logger.error('reloadCommand', output); + if (output!) void client.logger.error('reloadCommand', output); return message.util.send(`An error occurred while reloading:\n${await util.codeblock(e?.stack || e |
