From c571ef6d6539e19c8e1d51353b6f980efe5036b5 Mon Sep 17 00:00:00 2001 From: Ashley Graves Date: Fri, 11 Oct 2024 14:09:36 +0200 Subject: [PATCH 1/3] [indev] config --- src/commands/fun/serverconfig.js | 98 ++++++++++++++++++++++++++++++++ src/commands/fun/userconfig.js | 62 ++++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 src/commands/fun/serverconfig.js create mode 100644 src/commands/fun/userconfig.js diff --git a/src/commands/fun/serverconfig.js b/src/commands/fun/serverconfig.js new file mode 100644 index 0000000..2123fa4 --- /dev/null +++ b/src/commands/fun/serverconfig.js @@ -0,0 +1,98 @@ +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 new file mode 100644 index 0000000..83cc8f2 --- /dev/null +++ b/src/commands/fun/userconfig.js @@ -0,0 +1,62 @@ +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 From c8071dd94602800dd432cbc9e5f81ef9080c6274 Mon Sep 17 00:00:00 2001 From: Ashley Graves Date: Fri, 11 Oct 2024 14:11:50 +0200 Subject: [PATCH 2/3] the --- src/commands/fun/gelbooru.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/fun/gelbooru.js b/src/commands/fun/gelbooru.js index 09e0114..d331e0b 100644 --- a/src/commands/fun/gelbooru.js +++ b/src/commands/fun/gelbooru.js @@ -63,7 +63,7 @@ function notEmpty(str) { return str.trim() !== '' } -const regexCutTags = /[\S\s]{1,75}[^,]{0,125}/; +const regexCutTags = /[\S\s]{1,275}[^,]{0,225}/; function formatTags(tags) { const tagString = decode(tags.join(', ')); From fb5c126f0b66ad86f024ea8c292b31f3eac98261 Mon Sep 17 00:00:00 2001 From: Ashley Graves Date: Fri, 11 Oct 2024 14:12:39 +0200 Subject: [PATCH 3/3] guh --- 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