generated from nhcarrigan/template
1c31a49bc4
## 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>
149 lines
4.1 KiB
TypeScript
149 lines
4.1 KiB
TypeScript
/**
|
|
* @copyright nhcarrigan
|
|
* @license Naomi's Public License
|
|
* @author Naomi Carrigan
|
|
*/
|
|
/* eslint-disable max-lines-per-function -- Command handlers have many validation and action steps */
|
|
/* eslint-disable max-statements -- Command handlers have many validation and action steps */
|
|
/* eslint-disable complexity -- Command handlers have multiple validation branches */
|
|
|
|
import {
|
|
InteractionContextType,
|
|
PermissionFlagsBits,
|
|
SlashCommandBuilder,
|
|
} from "discord.js";
|
|
import { logModerationAction } from "../modules/logModAction.js";
|
|
import { sendSanction } from "../modules/sendSanction.js";
|
|
import { errorReply, successReply } from "../utils/components.js";
|
|
import { logger } from "../utils/logger.js";
|
|
import type { Command } from "../interfaces/command.js";
|
|
|
|
const kickCommand: Command = {
|
|
data: new SlashCommandBuilder().
|
|
setName("kick").
|
|
setDescription("Kick a member from the server.").
|
|
setDefaultMemberPermissions(PermissionFlagsBits.KickMembers).
|
|
setContexts([ InteractionContextType.Guild ]).
|
|
addUserOption((option) => {
|
|
return option.
|
|
setName("user").
|
|
setDescription("The member to kick.").
|
|
setRequired(true);
|
|
}).
|
|
addStringOption((option) => {
|
|
return option.
|
|
setName("reason").
|
|
setDescription("The reason for the kick.").
|
|
setRequired(true).
|
|
setMaxLength(512);
|
|
}),
|
|
|
|
execute: async(interaction) => {
|
|
await interaction.deferReply({ ephemeral: true });
|
|
|
|
const hasPermission = interaction.memberPermissions?.has(
|
|
PermissionFlagsBits.KickMembers,
|
|
);
|
|
if (hasPermission !== true) {
|
|
await interaction.editReply(
|
|
errorReply(
|
|
"Insufficient Permissions",
|
|
"You do not have permission to use this command.",
|
|
),
|
|
);
|
|
return;
|
|
}
|
|
|
|
const target = interaction.options.getUser("user", true);
|
|
const reason = interaction.options.getString("reason", true);
|
|
|
|
if (target.bot) {
|
|
await interaction.editReply(
|
|
errorReply("Invalid Target", "You cannot kick a bot."),
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (target.id === interaction.user.id) {
|
|
await interaction.editReply(
|
|
errorReply("Invalid Target", "You cannot kick yourself."),
|
|
);
|
|
return;
|
|
}
|
|
|
|
const member = interaction.guild?.members.cache.get(target.id);
|
|
|
|
if (!member) {
|
|
await interaction.editReply(
|
|
errorReply("Member Not Found", "That user is not in this server."),
|
|
);
|
|
return;
|
|
}
|
|
|
|
const selfMember = interaction.guild?.members.cache.get(
|
|
interaction.user.id,
|
|
);
|
|
if (
|
|
selfMember
|
|
&& member.roles.highest.position >= selfMember.roles.highest.position
|
|
) {
|
|
await interaction.editReply(
|
|
errorReply(
|
|
"Insufficient Permissions",
|
|
"You cannot kick someone with an equal or higher role.",
|
|
),
|
|
);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await target.send(
|
|
`You have been kicked from **${interaction.guild?.name ?? "the server"}**.\n**Reason:** ${reason}`,
|
|
);
|
|
} catch {
|
|
// DMs may be closed; continue without failing the command.
|
|
}
|
|
|
|
try {
|
|
await member.kick(reason);
|
|
} catch {
|
|
await interaction.editReply(
|
|
errorReply(
|
|
"Action Failed",
|
|
"Failed to kick the member. Check my permissions and role hierarchy.",
|
|
),
|
|
);
|
|
return;
|
|
}
|
|
|
|
const sanctionNumber = await sendSanction({
|
|
reason: reason,
|
|
type: "kick",
|
|
username: target.username,
|
|
uuid: target.id,
|
|
});
|
|
|
|
await logModerationAction(interaction.client, {
|
|
action: "Member Kicked",
|
|
emoji: "👢",
|
|
moderatorTag: interaction.user.username,
|
|
reason: reason,
|
|
sanctionNumber: sanctionNumber,
|
|
source: "Command",
|
|
targetId: target.id,
|
|
targetTag: target.username,
|
|
});
|
|
|
|
await interaction.editReply(
|
|
successReply(
|
|
"Member Kicked",
|
|
`**User**: ${target.username} (\`${target.id}\`)\n**Reason**: ${reason}`,
|
|
),
|
|
);
|
|
},
|
|
};
|
|
|
|
void logger.log("debug", "Kick command loaded.");
|
|
|
|
export { kickCommand };
|