From 18ef6e56c2eb6258b37d54cd68dd421804df733d Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 6 Aug 2023 09:14:44 -0400 Subject: [PATCH 1/2] Shouldn't be pushing to main --- .github/workflows/production-docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/production-docker.yml b/.github/workflows/production-docker.yml index 9785845..6b94711 100644 --- a/.github/workflows/production-docker.yml +++ b/.github/workflows/production-docker.yml @@ -1,7 +1,7 @@ name: NodBot Production Dockerization on: - push: + pull_request: branches: - main -- 2.45.2 From 17a9bd4ea2f6e758f17a2501570348b1c28e5d00 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 6 Aug 2023 17:29:17 -0400 Subject: [PATCH 2/2] Restructure /save commands --- package.json | 2 +- slash-commands/save.js | 238 +++++++++++++++++++++++++++++++++++ slash-commands/savegif.js | 93 -------------- slash-commands/savejoint.js | 17 --- slash-commands/savemd.js | 17 --- slash-commands/savepasta.js | 24 ---- slash-commands/savestrain.js | 54 -------- 7 files changed, 239 insertions(+), 206 deletions(-) create mode 100644 slash-commands/save.js delete mode 100644 slash-commands/savegif.js delete mode 100644 slash-commands/savejoint.js delete mode 100644 slash-commands/savemd.js delete mode 100644 slash-commands/savepasta.js delete mode 100644 slash-commands/savestrain.js diff --git a/package.json b/package.json index 05f8e83..55b30c9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodbot", - "version": "3.2.0", + "version": "3.2.1", "description": "Nods and Nod Accessories, now with ChatGPT!", "main": "main.js", "dependencies": { diff --git a/slash-commands/save.js b/slash-commands/save.js new file mode 100644 index 0000000..13f5d38 --- /dev/null +++ b/slash-commands/save.js @@ -0,0 +1,238 @@ +const tenor = require('tenorjs').client({ + 'Key': process.env.tenorAPIKey, // https://tenor.com/developer/keyregistration + 'Filter': 'off', // "off", "low", "medium", "high", not case sensitive + 'Locale': 'en_US', + 'MediaFilter': 'minimal', + 'DateFormat': 'D/MM/YYYY - H:mm:ss A', +}); + +const { SlashCommandBuilder } = require('@discordjs/builders'); +const { MessageActionRow, MessageButton } = require('discord.js'); +const fn = require('../functions.js'); +const strings = require('../strings.json'); +const { emoji } = strings; + +module.exports = { + data: new SlashCommandBuilder() + .setName('save') + .setDescription('Save content to Nodbot\'s database.') +// GIF Search + .addSubcommand(subcommand => + subcommand + .setName('gifsearch') + .setDescription('Search Tenor for a GIF.') + .addStringOption(option => + option + .setName('query') + .setDescription('Search Query') + .setRequired(true)) + .addStringOption(option => + option + .setName('name') + .setDescription('What to save the gif as') + .setRequired(true)) + ) +// GIF URL + .addSubcommand(subcommand => + subcommand + .setName('gifurl') + .setDescription('Specify a URL to save.') + .addStringOption(option => + option + .setName('url') + .setDescription('URL Link to the GIF') + .setRequired(true)) + .addStringOption(option => + option + .setName('name') + .setDescription('What to save the gif as') + .setRequired(true)) + ) +// Joint + .addSubcommand(subcommand => + subcommand + .setName('joint') + .setDescription('Roll a joint and stash it in the database.') + .addStringOption(option => + option + .setName('joint-content') + .setDescription('Phrase to save') + .setRequired(true) + ) + ) +// MD + .addSubcommand(subcommand => + subcommand + .setName('md') + .setDescription('Add medical advice to the database.') + .addStringOption(option => + option + .setName('advice-content') + .setDescription('Advice to save') + .setRequired(true) + ) + ) +// Pasta + .addSubcommand(subcommand => + subcommand + .setName('pasta') + .setDescription('Save a copypasta to the database.') + .addStringOption(option => + option + .setName('pasta-name') + .setDescription('Title of the copypasta') + .setRequired(true) + ) + .addStringOption(option => + option + .setName('pasta-content') + .setDescription('Content of the copypasta') + .setRequired(true) + ) + ) +// Strain + .addSubcommand(subcommand => + subcommand + .setName('strain') + .setDescription('Store a new Strain in the database!') + .addStringOption(option => + option + .setName('name') + .setDescription('Name of the Strain') + .setRequired(true)) + .addStringOption(option => + option + .setName('type') + .setDescription('Indica/Sativa/Hybrid') + .setRequired(true) + .addChoices( + { name: "Indica", value: "Indica" }, + { name: "Hybrid", value: "Hybrid" }, + { name: "Sativa", value: "Sativa" } + ) + ) + .addStringOption(option => + option + .setName('effects') + .setDescription('The effects given by the strain') + .setRequired(false)) + .addStringOption(option => + option + .setName('flavor') + .setDescription('Flavor notes') + .setRequired(false)) + .addStringOption(option => + option + .setName('rating') + .setDescription('Number of stars') + .setRequired(false)) + .addStringOption(option => + option + .setName('description') + .setDescription('Description of the strain') + .setRequired(false)) + ), + async execute(interaction) { + await interaction.deferReply({ ephemeral: true }); + try { + // Code Here... + const subcommand = interaction.options.getSubcommand(); + switch (subcommand) { +// GIF Search + case "gifsearch": + // TODO Check on option names + // Previous GIF button + const prevButton = new MessageButton().setCustomId('prevGif').setLabel('Previous GIF').setStyle('SECONDARY').setDisabled(true); + // Confirm GIF Button + const confirmButton = new MessageButton().setCustomId('confirmGif').setLabel('Confirm').setStyle('PRIMARY'); + // Next GIF Button + const nextButton = new MessageButton().setCustomId('nextGif').setLabel('Next GIF').setStyle('SECONDARY'); + // Cancel Button + const cancelButton = new MessageButton().setCustomId('cancelGif').setLabel('Cancel').setStyle('DANGER'); + // Put all the above into an ActionRow to be sent as a component of the reply + const actionRow = new MessageActionRow().addComponents(prevButton, confirmButton, nextButton, cancelButton); + + // Get the query + const query = interaction.options.getString('query'); + strings.temp.gifName = interaction.options.getString('name').toLowerCase(); + + // Search Tenor for the GIF + tenor.Search.Query(query, '10').then(res => { + strings.temp.gifs = []; + strings.temp.gifIndex = 0; + strings.temp.gifLimit = res.length - 1; + strings.temp.gifUserId = interaction.user.id; + + if (res[0] == undefined) { + interaction.editReply('Sorry I was unable to find a GIF of ' + query); + return; + } + for (const row of res) { + strings.temp.gifs.push({ + embed_url: row.media_formats.gif.url, + }); + } + interaction.editReply({ content: strings.temp.gifs[0].embed_url, components: [actionRow], ephemeral: true }); + }); + break; +// GIF URL + case "gifurl": + //TODO Check on option names + const gifData = { + name: interaction.options.getString('name').toLowerCase(), + embed_url: interaction.options.getString('url'), + }; + fn.upload.gif(gifData, interaction.client); + interaction.editReply({ content: `I've saved the GIF as ${gifData.name}.gif`, ephemeral: true }); + fn.download.gifs(interaction.client); + break; +// Joint + case "joint": + //TODO + fn.upload.joint(interaction.options.getString('joint-content'), interaction.client); + interaction.editReply({ content: `The joint has been rolled${emoji.joint}`, ephemeral: true }); + break; +// MD + case "md": + //TODO + fn.upload.medicalAdvice(interaction.options.getString('advice-content'), interaction.client); + interaction.editReply({ content: `The advice has been saved!`, ephemeral: true }); + break; +// Pasta + case "pasta": + //TODO + const pastaData = { + name: interaction.options.getString('pasta-name').toLowerCase(), + content: interaction.options.getString('pasta-content'), + }; + fn.upload.pasta(pastaData, interaction.client); + interaction.editReply({content: `The copypasta has been saved as ${pastaData.name}.pasta`, ephemeral: true }); + break; +// Strain + case "strain": + //TODO + fn.upload.strain(interaction).then(res => { + interaction.editReply({ + content: `The strain information has been saved. (${interaction.options.getString('name')})`, + ephemeral: true + }); + }).catch(err => { + console.log(`E: ${err}`); + interaction.editReply({ + content: 'There was a problem saving the strain.', + ephemeral: true + }); + }); + break; +// Default + default: + + break; + } + } catch (err) { + const errorId = fn.generateErrorId(); + console.error(`${errorId}: err`); + await interaction.editReply(`Sorry, an error has occured. Error ID: ${errorId}`); + } + } +}; \ No newline at end of file diff --git a/slash-commands/savegif.js b/slash-commands/savegif.js deleted file mode 100644 index 27f4778..0000000 --- a/slash-commands/savegif.js +++ /dev/null @@ -1,93 +0,0 @@ -const tenor = require('tenorjs').client({ - 'Key': process.env.tenorAPIKey, // https://tenor.com/developer/keyregistration - 'Filter': 'off', // "off", "low", "medium", "high", not case sensitive - 'Locale': 'en_US', - 'MediaFilter': 'minimal', - 'DateFormat': 'D/MM/YYYY - H:mm:ss A', -}); - -const { SlashCommandBuilder } = require('@discordjs/builders'); -const { MessageActionRow, MessageButton } = require('discord.js'); -const fn = require('../functions.js'); -const strings = require('../strings.json'); - -module.exports = { - data: new SlashCommandBuilder() - .setName('savegif') - .setDescription('Save a GIF to Nodbot\'s database.') - .addSubcommand(subcommand => - subcommand - .setName('searchgif') - .setDescription('Search Tenor for a GIF.') - .addStringOption(option => - option.setName('query') - .setDescription('Search Query') - .setRequired(true)) - .addStringOption(option => - option.setName('name') - .setDescription('What to save the gif as') - .setRequired(true)) - ) - .addSubcommand(subcommand => - subcommand - .setName('enterurl') - .setDescription('Specify a URL to save.') - .addStringOption(option => - option - .setName('url') - .setDescription('URL Link to the GIF') - .setRequired(true)) - .addStringOption(option => - option.setName('name') - .setDescription('What to save the gif as') - .setRequired(true)) - ), - async execute(interaction) { - if (interaction.options.getSubcommand() == 'searchgif') { - // Previous GIF button - const prevButton = new MessageButton().setCustomId('prevGif').setLabel('Previous GIF').setStyle('SECONDARY').setDisabled(true); - // Confirm GIF Button - const confirmButton = new MessageButton().setCustomId('confirmGif').setLabel('Confirm').setStyle('PRIMARY'); - // Next GIF Button - const nextButton = new MessageButton().setCustomId('nextGif').setLabel('Next GIF').setStyle('SECONDARY'); - // Cancel Button - const cancelButton = new MessageButton().setCustomId('cancelGif').setLabel('Cancel').setStyle('DANGER'); - // Put all the above into an ActionRow to be sent as a component of the reply - const actionRow = new MessageActionRow().addComponents(prevButton, confirmButton, nextButton, cancelButton); - - // Get the query - const query = interaction.options.getString('query'); - strings.temp.gifName = interaction.options.getString('name').toLowerCase(); - - // Search Tenor for the GIF - tenor.Search.Query(query, '10').then(res => { - strings.temp.gifs = []; - strings.temp.gifIndex = 0; - strings.temp.gifLimit = res.length - 1; - strings.temp.gifUserId = interaction.user.id; - - if (res[0] == undefined) { - interaction.reply('Sorry I was unable to find a GIF of ' + query); - return; - } - for (const row of res) { - strings.temp.gifs.push({ - embed_url: row.media[0].gif.url, - }); - } - interaction.reply({ content: strings.temp.gifs[0].embed_url, components: [actionRow], ephemeral: true }); - }); - } - - if (interaction.options.getSubcommand() == 'enterurl') { - const gifData = { - name: interaction.options.getString('name'), - embed_url: interaction.options.getString('url'), - }; - fn.upload.gif(gifData, interaction.client); - interaction.reply({ content: `I've saved the GIF as ${gifData.name}.gif`, ephemeral: true }); - fn.download.gifs(interaction.client); - } - - }, -}; \ No newline at end of file diff --git a/slash-commands/savejoint.js b/slash-commands/savejoint.js deleted file mode 100644 index ba48eac..0000000 --- a/slash-commands/savejoint.js +++ /dev/null @@ -1,17 +0,0 @@ -const { SlashCommandBuilder } = require('@discordjs/builders'); -const fn = require('../functions.js'); -const { emoji } = require('../strings.json'); - -module.exports = { - data: new SlashCommandBuilder() - .setName('savejoint') - .setDescription('Save a phrase for /joint!') - .addStringOption(option => - option.setName('joint-content') - .setDescription('What is the phrase?') - .setRequired(true)), - async execute(interaction) { - fn.upload.joint(interaction.options.getString('joint-content'), interaction.client); - interaction.reply({ content: `The joint has been rolled${emoji.joint}`, ephemeral: true }); - }, -}; \ No newline at end of file diff --git a/slash-commands/savemd.js b/slash-commands/savemd.js deleted file mode 100644 index 8391da3..0000000 --- a/slash-commands/savemd.js +++ /dev/null @@ -1,17 +0,0 @@ -const { SlashCommandBuilder } = require('@discordjs/builders'); -const fn = require('../functions.js'); -// const { emoji } = require('../strings.json'); - -module.exports = { - data: new SlashCommandBuilder() - .setName('savemd') - .setDescription('Add medical advice to NodBot\'s Database!') - .addStringOption(option => - option.setName('advice-content') - .setDescription('What is the advice?') - .setRequired(true)), - async execute(interaction) { - fn.upload.medicalAdvice(interaction.options.getString('advice-content'), interaction.client); - interaction.reply({ content: `The advice has been saved!`, ephemeral: true }); - }, -}; \ No newline at end of file diff --git a/slash-commands/savepasta.js b/slash-commands/savepasta.js deleted file mode 100644 index a89da4a..0000000 --- a/slash-commands/savepasta.js +++ /dev/null @@ -1,24 +0,0 @@ -const { SlashCommandBuilder } = require('@discordjs/builders'); -const fn = require('../functions.js'); - -module.exports = { - data: new SlashCommandBuilder() - .setName('savepasta') - .setDescription('Save a copypasta!') - .addStringOption(option => - option.setName('pasta-name') - .setDescription('What should the name of the copypasta be?') - .setRequired(true)) - .addStringOption(option => - option.setName('pasta-content') - .setDescription('What is the content of the copypasta?') - .setRequired(true)), - async execute(interaction) { - const pastaData = { - name: interaction.options.getString('pasta-name'), - content: interaction.options.getString('pasta-content'), - }; - fn.upload.pasta(pastaData, interaction.client); - interaction.reply({content: `The copypasta has been saved as ${pastaData.name}.pasta`, ephemeral: true }); - }, -}; \ No newline at end of file diff --git a/slash-commands/savestrain.js b/slash-commands/savestrain.js deleted file mode 100644 index 3cc90f8..0000000 --- a/slash-commands/savestrain.js +++ /dev/null @@ -1,54 +0,0 @@ -const { SlashCommandBuilder } = require('@discordjs/builders'); -const fn = require('../functions.js'); -const { emoji } = require('../strings.json'); - -// Strain Name | Type | Effects | Flavor | Rating | Description - -module.exports = { - data: new SlashCommandBuilder() - .setName('savestrain') - .setDescription('Store a new Strain in the database!') - .addStringOption(option => - option.setName('name') - .setDescription('Name of the Strain') - .setRequired(true)) - .addStringOption(option => - option.setName('type') - .setDescription('Indica/Sativa/Hybrid') - .setRequired(true) - .addChoices( - { name: "Indica", value: "Indica" }, - { name: "Hybrid", value: "Hybrid" }, - { name: "Sativa", value: "Sativa" } - )) - .addStringOption(option => - option.setName('effects') - .setDescription('The effects given by the strain') - .setRequired(false)) - .addStringOption(option => - option.setName('flavor') - .setDescription('Flavor notes') - .setRequired(false)) - .addStringOption(option => - option.setName('rating') - .setDescription('Number of stars') - .setRequired(false)) - .addStringOption(option => - option.setName('description') - .setDescription('Description of the strain') - .setRequired(false)), - async execute(interaction) { - fn.upload.strain(interaction).then(res => { - interaction.reply({ - content: `The strain information has been saved. (${interaction.options.getString('name')})`, - ephemeral: true - }); - }).catch(err => { - console.log(`E: ${err}`); - interaction.reply({ - content: 'There was a problem saving the strain.', - ephemeral: true - }); - }); - }, -}; \ No newline at end of file -- 2.45.2