diff --git a/autocomplete/tag.js b/autocomplete/tag.js index 7ebdcf8..98fe287 100644 --- a/autocomplete/tag.js +++ b/autocomplete/tag.js @@ -3,9 +3,9 @@ const fs = require('fs') module.exports = { id: 'tag', async execute(interaction) { - if (interaction.options.getSubcommand() !== 'remove' && interaction.options.getSubcommand() !== 'get') return + if (!['remove', 'get', 'edit'].includes(interaction.options.getSubcommand())) return const tags = JSON.parse(fs.readFileSync('./databases/tags.json')) - const tagNames = Object.keys(tags).filter(name => name.startsWith(interaction.options.getFocused())) + const tagNames = Object.keys(tags).filter(name => name.includes(interaction.options.getFocused())) return interaction.respond(tagNames.map(tag => ({ name: tag, value: tag }))) } } diff --git a/commands/reactionroles.js b/commands/reactionroles.js index ffad273..b40c65e 100644 --- a/commands/reactionroles.js +++ b/commands/reactionroles.js @@ -82,7 +82,10 @@ module.exports = { title: `Reaction roles in ${interaction.guild.name}`, color: config.getColor('accent'), description: roles - .map(r => `[Jump to Message](https://discord.com/channels/${interaction.guild.id}/${r.channelId}/${r.id})\n${r.roles.map(ro => `${ro.emojiName}: <@&${ro.role}>`).join('\n')}`) + .map( + r => + `[Jump to Message](https://discord.com/channels/${interaction.guild.id}/${r.channelId}/${r.id})\n${r.roles.map(ro => `${ro.emojiName}: <@&${ro.role}>`).join('\n')}` + ) .join('\n\n') } return interaction.reply({ diff --git a/commands/tag.js b/commands/tag.js index 96f77d7..ce819cd 100644 --- a/commands/tag.js +++ b/commands/tag.js @@ -1,25 +1,15 @@ -const { SlashCommandBuilder, resolveColor, ModalBuilder, TextInputBuilder, ActionRowBuilder, TextInputStyle } = require('discord.js') +const { SlashCommandBuilder, ModalBuilder, TextInputBuilder, ActionRowBuilder, TextInputStyle } = require('discord.js') const fs = require('fs') const checkUserPerms = require('../utils/checkUserPerms') const config = require('../utils/config') if (!fs.existsSync('./databases/tags.json')) fs.writeFileSync('./databases/tags.json', '{}') -let tags = JSON.parse(fs.readFileSync('./databases/tags.json', "utf-8")) module.exports = { data: new SlashCommandBuilder() .setName('tag') .setDescription('Manage tags') - .addSubcommand(subcommand => - subcommand - .setName('add') - .setDescription('Add a tag') - ) - .addSubcommand(subcommand => - subcommand - .setName('add-with-modal') - .setDescription('Add a tag with a modal') - ) + .addSubcommand(subcommand => subcommand.setName('add').setDescription('Add a tag')) .addSubcommand(subcommand => subcommand .setName('remove') @@ -38,12 +28,12 @@ module.exports = { subcommand .setName('edit') .setDescription('Edit a tag') - .addStringOption(option => option.setName('name').setDescription('The name of the tag').setRequired(true)) - .addStringOption(option => option.setName('content').setDescription('The new content of the tag').setRequired(true)) - .addStringOption(option => option.setName('image').setDescription('URL of image to attach')) + .addStringOption(option => option.setName('name').setDescription('The name of the tag').setRequired(true).setAutocomplete(true)) ), async execute(interaction) { + const tags = JSON.parse(fs.readFileSync('./databases/tags.json', 'utf-8')) + const subcommand = interaction.options.getSubcommand() if (subcommand === 'add') { if (!checkUserPerms(interaction)) { @@ -52,15 +42,13 @@ module.exports = { ephemeral: true }) } - - const modal = new ModalBuilder() - .setTitle('Add a tag') - .setCustomId('add-tag') + + const modal = new ModalBuilder().setTitle('Add a tag').setCustomId('add-tag') const nameInput = new TextInputBuilder() .setCustomId('name') .setPlaceholder('Name') - .setLabel("Name") + .setLabel('Name') .setMinLength(1) .setMaxLength(32) .setRequired(true) @@ -69,7 +57,7 @@ module.exports = { const contentInput = new TextInputBuilder() .setCustomId('content') .setPlaceholder('Content') - .setLabel("Content") + .setLabel('Content') .setMinLength(1) .setMaxLength(2000) .setRequired(true) @@ -77,18 +65,17 @@ module.exports = { const imageInput = new TextInputBuilder() .setCustomId('image') - .setLabel("Image") + .setLabel('Image') .setPlaceholder('Image URL') .setMinLength(1) .setMaxLength(2000) .setStyle(TextInputStyle.Short) .setRequired(false) - + modal.addComponents(new ActionRowBuilder().addComponents(nameInput), new ActionRowBuilder().addComponents(contentInput), new ActionRowBuilder().addComponents(imageInput)) await interaction.showModal(modal) - } - else if (subcommand === 'remove') { + } else if (subcommand === 'remove') { if (!checkUserPerms(interaction)) { return interaction.reply({ content: "Just don't use that tag then ¯\\_(ツ)_/¯ (You don't have permission to do that.)", @@ -121,7 +108,9 @@ module.exports = { // Shhhh, you didn't see anything. // i certainly did not ;) // Sorry for changing this again the lack of the question mark was really getting to me! + // might add my own one too then :) if (name === 'sbeve is amazing') return interaction.reply({ content: 'I know, right?!', ephemeral: true }) + if (name === 'bludood is the best') return interaction.reply({ content: 'very true', ephemeral: true }) return interaction.reply({ content: `A tag with the name ${name} does not exist.`, ephemeral: true }) } @@ -142,20 +131,43 @@ module.exports = { }) } const name = interaction.options.getString('name') - const content = interaction.options.getString('content') - const image = interaction.options.getString('image') if (!tags[name]) return interaction.reply({ content: `A tag with the name ${name} does not exist.`, ephemeral: true }) - tags[name] = { - content: content, - image: image || tags[name].image - } - fs.writeFileSync('./databases/tags.json', JSON.stringify(tags, null, 4)) - interaction.reply({ content: `Edited tag ${name}.`, ephemeral: true }) - } - }, + const modal = new ModalBuilder().setTitle('Edit a tag').setCustomId('edit-tag') + + const nameInput = new TextInputBuilder() + .setCustomId('name') + .setPlaceholder('Name') + .setLabel('Name') + .setMinLength(1) + .setMaxLength(32) + .setRequired(true) + .setStyle(TextInputStyle.Short) + .setValue(name) - updateTags(newTags) { - tags = newTags + const contentInput = new TextInputBuilder() + .setCustomId('content') + .setPlaceholder('Content') + .setLabel('Content') + .setMinLength(1) + .setMaxLength(2000) + .setRequired(true) + .setStyle(TextInputStyle.Paragraph) + .setValue(tags[name].content) + + const imageInput = new TextInputBuilder() + .setCustomId('image') + .setLabel('New image') + .setPlaceholder('New image URL') + .setMinLength(1) + .setMaxLength(2000) + .setStyle(TextInputStyle.Short) + .setRequired(false) + .setValue(tags[name].image) + + modal.addComponents(new ActionRowBuilder().addComponents(nameInput), new ActionRowBuilder().addComponents(contentInput), new ActionRowBuilder().addComponents(imageInput)) + + await interaction.showModal(modal) + } } } diff --git a/modals/add-tag.js b/modals/add-tag.js new file mode 100644 index 0000000..5b32686 --- /dev/null +++ b/modals/add-tag.js @@ -0,0 +1,21 @@ +const fs = require('fs') + +if (!fs.existsSync('./databases/tags.json')) fs.writeFileSync('./databases/tags.json', '{}') + +module.exports = { + id: 'add-tag', + async execute(interaction) { + const tags = JSON.parse(fs.readFileSync('./databases/tags.json', 'utf-8')) + const name = interaction.fields.fields.find(f => f.customId === 'name').value + const content = interaction.fields.fields.find(f => f.customId === 'content').value + const image = interaction.fields.fields.find(f => f.customId === 'image').value + if (tags[name]) return interaction.reply({ content: `A tag with the name ${name} already exists.`, ephemeral: true }) + + tags[name] = { + content, + image + } + fs.writeFileSync('./databases/tags.json', JSON.stringify(tags, null, 4)) + interaction.reply({ content: `Added tag ${name}.`, ephemeral: true }) + } +} diff --git a/modals/edit-tag.js b/modals/edit-tag.js new file mode 100644 index 0000000..0a0e137 --- /dev/null +++ b/modals/edit-tag.js @@ -0,0 +1,21 @@ +const fs = require('fs') + +if (!fs.existsSync('./databases/tags.json')) fs.writeFileSync('./databases/tags.json', '{}') + +module.exports = { + id: 'edit-tag', + async execute(interaction) { + const tags = JSON.parse(fs.readFileSync('./databases/tags.json', 'utf-8')) + const name = interaction.fields.fields.find(f => f.customId === 'name').value + const content = interaction.fields.fields.find(f => f.customId === 'content').value + const image = interaction.fields.fields.find(f => f.customId === 'image').value + if (!tags[name]) return interaction.reply({ content: `A tag with the name ${name} does not exist.`, ephemeral: true }) + + tags[name] = { + content, + image + } + fs.writeFileSync('./databases/tags.json', JSON.stringify(tags, null, 4)) + interaction.reply({ content: `Edited tag ${name}.`, ephemeral: true }) + } +} diff --git a/modals/nothing here yet b/modals/nothing here yet deleted file mode 100644 index e69de29..0000000 diff --git a/modals/tag.js b/modals/tag.js deleted file mode 100644 index f3e60a4..0000000 --- a/modals/tag.js +++ /dev/null @@ -1,25 +0,0 @@ -const fs = require("fs"); - -if (!fs.existsSync('./databases/tags.json')) fs.writeFileSync('./databases/tags.json', '{}') -const tags = JSON.parse(fs.readFileSync('./databases/tags.json', "utf-8")) - -const { updateTags } = require('../commands/tag.js'); - -module.exports = { - id: "add-tag", - - async execute(interaction) { - const name = interaction.fields.fields.find(f => f.customId === "name").value; - const content = interaction.fields.fields.find(f => f.customId === "content").value; - const image = interaction.fields.fields.find(f => f.customId === "image").value; - if (tags[name]) return interaction.reply({ content: `A tag with the name ${name} already exists.`, ephemeral: true }) - - tags[name] = { - content, - image - } - fs.writeFileSync('./databases/tags.json', JSON.stringify(tags, null, 4)) - updateTags(tags); - interaction.reply({ content: `Added tag ${name}.`, ephemeral: true }) - } -} \ No newline at end of file diff --git a/utils/setup.js b/utils/setup.js index 132ea45..e499c52 100644 --- a/utils/setup.js +++ b/utils/setup.js @@ -48,12 +48,17 @@ function readline() { current.customization.accent = await readline() console.log('Now enter a HEX color you would like as a "good" color. This will apply to embeds which remove a moderation. Leave blank for default.') current.customization.colors.good = await readline() - console.log('Now enter a HEX color you would like as a "medium" color. This will apply to embeds which add a semi-fatal moderation like a kick or timeout. Leave blank for default.') + console.log( + 'Now enter a HEX color you would like as a "medium" color. This will apply to embeds which add a semi-fatal moderation like a kick or timeout. Leave blank for default.' + ) current.customization.colors.medium = await readline() console.log('Now enter a HEX color you would like as a "bad" color. This will apply to embeds which add a fatal moderation like a ban. Leave blank for default.') current.customization.colors.bad = await readline() } - console.log((customColors === 'y' ? '' : "Alright, i'll use the default colors. ") + 'Now, time to set up your moderation roles. Enter all your moderation role IDs here, separated by a comma.') + console.log( + (customColors === 'y' ? '' : "Alright, i'll use the default colors. ") + + 'Now, time to set up your moderation roles. Enter all your moderation role IDs here, separated by a comma.' + ) current.modRoles = (await readline()).split(',').map(r => r.trim()) console.log("Got that. Now enter the channel you'd like me to send logs to:") current.channels.logs = (await readline()).trim()