diff options
Diffstat (limited to 'src/commands/moderation')
-rw-r--r-- | src/commands/moderation/ban.ts | 3 | ||||
-rw-r--r-- | src/commands/moderation/modlog.ts | 3 | ||||
-rw-r--r-- | src/commands/moderation/mute.ts | 3 | ||||
-rw-r--r-- | src/commands/moderation/role.ts | 90 | ||||
-rw-r--r-- | src/commands/moderation/slowmode.ts | 5 |
5 files changed, 57 insertions, 47 deletions
diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts index 7f1a67c..c33b39a 100644 --- a/src/commands/moderation/ban.ts +++ b/src/commands/moderation/ban.ts @@ -1,5 +1,4 @@ import { AllowedMentions, BushCommand, BushGuildMember, BushMessage, BushSlashMessage } from '@lib'; -import { Argument } from 'discord-akairo'; import { User } from 'discord.js'; export default class BanCommand extends BushCommand { @@ -110,7 +109,7 @@ export default class BanCommand extends BushCommand { if (reason) { time = typeof reason === 'string' - ? await Argument.cast('duration', client.commandHandler.resolver, message as BushMessage, reason) + ? await util.arg.cast('duration', client.commandHandler.resolver, message as BushMessage, reason) : reason.duration; } const parsedReason = reason?.contentWithoutTime ?? ''; diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts index 04264b8..ef0a56e 100644 --- a/src/commands/moderation/modlog.ts +++ b/src/commands/moderation/modlog.ts @@ -42,8 +42,7 @@ export default class ModlogCommand extends BushCommand { `**Moderator**: <@!${log.moderator}> (${log.moderator})` ]; if (log.duration) modLog.push(`**Duration**: ${util.humanizeDuration(log.duration)}`); - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - modLog.push(`**Reason**: ${log.reason || 'No Reason Specified.'}`); + modLog.push(`**Reason**: ${log.reason ?? 'No Reason Specified.'}`); if (log.evidence) modLog.push(`**Evidence:** ${log.evidence}`); return modLog.join(`\n`); } diff --git a/src/commands/moderation/mute.ts b/src/commands/moderation/mute.ts index 7b8689a..915302e 100644 --- a/src/commands/moderation/mute.ts +++ b/src/commands/moderation/mute.ts @@ -1,5 +1,4 @@ import { AllowedMentions, BushCommand, BushMessage, BushSlashMessage, BushUser } from '@lib'; -import { Argument } from 'discord-akairo'; export default class MuteCommand extends BushCommand { public constructor() { @@ -77,7 +76,7 @@ export default class MuteCommand extends BushCommand { if (reason) { time = typeof reason === 'string' - ? await Argument.cast('duration', client.commandHandler.resolver, message as BushMessage, reason) + ? await util.arg.cast('duration', client.commandHandler.resolver, message as BushMessage, reason) : reason.duration; } const parsedReason = reason?.contentWithoutTime ?? ''; diff --git a/src/commands/moderation/role.ts b/src/commands/moderation/role.ts index 4575a11..ddaefaa 100644 --- a/src/commands/moderation/role.ts +++ b/src/commands/moderation/role.ts @@ -1,51 +1,16 @@ -/* eslint-disable @typescript-eslint/no-empty-function */ import { AllowedMentions, BushCommand, BushGuildMember, BushMessage, BushRole, BushSlashMessage } from '@lib'; +import { ArgumentOptions, Flag } from 'discord-akairo'; export default class RoleCommand extends BushCommand { public constructor() { super('role', { - aliases: ['role'], + aliases: ['role', 'rr', 'ar', 'ra'], category: 'moderation', description: { content: "Manages users' roles.", usage: 'role <add|remove> <user> <role> [duration]', examples: ['role add spammer nogiveaways 7days'] }, - args: [ - { - id: 'action', - customType: [['add'], ['remove']], - prompt: { - start: 'Would you like to `add` or `remove` a role?', - retry: '{error} Choose whether you would you like to `add` or `remove` a role.' - } - }, - { - id: 'user', - type: 'member', - prompt: { - start: `What user do you want to add/remove the role to/from?`, - retry: `{error} Choose a valid user to add/remove the role to/from.` - } - }, - { - id: 'role', - type: 'role', - prompt: { - start: `What role do you want to add/remove to/from the user?`, - retry: `{error} Choose a valid role to add/remove.` - } - }, - { - id: 'duration', - type: 'duration', - prompt: { - start: 'How long would you like to role to last?', - retry: '{error} Choose a valid duration.', - optional: true - } - } - ], slash: true, slashOptions: [ { @@ -90,9 +55,56 @@ export default class RoleCommand extends BushCommand { }); } + *args(message: BushMessage): IterableIterator<ArgumentOptions | Flag> { + const action = ['rr'].includes(message.util.parsed?.alias ?? '') + ? 'remove' + : ['ar', 'ra'].includes(message.util.parsed?.alias ?? '') + ? 'add' + : yield { + id: 'action', + type: [['add'], ['remove']], + prompt: { + start: 'Would you like to `add` or `remove` a role?', + retry: (...arg) => { + console.debug(...arg); + return '{error} Choose whether you would you like to `add` or `remove` a role.'; + } + } + }; + console.debug(action); + const user = yield { + id: 'user', + type: 'member', + prompt: { + start: `What user do you want to ${action} the role ${action === 'add' ? 'to' : 'from'}?`, + retry: (...arg) => { + console.debug(...arg); + return `{error} Choose a valid user to ${action} the role ${action === 'add' ? 'to' : 'from'}.`; + } + } + }; + console.debug(user); + const _role = yield { + id: 'role', + type: `${action === 'add' ? 'roleWithDuration' : 'role'}`, + match: 'rest', + prompt: { + start: `What role do you want to ${action} ${action === 'add' ? 'to' : 'from'} the user${ + action === 'add' ? ', and for how long' : '' + }?`, + retry: (...arg) => { + console.debug(...arg); + return `{error} Choose a valid role to ${action}.`; + } + } + }; + console.debug(_role); + return { action, user, role: (_role as any).role ?? _role, duration: (_role as any).duration }; + } + public override async exec( message: BushMessage | BushSlashMessage, - { action, user, role, duration }: { action: 'add' | 'remove'; user: BushGuildMember; role: BushRole; duration: number } + { action, user, role, duration }: { action: 'add' | 'remove'; user: BushGuildMember; role: BushRole; duration?: number } ): Promise<unknown> { if (!message.member!.permissions.has('MANAGE_ROLES')) { const mappings = client.consts.mappings; @@ -131,6 +143,8 @@ export default class RoleCommand extends BushCommand { const responseMessage = () => { switch (responseCode) { case 'user hierarchy': + client.console.debug(role.position); + client.console.debug(user.roles.highest.position); return `${util.emojis.error} <@&${role.id}> is higher or equal to your highest role.`; case 'role managed': return `${util.emojis.error} <@&${role.id}> is managed by an integration and cannot be managed.`; diff --git a/src/commands/moderation/slowmode.ts b/src/commands/moderation/slowmode.ts index 1d47616..04fe3e4 100644 --- a/src/commands/moderation/slowmode.ts +++ b/src/commands/moderation/slowmode.ts @@ -66,12 +66,11 @@ export default class SlowModeCommand extends BushCommand { if (length) { length = typeof length === 'string' && !['off', 'none', 'disable'].includes(length) - ? await Argument.cast('duration', client.commandHandler.resolver, message as BushMessage, length) + ? await util.arg.cast('duration', client.commandHandler.resolver, message as BushMessage, length) : length; } - // @ts-expect-error: stop being dumb smh - const length2: number = ['off', 'none', 'disable'].includes(length) ? 0 : length; + const length2: number = ['off', 'none', 'disable'].includes(length as string) ? 0 : (length as number); const setSlowmode = await (channel as ThreadChannel | TextChannel) .setRateLimitPerUser(length2 / 1000, `Changed by ${message.author.tag} (${message.author.id}).`) |