Fix quotation marks in !mute and !unmute arguments
This commit is contained in:
parent
6e1ef12bce
commit
8e2808d42c
2 changed files with 30 additions and 29 deletions
13
src/index.ts
13
src/index.ts
|
@ -74,6 +74,8 @@ import { AutoReactionsPlugin } from "./plugins/AutoReactionsPlugin";
|
||||||
import { PingableRolesPlugin } from "./plugins/PingableRolesPlugin";
|
import { PingableRolesPlugin } from "./plugins/PingableRolesPlugin";
|
||||||
import { SelfGrantableRolesPlugin } from "./plugins/SelfGrantableRolesPlugin";
|
import { SelfGrantableRolesPlugin } from "./plugins/SelfGrantableRolesPlugin";
|
||||||
import { RemindersPlugin } from "./plugins/Reminders";
|
import { RemindersPlugin } from "./plugins/Reminders";
|
||||||
|
import { convertDelayStringToMS } from "./utils";
|
||||||
|
import { CommandValueTypeError } from "knub/dist/commandUtils";
|
||||||
|
|
||||||
// Run latest database migrations
|
// Run latest database migrations
|
||||||
logger.info("Running database migrations");
|
logger.info("Running database migrations");
|
||||||
|
@ -155,6 +157,17 @@ connect().then(async conn => {
|
||||||
size: 30,
|
size: 30,
|
||||||
threshold: 200,
|
threshold: 200,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
customArgumentTypes: {
|
||||||
|
delay(value) {
|
||||||
|
const result = convertDelayStringToMS(value);
|
||||||
|
if (result == null) {
|
||||||
|
throw new CommandValueTypeError(`Could not convert ${value} to a delay`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -429,11 +429,12 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@d.command("mute", "<member:Member> [time:string] [reason:string$]", {
|
@d.command("mute", "<member:Member> <time:delay> <reason:string$>", {
|
||||||
|
overloads: ["<member:Member> <time:delay>", "<member:Member> [reason:string$]"],
|
||||||
options: [{ name: "mod", type: "member" }],
|
options: [{ name: "mod", type: "member" }],
|
||||||
})
|
})
|
||||||
@d.permission("mute")
|
@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
|
// Make sure we're allowed to mute this member
|
||||||
if (!this.canActOn(msg.member, args.member)) {
|
if (!this.canActOn(msg.member, args.member)) {
|
||||||
msg.channel.createMessage(errorMessage("Cannot mute: insufficient permissions"));
|
msg.channel.createMessage(errorMessage("Cannot mute: insufficient permissions"));
|
||||||
|
@ -453,22 +454,14 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
|
||||||
|
|
||||||
let userMessageResult: IMessageResult = { status: MessageResultStatus.Ignored };
|
let userMessageResult: IMessageResult = { status: MessageResultStatus.Ignored };
|
||||||
|
|
||||||
// Convert mute time from e.g. "2h30m" to milliseconds
|
const timeUntilUnmute = args.time && humanizeDuration(args.time);
|
||||||
const muteTime = args.time ? convertDelayStringToMS(args.time) : null;
|
|
||||||
const timeUntilUnmute = muteTime && humanizeDuration(muteTime);
|
|
||||||
|
|
||||||
if (muteTime == null && args.time) {
|
|
||||||
// Invalid muteTime -> assume it's actually part of the reason
|
|
||||||
args.reason = `${args.time} ${args.reason ? args.reason : ""}`.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
const reason = this.formatReasonWithAttachments(args.reason, msg.attachments);
|
const reason = this.formatReasonWithAttachments(args.reason, msg.attachments);
|
||||||
|
|
||||||
// Apply "muted" role
|
// Apply "muted" role
|
||||||
this.serverLogs.ignoreLog(LogType.MEMBER_ROLE_ADD, args.member.id);
|
this.serverLogs.ignoreLog(LogType.MEMBER_ROLE_ADD, args.member.id);
|
||||||
const mute: Mute = await this.actions.fire("mute", {
|
const mute: Mute = await this.actions.fire("mute", {
|
||||||
member: args.member,
|
member: args.member,
|
||||||
muteTime,
|
muteTime: args.time,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!mute) {
|
if (!mute) {
|
||||||
|
@ -483,7 +476,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
|
||||||
if (hasOldCase) {
|
if (hasOldCase) {
|
||||||
// Update old case
|
// Update old case
|
||||||
theCase = await this.cases.find(mute.case_id);
|
theCase = await this.cases.find(mute.case_id);
|
||||||
const caseNote = `__[Mute updated to ${muteTime ? timeUntilUnmute : "indefinite"}]__ ${reason}`.trim();
|
const caseNote = `__[Mute updated to ${args.time ? timeUntilUnmute : "indefinite"}]__ ${reason}`.trim();
|
||||||
await this.actions.fire("createCaseNote", {
|
await this.actions.fire("createCaseNote", {
|
||||||
caseId: mute.case_id,
|
caseId: mute.case_id,
|
||||||
modId: mod.id,
|
modId: mod.id,
|
||||||
|
@ -491,7 +484,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Create new case
|
// Create new case
|
||||||
const caseNote = `__[Muted ${muteTime ? `for ${timeUntilUnmute}` : "indefinitely"}]__ ${reason}`.trim();
|
const caseNote = `__[Muted ${args.time ? `for ${timeUntilUnmute}` : "indefinitely"}]__ ${reason}`.trim();
|
||||||
theCase = await this.actions.fire("createCase", {
|
theCase = await this.actions.fire("createCase", {
|
||||||
userId: args.member.id,
|
userId: args.member.id,
|
||||||
modId: mod.id,
|
modId: mod.id,
|
||||||
|
@ -507,7 +500,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
|
||||||
// Message the user informing them of the mute
|
// Message the user informing them of the mute
|
||||||
// Don't message them if we're updating an old mute
|
// Don't message them if we're updating an old mute
|
||||||
if (reason && !hasOldCase) {
|
if (reason && !hasOldCase) {
|
||||||
const template = muteTime ? config.timed_mute_message : config.mute_message;
|
const template = args.time ? config.timed_mute_message : config.mute_message;
|
||||||
|
|
||||||
const muteMessage = await renderTemplate(template, {
|
const muteMessage = await renderTemplate(template, {
|
||||||
guildName: this.guild.name,
|
guildName: this.guild.name,
|
||||||
|
@ -525,7 +518,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
|
||||||
|
|
||||||
// Confirm the action to the moderator
|
// Confirm the action to the moderator
|
||||||
let response;
|
let response;
|
||||||
if (muteTime) {
|
if (args.time) {
|
||||||
if (hasOldCase) {
|
if (hasOldCase) {
|
||||||
response = asSingleLine(`
|
response = asSingleLine(`
|
||||||
Updated **${args.member.user.username}#${args.member.user.discriminator}**'s
|
Updated **${args.member.user.username}#${args.member.user.discriminator}**'s
|
||||||
|
@ -555,7 +548,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
|
||||||
msg.channel.createMessage(successMessage(response));
|
msg.channel.createMessage(successMessage(response));
|
||||||
|
|
||||||
// Log the action
|
// Log the action
|
||||||
if (muteTime) {
|
if (args.time) {
|
||||||
this.serverLogs.log(LogType.MEMBER_TIMED_MUTE, {
|
this.serverLogs.log(LogType.MEMBER_TIMED_MUTE, {
|
||||||
mod: stripObjectToScalars(mod.user),
|
mod: stripObjectToScalars(mod.user),
|
||||||
member: stripObjectToScalars(args.member, ["user"]),
|
member: stripObjectToScalars(args.member, ["user"]),
|
||||||
|
@ -569,11 +562,12 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@d.command("unmute", "<member:Member> [time:string] [reason:string$]", {
|
@d.command("unmute", "<member:Member> <time:delay> <reason:string$>", {
|
||||||
|
overloads: ["<member:Member> <time:delay>", "<member:Member> [reason:string$]"],
|
||||||
options: [{ name: "mod", type: "member" }],
|
options: [{ name: "mod", type: "member" }],
|
||||||
})
|
})
|
||||||
@d.permission("mute")
|
@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
|
// Make sure we're allowed to mute this member
|
||||||
if (!this.canActOn(msg.member, args.member)) {
|
if (!this.canActOn(msg.member, args.member)) {
|
||||||
msg.channel.createMessage(errorMessage("Cannot unmute: insufficient permissions"));
|
msg.channel.createMessage(errorMessage("Cannot unmute: insufficient permissions"));
|
||||||
|
@ -599,16 +593,10 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert unmute time from e.g. "2h30m" to milliseconds
|
// Convert unmute time from e.g. "2h30m" to milliseconds
|
||||||
const unmuteTime = args.time ? convertDelayStringToMS(args.time) : null;
|
const timeUntilUnmute = args.time && humanizeDuration(args.time);
|
||||||
const timeUntilUnmute = unmuteTime && humanizeDuration(unmuteTime);
|
|
||||||
|
|
||||||
if (unmuteTime == null && args.time) {
|
|
||||||
// Invalid unmuteTime -> assume it's actually part of the reason
|
|
||||||
args.reason = `${args.time} ${args.reason ? args.reason : ""}`.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
const reason = this.formatReasonWithAttachments(args.reason, msg.attachments);
|
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
|
// Create a case
|
||||||
const createdCase = await this.actions.fire("createCase", {
|
const createdCase = await this.actions.fire("createCase", {
|
||||||
|
@ -619,9 +607,9 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
|
||||||
ppId: mod.id !== msg.author.id ? msg.author.id : null,
|
ppId: mod.id !== msg.author.id ? msg.author.id : null,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (unmuteTime) {
|
if (args.time) {
|
||||||
// If we have an unmute time, just update the old mute to expire in that time
|
// If we have an unmute time, just update the old mute to expire in that time
|
||||||
await this.actions.fire("unmute", { member: args.member, unmuteTime });
|
await this.actions.fire("unmute", { member: args.member, unmuteTime: args.time });
|
||||||
|
|
||||||
// Confirm the action to the moderator
|
// Confirm the action to the moderator
|
||||||
msg.channel.createMessage(
|
msg.channel.createMessage(
|
||||||
|
|
Loading…
Add table
Reference in a new issue