Skip to content
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
6 changes: 5 additions & 1 deletion backend/src/plugins/Cases/functions/getCaseEmbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ export async function getCaseEmbed(
const createdAtWithTz = requestMemberId
? await timeAndDate.inMemberTz(requestMemberId, createdAt)
: timeAndDate.inGuildTz(createdAt);
const createdAtTs = Math.ceil(createdAt.valueOf() / 1000);
const createdAtRelative = `<t:${createdAtTs}:R>`;

const embed: any = {
title: `${actionTypeStr} - Case #${theCase.case_number}`,
footer: {
text: `Case created on ${createdAtWithTz.format(timeAndDate.getDateFormat("pretty_datetime"))}`,
text: `Case created on ${createdAtWithTz.format(
timeAndDate.getDateFormat("pretty_datetime"),
)} (${createdAtRelative})`,
},
fields: [
{
Expand Down
23 changes: 21 additions & 2 deletions backend/src/plugins/ModActions/commands/ban/actualBanCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,25 @@ export async function actualBanCmd(
}

// Create a new case for the updated ban since we never stored the old case id and log the action
const expiryTimestamp = time && time > 0 ? Math.ceil((Date.now() + time) / 1000) : null;
const expiryRelative = expiryTimestamp ? `<t:${expiryTimestamp}:R>` : null;
const noteDetails: string[] = [];
if (time && time > 0) {
noteDetails.push(`Ban updated to ${humanizeDuration(time)}`);
if (expiryRelative) {
noteDetails.push(`Expires ${expiryRelative}`);
}
} else {
noteDetails.push("Ban updated to indefinite");
}

const casesPlugin = pluginData.getPlugin(CasesPlugin);
const createdCase = await casesPlugin.createCase({
modId: mod.id,
type: CaseTypes.Ban,
userId: user.id,
reason: formattedReason,
noteDetails: [`Ban updated to ${time ? humanizeDuration(time) : "indefinite"}`],
noteDetails,
});
if (time) {
pluginData.getPlugin(LogsPlugin).logMemberTimedBan({
Expand All @@ -124,7 +136,7 @@ export async function actualBanCmd(

pluginData.state.common.sendSuccessMessage(
context,
`Ban updated to ${time ? "expire in " + humanizeDuration(time) + " from now" : "indefinite"}`,
`Ban updated to ${time && expiryRelative ? `expire ${expiryRelative}` : "indefinite"}`,
);
lock.unlock();
return;
Expand Down Expand Up @@ -171,6 +183,9 @@ export async function actualBanCmd(
return;
}

const banExpiryTimestamp = time && time > 0 ? Math.ceil((Date.now() + time) / 1000) : null;
const banExpiryRelative = banExpiryTimestamp ? `<t:${banExpiryTimestamp}:R>` : null;

let forTime = "";
if (time && time > 0) {
forTime = `for ${humanizeDuration(time)} `;
Expand All @@ -185,6 +200,10 @@ export async function actualBanCmd(
response = `Member forcebanned ${forTime}(Case #${banResult.case.case_number})`;
}

if (banExpiryRelative) {
response += ` ⏰ ${banExpiryRelative}`;
}

lock.unlock();
pluginData.state.common.sendSuccessMessage(context, response);
}
17 changes: 14 additions & 3 deletions backend/src/plugins/ModActions/functions/banUserId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ export async function banUserId(

const tempbanLock = await pluginData.locks.acquire(`tempban-${user.id}`);
const existingTempban = await pluginData.state.tempbans.findExistingTempbanForUserId(user.id);
const banExpiresAt = banTime && banTime > 0 ? Date.now() + banTime : null;
const banExpiryTimestamp = banExpiresAt ? Math.ceil(banExpiresAt / 1000) : null;
const banExpiryRelative = banExpiryTimestamp ? `<t:${banExpiryTimestamp}:R>` : null;
if (banTime && banTime > 0) {
const selfId = pluginData.client.user!.id;
if (existingTempban) {
Expand All @@ -151,9 +154,17 @@ export async function banUserId(

const noteDetails: string[] = [];
const timeUntilUnban = banTime ? humanizeDuration(banTime) : "indefinite";
const timeDetails = `Banned ${banTime ? `for ${timeUntilUnban}` : "indefinitely"}`;
if (notifyResult.text) noteDetails.push(ucfirst(notifyResult.text));
noteDetails.push(timeDetails);
if (notifyResult.text) {
noteDetails.push(ucfirst(notifyResult.text));
}
if (banTime && banTime > 0) {
noteDetails.push(`Banned for ${timeUntilUnban}`);
if (banExpiryRelative) {
noteDetails.push(`Expires ${banExpiryRelative}`);
}
} else {
noteDetails.push("Banned indefinitely");
}

const createdCase = await casesPlugin.createCase({
...(banOptions.caseArgs || {}),
Expand Down
10 changes: 4 additions & 6 deletions backend/src/plugins/Mutes/commands/MutesCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
} from "discord.js";
import moment from "moment-timezone";
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
import { humanizeDurationShort } from "../../../humanizeDuration.js";

Check warning on line 11 in backend/src/plugins/Mutes/commands/MutesCmd.ts

View workflow job for this annotation

GitHub Actions / build

'humanizeDurationShort' is defined but never used
import { getBaseUrl } from "../../../pluginUtils.js";
import { DBDateFormat, MINUTES, renderUsername, resolveMember } from "../../../utils.js";
import { IMuteWithDetails, mutesCmd } from "../types.js";
Expand Down Expand Up @@ -130,16 +130,14 @@
let line = `<@!${mute.user_id}> (**${username}**, \`${mute.user_id}\`) 📋 ${caseName}`;

if (mute.expires_at) {
const timeUntilExpiry = moment.utc().diff(moment.utc(mute.expires_at, DBDateFormat));
const humanizedTime = humanizeDurationShort(timeUntilExpiry, { largest: 2, round: true });
line += ` ⏰ Expires in ${humanizedTime}`;
const expiresAtTs = Math.ceil(moment.utc(mute.expires_at).valueOf() / 1000);
line += ` ⏰ Expires <t:${expiresAtTs}:R>`;
} else {
line += ` ⏰ Indefinite`;
}

const timeFromMute = moment.utc(mute.created_at, DBDateFormat).diff(moment.utc());
const humanizedTimeFromMute = humanizeDurationShort(timeFromMute, { largest: 2, round: true });
line += ` 🕒 Muted ${humanizedTimeFromMute} ago`;
const mutedAtTs = Math.ceil(moment.utc(mute.created_at).valueOf() / 1000);
line += ` 🕒 Muted <t:${mutedAtTs}:R>`;

if (mute.banned) {
line += ` 🔨 Banned`;
Expand Down
22 changes: 20 additions & 2 deletions backend/src/plugins/Mutes/functions/muteUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export async function muteUser(
const muteType = getDefaultMuteType(pluginData);
const muteExpiresAt = muteTime ? Date.now() + muteTime : null;
const timeoutUntil = getTimeoutExpiryTime(muteExpiresAt);
const muteExpiryTimestamp = muteExpiresAt ? Math.ceil(muteExpiresAt / 1000) : null;
const muteExpiryRelative = muteExpiryTimestamp ? `<t:${muteExpiryTimestamp}:R>` : null;

// No mod specified -> mark Zeppelin as the mod
if (!muteOptions.caseArgs?.modId) {
Expand Down Expand Up @@ -245,7 +247,15 @@ export async function muteUser(

if (theCase) {
// Update old case
const noteDetails = [`Mute updated to ${muteTime ? timeUntilUnmuteStr : "indefinite"}`];
const noteDetails: string[] = [];
if (muteTime) {
noteDetails.push(`Mute updated to ${timeUntilUnmuteStr}`);
if (muteExpiryRelative) {
noteDetails.push(`Expires ${muteExpiryRelative}`);
}
} else {
noteDetails.push("Mute updated to indefinite");
}
const reasons = reason ? [reason] : [""]; // Empty string so that there is a case update even without reason

if (muteOptions.caseArgs?.extraNotes) {
Expand All @@ -263,7 +273,15 @@ export async function muteUser(
}
} else {
// Create new case
const noteDetails = [`Muted ${muteTime ? `for ${timeUntilUnmuteStr}` : "indefinitely"}`];
const noteDetails: string[] = [];
if (muteTime) {
noteDetails.push(`Muted for ${timeUntilUnmuteStr}`);
if (muteExpiryRelative) {
noteDetails.push(`Expires ${muteExpiryRelative}`);
}
} else {
noteDetails.push("Muted indefinitely");
}
if (notifyResult.text) {
noteDetails.push(ucfirst(notifyResult.text));
}
Expand Down
Loading