diff options
Diffstat (limited to 'src/commands')
26 files changed, 159 insertions, 227 deletions
diff --git a/src/commands/config/blacklist.ts b/src/commands/config/blacklist.ts index 9f3737d..8a575c3 100644 --- a/src/commands/config/blacklist.ts +++ b/src/commands/config/blacklist.ts @@ -68,8 +68,7 @@ export default class BlacklistCommand extends BushCommand { const global = args.global && message.author.isOwner(); const target = typeof args.target === 'string' - ? (await util.arg.cast('channel', client.commandHandler.resolver, message as BushMessage, args.target)) ?? - (await util.arg.cast('user', client.commandHandler.resolver, message as BushMessage, args.target)) + ? (await util.arg.cast('channel', message, args.target)) ?? (await util.arg.cast('user', message, args.target)) : args.target; if (!target) return await message.util.reply(`${util.emojis.error} Choose a valid channel or user.`); const targetID = target.id; diff --git a/src/commands/config/config.ts b/src/commands/config/config.ts index 72ba566..83bcebe 100644 --- a/src/commands/config/config.ts +++ b/src/commands/config/config.ts @@ -336,15 +336,9 @@ export default class SettingsCommand extends BushCommand { ); settingsEmbed.setFooter( - `Run "${ - message.util.isSlash - ? '/' - : client.config.isDevelopment - ? 'dev ' - : message.util.parsed?.prefix ?? client.config.prefix - }${message.util.parsed?.alias ?? 'config'} ${message.util.isSlash ? _.snakeCase(setting) : setting} ${ - guildSettingsObj[setting].type.includes('-array') ? 'add/remove' : 'set' - } <value>" to set this setting.` + `Run "${util.prefix(message)}${message.util.parsed?.alias ?? 'config'} ${ + message.util.isSlash ? _.snakeCase(setting) : setting + } ${guildSettingsObj[setting].type.includes('-array') ? 'add/remove' : 'set'} <value>" to set this setting.` ); settingsEmbed.addField('value', (await generateCurrentValue(guildSettingsObj[setting].type)) || '[No Value Set]'); return { embeds: [settingsEmbed], components: [components] }; diff --git a/src/commands/dev/test.ts b/src/commands/dev/test.ts index a1e5052..38ea920 100644 --- a/src/commands/dev/test.ts +++ b/src/commands/dev/test.ts @@ -107,19 +107,19 @@ export default class TestCommand extends BushCommand { fields.push({ name: `Field ${i}`, value: `Field Value ${i}` }); } const c = util.colors; - const o = { description, author, footer, fields }!; + const o = { description, author, footer, fields, time: Date.now() }; const embeds = [ - new MessageEmbed({ ...o, ...{ title: 'Embed Title 0', color: c.red } }).setTimestamp(), - new MessageEmbed({ ...o, ...{ title: 'Embed Title 1', color: c.orange } }).setTimestamp(), - new MessageEmbed({ ...o, ...{ title: 'Embed Title 2', color: c.gold } }).setTimestamp(), - new MessageEmbed({ ...o, ...{ title: 'Embed Title 3', color: c.yellow } }).setTimestamp(), - new MessageEmbed({ ...o, ...{ title: 'Embed Title 4', color: c.green } }).setTimestamp(), - new MessageEmbed({ ...o, ...{ title: 'Embed Title 5', color: c.darkGreen } }).setTimestamp(), - new MessageEmbed({ ...o, ...{ title: 'Embed Title 6', color: c.aqua } }).setTimestamp(), - new MessageEmbed({ ...o, ...{ title: 'Embed Title 7', color: c.blue } }).setTimestamp(), - new MessageEmbed({ ...o, ...{ title: 'Embed Title 8', color: c.purple } }).setTimestamp(), - new MessageEmbed({ ...o, ...{ title: 'Embed Title 9', color: c.pink } }).setTimestamp() + { ...o, title: 'Embed Title 0', color: c.red }, + { ...o, title: 'Embed Title 1', color: c.orange }, + { ...o, title: 'Embed Title 2', color: c.gold }, + { ...o, title: 'Embed Title 3', color: c.yellow }, + { ...o, title: 'Embed Title 4', color: c.green }, + { ...o, title: 'Embed Title 5', color: c.darkGreen }, + { ...o, title: 'Embed Title 6', color: c.aqua }, + { ...o, title: 'Embed Title 7', color: c.blue }, + { ...o, title: 'Embed Title 8', color: c.purple }, + { ...o, title: 'Embed Title 9', color: c.pink } ]; const ButtonRows: MessageActionRow[] = []; diff --git a/src/commands/info/guildInfo.ts b/src/commands/info/guildInfo.ts index 4a79918..44c388d 100644 --- a/src/commands/info/guildInfo.ts +++ b/src/commands/info/guildInfo.ts @@ -45,6 +45,7 @@ export default class GuildInfoCommand extends BushCommand { `${util.emojis.error} You must either provide an server to provide info about or run this command in a server.` ); } + const otherEmojis = client.consts.mappings.otherEmojis; let isPreview = false; if (['number', 'string'].includes(typeof args?.guild)) { const preview = await client.fetchGuildPreview(`${args.guild}` as Snowflake).catch(() => {}); @@ -61,47 +62,27 @@ export default class GuildInfoCommand extends BushCommand { const guildStats: string[] = []; const guildSecurity: string[] = []; const verifiedGuilds = Object.values(client.consts.mappings.guilds); - if (verifiedGuilds.includes(guild.id)) emojis.push(client.consts.mappings.otherEmojis.BUSH_VERIFIED); + if (verifiedGuilds.includes(guild.id)) emojis.push(otherEmojis.BUSH_VERIFIED); if (!isPreview && guild instanceof Guild) { - if (guild.premiumTier) - emojis.push( - client.consts.mappings.otherEmojis[`BOOST_${guild.premiumTier}` as keyof typeof client.consts.mappings.otherEmojis] - ); + if (guild.premiumTier !== 'NONE') emojis.push(otherEmojis[`BOOST_${guild.premiumTier}`]); await guild.fetch(); + const channels = guild.channels.cache; const channelTypes = [ - `${client.consts.mappings.otherEmojis.TEXT} ${guild.channels.cache - .filter((channel) => channel.type === 'GUILD_TEXT') - .size.toLocaleString()}`, - `${client.consts.mappings.otherEmojis.NEWS} ${guild.channels.cache - .filter((channel) => channel.type === 'GUILD_NEWS') - .size.toLocaleString()}`, - `${client.consts.mappings.otherEmojis.VOICE} ${guild.channels.cache - .filter((channel) => channel.type === 'GUILD_VOICE') - .size.toLocaleString()}`, - `${client.consts.mappings.otherEmojis.STAGE} ${guild.channels.cache - .filter((channel) => channel.type === 'GUILD_STAGE_VOICE') - .size.toLocaleString()}`, - `${client.consts.mappings.otherEmojis.STORE} ${guild.channels.cache - .filter((channel) => channel.type === 'GUILD_STORE') - .size.toLocaleString()}`, - `${client.consts.mappings.otherEmojis.CATEGORY} ${guild.channels.cache - .filter((channel) => channel.type === 'GUILD_CATEGORY') - .size.toLocaleString()}`, - `${client.consts.mappings.otherEmojis.THREAD} ${guild.channels.cache - .filter((channel) => - ['GUILD_NEWS_THREAD', 'GUILD_PUBLIC_THREAD', 'GUILD_PRIVATE_THREAD', 'GUILD_STAGE_VOICE'].includes(channel.type) - ) - .size.toLocaleString()}` + `${otherEmojis.TEXT} ${channels.filter((channel) => channel.type === 'GUILD_TEXT').size.toLocaleString()}`, + `${otherEmojis.NEWS} ${channels.filter((channel) => channel.type === 'GUILD_NEWS').size.toLocaleString()}`, + `${otherEmojis.VOICE} ${channels.filter((channel) => channel.type === 'GUILD_VOICE').size.toLocaleString()}`, + `${otherEmojis.STAGE} ${channels.filter((channel) => channel.type === 'GUILD_STAGE_VOICE').size.toLocaleString()}`, + `${otherEmojis.STORE} ${channels.filter((channel) => channel.type === 'GUILD_STORE').size.toLocaleString()}`, + `${otherEmojis.CATEGORY} ${channels.filter((channel) => channel.type === 'GUILD_CATEGORY').size.toLocaleString()}`, + `${otherEmojis.THREAD} ${channels.filter((channel) => channel.type.includes('_THREAD')).size.toLocaleString()}` ]; - const guildRegions: string[] = []; - guild.channels.cache.forEach((channel) => { - if (!channel.type.includes('VOICE')) return; - else if (!guildRegions.includes((channel as BaseGuildVoiceChannel).rtcRegion ?? 'automatic')) { - guildRegions.push((channel as BaseGuildVoiceChannel).rtcRegion ?? 'automatic'); - } - }); + const guildRegions = [ + ...new Set( + guild.channels.cache.filter((c) => c.isVoice()).map((c) => (c as BaseGuildVoiceChannel).rtcRegion ?? 'automatic') + ) + ] as RTCRegion[]; guildAbout.push( `**Owner:** ${guild.members.cache.get(guild.ownerId)?.user.tag}`, @@ -109,9 +90,7 @@ export default class GuildInfoCommand extends BushCommand { `**Members:** ${guild.memberCount.toLocaleString() ?? 0} (${util.emojis.onlineCircle} ${ guild.approximatePresenceCount?.toLocaleString() ?? 0 }, ${util.emojis.offlineCircle} ${(guild.memberCount - (guild.approximatePresenceCount ?? 0)).toLocaleString() ?? 0})`, - `**Regions:** ${guildRegions - .map((region) => client.consts.mappings.regions[region as keyof typeof client.consts.mappings.regions] || region) - .join(', ')}` + `**Regions:** ${guildRegions.map((region) => client.consts.mappings.regions[region] || region).join(', ')}` ); if (guild.premiumSubscriptionCount) guildAbout.push( @@ -171,28 +150,21 @@ export default class GuildInfoCommand extends BushCommand { ); } + const features = client.consts.mappings.features; const guildFeatures = guild.features.sort((a, b): number => { - const aWeight = client.consts.mappings.features[a]?.weight; - const bWeight = client.consts.mappings.features[b]?.weight; + const aWeight = features[a]?.weight; + const bWeight = features[b]?.weight; - if (aWeight != undefined && bWeight != undefined) { - return aWeight - bWeight; - } else if (aWeight == undefined) { - return 1; - } else if (bWeight == undefined) { - return -1; - } + if (aWeight !== undefined && bWeight !== undefined) return aWeight - bWeight; + else if (aWeight == undefined) return 1; + else if (bWeight == undefined) return -1; return 0; }); if (guildFeatures.length) { guildFeatures.forEach((feature) => { - if (client.consts.mappings.features[feature]?.emoji) { - emojis.push(`${client.consts.mappings.features[feature].emoji}`); - } else if (client.consts.mappings.features[feature]?.name) { - emojis.push(`\`${client.consts.mappings.features[feature].name}\``); - } else { - emojis.push(`\`${feature}\``); - } + if (features[feature]?.emoji) emojis.push(`${features[feature].emoji}`); + else if (features[feature]?.name) emojis.push(`\`${features[feature].name}\``); + else emojis.push(`\`${feature}\``); }); } @@ -204,7 +176,7 @@ export default class GuildInfoCommand extends BushCommand { .setTitle(guild.name) .setColor(util.colors.default) .addField('» About', guildAbout.join('\n')); - if (guildStats) guildInfoEmbed.addField('» Stats', guildStats.join('\n')); + if (guildStats.length) guildInfoEmbed.addField('» Stats', guildStats.join('\n')); const guildIcon = guild.iconURL({ size: 2048, format: 'png', dynamic: true }); if (guildIcon) { guildInfoEmbed.setThumbnail(guildIcon); @@ -218,3 +190,19 @@ export default class GuildInfoCommand extends BushCommand { return await message.util.reply({ embeds: [guildInfoEmbed] }); } } + +type RTCRegion = + | 'us-west' + | 'us-east' + | 'us-central' + | 'us-south' + | 'singapore' + | 'southafrica' + | 'sydney' + | 'europe' + | 'brazil' + | 'hongkong' + | 'russia' + | 'japan' + | 'india' + | 'automatic'; diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index 5e80199..440bcb2 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -22,11 +22,7 @@ export default class HelpCommand extends BushCommand { optional: true } }, - { - id: 'showHidden', - match: 'flag', - flag: '--hidden' - } + { id: 'showHidden', match: 'flag', flag: '--hidden' } ], slash: true, slashOptions: [ @@ -46,11 +42,7 @@ export default class HelpCommand extends BushCommand { message: BushMessage | BushSlashMessage, args: { command: BushCommand | string; showHidden?: boolean } ): Promise<unknown> { - const prefix = message.util.isSlash - ? '/' - : client.config.isDevelopment - ? 'dev ' - : message.util.parsed?.prefix ?? client.config.prefix; + const prefix = util.prefix(message); const row = new MessageActionRow(); if (!client.config.isDevelopment && !client.guilds.cache.some((guild) => guild.ownerId === message.author.id)) { @@ -101,8 +93,7 @@ export default class HelpCommand extends BushCommand { if (command.superUserOnly && !isSuperUser) { return false; } - // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain - return !(command.restrictedGuilds?.includes(message.guild?.id!) === false && !args.showHidden); + return !(command.restrictedGuilds?.includes(message.guild?.id ?? '') === false && !args.showHidden); }); const categoryNice = category.id .replace(/(\b\w)/gi, (lc): string => lc.toUpperCase()) diff --git a/src/commands/info/links.ts b/src/commands/info/links.ts index 569b959..754b22b 100644 --- a/src/commands/info/links.ts +++ b/src/commands/info/links.ts @@ -12,8 +12,6 @@ export default class LinksCommand extends BushCommand { usage: 'links', examples: ['links'] }, - ratelimit: 4, - cooldown: 4000, clientPermissions: (m) => util.clientSendAndPermCheck(m), userPermissions: [], slash: true diff --git a/src/commands/info/snowflake.ts b/src/commands/info/snowflake.ts index 81b3f9d..083acbf 100644 --- a/src/commands/info/snowflake.ts +++ b/src/commands/info/snowflake.ts @@ -22,8 +22,6 @@ export default class SnowflakeCommand extends BushCommand { super('snowflake', { aliases: ['snowflake', 'info', 'sf'], category: 'info', - ratelimit: 4, - cooldown: 4000, description: { content: 'Provides information about the specified Snowflake.', usage: 'snowflake <snowflake>', diff --git a/src/commands/info/userInfo.ts b/src/commands/info/userInfo.ts index 353d844..17be687 100644 --- a/src/commands/info/userInfo.ts +++ b/src/commands/info/userInfo.ts @@ -20,8 +20,7 @@ export default class UserInfoCommand extends BushCommand { start: 'What user would you like to find information about?', retry: '{error} Choose a valid user to find information about.', optional: true - }, - default: null + } } ], slash: true, diff --git a/src/commands/leveling/leaderboard.ts b/src/commands/leveling/leaderboard.ts index e3344a0..dde2270 100644 --- a/src/commands/leveling/leaderboard.ts +++ b/src/commands/leveling/leaderboard.ts @@ -44,13 +44,7 @@ export default class LeaderboardCommand extends BushCommand { return await message.util.reply( `${util.emojis.error} This command can only be run in servers with the leveling feature enabled.${ message.member?.permissions.has('MANAGE_GUILD') - ? ` You can toggle features using the \`${ - message.util.isSlash - ? '/' - : client.config.isDevelopment - ? 'dev ' - : message.util.parsed?.prefix ?? client.config.prefix - }features\` command.` + ? ` You can toggle features using the \`${util.prefix(message)}features\` command.` : '' }` ); diff --git a/src/commands/leveling/level.ts b/src/commands/leveling/level.ts index 4d7adb3..219aab1 100644 --- a/src/commands/leveling/level.ts +++ b/src/commands/leveling/level.ts @@ -56,13 +56,7 @@ export default class LevelCommand extends BushCommand { return await message.util.reply( `${util.emojis.error} This command can only be run in servers with the leveling feature enabled.${ message.member?.permissions.has('MANAGE_GUILD') - ? ` You can toggle features using the \`${ - message.util.isSlash - ? '/' - : client.config.isDevelopment - ? 'dev ' - : message.util.parsed?.prefix ?? client.config.prefix - }features\` command.` + ? ` You can toggle features using the \`${util.prefix(message)}features\` command.` : '' }` ); diff --git a/src/commands/leveling/setLevel.ts b/src/commands/leveling/setLevel.ts index 9a7337a..d3ee162 100644 --- a/src/commands/leveling/setLevel.ts +++ b/src/commands/leveling/setLevel.ts @@ -55,8 +55,6 @@ export default class SetLevelCommand extends BushCommand { { user, level }: { user: User; level: number } ): Promise<unknown> { if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a guild.`); - if (message.author.id === '496409778822709251') - return await message.util.reply(`${util.emojis.error} This command is Bestower proof.`); if (!user.id) throw new Error('user.id is null'); if (isNaN(level)) diff --git a/src/commands/leveling/setXp.ts b/src/commands/leveling/setXp.ts index a73ae58..a140bfc 100644 --- a/src/commands/leveling/setXp.ts +++ b/src/commands/leveling/setXp.ts @@ -58,8 +58,6 @@ export default class SetXpCommand extends BushCommand { { user, xp }: { user: User; xp: number } ): Promise<unknown> { if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a guild.`); - if (message.author.id === '496409778822709251') - return await message.util.reply(`${util.emojis.error} This command is Bestower proof.`); if (!user.id) throw new Error('user.id is null'); if (isNaN(xp)) return await message.util.reply(`${util.emojis.error} Provide a valid number.`); diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts index b3d97d2..74b1b54 100644 --- a/src/commands/moderation/ban.ts +++ b/src/commands/moderation/ban.ts @@ -118,10 +118,7 @@ export default class BanCommand extends BushCommand { let time: number; if (reason) { - time = - typeof reason === 'string' - ? await util.arg.cast('duration', client.commandHandler.resolver, message as BushMessage, reason) - : reason.duration; + time = typeof reason === 'string' ? await util.arg.cast('duration', message, reason) : reason.duration; } const parsedReason = reason?.contentWithoutTime ?? null; @@ -141,19 +138,20 @@ export default class BanCommand extends BushCommand { }); const responseMessage = () => { + const victim = util.format.bold(user.tag); switch (responseCode) { case 'missing permissions': - return `${util.emojis.error} Could not ban **${user.tag}** because I do not have permissions`; + return `${util.emojis.error} Could not ban ${victim} because I am missing the **Ban Members** permission.`; case 'error banning': - return `${util.emojis.error} An error occurred while trying to ban **${user.tag}**.`; + return `${util.emojis.error} An error occurred while trying to ban ${victim}.`; case 'error creating ban entry': - return `${util.emojis.error} While banning **${user.tag}**, there was an error creating a ban entry, please report this to my developers.`; + return `${util.emojis.error} While banning ${victim}, there was an error creating a ban entry, please report this to my developers.`; case 'error creating modlog entry': - return `${util.emojis.error} While banning **${user.tag}**, there was an error creating a modlog entry, please report this to my developers.`; + return `${util.emojis.error} While banning ${victim}, there was an error creating a modlog entry, please report this to my developers.`; case 'failed to dm': - return `${util.emojis.warn} Banned **${user.tag}** however I could not send them a dm.`; + return `${util.emojis.warn} Banned ${victim} however I could not send them a dm.`; case 'success': - return `${util.emojis.success} Successfully banned **${user.tag}**.`; + return `${util.emojis.success} Successfully banned ${victim}.`; } }; return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() }); diff --git a/src/commands/moderation/hideCase.ts b/src/commands/moderation/hideCase.ts index 38cfe31..981a8bc 100644 --- a/src/commands/moderation/hideCase.ts +++ b/src/commands/moderation/hideCase.ts @@ -20,8 +20,6 @@ export default class HideCaseCommand extends BushCommand { } } ], - clientPermissions: (m) => util.clientSendAndPermCheck(m), - userPermissions: (m) => util.userGuildPermCheck(m, ['MANAGE_MESSAGES']), slash: true, slashOptions: [ { @@ -31,6 +29,8 @@ export default class HideCaseCommand extends BushCommand { required: true } ], + clientPermissions: (m) => util.clientSendAndPermCheck(m), + userPermissions: (m) => util.userGuildPermCheck(m, ['MANAGE_MESSAGES']), channel: 'guild' }); } @@ -39,8 +39,6 @@ export default class HideCaseCommand extends BushCommand { message: BushMessage | BushSlashMessage, { case_id: caseID }: { case_id: string } ): Promise<unknown> { - if (message.author.id === '496409778822709251') - return await message.util.reply(`${util.emojis.error} This command is Bestower proof.`); const entry = await ModLog.findByPk(caseID); if (!entry || entry.pseudo) return message.util.send(`${util.emojis.error} Invalid entry.`); if (entry.guild !== message.guild!.id) diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts index 9bd5658..3238217 100644 --- a/src/commands/moderation/kick.ts +++ b/src/commands/moderation/kick.ts @@ -80,17 +80,18 @@ export default class KickCommand extends BushCommand { }); const responseMessage = () => { + const victim = util.format.bold(member.user.tag); switch (responseCode) { case 'missing permissions': - return `${util.emojis.error} Could not kick **${member.user.tag}** because I am missing the \`Kick Members\` permission.`; + return `${util.emojis.error} Could not kick ${victim} because I am missing the \`Kick Members\` permission.`; case 'error kicking': - return `${util.emojis.error} An error occurred while trying to kick **${member.user.tag}**.`; + return `${util.emojis.error} An error occurred while trying to kick ${victim}.`; case 'error creating modlog entry': - return `${util.emojis.error} While muting **${member.user.tag}**, there was an error creating a modlog entry, please report this to my developers.`; + return `${util.emojis.error} While muting ${victim}, there was an error creating a modlog entry, please report this to my developers.`; case 'failed to dm': - return `${util.emojis.warn} Kicked **${member.user.tag}** however I could not send them a dm.`; + return `${util.emojis.warn} Kicked ${victim} however I could not send them a dm.`; case 'success': - return `${util.emojis.success} Successfully kicked **${member.user.tag}**.`; + return `${util.emojis.success} Successfully kicked ${victim}.`; } }; return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() }); diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts index eb37681..4abaa6f 100644 --- a/src/commands/moderation/modlog.ts +++ b/src/commands/moderation/modlog.ts @@ -50,7 +50,7 @@ export default class ModlogCommand extends BushCommand { #generateModlogInfo(log: ModLog, showUser: boolean): string { const trim = (str: string): string => (str.endsWith('\n') ? str.substring(0, str.length - 1).trim() : str.trim()); - const modLog = [`**Case ID**: ${util.discord.escapeItalic(log.id)}`, `**Type**: ${log.type.toLowerCase()}`]; + const modLog = [`**Case ID**: ${util.discord.escapeMarkdown(log.id)}`, `**Type**: ${log.type.toLowerCase()}`]; if (showUser) modLog.push(`**User**: <@!${log.user}>`); modLog.push(`**Moderator**: <@!${log.moderator}>`); if (log.duration) modLog.push(`**Duration**: ${util.humanizeDuration(log.duration)}`); diff --git a/src/commands/moderation/mute.ts b/src/commands/moderation/mute.ts index 03ecf2a..00631ba 100644 --- a/src/commands/moderation/mute.ts +++ b/src/commands/moderation/mute.ts @@ -30,11 +30,7 @@ export default class MuteCommand extends BushCommand { optional: true } }, - { - id: 'force', - flag: '--force', - match: 'flag' - } + { id: 'force', flag: '--force', match: 'flag' } ], slash: true, slashOptions: [ @@ -59,66 +55,67 @@ export default class MuteCommand extends BushCommand { public override async exec( message: BushMessage | BushSlashMessage, - { - user, - reason, - force - }: { user: BushUser; reason?: { duration: number | null; contentWithoutTime: string }; force: boolean } + args: { user: BushUser; reason?: { duration: number | null; contentWithoutTime: string } | string; force: boolean } ): Promise<unknown> { - if (reason?.duration === null) reason.duration = 0; - const member = await message.guild!.members.fetch(user.id).catch(() => null); + const reason: { duration: number | null; contentWithoutTime: string } = args.reason + ? typeof args.reason === 'string' + ? await util.arg.cast('contentWithDuration', message, args.reason) + : args.reason + : { duration: null, contentWithoutTime: '' }; + + if (reason.duration === null) reason.duration = 0; + const member = await message.guild!.members.fetch(args.user.id).catch(() => null); if (!member) return await message.util.reply( `${util.emojis.error} The user you selected is not in the server or is not a valid user.` ); if (!message.member) throw new Error(`message.member is null`); - const useForce = force && message.author.isOwner(); + const useForce = args.force && message.author.isOwner(); const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'mute', true, useForce); - const victimBoldTag = `**${member.user.tag}**`; if (canModerateResponse !== true) { return message.util.reply(canModerateResponse); } - let time: number; - if (reason) { - time = - typeof reason === 'string' - ? await util.arg.cast('duration', client.commandHandler.resolver, message as BushMessage, reason) - : reason.duration; - } + const time = reason + ? typeof reason === 'string' + ? ((await util.arg.cast('duration', message, reason)) as number) + : reason.duration + : undefined; + const parsedReason = reason?.contentWithoutTime ?? ''; const responseCode = await member.mute({ reason: parsedReason, moderator: message.member, - duration: time! ?? 0 + duration: time ?? 0 }); - const responseMessage = async () => { - const prefix = await message.guild!.getSetting('prefix'); + const responseMessage = () => { + const prefix = util.prefix(message); + const victim = util.format.bold(member.user.tag); switch (responseCode) { case 'missing permissions': - return `${util.emojis.error} Could not mute ${victimBoldTag} because I am missing the **Manage Roles** permission.`; + return `${util.emojis.error} Could not mute ${victim} because I am missing the **Manage Roles** permission.`; case 'no mute role': - return `${util.emojis.error} Could not mute ${victimBoldTag}, you must set a mute role with \`${prefix}config muteRole\`.`; + return `${util.emojis.error} Could not mute ${victim}, you must set a mute role with \`${prefix}config muteRole\`.`; case 'invalid mute role': - return `${util.emojis.error} Could not mute ${victimBoldTag} because the current mute role no longer exists. Please set a new mute role with \`${prefix}config muteRole\`.`; + return `${util.emojis.error} Could not mute ${victim} because the current mute role no longer exists. Please set a new mute role with \`${prefix}config muteRole\`.`; case 'mute role not manageable': - return `${util.emojis.error} Could not mute ${victimBoldTag} because I cannot assign the current mute role, either change the role's position or set a new mute role with \`${prefix}config muteRole\`.`; + return `${util.emojis.error} Could not mute ${victim} because I cannot assign the current mute role, either change the role's position or set a new mute role with \`${prefix}config muteRole\`.`; case 'error giving mute role': - return `${util.emojis.error} Could not mute ${victimBoldTag}, there was an error assigning them the mute role.`; + return `${util.emojis.error} Could not mute ${victim}, there was an error assigning them the mute role.`; case 'error creating modlog entry': return `${util.emojis.error} There was an error creating a modlog entry, please report this to my developers.`; case 'error creating mute entry': return `${util.emojis.error} There was an error creating a punishment entry, please report this to my developers.`; case 'failed to dm': - return `${util.emojis.warn} Muted **${member.user.tag}** however I could not send them a dm.`; + return `${util.emojis.warn} Muted ${victim} however I could not send them a dm.`; case 'success': - return `${util.emojis.success} Successfully muted **${member.user.tag}**.`; + return `${util.emojis.success} Successfully muted ${victim}.`; } }; - return await message.util.reply({ content: await responseMessage(), allowedMentions: AllowedMentions.none() }); + return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() }); } } diff --git a/src/commands/moderation/role.ts b/src/commands/moderation/role.ts index fe34d75..d6a85af 100644 --- a/src/commands/moderation/role.ts +++ b/src/commands/moderation/role.ts @@ -18,14 +18,8 @@ export default class RoleCommand extends BushCommand { description: 'Would you like to add or remove a role?', type: 'STRING', choices: [ - { - name: 'add', - value: 'add' - }, - { - name: 'remove', - value: 'remove' - } + { name: 'add', value: 'add' }, + { name: 'remove', value: 'remove' } ], required: true }, @@ -97,7 +91,7 @@ export default class RoleCommand extends BushCommand { message: BushMessage | BushSlashMessage, { action, - user, + user: member, role, duration }: { action: 'add' | 'remove'; user: BushGuildMember; role: BushRole; duration?: number | null } @@ -114,7 +108,7 @@ export default class RoleCommand extends BushCommand { const a = mappings.roleMap[i]; if (a.id == role.id) mappedRole = a; } - if (!mappedRole! || !mappings.roleWhitelist[mappedRole.name as keyof typeof mappings.roleWhitelist]) { + if (!mappedRole! || !Reflect.has(mappings.roleWhitelist, mappedRole.name)) { return await message.util.reply({ content: `${util.emojis.error} <@&${role.id}> is not whitelisted, and you do not have manage roles permission.`, allowedMentions: AllowedMentions.none() @@ -138,10 +132,11 @@ export default class RoleCommand extends BushCommand { const responseCode = action === 'add' - ? await user.addRole({ moderator: message.member!, addToModlog: shouldLog, role, duration }) - : await user.removeRole({ moderator: message.member!, addToModlog: shouldLog, role, duration }); + ? await member.addRole({ moderator: message.member!, addToModlog: shouldLog, role, duration }) + : await member.removeRole({ moderator: message.member!, addToModlog: shouldLog, role, duration }); const responseMessage = () => { + const victim = util.format.bold(member.user.tag); switch (responseCode) { case 'user hierarchy': return `${util.emojis.error} <@&${role.id}> is higher or equal to your highest role.`; @@ -158,11 +153,11 @@ export default class RoleCommand extends BushCommand { case 'error adding role' || 'error removing role': return `${util.emojis.error} An error occurred while trying to ${action} <@&${role.id}> ${ action === 'add' ? 'to' : 'from' - } **${user.user.tag}**.`; + } ${victim}.`; case 'success': return `${util.emojis.success} Successfully ${action === 'add' ? 'added' : 'removed'} <@&${role.id}> ${ action === 'add' ? 'to' : 'from' - } **${user.user.tag}**${duration ? ` for ${util.humanizeDuration(duration)}` : ''}.`; + } ${victim}${duration ? ` for ${util.humanizeDuration(duration)}` : ''}.`; } }; diff --git a/src/commands/moderation/slowmode.ts b/src/commands/moderation/slowmode.ts index d90f122..75d795c 100644 --- a/src/commands/moderation/slowmode.ts +++ b/src/commands/moderation/slowmode.ts @@ -65,7 +65,7 @@ export default class SlowModeCommand extends BushCommand { if (length) { length = typeof length === 'string' && !['off', 'none', 'disable'].includes(length) - ? await util.arg.cast('duration', client.commandHandler.resolver, message as BushMessage, length) + ? await util.arg.cast('duration', message, length) : length; } diff --git a/src/commands/moderation/unban.ts b/src/commands/moderation/unban.ts index 61e27cf..9d52dd2 100644 --- a/src/commands/moderation/unban.ts +++ b/src/commands/moderation/unban.ts @@ -61,19 +61,20 @@ export default class UnbanCommand extends BushCommand { }); const responseMessage = () => { + const victim = util.format.bold(user.tag); switch (responseCode) { case 'missing permissions': - return `${util.emojis.error} Could not unban **${user.tag}** because I do not have permissions`; + return `${util.emojis.error} Could not unban ${victim} because I am missing the **Ban Members** permission.`; case 'error unbanning': - return `${util.emojis.error} An error occurred while trying to unban **${user.tag}**.`; + return `${util.emojis.error} An error occurred while trying to unban ${victim}.`; case 'error removing ban entry': - return `${util.emojis.error} While unbanning **${user.tag}**, there was an error removing their ban entry, please report this to my developers.`; + return `${util.emojis.error} While unbanning ${victim}, there was an error removing their ban entry, please report this to my developers.`; case 'error creating modlog entry': - return `${util.emojis.error} While unbanning **${user.tag}**, there was an error creating a modlog entry, please report this to my developers.`; + return `${util.emojis.error} While unbanning ${victim}, there was an error creating a modlog entry, please report this to my developers.`; case 'user not banned': - return `${util.emojis.warn} **${user.tag}** is not banned but I tried to unban them anyways.`; + return `${util.emojis.warn} ${victim} is not banned but I tried to unban them anyways.`; case 'success': - return `${util.emojis.success} Successfully unbanned **${user.tag}**.`; + return `${util.emojis.success} Successfully unbanned ${victim}.`; } }; return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() }); diff --git a/src/commands/moderation/unmute.ts b/src/commands/moderation/unmute.ts index e430b83..f9335c4 100644 --- a/src/commands/moderation/unmute.ts +++ b/src/commands/moderation/unmute.ts @@ -67,11 +67,8 @@ export default class UnmuteCommand extends BushCommand { if (!message.member) throw new Error(`message.member is null`); const useForce = force && message.author.isOwner(); - const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'unmute', true, useForce); - const victimBoldTag = `**${member.user.tag}**`; - if (canModerateResponse !== true) { return message.util.reply(canModerateResponse); } @@ -81,29 +78,30 @@ export default class UnmuteCommand extends BushCommand { moderator: message.member }); - const responseMessage = async () => { - const prefix = await message.guild!.getSetting('prefix'); + const responseMessage = () => { + const prefix = util.prefix(message); + const victim = util.format.bold(member.user.tag); switch (responseCode) { case 'missing permissions': - return `${error} Could not unmute ${victimBoldTag} because I am missing the \`Manage Roles\` permission.`; + return `${error} Could not unmute ${victim} because I am missing the **Manage Roles** permission.`; case 'no mute role': - return `${error} Could not unmute ${victimBoldTag}, you must set a mute role with \`${prefix}muterole\`.`; + return `${error} Could not unmute ${victim}, you must set a mute role with \`${prefix}config muteRole\`.`; case 'invalid mute role': - return `${error} Could not unmute ${victimBoldTag} because the current mute role no longer exists. Please set a new mute role with \`${prefix}muterole\`.`; + return `${error} Could not unmute ${victim} because the current mute role no longer exists. Please set a new mute role with \`${prefix}config muteRole\`.`; case 'mute role not manageable': - return `${error} Could not unmute ${victimBoldTag} because I cannot assign the current mute role, either change the role's position or set a new mute role with \`${prefix}muterole\`.`; + return `${error} Could not unmute ${victim} because I cannot assign the current mute role, either change the role's position or set a new mute role with \`${prefix}config muteRole\`.`; case 'error removing mute role': - return `${error} Could not unmute ${victimBoldTag}, there was an error removing their mute role.`; + return `${error} Could not unmute ${victim}, there was an error removing their mute role.`; case 'error creating modlog entry': - return `${error} While muting ${victimBoldTag}, there was an error creating a modlog entry, please report this to my developers.`; + return `${error} While muting ${victim}, there was an error creating a modlog entry, please report this to my developers.`; case 'error removing mute entry': - return `${error} While muting ${victimBoldTag}, there was an error removing their mute entry, please report this to my developers.`; + return `${error} While muting ${victim}, there was an error removing their mute entry, please report this to my developers.`; case 'failed to dm': - return `${util.emojis.warn} unmuted **${member.user.tag}** however I could not send them a dm.`; + return `${util.emojis.warn} unmuted ${victim} however I could not send them a dm.`; case 'success': - return `${util.emojis.success} Successfully unmuted **${member.user.tag}**.`; + return `${util.emojis.success} Successfully unmuted ${victim}.`; } }; - return await message.util.reply({ content: await responseMessage(), allowedMentions: AllowedMentions.none() }); + return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() }); } } diff --git a/src/commands/moderation/warn.ts b/src/commands/moderation/warn.ts index 6ae8442..c67466b 100644 --- a/src/commands/moderation/warn.ts +++ b/src/commands/moderation/warn.ts @@ -1,4 +1,4 @@ -import { BushCommand, BushGuildMember, BushMessage, BushSlashMessage, BushUser } from '@lib'; +import { AllowedMentions, BushCommand, BushGuildMember, BushMessage, BushSlashMessage, BushUser } from '@lib'; import { Moderation } from '../../lib/common/Moderation'; export default class WarnCommand extends BushCommand { @@ -65,7 +65,6 @@ export default class WarnCommand extends BushCommand { const useForce = force && message.author.isOwner(); if (!message.member) throw new Error(`message.member is null`); const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'warn', true, useForce); - const victimBoldTag = `**${member.user.tag}**`; if (canModerateResponse !== true) { return message.util.reply(canModerateResponse); @@ -76,21 +75,19 @@ export default class WarnCommand extends BushCommand { moderator: message.member }); - switch (response) { - case 'error creating modlog entry': - return message.util.reply( - `${util.emojis.error} While warning ${victimBoldTag}, there was an error creating a modlog entry, please report this to my developers.` - ); - case 'failed to dm': - return message.util.reply( - `${util.emojis.warn} **${member.user.tag}** has been warned for the ${util.ordinal( + const responseMessage = () => { + const victim = util.format.bold(member.user.tag); + switch (response) { + case 'error creating modlog entry': + return `${util.emojis.error} While warning ${victim}, there was an error creating a modlog entry, please report this to my developers.`; + case 'failed to dm': + return `${util.emojis.warn} ${victim} has been warned for the ${util.ordinal( caseNum ?? 0 - )} time, however I could not send them a dm.` - ); - case 'success': - return message.util.reply( - `${util.emojis.success} Successfully warned **${member.user.tag}** for the ${util.ordinal(caseNum ?? 0)} time.` - ); - } + )} time, however I could not send them a dm.`; + case 'success': + return `${util.emojis.success} Successfully warned ${victim} for the ${util.ordinal(caseNum ?? 0)} time.`; + } + }; + return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() }); } } diff --git a/src/commands/moulberry-bush/capePerms.ts b/src/commands/moulberry-bush/capePerms.ts index e26a5a4..4b7a3eb 100644 --- a/src/commands/moulberry-bush/capePerms.ts +++ b/src/commands/moulberry-bush/capePerms.ts @@ -23,9 +23,6 @@ export default class CapePermissionsCommand extends BushCommand { } } ], - clientPermissions: (m) => util.clientSendAndPermCheck(m, ['EMBED_LINKS'], true), - userPermissions: [], - channel: 'guild', slash: true, slashOptions: [ { @@ -34,7 +31,10 @@ export default class CapePermissionsCommand extends BushCommand { type: 'STRING', required: true } - ] + ], + clientPermissions: (m) => util.clientSendAndPermCheck(m, ['EMBED_LINKS'], true), + userPermissions: [], + channel: 'guild' }); } diff --git a/src/commands/moulberry-bush/serverStatus.ts b/src/commands/moulberry-bush/serverStatus.ts index f4a80d4..568dd38 100644 --- a/src/commands/moulberry-bush/serverStatus.ts +++ b/src/commands/moulberry-bush/serverStatus.ts @@ -12,8 +12,6 @@ export default class ServerStatusCommand extends BushCommand { examples: ['serverstatus', 'ss'], content: "Gives the status of moulberry's server" }, - ratelimit: 4, - cooldown: 4000, clientPermissions: (m) => util.clientSendAndPermCheck(m, ['EMBED_LINKS'], true), userPermissions: [], slash: true diff --git a/src/commands/utilities/activity.ts b/src/commands/utilities/activity.ts index c3839e5..e2a3352 100644 --- a/src/commands/utilities/activity.ts +++ b/src/commands/utilities/activity.ts @@ -15,7 +15,7 @@ const activityMap = { function map(phase: string) { if (client.consts.regex.snowflake.test(phase)) return phase; - else if (Object.keys(activityMap).includes(phase)) return activityMap[phase as keyof typeof activityMap]; + else if (Reflect.has(activityMap, phase)) return activityMap[phase as keyof typeof activityMap]; else if (['yt', 'youtube'].includes(phase)) return activityMap['Watch Together']; else if (['chess', 'park'].includes(phase)) return activityMap['Chess in the Park']; else if (['poker'].includes(phase)) return activityMap['Poker Night']; diff --git a/src/commands/utilities/price.ts b/src/commands/utilities/price.ts index a012501..be3da8e 100644 --- a/src/commands/utilities/price.ts +++ b/src/commands/utilities/price.ts @@ -90,8 +90,6 @@ export default class PriceCommand extends BushCommand { ], clientPermissions: (m) => util.clientSendAndPermCheck(m, ['EMBED_LINKS'], true), userPermissions: [], - ratelimit: 4, - cooldown: 4000, typing: true }); } |