diff options
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/config/blacklist.ts | 105 | ||||
-rw-r--r-- | src/commands/config/config.ts | 2 | ||||
-rw-r--r-- | src/commands/config/disable.ts | 23 | ||||
-rw-r--r-- | src/commands/config/log.ts | 7 | ||||
-rw-r--r-- | src/commands/info/snowflake.ts | 5 | ||||
-rw-r--r-- | src/commands/info/userInfo.ts | 34 | ||||
-rw-r--r-- | src/commands/moderation/role.ts | 2 | ||||
-rw-r--r-- | src/commands/utilities/suicide.ts | 6 |
8 files changed, 88 insertions, 96 deletions
diff --git a/src/commands/config/blacklist.ts b/src/commands/config/blacklist.ts index da4ad18..a6e6a3d 100644 --- a/src/commands/config/blacklist.ts +++ b/src/commands/config/blacklist.ts @@ -1,6 +1,5 @@ -import { AllowedMentions, BushCommand, Global, type BushMessage, type BushSlashMessage } from '#lib'; -import { GuildTextBasedChannels } from 'discord-akairo'; -import { User } from 'discord.js'; +import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { GuildTextBasedChannel, User } from 'discord.js'; export default class BlacklistCommand extends BushCommand { public constructor() { @@ -52,10 +51,10 @@ export default class BlacklistCommand extends BushCommand { public override async exec( message: BushMessage | BushSlashMessage, - args: { action: 'blacklist' | 'unblacklist'; target: GuildTextBasedChannels | User | string; global: boolean } + args: { action?: 'blacklist' | 'unblacklist'; target: GuildTextBasedChannel | User | string; global: boolean } ) { let action: 'blacklist' | 'unblacklist' | 'toggle' = - args.action ?? (message?.util?.parsed?.alias as 'blacklist' | 'unblacklist') ?? 'toggle'; + args.action ?? (message?.util?.parsed?.alias as 'blacklist' | 'unblacklist' | undefined) ?? 'toggle'; const global = args.global && message.author.isOwner(); const target = typeof args.target === 'string' @@ -64,65 +63,43 @@ export default class BlacklistCommand extends BushCommand { if (!target) return await message.util.reply(`${util.emojis.error} Choose a valid channel or user.`); const targetID = target.id; - if (global) { - 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 - .insertOrRemoveFromGlobal( - action === 'blacklist' ? 'add' : 'remove', - target instanceof User ? 'blacklistedUsers' : 'blacklistedChannels', - targetID - ) - .catch(() => false); - if (!success) - return await message.util.reply({ - content: `${util.emojis.error} There was an error globally ${action}ing ${util.format.input( - target instanceof User ? target.tag : target.name - )}.`, - allowedMentions: AllowedMentions.none() - }); - else - return await message.util.reply({ - content: `${util.emojis.success} Successfully ${action}ed ${util.format.input( - target instanceof User ? target.tag : target.name - )} globally.`, - allowedMentions: AllowedMentions.none() - }); - // 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 as 'blacklist' | 'unblacklist' | 'toggle') === 'toggle') { - action = blacklistedChannels.includes(targetID) ?? blacklistedUsers.includes(targetID) ? 'unblacklist' : 'blacklist'; - } - const newValue = util.addOrRemoveFromArray( - action === 'blacklist' ? 'add' : 'remove', - target instanceof User ? blacklistedUsers : blacklistedChannels, - targetID - ); - const success = await message.guild - .setSetting(target instanceof User ? 'blacklistedUsers' : 'blacklistedChannels', newValue, message.member!) - .catch(() => false); - if (!success) - return await message.util.reply({ - content: `${util.emojis.error} There was an error ${action}ing ${util.format.input( - target instanceof User ? target.tag : target.name - )}.`, - allowedMentions: AllowedMentions.none() - }); - else - return await message.util.reply({ - content: `${util.emojis.success} Successfully ${action}ed ${util.format.input( - target instanceof User ? target.tag : target.name - )}.`, - allowedMentions: AllowedMentions.none() - }); + if (!message.guild && global) + return await message.util.reply(`${util.emojis.error} You have to be in a guild to disable commands.`); + const blacklistedUsers = global + ? util.getGlobal('blacklistedUsers') + : (await message.guild!.getSetting('blacklistedChannels')) ?? []; + const blacklistedChannels = global + ? util.getGlobal('blacklistedChannels') + : (await message.guild!.getSetting('blacklistedUsers')) ?? []; + if (action === 'toggle') { + action = blacklistedUsers.includes(targetID) || blacklistedChannels.includes(targetID) ? 'unblacklist' : 'blacklist'; } + const newValue = util.addOrRemoveFromArray( + action === 'blacklist' ? 'add' : 'remove', + target instanceof User ? blacklistedUsers : blacklistedChannels, + targetID + ); + + const key = target instanceof User ? 'blacklistedUsers' : 'blacklistedChannels'; + + const success = await (global + ? util.setGlobal(key, newValue) + : message.guild!.setSetting(key, newValue, message.member!) + ).catch(() => false); + + if (!success) + return await message.util.reply({ + content: `${util.emojis.error} There was an error${global ? ' globally' : ''} ${action}ing ${util.format.input( + target instanceof User ? target.tag : target.name + )}.`, + allowedMentions: AllowedMentions.none() + }); + else + return await message.util.reply({ + content: `${util.emojis.success} Successfully ${action}ed ${util.format.input( + target instanceof User ? target.tag : target.name + )}${global ? ' globally' : ''}.`, + allowedMentions: AllowedMentions.none() + }); } } diff --git a/src/commands/config/config.ts b/src/commands/config/config.ts index 6af5895..b88147d 100644 --- a/src/commands/config/config.ts +++ b/src/commands/config/config.ts @@ -97,7 +97,7 @@ export default class SettingsCommand extends BushCommand { }); } - override *args(message: BushMessage): Generator<ArgumentOptions | Flag> { + public override *args(message: BushMessage): Generator<ArgumentOptions | Flag> { const optional = message.util.parsed!.alias === 'settings'; const setting = yield { id: 'setting', diff --git a/src/commands/config/disable.ts b/src/commands/config/disable.ts index a30652a..44c28d3 100644 --- a/src/commands/config/disable.ts +++ b/src/commands/config/disable.ts @@ -1,6 +1,8 @@ -import { AllowedMentions, BushCommand, Global, type BushMessage, type BushSlashMessage } from '#lib'; +import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; export default class DisableCommand extends BushCommand { + private static blacklistedCommands = ['eval', 'disable']; + public constructor() { super('disable', { aliases: ['disable', 'enable'], @@ -45,20 +47,23 @@ export default class DisableCommand extends BushCommand { }); } - blacklistedCommands = ['eval', 'disable']; - public override async exec( message: BushMessage | BushSlashMessage, - args: { action: 'enable' | 'disable'; command: BushCommand | string; global: boolean } + args: { action?: 'enable' | 'disable'; command: BushCommand | string; global: boolean } ) { let action = (args.action ?? message?.util?.parsed?.alias ?? 'toggle') as 'disable' | 'enable' | 'toggle'; const global = args.global && message.author.isOwner(); - const commandID = (args.command as BushCommand).id; + const commandID = + args.command instanceof BushCommand + ? args.command.id + : (await util.arg.cast(util.arg.union('commandAlias', 'command'), message, args.command))?.id; + + if (!commandID) return await message.util.reply(`${util.emojis.error} Invalid command.`); + + if (DisableCommand.blacklistedCommands.includes(commandID)) + return message.util.send(`${util.emojis.error} the ${commandID} command cannot be disabled.`); - const disabledCommands = global - ? ((await Global.findByPk(client.config.environment)) ?? (await Global.create({ environment: client.config.environment }))) - .disabledCommands - : await message.guild!.getSetting('disabledCommands'); + const disabledCommands = global ? util.getGlobal('disabledCommands') : await message.guild!.getSetting('disabledCommands'); if (action === 'toggle') action = disabledCommands.includes(commandID) ? 'disable' : 'enable'; const newValue = util.addOrRemoveFromArray(action === 'disable' ? 'remove' : 'add', disabledCommands, commandID); diff --git a/src/commands/config/log.ts b/src/commands/config/log.ts index 6121ad7..52cb8f5 100644 --- a/src/commands/config/log.ts +++ b/src/commands/config/log.ts @@ -22,11 +22,12 @@ export default class LogCommand extends BushCommand { }, { id: 'channel', - description: 'The channel to have logs of the seleted type to be sent in.', + description: 'The channel to have logs of the selected type to be sent in.', type: 'channel', prompt: 'What channel would you like these logs to be sent in?', slashType: 'CHANNEL', - channelTypes: ['GUILD_TEXT', 'GUILD_NEWS', 'GUILD_NEWS_THREAD', 'GUILD_PUBLIC_THREAD', 'GUILD_PRIVATE_THREAD'] + channelTypes: ['GUILD_TEXT', 'GUILD_NEWS', 'GUILD_NEWS_THREAD', 'GUILD_PUBLIC_THREAD', 'GUILD_PRIVATE_THREAD'], + only: 'slash' } ], channel: 'guild', @@ -35,7 +36,7 @@ export default class LogCommand extends BushCommand { }); } - override *args(): IterableIterator<ArgumentOptions | Flag> { + public override *args(): IterableIterator<ArgumentOptions | Flag> { const log_type = yield { id: 'log_type', type: guildLogsArr, diff --git a/src/commands/info/snowflake.ts b/src/commands/info/snowflake.ts index bd0924f..f2ffaa8 100644 --- a/src/commands/info/snowflake.ts +++ b/src/commands/info/snowflake.ts @@ -4,7 +4,6 @@ import { SnowflakeUtil, VoiceChannel, type CategoryChannel, - type Channel, type DeconstructedSnowflake, type DMChannel, type Guild, @@ -46,9 +45,9 @@ export default class SnowflakeCommand extends BushCommand { // Channel if (client.channels.cache.has(snowflake)) { - const channel: Channel = client.channels.cache.get(snowflake)!; + const channel = client.channels.cache.get(snowflake)!; const channelInfo = [`**Type:** ${channel.type}`]; - if ((['DM', 'GROUP_DM'] as const).includes(channel.type)) { + if (['DM', 'GROUP_DM'].includes(channel.type)) { const _channel = channel as DMChannel; channelInfo.push(`**Recipient:** ${util.discord.escapeMarkdown(_channel.recipient.tag)} (${_channel.recipient.id})`); snowflakeEmbed.setTitle( diff --git a/src/commands/info/userInfo.ts b/src/commands/info/userInfo.ts index 2d7fcfb..c62be93 100644 --- a/src/commands/info/userInfo.ts +++ b/src/commands/info/userInfo.ts @@ -1,4 +1,11 @@ -import { BushCommand, type BushMessage, type BushSlashMessage, type BushUser } from '#lib'; +import { + BushCommand, + BushGuild, + BushGuildMember, + type BushMessage, + type BushSlashMessage, + type BushUser +} from '#lib'; import { MessageEmbed, type Snowflake } from 'discord.js'; // TODO: Add bot information @@ -37,11 +44,17 @@ export default class UserInfoCommand extends BushCommand { : await client.users.fetch(`${args.user}`).catch(() => undefined); if (user === undefined) return message.util.reply(`${util.emojis.error} Invalid user.`); const member = message.guild ? message.guild.members.cache.get(user.id) : undefined; + await user.fetch(true); // gets banner info and accent color + + const userEmbed = await UserInfoCommand.makeUserInfoEmbed(user, member, message.guild); + + return await message.util.reply({ embeds: [userEmbed] }); + } + + public static async makeUserInfoEmbed(user: BushUser, member?: BushGuildMember, guild?: BushGuild | null) { const emojis = []; const superUsers = client.cache.global.superUsers; - await user.fetch(true); // gets banner info and accent color - const userEmbed: MessageEmbed = new MessageEmbed() .setTitle(util.discord.escapeMarkdown(user.tag)) .setThumbnail(user.displayAvatarURL({ size: 2048, format: 'png', dynamic: true })) @@ -69,7 +82,7 @@ export default class UserInfoCommand extends BushCommand { emojis.push(client.consts.mappings.otherEmojis.NITRO); } - if (message.guild?.ownerId == user.id) emojis.push(client.consts.mappings.otherEmojis.OWNER); + if (guild?.ownerId == user.id) emojis.push(client.consts.mappings.otherEmojis.OWNER); else if (member?.permissions.has('ADMINISTRATOR')) emojis.push(client.consts.mappings.otherEmojis.ADMIN); if (member?.premiumSinceTimestamp) emojis.push(client.consts.mappings.otherEmojis.BOOSTER); @@ -92,16 +105,14 @@ export default class UserInfoCommand extends BushCommand { // Server User Info const serverUserInfo = []; if (joinedAt) - serverUserInfo.push( - `**${message.guild!.ownerId == user.id ? 'Created Server' : 'Joined'}:** ${joinedAt} (${joinedAtDelta} ago)` - ); + serverUserInfo.push(`**${guild!.ownerId == user.id ? 'Created Server' : 'Joined'}:** ${joinedAt} (${joinedAtDelta} ago)`); if (premiumSince) serverUserInfo.push(`**Boosting Since:** ${premiumSince} (${premiumSinceDelta} ago)`); if (member?.displayHexColor) serverUserInfo.push(`**Display Color:** ${member.displayHexColor}`); - if (user.id == '322862723090219008' && message.guild?.id == client.consts.mappings.guilds.bush) + if (user.id == '322862723090219008' && guild?.id == client.consts.mappings.guilds.bush) serverUserInfo.push(`**General Deletions:** 1⅓`); if ( (['384620942577369088', '496409778822709251'] as const).includes(user.id) && - message.guild?.id == client.consts.mappings.guilds.bush + guild?.id == client.consts.mappings.guilds.bush ) serverUserInfo.push(`**General Deletions:** ⅓`); if (member?.nickname) serverUserInfo.push(`**Nickname:** ${util.discord.escapeMarkdown(member?.nickname)}`); @@ -154,7 +165,7 @@ export default class UserInfoCommand extends BushCommand { // Important Perms const perms = []; - if (member?.permissions.has('ADMINISTRATOR') || message.guild?.ownerId == user.id) { + if (member?.permissions.has('ADMINISTRATOR') || guild?.ownerId == user.id) { perms.push('`Administrator`'); } else if (member?.permissions.toArray(false).length) { member.permissions.toArray(false).forEach((permission) => { @@ -166,7 +177,6 @@ export default class UserInfoCommand extends BushCommand { if (perms.length) userEmbed.addField('» Important Perms', perms.join(' ')); if (emojis) userEmbed.setDescription(`\u200B${emojis.join(' ')}`); // zero width space - - return await message.util.reply({ embeds: [userEmbed] }); + return userEmbed } } diff --git a/src/commands/moderation/role.ts b/src/commands/moderation/role.ts index 275db38..689ef1e 100644 --- a/src/commands/moderation/role.ts +++ b/src/commands/moderation/role.ts @@ -56,7 +56,7 @@ export default class RoleCommand extends BushCommand { }); } - override *args(message: BushMessage): Generator<ArgumentOptions | Flag> { + public override *args(message: BushMessage): Generator<ArgumentOptions | Flag> { const action = (['rr'] as const).includes(message.util.parsed?.alias ?? '') ? 'remove' : (['ar', 'ra'] as const).includes(message.util.parsed?.alias ?? '') diff --git a/src/commands/utilities/suicide.ts b/src/commands/utilities/suicide.ts index 05f8d47..641f7ec 100644 --- a/src/commands/utilities/suicide.ts +++ b/src/commands/utilities/suicide.ts @@ -1,5 +1,5 @@ import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; -import { MessageEmbed } from 'discord.js'; +import { Message, MessageEmbed } from 'discord.js'; export default class TemplateCommand extends BushCommand { public constructor() { @@ -46,8 +46,8 @@ export default class TemplateCommand extends BushCommand { return ( // If the original message was a reply -> imitate it - !message.util.isSlashMessage(message) && message.reference?.messageId && message.guild && message.channel - ? await message.channel.messages.fetch(message.reference!.messageId!).then(async (message1) => { + !message.util.isSlashMessage(message) && (message as Message).reference?.messageId && message.guild && message.channel + ? await message.channel.messages.fetch((message as Message).reference!.messageId!).then(async (message1) => { await message1.reply({ embeds: [suicideEmbed], allowedMentions: AllowedMentions.users(), |