Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for default duration of mutes #216

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions backend/src/plugins/ModActions/functions/actualMuteUserCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export async function actualMuteUserCmd(
pp = msg.author;
}

const timeUntilUnmute = args.time && humanizeDuration(args.time);
const reason = args.reason ? formatReasonWithAttachments(args.reason, msg.attachments) : undefined;

let muteResult: MuteResult;
Expand Down Expand Up @@ -76,16 +75,16 @@ export async function actualMuteUserCmd(

// Confirm the action to the moderator
let response;
if (args.time) {
if (muteResult.timeUntilUnmute) {
if (muteResult.updatedExistingMute) {
response = asSingleLine(`
Updated **${user.username}#${user.discriminator}**'s
mute to ${timeUntilUnmute} (Case #${muteResult.case.case_number})
mute to ${muteResult.timeUntilUnmute} (Case #${muteResult.case.case_number})
`);
} else {
response = asSingleLine(`
Muted **${user.username}#${user.discriminator}**
for ${timeUntilUnmute} (Case #${muteResult.case.case_number})
for ${muteResult.timeUntilUnmute} (Case #${muteResult.case.case_number})
`);
}
} else {
Expand Down
1 change: 1 addition & 0 deletions backend/src/plugins/Mutes/MutesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const defaultOptions = {
mute_role: null,
move_to_voice_channel: null,
kick_from_voice_channel: false,
default_duration: null,

dm_on_mute: false,
dm_on_update: false,
Expand Down
11 changes: 9 additions & 2 deletions backend/src/plugins/Mutes/functions/muteUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
UserNotificationResult,
resolveMember,
UserNotificationMethod,
convertDelayStringToMS,
} from "../../../utils";
import { renderTemplate } from "../../../templateFormatter";
import { MemberOptions, TextChannel, User } from "eris";
Expand Down Expand Up @@ -37,8 +38,6 @@ export async function muteUser(
throw new RecoverablePluginError(ERRORS.NO_MUTE_ROLE_IN_CONFIG);
}

const timeUntilUnmute = muteTime ? humanizeDuration(muteTime) : "indefinite";

// No mod specified -> mark Zeppelin as the mod
if (!muteOptions.caseArgs?.modId) {
muteOptions.caseArgs = muteOptions.caseArgs ?? {};
Expand All @@ -54,6 +53,13 @@ export async function muteUser(
const member = await resolveMember(pluginData.client, pluginData.guild, user.id, true); // Grab the fresh member so we don't have stale role info
const config = await pluginData.config.getMatchingConfig({ member, userId });

muteTime = muteTime !== undefined
? muteTime
: config.default_duration
? convertDelayStringToMS(config.default_duration)!
: undefined;
Comment on lines +56 to +60
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
muteTime = muteTime !== undefined
? muteTime
: config.default_duration
? convertDelayStringToMS(config.default_duration)!
: undefined;
muteTime ??= config.default_duration
? convertDelayStringToMS(config.default_duration)!
: undefined;

const timeUntilUnmute = muteTime ? humanizeDuration(muteTime) : "indefinite";

let rolesToRestore: string[] = [];
if (member) {
const logs = pluginData.getPlugin(LogsPlugin);
Expand Down Expand Up @@ -245,6 +251,7 @@ export async function muteUser(

return {
case: theCase,
timeUntilUnmute,
notifyResult,
updatedExistingMute: !!existingMute,
};
Expand Down
4 changes: 3 additions & 1 deletion backend/src/plugins/Mutes/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as t from "io-ts";
import { tNullable, UserNotificationMethod, UserNotificationResult } from "../../utils";
import { tDelayString, tNullable, UserNotificationMethod, UserNotificationResult } from "../../utils";
import { Mute } from "../../data/entities/Mute";
import { Member } from "eris";
import { Case } from "../../data/entities/Case";
Expand All @@ -16,6 +16,7 @@ export const ConfigSchema = t.type({
mute_role: tNullable(t.string),
move_to_voice_channel: tNullable(t.string),
kick_from_voice_channel: t.boolean,
default_duration: tNullable(tDelayString),

dm_on_mute: t.boolean,
dm_on_update: t.boolean,
Expand Down Expand Up @@ -64,6 +65,7 @@ export interface IMuteWithDetails extends Mute {

export type MuteResult = {
case: Case;
timeUntilUnmute: string;
notifyResult: UserNotificationResult;
updatedExistingMute: boolean;
};
Expand Down