import { ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; import 'dotenv/config'; import fs = require('node:fs'); import path = require('node:path'); const syspromptCache = path.resolve(__dirname, 'sysprompt_cache'); const SAFE_NAME_REGEX = /^[\w\d]+$/; async function editSyspromptCommand(interaction: ChatInputCommandInteraction) { if (interaction.user.id !== process.env.ADMIN) { await interaction.reply("You are not authorized to change model settings"); return; } const name = interaction.options.getString('name', true); if (!SAFE_NAME_REGEX.test(name)) { await interaction.reply('Failed to edit system prompt: name must be alphanumeric.'); return; } const content = interaction.options.getString('content', true); fs.writeFileSync(path.resolve(syspromptCache, `${name}.txt`), content); await interaction.reply(`System prompt "${name}" set to \`\`\` ${content} \`\`\``); } export = { data: new SlashCommandBuilder() .setName('edit') .setDescription('Edit system prompts') .addStringOption( opt => opt.setName('name').setDescription('Name (must be alphanumeric)').setRequired(true) ) .addStringOption( opt => opt.setName('content').setDescription('The system prompt').setRequired(true) ), execute: editSyspromptCommand };