Refactor moderation actions to include channel and source metadata

- Updated moderation action functions to include `channelId` and `source` in the metadata for better tracking of actions.
- Introduced an `auditFrom` function to streamline the addition of audit information across various commands.
- Removed `prisma/migrations` from .gitignore to ensure migration files are tracked.
- Enhanced the `CreateCaseInput` type to accommodate new metadata structure.
This commit is contained in:
smueller
2026-07-22 11:28:43 +02:00
parent 878478e4fc
commit 405b70bdfc
7 changed files with 140 additions and 8 deletions

View File

@@ -18,6 +18,13 @@ function reasonFrom(i: ChatInputCommandInteraction, locale: 'de' | 'en'): string
return i.options.getString('reason') ?? t(locale, 'moderation.reason.none');
}
function auditFrom(interaction: ChatInputCommandInteraction) {
return {
channelId: interaction.channelId ?? undefined,
source: 'slash_command' as const
};
}
async function ensureMod(
interaction: ChatInputCommandInteraction,
permission: bigint,
@@ -70,6 +77,7 @@ const unbanCommand: SlashCommand = {
guildId: interaction.guildId!,
targetUserId: userId,
moderatorId: interaction.user.id,
...auditFrom(interaction),
action: 'UNBAN',
reason
});
@@ -94,6 +102,7 @@ const kickCommand: SlashCommand = {
guildId: interaction.guildId!,
targetUserId: user.id,
moderatorId: interaction.user.id,
...auditFrom(interaction),
action: 'KICK',
reason
});
@@ -122,6 +131,7 @@ const timeoutCommand: SlashCommand = {
guildId: interaction.guildId!,
targetUserId: user.id,
moderatorId: interaction.user.id,
...auditFrom(interaction),
action: 'TIMEOUT',
reason,
metadata: { durationMs: duration }
@@ -147,6 +157,7 @@ const untimeoutCommand: SlashCommand = {
guildId: interaction.guildId!,
targetUserId: user.id,
moderatorId: interaction.user.id,
...auditFrom(interaction),
action: 'UN_TIMEOUT',
reason
});
@@ -369,6 +380,7 @@ const warnCommand: SlashCommand = {
guildId: interaction.guildId!,
targetUserId: user.id,
moderatorId: interaction.user.id,
...auditFrom(interaction),
action: 'WARN_CLEAR',
reason: 'Warnings cleared'
});
@@ -446,6 +458,7 @@ const slowmodeCommand: SlashCommand = {
guildId: interaction.guildId!,
targetUserId: interaction.user.id,
moderatorId: interaction.user.id,
...auditFrom(interaction),
action: 'SLOWMODE',
reason: `Set slowmode to ${seconds}s`
});
@@ -467,6 +480,7 @@ const lockCommand: SlashCommand = {
guildId: interaction.guildId!,
targetUserId: interaction.user.id,
moderatorId: interaction.user.id,
...auditFrom(interaction),
action: 'LOCK',
reason: 'Channel locked'
});
@@ -488,6 +502,7 @@ const unlockCommand: SlashCommand = {
guildId: interaction.guildId!,
targetUserId: interaction.user.id,
moderatorId: interaction.user.id,
...auditFrom(interaction),
action: 'UNLOCK',
reason: 'Channel unlocked'
});