3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

ModActions: don't re-message on overlapping mute, update old case instead; allow specifying an unmute time

This commit is contained in:
Dragory 2018-08-05 00:58:03 +03:00
parent ea68512c7e
commit ff9db47c7a

View file

@ -343,6 +343,8 @@ export class ModActionsPlugin extends Plugin {
return; return;
} }
let messageSent = true;
// Convert mute time from e.g. "2h30m" to milliseconds // Convert mute time from e.g. "2h30m" to milliseconds
const muteTime = args.time ? convertDelayStringToMS(args.time) : null; const muteTime = args.time ? convertDelayStringToMS(args.time) : null;
const timeUntilUnmute = muteTime && humanizeDuration(muteTime); const timeUntilUnmute = muteTime && humanizeDuration(muteTime);
@ -354,21 +356,31 @@ export class ModActionsPlugin extends Plugin {
// 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);
this.muteMember(args.member, muteTime, args.reason); await this.muteMember(args.member, muteTime, args.reason);
// Create a case const mute = await this.mutes.findExistingMuteForUserId(args.member.id);
const caseId = await this.createCase( const hasOldCase = mute && mute.case_id != null;
args.member.id,
msg.author.id, if (hasOldCase) {
CaseType.Mute, if (args.reason) {
null, await this.createCaseNote(mute.case_id, msg.author.id, args.reason);
args.reason this.postCaseToCaseLog(mute.case_id);
); }
await this.mutes.setCaseId(args.member.id, caseId); } else {
// Create a case
const caseId = await this.createCase(
args.member.id,
msg.author.id,
CaseType.Mute,
null,
args.reason
);
await this.mutes.setCaseId(args.member.id, caseId);
}
// Message the user informing them of the mute // Message the user informing them of the mute
let messageSent = true; // Don't message them if we're updating an old mute
if (args.reason) { if (args.reason && !hasOldCase) {
const template = muteTime const template = muteTime
? this.configValue("timed_mute_message") ? this.configValue("timed_mute_message")
: this.configValue("mute_message"); : this.configValue("mute_message");
@ -409,7 +421,7 @@ export class ModActionsPlugin extends Plugin {
}); });
} }
@d.command("unmute", "<member:Member> [reason:string$]") @d.command("unmute", "<member:Member> [time:string] [reason:string$]")
@d.permission("mute") @d.permission("mute")
async unmuteCmd(msg: Message, args: any) { async unmuteCmd(msg: Message, args: any) {
if (!this.configValue("mute_role")) { if (!this.configValue("mute_role")) {
@ -430,15 +442,39 @@ export class ModActionsPlugin extends Plugin {
return; return;
} }
// Remove "muted" role // Convert unmute time from e.g. "2h30m" to milliseconds
this.serverLogs.ignoreLog(LogType.MEMBER_ROLE_REMOVE, args.member.id); const unmuteTime = args.time ? convertDelayStringToMS(args.time) : null;
await args.member.removeRole(this.configValue("mute_role"));
await this.mutes.clear(args.member.id);
// Confirm the action to the moderator if (unmuteTime == null && args.time) {
msg.channel.createMessage( // Invalid unmuteTime -> assume it's actually part of the reason
successMessage(`Unmuted **${args.member.user.username}#${args.member.user.discriminator}**`) args.reason = `${args.time} ${args.reason ? args.reason : ""}`.trim();
); }
if (unmuteTime) {
// If we have an unmute time, just update the old mute to expire in that time
const timeUntilUnmute = unmuteTime && humanizeDuration(unmuteTime);
this.mutes.addOrUpdateMute(args.member.id, unmuteTime);
args.reason = args.reason ? `Timed unmute: ${args.reason}` : "Timed unmute";
// Confirm the action to the moderator
msg.channel.createMessage(
successMessage(
`Unmuting **${args.member.user.username}#${
args.member.user.discriminator
}** in ${timeUntilUnmute}`
)
);
} else {
// Otherwise remove "muted" role immediately
this.serverLogs.ignoreLog(LogType.MEMBER_ROLE_REMOVE, args.member.id);
await args.member.removeRole(this.configValue("mute_role"));
await this.mutes.clear(args.member.id);
// Confirm the action to the moderator
msg.channel.createMessage(
successMessage(`Unmuted **${args.member.user.username}#${args.member.user.discriminator}**`)
);
}
// Create a case // Create a case
await this.createCase(args.member.id, msg.author.id, CaseType.Unmute, null, args.reason); await this.createCase(args.member.id, msg.author.id, CaseType.Unmute, null, args.reason);