aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/arguments/contentWithDuration.ts2
-rw-r--r--src/arguments/duration.ts2
-rw-r--r--src/arguments/durationSeconds.ts6
-rw-r--r--src/arguments/roleWithDuation.ts2
-rw-r--r--src/commands/moderation/ban.ts9
-rw-r--r--src/commands/moderation/mute.ts7
-rw-r--r--src/commands/moderation/role.ts8
-rw-r--r--src/commands/moderation/slowmode.ts3
-rw-r--r--src/commands/moderation/unmute.ts2
-rw-r--r--src/lib/extensions/discord-akairo/BushClient.ts4
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts9
11 files changed, 40 insertions, 14 deletions
diff --git a/src/arguments/contentWithDuration.ts b/src/arguments/contentWithDuration.ts
index 38b3fa4..27ff1db 100644
--- a/src/arguments/contentWithDuration.ts
+++ b/src/arguments/contentWithDuration.ts
@@ -3,6 +3,6 @@ import { BushArgumentTypeCaster } from '@lib';
export const contentWithDurationTypeCaster: BushArgumentTypeCaster = async (
_,
phrase
-): Promise<{ duration: number; contentWithoutTime: string | null }> => {
+): Promise<{ duration: number | null; contentWithoutTime: string | null }> => {
return client.util.parseDuration(phrase);
};
diff --git a/src/arguments/duration.ts b/src/arguments/duration.ts
index 6e76034..9f3cf99 100644
--- a/src/arguments/duration.ts
+++ b/src/arguments/duration.ts
@@ -1,5 +1,5 @@
import { BushArgumentTypeCaster } from '@lib';
-export const durationTypeCaster: BushArgumentTypeCaster = (_, phrase): number => {
+export const durationTypeCaster: BushArgumentTypeCaster = (_, phrase): number | null => {
return client.util.parseDuration(phrase).duration;
};
diff --git a/src/arguments/durationSeconds.ts b/src/arguments/durationSeconds.ts
new file mode 100644
index 0000000..6b0e91d
--- /dev/null
+++ b/src/arguments/durationSeconds.ts
@@ -0,0 +1,6 @@
+import { BushArgumentTypeCaster } from '../lib';
+
+export const durationSecondsTypeCaster: BushArgumentTypeCaster = (_, phrase): number | null => {
+ phrase += 's';
+ return client.util.parseDuration(phrase).duration;
+};
diff --git a/src/arguments/roleWithDuation.ts b/src/arguments/roleWithDuation.ts
index 54e6390..a63026d 100644
--- a/src/arguments/roleWithDuation.ts
+++ b/src/arguments/roleWithDuation.ts
@@ -3,7 +3,7 @@ import { BushArgumentTypeCaster } from '@lib';
export const roleWithDurationTypeCaster: BushArgumentTypeCaster = async (
message,
phrase
-): Promise<{ duration: number; role: string | null } | null> => {
+): Promise<{ duration: number | null; role: string | null } | null> => {
// eslint-disable-next-line prefer-const
let { duration, contentWithoutTime } = client.util.parseDuration(phrase);
if (contentWithoutTime === null || contentWithoutTime === undefined) return null;
diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts
index fea5543..88ad8e4 100644
--- a/src/commands/moderation/ban.ts
+++ b/src/commands/moderation/ban.ts
@@ -87,8 +87,15 @@ export default class BanCommand extends BushCommand {
reason,
days,
force
- }: { user: User | Snowflake; reason?: { duration: number; contentWithoutTime: string }; days?: number; force: boolean }
+ }: {
+ user: User | Snowflake;
+ reason?: { duration: number | null; contentWithoutTime: string };
+ days?: number;
+ force: boolean;
+ }
): Promise<unknown> {
+ if (reason?.duration === null) reason.duration = 0;
+
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 as User)?.id);
const user = member?.user ?? (await util.resolveNonCachedUser(_user));
diff --git a/src/commands/moderation/mute.ts b/src/commands/moderation/mute.ts
index fba548b..de79b32 100644
--- a/src/commands/moderation/mute.ts
+++ b/src/commands/moderation/mute.ts
@@ -58,8 +58,13 @@ export default class MuteCommand extends BushCommand {
public override async exec(
message: BushMessage | BushSlashMessage,
- { user, reason, force }: { user: BushUser; reason?: { duration: number; contentWithoutTime: string }; force: boolean }
+ {
+ user,
+ reason,
+ force
+ }: { user: BushUser; reason?: { duration: number | null; contentWithoutTime: string }; force: boolean }
): Promise<unknown> {
+ if (reason?.duration === null) reason.duration = 0;
const member = message.guild!.members.cache.get(user.id);
if (!member)
return await message.util.reply(
diff --git a/src/commands/moderation/role.ts b/src/commands/moderation/role.ts
index 69432ab..fd7b817 100644
--- a/src/commands/moderation/role.ts
+++ b/src/commands/moderation/role.ts
@@ -95,8 +95,14 @@ export default class RoleCommand extends BushCommand {
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 | null }
): Promise<unknown> {
+ if (duration === null) duration = 0;
if (
!message.member!.permissions.has('MANAGE_ROLES') &&
message.member!.id !== message.guild?.ownerId &&
diff --git a/src/commands/moderation/slowmode.ts b/src/commands/moderation/slowmode.ts
index 4b3a976..94e40ca 100644
--- a/src/commands/moderation/slowmode.ts
+++ b/src/commands/moderation/slowmode.ts
@@ -15,8 +15,7 @@ export default class SlowModeCommand extends BushCommand {
args: [
{
id: 'length',
- customType: Argument.union('duration', 'off', 'none', 'disable'),
- default: 0,
+ customType: Argument.union('duration', 'durationSeconds', 'off', 'none', 'disable'),
prompt: {
start: 'What would you like to set the slowmode to?',
retry: '{error} Please set the slowmode to a valid length.',
diff --git a/src/commands/moderation/unmute.ts b/src/commands/moderation/unmute.ts
index ee4bebe..680c7ba 100644
--- a/src/commands/moderation/unmute.ts
+++ b/src/commands/moderation/unmute.ts
@@ -7,7 +7,7 @@ export default class UnmuteCommand extends BushCommand {
category: 'moderation',
description: {
content: 'unmute a user.',
- usage: 'unmute <member> [reason] [duration]',
+ usage: 'unmute <member> [reason]',
examples: ['unmute 322862723090219008 1 day commands in #general']
},
args: [
diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts
index 48ba90d..1ac0ee9 100644
--- a/src/lib/extensions/discord-akairo/BushClient.ts
+++ b/src/lib/extensions/discord-akairo/BushClient.ts
@@ -26,6 +26,7 @@ import { abbreviatedNumberTypeCaster } from '../../../arguments/abbreviatedNumbe
import { contentWithDurationTypeCaster } from '../../../arguments/contentWithDuration';
import { discordEmojiTypeCaster } from '../../../arguments/discordEmoji';
import { durationTypeCaster } from '../../../arguments/duration';
+import { durationSecondsTypeCaster } from '../../../arguments/durationSeconds';
import { permissionTypeCaster } from '../../../arguments/permission';
import { roleWithDurationTypeCaster } from '../../../arguments/roleWithDuation';
import { snowflakeTypeCaster } from '../../../arguments/snowflake';
@@ -326,7 +327,8 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
snowflake: snowflakeTypeCaster,
discordEmoji: discordEmojiTypeCaster,
roleWithDuration: roleWithDurationTypeCaster,
- abbreviatedNumber: abbreviatedNumberTypeCaster
+ abbreviatedNumber: abbreviatedNumberTypeCaster,
+ durationSeconds: durationSecondsTypeCaster
});
// loads all the handlers
const loaders = {
diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts
index 5a71167..2345ac7 100644
--- a/src/lib/extensions/discord-akairo/BushClientUtil.ts
+++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts
@@ -1056,10 +1056,11 @@ export class BushClientUtil extends ClientUtil {
return array.map((a) => `${surroundChar1}${a}${surroundChar2 ?? surroundChar1}`);
}
- public parseDuration(content: string, remove = true): { duration: number; contentWithoutTime: string | null } {
+ public parseDuration(content: string, remove = true): { duration: number | null; contentWithoutTime: string | null } {
if (!content) return { duration: 0, contentWithoutTime: null };
- let duration = 0;
+ // eslint-disable-next-line prefer-const
+ let duration = null;
// Try to reduce false positives by requiring a space before the duration, this makes sure it still matches if it is
// in the beginning of the argument
let contentWithoutTime = ` ${content}`;
@@ -1067,8 +1068,8 @@ export class BushClientUtil extends ClientUtil {
for (const unit in BushConstants.TimeUnits) {
const regex = BushConstants.TimeUnits[unit].match;
const match = regex.exec(contentWithoutTime);
- const value = Number(match?.groups?.[unit] ?? 0);
- duration += value * BushConstants.TimeUnits[unit].value;
+ const value = Number(match?.groups?.[unit]);
+ if (!isNaN(value)) (duration as unknown as number) += value * BushConstants.TimeUnits[unit].value;
if (remove) contentWithoutTime = contentWithoutTime.replace(regex, '');
}