Skip to content

Commit 9ccbd89

Browse files
committed
Direct message -> DM
1 parent b32de19 commit 9ccbd89

5 files changed

Lines changed: 14 additions & 8 deletions

File tree

backend/src/bot/plugin/moderation/command/action/ban.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const banCommand = defineCommand({
2727
},
2828
dm: {
2929
type: OptionType.Flag,
30-
description: "Choose whether to notify the banned user with a direct message - overrides the configured default!",
30+
description: "Choose whether to notify the banned user with a DM (overrides the configured default).",
3131
name: ["dm", "d", "direct-message"],
3232
negativeName: ["no-dm", "nd", "no-direct-message"],
3333
},

backend/src/bot/plugin/moderation/command/action/kick.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const kickCommand = defineCommand({
2828
dm: {
2929
type: OptionType.Flag,
3030
name: ["dm", "d", "direct-message"],
31-
description: "Choose whether to notify the kicked user with a direct message - overrides the configured default!",
31+
description: "Choose whether to notify the kicked user with a DM (overrides the configured default).",
3232
negativeName: ["no-dm", "nd", "no-direct-message"],
3333
},
3434
},

backend/src/bot/plugin/moderation/command/action/timeout.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Permissions } from "oceanic.js";
12
import { humanizeDuration } from "../../../../../common/time.ts";
23
import { CaseType } from "../../../../../db/moderation/cases.ts";
34
import { escapeMarkdown } from "../../../../common/discord/markdown.ts";
@@ -10,7 +11,7 @@ import { moderationConfig } from "../../index.ts";
1011

1112
export const timeoutCommand = defineCommand({
1213
name: ["timeout", "mute", "chatmute"],
13-
description: "Prevent a member from chatting - or doing anything other than reading messages - in the server.",
14+
description: "Time out a member (only allow them to read messages).",
1415

1516
options: {
1617
user: {
@@ -34,7 +35,7 @@ export const timeoutCommand = defineCommand({
3435
},
3536
dm: {
3637
type: OptionType.Flag,
37-
description: "Choose whether to notify the affected user with a direct message - overrides the configured default!",
38+
description: "Choose whether to notify the timed out user with a DM (overrides the configured default).",
3839
name: ["dm", "d", "direct-message"],
3940
negativeName: ["no-dm", "nd", "no-direct-message"],
4041
}
@@ -59,6 +60,7 @@ export const timeoutCommand = defineCommand({
5960

6061
membersOnly: true,
6162

63+
canPerform: member => member.permissions.has(Permissions.ADMINISTRATOR),
6264
async perform(member, calculatedExpiry) {
6365
await context.guild.editMember(member.id, {
6466
communicationDisabledUntil: calculatedExpiry!.toISOString(),
@@ -78,7 +80,7 @@ export const timeoutCommand = defineCommand({
7880
if (successful.length === 1)
7981
await context.respond(`${icons.success} Timed out ${formatBulkSuccess(successful[0]!)}!`);
8082
else if (unsuccessful.length === 1)
81-
await context.respond(`${icons.error} Could not timeout ${formatBulkError(unsuccessful[0]!)}!`);
83+
await context.respond(`${icons.error} Could not time out ${formatBulkError(unsuccessful[0]!)}!`);
8284
} else {
8385
const successfulMessage = successful.map(item => `- ${formatBulkSuccess(item)}`).join("\n");
8486
const unsuccessfulMessage = unsuccessful.map(item => `- ${formatBulkError(item)}`).join("\n");

backend/src/bot/plugin/moderation/command/action/warn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const warnCommand = defineCommand({
2626
},
2727
dm: {
2828
type: OptionType.Flag,
29-
description: "Choose whether to notify the warned user with a direct message - overrides the configured default!",
29+
description: "Choose whether to notify the warned user with a DM (overrides the configured default).",
3030
name: ["dm", "d", "direct-message"],
3131
negativeName: ["no-dm", "nd", "no-direct-message"],
3232
},

backend/src/bot/plugin/moderation/helper/bulkAction.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type BulkAction =
88
(
99
{
1010
membersOnly: true;
11-
perform: (user: Member, calculatedExpiry: Date | undefined) => Promise<void> | void;
11+
perform: (member: Member, calculatedExpiry: Date | undefined) => Promise<void> | void;
1212
}
1313
| {
1414
membersOnly: false;
@@ -23,6 +23,7 @@ type BulkAction =
2323
directMessage?: CreateMessageOptions;
2424
duration?: number;
2525

26+
canPerform?(member: Member): Promise<boolean> | boolean;
2627
makeCase(options: Pick<CreateCaseOptions, "createdAt" | "expiresAt" | "actorID" | "targetID" | "dmDelivered">): CreateCaseOptions;
2728
};
2829

@@ -47,6 +48,9 @@ export async function doBulkAction(action: BulkAction): Promise<BulkResult> {
4748

4849
const members = await fetchMembersCached(action.guild, action.ids);
4950

51+
// eslint-disable-next-line @typescript-eslint/unbound-method
52+
action.canPerform ??= () => true;
53+
5054
for (const targetID of action.ids) {
5155
let target: Member | User;
5256
let dmDelivered = false;
@@ -64,7 +68,7 @@ export async function doBulkAction(action: BulkAction): Promise<BulkResult> {
6468
continue;
6569
}
6670

67-
if (!canModerate(action.guild.clientMember, target)) {
71+
if (!action.canPerform(target) || !canModerate(action.guild.clientMember, target)) {
6872
result.unsuccessful.push({
6973
error: "App lacks permission to moderate the user",
7074
user: target,

0 commit comments

Comments
 (0)