Merge pull request 'didnt mean to push that' (#2) from dev into mistress
Reviewed-on: https://git.incest.world/sisterkissers/discord-bot/pulls/2
This commit is contained in:
commit
aa34834562
2 changed files with 0 additions and 160 deletions
|
@ -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 })))
|
||||
},
|
||||
};
|
|
@ -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 })))
|
||||
},
|
||||
};
|
Loading…
Reference in a new issue