generated from nhcarrigan/template
feat: rewrite as moderation bot (#11)
## Summary - Replaces the old AI companion bot with a full Discord moderation system - Adds 8 slash commands: `warn`, `mute`, `unmute`, `kick`, `softban`, `ban`, `unban`, `prune` - Adds logging for member join/leave, activity (messages, threads, voice), and moderation actions - Audit log integration captures manual bans, kicks, timeouts, and unbans - All applicable actions post sanctions to the Hikari sanction API - All commands are ephemeral, use Components v2, and enforce permission + role hierarchy checks ## Test plan - [ ] Run `pnpm register` to register all 8 commands to the guild - [ ] Verify each command appears in Discord and is only visible to members with the appropriate permissions - [ ] Test each command against a valid target and confirm mod log entry, DM notification, and sanction record - [ ] Test each command against an invalid target (equal/higher role, self, bot) and confirm correct error response - [ ] Perform a manual ban, kick, and timeout in the Discord UI and confirm audit log handler picks them up - [ ] Perform a manual unban and confirm it logs correctly without creating a sanction - [ ] Verify join/leave messages appear in the welcome log channel - [ ] Verify message edits, deletes, thread events, and voice state changes appear in the activity log channel ✨ This issue was created with help from Hikari~ 🌸 Reviewed-on: #11 Co-authored-by: Hikari <hikari@nhcarrigan.com> Co-committed-by: Hikari <hikari@nhcarrigan.com>
This commit was merged in pull request #11.
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import { logActivity } from "../modules/logActivity.js";
|
||||
import { logger } from "../utils/logger.js";
|
||||
import type { Message, PartialMessage } from "discord.js";
|
||||
|
||||
/**
|
||||
* Resolves the displayable content for a deleted message.
|
||||
* @param rawContent - The raw message content, which may be null if uncached.
|
||||
* @returns A displayable string representation of the content.
|
||||
*/
|
||||
const resolveContent = (rawContent: string | null): string => {
|
||||
if (rawContent === null || rawContent === "") {
|
||||
return "*Not cached*";
|
||||
}
|
||||
|
||||
if (rawContent.length > 1024) {
|
||||
return `${rawContent.slice(0, 1021)}...`;
|
||||
}
|
||||
|
||||
return rawContent;
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs message deletion events to the activity log channel.
|
||||
* Content is only available if the message was cached prior to deletion.
|
||||
* @param message - The deleted message (may be partial if uncached).
|
||||
* @returns A promise that resolves when the event has been logged.
|
||||
*/
|
||||
export const onMessageDelete = async(
|
||||
message: Message | PartialMessage,
|
||||
): Promise<void> => {
|
||||
if (message.author?.bot === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!message.guild) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const content = resolveContent(message.content);
|
||||
|
||||
const fields = [
|
||||
`**Channel**: <#${message.channelId}>`,
|
||||
`**Message ID**: \`${message.id}\``,
|
||||
`**Author**: ${message.author?.username ?? "Unknown"} (\`${message.author?.id ?? "Unknown"}\`)`,
|
||||
`**Content**: ${content}`,
|
||||
].join("\n");
|
||||
|
||||
await logActivity({
|
||||
client: message.client,
|
||||
emoji: "🗑️",
|
||||
fields: fields,
|
||||
title: "Message Deleted",
|
||||
});
|
||||
} catch (error) {
|
||||
await logger.error(
|
||||
"Failed to log message delete",
|
||||
error instanceof Error
|
||||
? error
|
||||
: new Error(String(error)),
|
||||
);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user