diff --git a/src/index.ts b/src/index.ts index 6a32644d..0386b71b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -74,6 +74,8 @@ import { AutoReactionsPlugin } from "./plugins/AutoReactionsPlugin"; import { PingableRolesPlugin } from "./plugins/PingableRolesPlugin"; import { SelfGrantableRolesPlugin } from "./plugins/SelfGrantableRolesPlugin"; import { RemindersPlugin } from "./plugins/Reminders"; +import { convertDelayStringToMS } from "./utils"; +import { CommandValueTypeError } from "knub/dist/commandUtils"; // Run latest database migrations logger.info("Running database migrations"); @@ -155,6 +157,17 @@ connect().then(async conn => { size: 30, threshold: 200, }, + + customArgumentTypes: { + delay(value) { + const result = convertDelayStringToMS(value); + if (result == null) { + throw new CommandValueTypeError(`Could not convert ${value} to a delay`); + } + + return result; + }, + }, }, }); diff --git a/src/plugins/ModActions.ts b/src/plugins/ModActions.ts index ae0ea773..8cad1c2d 100644 --- a/src/plugins/ModActions.ts +++ b/src/plugins/ModActions.ts @@ -429,11 +429,12 @@ export class ModActionsPlugin extends ZeppelinPlugin [time:string] [reason:string$]", { + @d.command("mute", " ", { + overloads: [" ", " [reason:string$]"], options: [{ name: "mod", type: "member" }], }) @d.permission("mute") - async muteCmd(msg: Message, args: { member: Member; time: string; reason: string; mod: Member }) { + async muteCmd(msg: Message, args: { member: Member; time?: number; reason?: string; mod: Member }) { // Make sure we're allowed to mute this member if (!this.canActOn(msg.member, args.member)) { msg.channel.createMessage(errorMessage("Cannot mute: insufficient permissions")); @@ -453,22 +454,14 @@ export class ModActionsPlugin extends ZeppelinPlugin assume it's actually part of the reason - args.reason = `${args.time} ${args.reason ? args.reason : ""}`.trim(); - } - + const timeUntilUnmute = args.time && humanizeDuration(args.time); const reason = this.formatReasonWithAttachments(args.reason, msg.attachments); // Apply "muted" role this.serverLogs.ignoreLog(LogType.MEMBER_ROLE_ADD, args.member.id); const mute: Mute = await this.actions.fire("mute", { member: args.member, - muteTime, + muteTime: args.time, }); if (!mute) { @@ -483,7 +476,7 @@ export class ModActionsPlugin extends ZeppelinPlugin [time:string] [reason:string$]", { + @d.command("unmute", " ", { + overloads: [" ", " [reason:string$]"], options: [{ name: "mod", type: "member" }], }) @d.permission("mute") - async unmuteCmd(msg: Message, args: any) { + async unmuteCmd(msg: Message, args: { member: Member; time?: number; reason?: string; mod?: Member }) { // Make sure we're allowed to mute this member if (!this.canActOn(msg.member, args.member)) { msg.channel.createMessage(errorMessage("Cannot unmute: insufficient permissions")); @@ -599,16 +593,10 @@ export class ModActionsPlugin extends ZeppelinPlugin assume it's actually part of the reason - args.reason = `${args.time} ${args.reason ? args.reason : ""}`.trim(); - } + const timeUntilUnmute = args.time && humanizeDuration(args.time); const reason = this.formatReasonWithAttachments(args.reason, msg.attachments); - const caseNote = unmuteTime ? `__[Scheduled unmute in ${timeUntilUnmute}]__ ${reason}` : reason; + const caseNote = args.time ? `__[Scheduled unmute in ${timeUntilUnmute}]__ ${reason}` : reason; // Create a case const createdCase = await this.actions.fire("createCase", { @@ -619,9 +607,9 @@ export class ModActionsPlugin extends ZeppelinPlugin