diff options
Diffstat (limited to 'src/commands/moderation')
-rw-r--r-- | src/commands/moderation/ban.ts | 51 | ||||
-rw-r--r-- | src/commands/moderation/kick.ts | 5 | ||||
-rw-r--r-- | src/commands/moderation/modlog.ts | 9 | ||||
-rw-r--r-- | src/commands/moderation/mute.ts | 5 |
4 files changed, 44 insertions, 26 deletions
diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts index c33b39a..2c3e429 100644 --- a/src/commands/moderation/ban.ts +++ b/src/commands/moderation/ban.ts @@ -1,5 +1,5 @@ -import { AllowedMentions, BushCommand, BushGuildMember, BushMessage, BushSlashMessage } from '@lib'; -import { User } from 'discord.js'; +import { AllowedMentions, BushCommand, BushMessage, BushSlashMessage } from '@lib'; +import { Snowflake, User } from 'discord.js'; export default class BanCommand extends BushCommand { public constructor() { @@ -14,7 +14,7 @@ export default class BanCommand extends BushCommand { args: [ { id: 'user', - type: 'user', + customType: util.arg.union('user', 'snowflake'), prompt: { start: 'What user would you like to ban?', retry: '{error} Choose a valid user to ban.' @@ -83,17 +83,19 @@ export default class BanCommand extends BushCommand { public override async exec( message: BushMessage | BushSlashMessage, { - user, + user: _user, reason, days, force - }: { user: User; reason?: { duration: number; contentWithoutTime: string }; days?: number; force: boolean } + }: { user: User | Snowflake; reason?: { duration: number; contentWithoutTime: string }; days?: number; force: boolean } ): Promise<unknown> { if (!message.guild) return message.util.reply(`${util.emojis.error} This command cannot be used in dms.`); - const member = message.guild!.members.cache.get(user.id) as BushGuildMember; + const member = message.guild!.members.cache.get((_user as User)?.id); + const user = member?.user ?? (await util.resolveNonCachedUser(_user)); + if (!user) return message.util.reply(`${util.emojis.error} Invalid user.`); const useForce = force && message.author.isOwner(); if (!message.member) throw new Error(`message.member is null`); - const canModerateResponse = util.moderationPermissionCheck(message.member, member, 'ban', true, useForce); + const canModerateResponse = member ? util.moderationPermissionCheck(message.member, member, 'ban', true, useForce) : true; if (canModerateResponse !== true) { return message.util.reply(canModerateResponse); @@ -112,31 +114,40 @@ export default class BanCommand extends BushCommand { ? await util.arg.cast('duration', client.commandHandler.resolver, message as BushMessage, reason) : reason.duration; } - const parsedReason = reason?.contentWithoutTime ?? ''; + const parsedReason = reason?.contentWithoutTime ?? null; - const responseCode = await member.bushBan({ - reason: parsedReason, - moderator: message.author, - duration: time! ?? 0, - deleteDays: days ?? 0 - }); + const responseCode = member + ? await member.bushBan({ + reason: parsedReason, + moderator: message.author, + duration: time! ?? 0, + deleteDays: days ?? 0 + }) + : await message.guild.ban({ + user, + reason: parsedReason, + moderator: message.author, + duration: time! ?? 0, + deleteDays: days ?? 0 + }); const responseMessage = () => { switch (responseCode) { case 'missing permissions': - return `${util.emojis.error} Could not ban **${member.user.tag}** because I do not have permissions`; + return `${util.emojis.error} Could not ban **${user.tag}** because I do not have permissions`; case 'error banning': - return `${util.emojis.error} An error occurred while trying to ban **${member.user.tag}**.`; + return `${util.emojis.error} An error occurred while trying to ban **${user.tag}**.`; case 'error creating ban entry': - return `${util.emojis.error} While banning **${member.user.tag}**, there was an error creating a ban entry, please report this to my developers.`; + return `${util.emojis.error} While banning **${user.tag}**, 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 **${member.user.tag}**, there was an error creating a modlog entry, please report this to my developers.`; + return `${util.emojis.error} While banning **${user.tag}**, there was an error creating a modlog entry, please report this to my developers.`; case 'failed to dm': - return `${util.emojis.warn} Banned **${member.user.tag}** however I could not send them a dm.`; + return `${util.emojis.warn} Banned **${user.tag}** however I could not send them a dm.`; case 'success': - return `${util.emojis.success} Successfully banned **${member.user.tag}**.`; + return `${util.emojis.success} Successfully banned **${user.tag}**.`; } }; + client.console.debug(responseCode); return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() }); } } diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts index 2315712..341d83c 100644 --- a/src/commands/moderation/kick.ts +++ b/src/commands/moderation/kick.ts @@ -61,7 +61,10 @@ export default class KickCommand extends BushCommand { ): Promise<unknown> { const member = message.guild!.members.cache.get(user.id) as BushGuildMember; - if (!member) return await message.util.reply(`${util.emojis.error} You cannot kick members that are not in the server.`); + 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 canModerateResponse = util.moderationPermissionCheck(message.member, member, 'kick', true, useForce); diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts index ef0a56e..fd53ea7 100644 --- a/src/commands/moderation/modlog.ts +++ b/src/commands/moderation/modlog.ts @@ -35,6 +35,7 @@ export default class ModlogCommand extends BushCommand { } #generateModlogInfo(log: ModLog): string { + const trim = (str: string): string => (str.endsWith('\n') ? str.substring(0, str.length - 1).trim() : str.trim()); const modLog = [ `**Case ID**: ${log.id}`, `**Type**: ${log.type.toLowerCase()}`, @@ -42,8 +43,8 @@ export default class ModlogCommand extends BushCommand { `**Moderator**: <@!${log.moderator}> (${log.moderator})` ]; if (log.duration) modLog.push(`**Duration**: ${util.humanizeDuration(log.duration)}`); - modLog.push(`**Reason**: ${log.reason ?? 'No Reason Specified.'}`); - if (log.evidence) modLog.push(`**Evidence:** ${log.evidence}`); + modLog.push(`**Reason**: ${trim(log.reason ?? 'No Reason Specified.')}`); + if (log.evidence) modLog.push(`**Evidence:** ${trim(log.evidence)}`); return modLog.join(`\n`); } @@ -70,11 +71,11 @@ export default class ModlogCommand extends BushCommand { (chunk) => new MessageEmbed({ title: `${foundUser.tag}'s Mod Logs`, - description: chunk.join('\n**―――――――――――――――――――――――――――**\n'), + description: chunk.join('\n━━━━━━━━━━━━━━━\n'), color: util.colors.default }) ); - return await util.buttonPaginate(message, embedPages, '', true); + return await util.buttonPaginate(message, embedPages, undefined, true); } else if (search) { const entry = await ModLog.findByPk(search as string); if (!entry) return message.util.send(`${util.emojis.error} That modlog does not exist.`); diff --git a/src/commands/moderation/mute.ts b/src/commands/moderation/mute.ts index 915302e..ea2ff41 100644 --- a/src/commands/moderation/mute.ts +++ b/src/commands/moderation/mute.ts @@ -61,7 +61,10 @@ export default class MuteCommand extends BushCommand { { user, reason, force }: { user: BushUser; reason?: { duration: number; contentWithoutTime: string }; force: boolean } ): Promise<unknown> { const member = message.guild!.members.cache.get(user.id); - if (!member) return await message.util.reply(`${util.emojis.error} You cannot kick members that are not in the server.`); + 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(); |