Skip to content
This repository has been archived by the owner on Oct 12, 2024. It is now read-only.

Commit

Permalink
Int-CI-Moderation-Case: Initial code
Browse files Browse the repository at this point in the history
  • Loading branch information
RadiatedExodus committed Feb 16, 2024
1 parent c1b71f2 commit 4c5a7ca
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/interactions/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
export * as Test from "./tests/test.js";
export * as TestError from "./tests/error.js";
export * as TestDefferedError from "./tests/deferredError.js";

// Moderation
export * as case from "./moderation/case.js";
82 changes: 82 additions & 0 deletions src/interactions/commands/moderation/case.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { PermissionFlagsBits, SlashCommandBuilder, userMention } from "discord.js";
import type { MeteoriumChatCommand } from "../../index.js";
import MeteoriumEmbedBuilder from "../../../classes/embedBuilder.js";
import { ModerationAction } from "@prisma/client";
import moment from "moment";

export const Command: MeteoriumChatCommand = {
interactionData: new SlashCommandBuilder()
.setName("case")
.setDescription("Gives information about a recorded moderation case")
.addNumberOption((option) =>
option.setName("caseid").setDescription("The id of the case you want to view").setRequired(true),
)
.addNumberOption((option) =>
option
.setName("historylevel")
.setDescription("The history level, set to 0 to view the original case")
.setRequired(false),
)
.addBooleanOption((option) =>
option.setName("ephmeral").setDescription("If true, response will be shown only to you").setRequired(false),
)
.setDefaultMemberPermissions(PermissionFlagsBits.ViewAuditLog)
.setDMPermission(false),
async callback(interaction, client) {
const caseId = interaction.options.getNumber("caseid", true);
const historyLevel = interaction.options.getNumber("historylevel", false) || undefined;
const ephmeral = interaction.options.getBoolean("ephmeral", false) || false;

// Defer the reply
await interaction.deferReply({ ephemeral: ephmeral });

// Get case data
const caseDb = await client.dbUtils.getCaseData(interaction.guildId, caseId, historyLevel);
if (!caseDb) return await interaction.editReply("The case you specified doesn't exist.");

// Get user datas
const modUser = await client.users.fetch(caseDb.ModeratorUserId).catch(() => null);
const targetUser = await client.users.fetch(caseDb.TargetUserId).catch(() => null);

// Create embed
const embed = new MeteoriumEmbedBuilder(interaction.user)
.setAuthor({
name: `Case: #${caseId} | ${caseDb.Action.toLowerCase()} | ${targetUser != null ? `${targetUser.username} (${targetUser.id})` : caseDb.TargetUserId}`,
iconURL: targetUser != null ? targetUser.displayAvatarURL({ extension: "png", size: 256 }) : undefined,
})
.addFields([
{
name: "Moderator",
value: `${userMention(caseDb.ModeratorUserId)} (${modUser != null ? `${modUser.username} - ${modUser.id}` : caseDb.ModeratorUserId})`,
},
{
name: "Target",
value: `${userMention(caseDb.TargetUserId)} (${targetUser != null ? `${targetUser.username} - ${targetUser.id}` : caseDb.TargetUserId})`,
},
{ name: "Reason", value: caseDb.Reason },
])
.setImage(caseDb.AttachmentProof != "" ? caseDb.AttachmentProof : null)
.setThumbnail(caseDb.ModeratorAttachment != "" ? caseDb.ModeratorAttachment : null)
.setColor("Yellow");

// Action specific fields
if (caseDb.Action == ModerationAction.Mute || caseDb.Action == ModerationAction.TempBan)
embed.addFields([{ name: "Duration", value: caseDb.Duration }]);
if (caseDb.Action == ModerationAction.Ban)
embed.addFields([{ name: "Appealable", value: caseDb.NotAppealable ? "No" : "Yes" }]);

// Remaining fields
embed.addFields([
{ name: "Moderator note", value: caseDb.ModeratorNote != "" ? caseDb.ModeratorNote : "N/A" },
{ name: "Attachment proof", value: caseDb.AttachmentProof != "" ? caseDb.AttachmentProof : "N/A" },
{
name: "Moderator attachment",
value: caseDb.ModeratorAttachment != "" ? caseDb.ModeratorAttachment : "N/A",
},
{ name: "Removed", value: caseDb.Removed ? "Yes" : "No" },
{ name: "Created at", value: moment(caseDb.CreatedAt).format("DD-MM-YYYY hh:mm:ss:SSS A Z") },
]);

return await interaction.editReply({ embeds: [embed] });
},
};

0 comments on commit 4c5a7ca

Please sign in to comment.