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 { Collection } = require('discord.js'); const fn = require('../functions.js'); const strings = require('../strings.json'); const { GifData } = require('../CustomModules/NodBot.js'); const customEmbeds = require('../CustomModules/Embeds.js'); const Indexer = require('../CustomModules/Indexer.js'); const Embeds = require('../CustomModules/Embeds.js'); 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": // Grab the inputs from the command const query = interaction.options.getString('query'); const gifName = interaction.options.getString('name').toLowerCase(); const iStorage = interaction.client.iStorage.get(interaction.id); iStorage.page = 0; iStorage.gifsCollection = new Collection(); iStorage.gifName = gifName; iStorage.query = query; // Search Tenor for the GIF tenor.Search.Query(query, '20').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) { iStorage.gifsCollection.set(row.id, row); } // Generate the initial action row const actionRow = customEmbeds.actionRows.gifSearchAR('first'); // Get the index built const gifPage = Indexer(iStorage.gifsCollection, 0, 1); gifPage.query = query; gifPage.gifName = gifName; // Generate the embed const gifEmbed = Embeds.core.gifSearch({ author: interaction.member.displayName }, gifPage); interaction.editReply({ embeds: [gifEmbed], components: [actionRow], ephemeral: true }); }); break; // GIF URL case "gifurl": //TODO Check on option names // const gifData = { // name: interaction.options.getString('name').toLowerCase(), // url: interaction.options.getString('url'), // }; const gifData = new GifData().setInfo(interaction.options.getString('name').toLowerCase(), 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'), }; await 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}`); } } };