aboutsummaryrefslogtreecommitdiff
path: root/src/commands/moderation
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-12-27 13:12:49 -0500
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-12-27 13:12:49 -0500
commite05f25f4b98cac3c2409cee9a664ab5ea6251467 (patch)
treef8e3dc4fde8f6deaa543b910acb9a725abbac999 /src/commands/moderation
parent84f246ebb5ddee984012d3043dcc67ffae806856 (diff)
downloadtanzanite-e05f25f4b98cac3c2409cee9a664ab5ea6251467.tar.gz
tanzanite-e05f25f4b98cac3c2409cee9a664ab5ea6251467.tar.bz2
tanzanite-e05f25f4b98cac3c2409cee9a664ab5ea6251467.zip
better typings and some other stuff
Diffstat (limited to 'src/commands/moderation')
-rw-r--r--src/commands/moderation/ban.ts18
-rw-r--r--src/commands/moderation/kick.ts4
-rw-r--r--src/commands/moderation/modlog.ts28
-rw-r--r--src/commands/moderation/mute.ts4
-rw-r--r--src/commands/moderation/purge.ts4
-rw-r--r--src/commands/moderation/removeReactionEmoji.ts9
-rw-r--r--src/commands/moderation/role.ts18
-rw-r--r--src/commands/moderation/slowmode.ts15
-rw-r--r--src/commands/moderation/unban.ts7
-rw-r--r--src/commands/moderation/unmute.ts7
-rw-r--r--src/commands/moderation/warn.ts7
11 files changed, 71 insertions, 50 deletions
diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts
index 506a7c3..c0375e0 100644
--- a/src/commands/moderation/ban.ts
+++ b/src/commands/moderation/ban.ts
@@ -1,5 +1,13 @@
-import { AllowedMentions, BushCommand, Moderation, type BushMessage, type BushSlashMessage } from '#lib';
-import { type Snowflake, type User } from 'discord.js';
+import {
+ AllowedMentions,
+ ArgType,
+ BushCommand,
+ Moderation,
+ OptionalArgType,
+ type BushMessage,
+ type BushSlashMessage
+} from '#lib';
+import { type User } from 'discord.js';
export default class BanCommand extends BushCommand {
public constructor() {
@@ -61,9 +69,9 @@ export default class BanCommand extends BushCommand {
public override async exec(
message: BushMessage | BushSlashMessage,
args: {
- user: User | Snowflake;
- reason: { duration: number | null; contentWithoutTime: string } | null;
- days: number | null;
+ user: ArgType<'user'> | ArgType<'snowflake'>;
+ reason: OptionalArgType<'contentWithDuration'>;
+ days: OptionalArgType<'integer'>;
force: boolean;
}
) {
diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts
index 9463154..b59b9f9 100644
--- a/src/commands/moderation/kick.ts
+++ b/src/commands/moderation/kick.ts
@@ -1,4 +1,4 @@
-import { AllowedMentions, BushCommand, Moderation, type BushMessage, type BushSlashMessage, type BushUser } from '#lib';
+import { AllowedMentions, ArgType, BushCommand, Moderation, type BushMessage, type BushSlashMessage } from '#lib';
export default class KickCommand extends BushCommand {
public constructor() {
@@ -46,7 +46,7 @@ export default class KickCommand extends BushCommand {
public override async exec(
message: BushMessage | BushSlashMessage,
- { user, reason, force }: { user: BushUser; reason?: string; force: boolean }
+ { user, reason, force }: { user: ArgType<'user'>; reason: ArgType<'string'>; force: boolean }
) {
const member = await message.guild!.members.fetch(user.id);
diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts
index 0f2d33c..be6e6b4 100644
--- a/src/commands/moderation/modlog.ts
+++ b/src/commands/moderation/modlog.ts
@@ -1,4 +1,4 @@
-import { BushCommand, ButtonPaginator, ModLog, type BushMessage, type BushSlashMessage, type BushUser } from '#lib';
+import { ArgType, BushCommand, ButtonPaginator, ModLog, type BushMessage, type BushSlashMessage } from '#lib';
import { MessageEmbed, User } from 'discord.js';
export default class ModlogCommand extends BushCommand {
@@ -35,21 +35,9 @@ export default class ModlogCommand extends BushCommand {
});
}
- static 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.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)}`);
- modLog.push(`**Reason**: ${trim(log.reason ?? 'No Reason Specified.')}`);
- modLog.push(`**Date**: ${util.timestamp(log.createdAt)}`);
- if (log.evidence) modLog.push(`**Evidence:** ${trim(log.evidence)}`);
- return modLog.join(`\n`);
- }
-
public override async exec(
message: BushMessage | BushSlashMessage,
- { search, hidden }: { search: BushUser | string; hidden: boolean }
+ { search, hidden }: { search: ArgType<'user'> | string; hidden: boolean }
) {
const foundUser = search instanceof User ? search : await util.resolveUserAsync(search);
if (foundUser) {
@@ -90,4 +78,16 @@ export default class ModlogCommand extends BushCommand {
return await ButtonPaginator.send(message, [embed]);
}
}
+
+ public static 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.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)}`);
+ modLog.push(`**Reason**: ${trim(log.reason ?? 'No Reason Specified.')}`);
+ modLog.push(`**Date**: ${util.timestamp(log.createdAt)}`);
+ if (log.evidence) modLog.push(`**Evidence:** ${trim(log.evidence)}`);
+ return modLog.join(`\n`);
+ }
}
diff --git a/src/commands/moderation/mute.ts b/src/commands/moderation/mute.ts
index c7091b3..2c0a1e8 100644
--- a/src/commands/moderation/mute.ts
+++ b/src/commands/moderation/mute.ts
@@ -1,4 +1,4 @@
-import { AllowedMentions, BushCommand, Moderation, type BushMessage, type BushSlashMessage, type BushUser } from '#lib';
+import { AllowedMentions, ArgType, BushCommand, Moderation, type BushMessage, type BushSlashMessage } from '#lib';
export default class MuteCommand extends BushCommand {
public constructor() {
@@ -47,7 +47,7 @@ export default class MuteCommand extends BushCommand {
public override async exec(
message: BushMessage | BushSlashMessage,
- args: { user: BushUser; reason?: { duration: number | null; contentWithoutTime: string } | string; force: boolean }
+ args: { user: ArgType<'user'>; reason?: ArgType<'contentWithDuration'> | string; force: boolean }
) {
const reason: { duration: number | null; contentWithoutTime: string | null } = args.reason
? typeof args.reason === 'string'
diff --git a/src/commands/moderation/purge.ts b/src/commands/moderation/purge.ts
index f039046..7a25a0d 100644
--- a/src/commands/moderation/purge.ts
+++ b/src/commands/moderation/purge.ts
@@ -1,4 +1,4 @@
-import { BushCommand, BushMessage, BushUser } from '#lib';
+import { ArgType, BushCommand, BushMessage } from '#lib';
import { Collection, type Snowflake } from 'discord.js';
export default class PurgeCommand extends BushCommand {
@@ -47,7 +47,7 @@ export default class PurgeCommand extends BushCommand {
});
}
- public override async exec(message: BushMessage, args: { amount: number; bot: boolean; user: BushUser }) {
+ public override async exec(message: BushMessage, args: { amount: number; bot: boolean; user: ArgType<'user'> }) {
if (message.channel.type === 'DM') return message.util.reply(`${util.emojis.error} You cannot run this command in dms.`);
if (args.amount > 100 || args.amount < 1) return message.util.reply(`${util.emojis.error} `);
diff --git a/src/commands/moderation/removeReactionEmoji.ts b/src/commands/moderation/removeReactionEmoji.ts
index 4ada9d5..bede2cf 100644
--- a/src/commands/moderation/removeReactionEmoji.ts
+++ b/src/commands/moderation/removeReactionEmoji.ts
@@ -1,5 +1,5 @@
-import { BushCommand, type BushMessage } from '#lib';
-import { Message, type Emoji, type Snowflake } from 'discord.js';
+import { ArgType, BushCommand, type BushMessage } from '#lib';
+import { Message, type Emoji } from 'discord.js';
export default class RemoveReactionEmojiCommand extends BushCommand {
public constructor() {
@@ -36,7 +36,10 @@ export default class RemoveReactionEmojiCommand extends BushCommand {
});
}
- public override async exec(message: BushMessage, args: { message: BushMessage | Snowflake; emoji: Emoji | Snowflake }) {
+ public override async exec(
+ message: BushMessage,
+ args: { message: ArgType<'guildMessage'> | string; emoji: ArgType<'emoji'> | ArgType<'snowflake'> }
+ ) {
const resolvedMessage = args.message instanceof Message ? args.message : await message.channel.messages.fetch(args.message);
const id = !(['string'] as const).includes(typeof args.emoji);
diff --git a/src/commands/moderation/role.ts b/src/commands/moderation/role.ts
index 689ef1e..651762b 100644
--- a/src/commands/moderation/role.ts
+++ b/src/commands/moderation/role.ts
@@ -1,4 +1,4 @@
-import { AllowedMentions, BushCommand, type BushGuildMember, type BushMessage, type BushRole, type BushSlashMessage } from '#lib';
+import { AllowedMentions, ArgType, BushCommand, OptionalArgType, type BushMessage, type BushSlashMessage } from '#lib';
import { type ArgumentOptions, type Flag } from 'discord-akairo';
import { Snowflake } from 'discord.js';
@@ -98,12 +98,24 @@ export default class RoleCommand extends BushCommand {
match: 'flag'
};
- return { action, member: member, role: (_role as any).role ?? _role, duration: (_role as any).duration, force };
+ return {
+ action,
+ member: member,
+ role: (_role as ArgType<'roleWithDuration'>).role ?? _role,
+ duration: (_role as ArgType<'roleWithDuration'>).duration,
+ force
+ };
}
public override async exec(
message: BushMessage | BushSlashMessage,
- args: { action: 'add' | 'remove'; member: BushGuildMember; role: BushRole; duration?: number | null; force?: boolean }
+ args: {
+ action: 'add' | 'remove';
+ member: ArgType<'member'>;
+ role: ArgType<'role'>;
+ duration?: OptionalArgType<'duration'>;
+ force?: boolean;
+ }
) {
if (!args.role) return await message.util.reply(`${util.emojis.error} You must specify a role.`);
if (args.duration === null) args.duration = 0;
diff --git a/src/commands/moderation/slowmode.ts b/src/commands/moderation/slowmode.ts
index f4ab822..d38b266 100644
--- a/src/commands/moderation/slowmode.ts
+++ b/src/commands/moderation/slowmode.ts
@@ -1,13 +1,6 @@
-import {
- BushCommand,
- type BushMessage,
- type BushNewsChannel,
- type BushSlashMessage,
- type BushTextChannel,
- type BushThreadChannel
-} from '#lib';
+import { ArgType, BushCommand, type BushMessage, type BushSlashMessage } from '#lib';
import { Argument } from 'discord-akairo';
-import { TextChannel, ThreadChannel, type NewsChannel } from 'discord.js';
+import { TextChannel, ThreadChannel } from 'discord.js';
export default class SlowModeCommand extends BushCommand {
public constructor() {
@@ -52,8 +45,8 @@ export default class SlowModeCommand extends BushCommand {
length,
channel
}: {
- length: number | 'off' | 'none' | 'disable' | null;
- channel: TextChannel | ThreadChannel | BushTextChannel | BushNewsChannel | BushThreadChannel | NewsChannel;
+ length: ArgType<'duration'> | ArgType<'durationSeconds'> | 'off' | 'none' | 'disable' | null;
+ channel: ArgType<'channel'>;
}
) {
if (message.channel!.type === 'DM')
diff --git a/src/commands/moderation/unban.ts b/src/commands/moderation/unban.ts
index 8444801..dbbb9a5 100644
--- a/src/commands/moderation/unban.ts
+++ b/src/commands/moderation/unban.ts
@@ -1,4 +1,4 @@
-import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage, type BushUser } from '#lib';
+import { AllowedMentions, ArgType, BushCommand, OptionalArgType, type BushMessage, type BushSlashMessage } from '#lib';
export default class UnbanCommand extends BushCommand {
public constructor() {
@@ -34,7 +34,10 @@ export default class UnbanCommand extends BushCommand {
userPermissions: ['BAN_MEMBERS']
});
}
- public override async exec(message: BushMessage | BushSlashMessage, { user, reason }: { user: BushUser; reason?: string }) {
+ public override async exec(
+ message: BushMessage | BushSlashMessage,
+ { user, reason }: { user: ArgType<'user'>; reason: OptionalArgType<'string'> }
+ ) {
const responseCode = await message.guild!.bushUnban({
user,
moderator: message.author,
diff --git a/src/commands/moderation/unmute.ts b/src/commands/moderation/unmute.ts
index 0c59b1f..d36a5db 100644
--- a/src/commands/moderation/unmute.ts
+++ b/src/commands/moderation/unmute.ts
@@ -1,11 +1,12 @@
import {
AllowedMentions,
+ ArgType,
BushCommand,
Moderation,
+ OptionalArgType,
type BushGuildMember,
type BushMessage,
- type BushSlashMessage,
- type BushUser
+ type BushSlashMessage
} from '#lib';
export default class UnmuteCommand extends BushCommand {
@@ -55,7 +56,7 @@ export default class UnmuteCommand extends BushCommand {
public override async exec(
message: BushMessage | BushSlashMessage,
- { user, reason, force }: { user: BushUser; reason?: string; force: boolean }
+ { user, reason, force }: { user: ArgType<'user'>; reason: OptionalArgType<'string'>; force: boolean }
) {
const error = util.emojis.error;
const member = message.guild!.members.cache.get(user.id) as BushGuildMember;
diff --git a/src/commands/moderation/warn.ts b/src/commands/moderation/warn.ts
index 2212548..95e409d 100644
--- a/src/commands/moderation/warn.ts
+++ b/src/commands/moderation/warn.ts
@@ -1,11 +1,12 @@
import {
AllowedMentions,
+ ArgType,
BushCommand,
Moderation,
+ OptionalArgType,
type BushGuildMember,
type BushMessage,
- type BushSlashMessage,
- type BushUser
+ type BushSlashMessage
} from '#lib';
export default class WarnCommand extends BushCommand {
@@ -54,7 +55,7 @@ export default class WarnCommand extends BushCommand {
public override async exec(
message: BushMessage | BushSlashMessage,
- { user, reason, force }: { user: BushUser; reason: string; force: boolean }
+ { user, reason, force }: { user: ArgType<'user'>; reason: OptionalArgType<'string'>; force?: boolean }
) {
const member = message.guild!.members.cache.get(user.id) as BushGuildMember;
if (!member) return message.util.reply(`${util.emojis.error} I cannot warn users that are not in the server.`);