From 5f227f9a5b133f37778034c1079d487864e2fdf7 Mon Sep 17 00:00:00 2001 From: Ashley Graves Date: Fri, 11 Oct 2024 14:09:00 +0200 Subject: [PATCH] didnt mean to push that --- src/commands/fun/serverconfig.js | 98 -------------------------------- src/commands/fun/userconfig.js | 62 -------------------- 2 files changed, 160 deletions(-) delete mode 100644 src/commands/fun/serverconfig.js delete mode 100644 src/commands/fun/userconfig.js diff --git a/src/commands/fun/serverconfig.js b/src/commands/fun/serverconfig.js deleted file mode 100644 index 2123fa4..0000000 --- a/src/commands/fun/serverconfig.js +++ /dev/null @@ -1,98 +0,0 @@ -const { InteractionContextType, ApplicationIntegrationType, SlashCommandBuilder } = require("discord.js"); -const { format } = require("node:util"); -const { knex } = require("../../db.js"); - -const configData = { - "yuri": { - "description": "Automated yuri posting", - "options": [{ - "name": "enable", - "required": true, - "type": "Boolean", - "description": "Should the bot post yuri?" - }, { - "name": "channel", - "type": "Channel", - "description": "Where to post yuri", - }] - } -} - -const data = new SlashCommandBuilder() - .setName("serverconfig") - .setDescription("Manage your server settings") - .setContexts([ - InteractionContextType.Guild - ]) - .setIntegrationTypes([ - ApplicationIntegrationType.GuildInstall - ]); - -for (const cfg in configData) { - const config = configData[cfg]; - - data.addSubcommand((builder) => { - builder - .setName(cfg) - .setDescription(config.description); - - for (const opt in config.options) { - const option = config.options[opt]; - - builder[`add${option.type}Option`](optionBuilder => - optionBuilder - .setName(option.name) - .setRequired(option.required ?? false) - .setDescription(option.description) - ); - } - return builder; - }); -} - -module.exports = { - data, - async execute(interaction) { - var result = await knex.select("data").from("serverconfigs").where("id", interaction.guildId).first(); - if (!result) - result = { data: '{}' }; - - const config = JSON.parse(result.data); - const cfg = interaction.options.getSubcommand(true); - config[cfg] = config[cfg] ?? {}; - - for (const option of configData[cfg].options) { - config[cfg][option.name] = interaction.options[`get${option.type}`](option.name); - } - - const data = { - id: interaction.guildId, - data: JSON.stringify(config) - } - - await knex.raw(format('%s ON CONFLICT (id) DO UPDATE SET %s', - knex("serverconfigs").insert(data).toString().toString(), - knex("serverconfigs").update(data).whereRaw(`'serverconfigs'.id = '${interaction.guildId}'`).toString().replace(/^update\s.*\sset\s/i, '') - )); - - interaction.reply({ content: "Settings updated!", ephemeral: true }); - }, - async autocomplete(interaction) { - const focusedOption = interaction.options.getFocused(true); - const command = interaction.options.getSubcommand(true); - - console.log(command, focusedOption); - - const id = ""; - - const choices = []; - for (const option in configData) { - if (focusedOption.name == "name" && option.startsWith(focusedOption.value)) - choices.push(option); - else if (focusedOption.name == "value" && (option == interaction.options.getString("name") ?? "")) - choices.push(...buildChoices(option, interaction)); - } - - await interaction.respond(choices.map(choice => ({ name: choice, value: choice }))) - }, -}; \ No newline at end of file diff --git a/src/commands/fun/userconfig.js b/src/commands/fun/userconfig.js deleted file mode 100644 index 83cc8f2..0000000 --- a/src/commands/fun/userconfig.js +++ /dev/null @@ -1,62 +0,0 @@ -const { InteractionContextType, ApplicationIntegrationType, SlashCommandBuilder } = require("discord.js"); -const { knex } = require("../../db.js"); - -const configData = {} - -const data = new SlashCommandBuilder() - .setName("userconfig") - .setDescription("Manage your user settings") - .setContexts([ - InteractionContextType.Guild, - InteractionContextType.BotDM, - InteractionContextType.PrivateChannel - ]) - .setIntegrationTypes([ - ApplicationIntegrationType.UserInstall - ]); - -for (const option in configData) { - const config = configData[option]; - - data.addSubcommand((builder) => { - builder - .setName(option) - .setDescription(config.description) - switch (config.type) { - case "bool": - builder.addBooleanOption(builder => - builder.setName("value") - ); - case "channel": - builder.addChannelOption(builder => - builder.setName("channel") - ); - default: - } - }) -} - -module.exports = { - data, - async execute(interaction) { - interaction.reply("Not implemented yet, sorry!"); - }, - async autocomplete(interaction) { - const focusedOption = interaction.options.getFocused(true); - const command = interaction.options.getSubcommand(true); - - console.log(command, focusedOption); - - const id = ""; - - const choices = []; - for (const option in configData) { - if (focusedOption.name == "name" && option.startsWith(focusedOption.value)) - choices.push(option); - else if (focusedOption.name == "value" && (option == interaction.options.getString("name") ?? "")) - choices.push(...buildChoices(option, interaction)); - } - - await interaction.respond(choices.map(choice => ({ name: choice, value: choice }))) - }, -}; \ No newline at end of file