Log knowledgebase updates
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { ApplicationIntegrationType, AutocompleteInteraction, ChatInputCommandInteraction, Client, InteractionContextType, MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
import { ApplicationIntegrationType, AutocompleteInteraction, ChatInputCommandInteraction, Client, InteractionContextType, MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||||
import { Database } from '../shared/Database';
|
import { Database } from '../shared/Database';
|
||||||
import { KnowledgebaseItem } from '../types';
|
import { KnowledgebaseItem } from '../types';
|
||||||
import { deferInteraction } from '../utils';
|
import { deferInteraction, logCustomEvent } from '../utils';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'knowledgebase',
|
name: 'knowledgebase',
|
||||||
@@ -69,10 +69,36 @@ export default {
|
|||||||
const name = interaction.options.getString('name', true);
|
const name = interaction.options.getString('name', true);
|
||||||
const content = interaction.options.getString('content', 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);
|
const existingItem = await Database.getFromKnowledgebaseByName(interaction.guild.id, name);
|
||||||
|
|
||||||
if (existingItem) return interaction.editReply(`Knowledgebase item ${name} already exists!`);
|
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);
|
await Database.addToKnowledgebase(interaction.guild.id, name, content);
|
||||||
|
|
||||||
return interaction.editReply('Knowledge expanded.');
|
return interaction.editReply('Knowledge expanded.');
|
||||||
@@ -84,6 +110,30 @@ export default {
|
|||||||
|
|
||||||
if (!item) return interaction.editReply('Knowledgebase item not found.');
|
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);
|
await Database.removeFromKnowledgebase(id);
|
||||||
|
|
||||||
return interaction.editReply('Knowledge removed.');
|
return interaction.editReply('Knowledge removed.');
|
||||||
@@ -97,6 +147,37 @@ export default {
|
|||||||
|
|
||||||
if (!existingItem) return interaction.editReply('Knowledgebase item not found.');
|
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);
|
await Database.editKnowledgebaseItem(id, content);
|
||||||
|
|
||||||
return interaction.editReply('Information exchange completed.');
|
return interaction.editReply('Information exchange completed.');
|
||||||
|
|||||||
Reference in New Issue
Block a user