From 0a896e8466fad757038c890bdf23fb98f017270a Mon Sep 17 00:00:00 2001 From: Tarrgon <61888458+Tarrgon@users.noreply.github.com> Date: Wed, 17 Sep 2025 18:10:07 -0400 Subject: [PATCH] Log knowledgebase updates --- src/commands/knowledgebase.ts | 83 ++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/src/commands/knowledgebase.ts b/src/commands/knowledgebase.ts index dae34a6..4648da2 100644 --- a/src/commands/knowledgebase.ts +++ b/src/commands/knowledgebase.ts @@ -1,7 +1,7 @@ import { ApplicationIntegrationType, AutocompleteInteraction, ChatInputCommandInteraction, Client, InteractionContextType, MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js'; import { Database } from '../shared/Database'; import { KnowledgebaseItem } from '../types'; -import { deferInteraction } from '../utils'; +import { deferInteraction, logCustomEvent } from '../utils'; export default { name: 'knowledgebase', @@ -69,10 +69,36 @@ export default { const name = interaction.options.getString('name', true); const content = interaction.options.getString('content', true); + if (content.length > 2000) return interaction.editReply('Content cannot be over 2000 characters long.'); + const existingItem = await Database.getFromKnowledgebaseByName(interaction.guild.id, name); if (existingItem) return interaction.editReply(`Knowledgebase item ${name} already exists!`); + logCustomEvent(interaction.guild!, { + title: 'Knowledgebase Item Added', + description: null, + color: 0x00FF00, + timestamp: new Date(), + fields: [ + { + name: 'User', + value: `<@${interaction.user.id}>\n${interaction.user.username}`, + inline: true + }, + { + name: 'Name', + value: name, + inline: true + }, + { + name: 'Content', + value: content, + inline: true + } + ] + }); + await Database.addToKnowledgebase(interaction.guild.id, name, content); return interaction.editReply('Knowledge expanded.'); @@ -84,6 +110,30 @@ export default { if (!item) return interaction.editReply('Knowledgebase item not found.'); + logCustomEvent(interaction.guild!, { + title: 'Knowledgebase Item Removed', + description: null, + color: 0xFF0000, + timestamp: new Date(), + fields: [ + { + name: 'User', + value: `<@${interaction.user.id}>\n${interaction.user.username}`, + inline: true + }, + { + name: 'Name', + value: item.name, + inline: true + }, + { + name: 'Content', + value: item.content, + inline: true + } + ] + }); + await Database.removeFromKnowledgebase(id); return interaction.editReply('Knowledge removed.'); @@ -97,6 +147,37 @@ export default { if (!existingItem) return interaction.editReply('Knowledgebase item not found.'); + if (content.length > 2000) return interaction.editReply('Content cannot be over 2000 characters long.'); + + logCustomEvent(interaction.guild!, { + title: 'Knowledgebase Item Edited', + description: null, + color: 0xFFFF00, + timestamp: new Date(), + fields: [ + { + name: 'User', + value: `<@${interaction.user.id}>\n${interaction.user.username}`, + inline: true + }, + { + name: 'Name', + value: existingItem.name, + inline: true + }, + { + name: 'Old Content', + value: existingItem.content, + inline: true + }, + { + name: 'New Content', + value: content, + inline: true + } + ] + }); + await Database.editKnowledgebaseItem(id, content); return interaction.editReply('Information exchange completed.');