Add ability to save links as well as search for gifs
This commit is contained in:
parent
689ee529e2
commit
696e370c0b
@ -14,48 +14,80 @@ const strings = require('../strings.json');
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName('savegif')
|
.setName('savegif')
|
||||||
.setDescription('Search Tenor for a GIF to save')
|
.setDescription('Save a GIF to Nodbot\'s database.')
|
||||||
.addStringOption(option =>
|
.addSubcommand(subcommand =>
|
||||||
option.setName('query')
|
subcommand
|
||||||
.setDescription('Search Query')
|
.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))
|
.setRequired(true))
|
||||||
.addStringOption(option =>
|
.addStringOption(option =>
|
||||||
option.setName('name')
|
option.setName('name')
|
||||||
.setDescription('What to save the gif as')
|
.setDescription('What to save the gif as')
|
||||||
.setRequired(true)),
|
.setRequired(true))
|
||||||
|
),
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
// Previous GIF button
|
if (interaction.options.getSubcommand() == 'searchgif') {
|
||||||
const prevButton = new MessageButton().setCustomId('prevGif').setLabel('Previous GIF').setStyle('SECONDARY').setDisabled(true);
|
// Previous GIF button
|
||||||
// Confirm GIF Button
|
const prevButton = new MessageButton().setCustomId('prevGif').setLabel('Previous GIF').setStyle('SECONDARY').setDisabled(true);
|
||||||
const confirmButton = new MessageButton().setCustomId('confirmGif').setLabel('Confirm').setStyle('PRIMARY');
|
// Confirm GIF Button
|
||||||
// Next GIF Button
|
const confirmButton = new MessageButton().setCustomId('confirmGif').setLabel('Confirm').setStyle('PRIMARY');
|
||||||
const nextButton = new MessageButton().setCustomId('nextGif').setLabel('Next GIF').setStyle('SECONDARY');
|
// Next GIF Button
|
||||||
// Cancel Button
|
const nextButton = new MessageButton().setCustomId('nextGif').setLabel('Next GIF').setStyle('SECONDARY');
|
||||||
const cancelButton = new MessageButton().setCustomId('cancelGif').setLabel('Cancel').setStyle('DANGER');
|
// Cancel Button
|
||||||
// Put all the above into an ActionRow to be sent as a component of the reply
|
const cancelButton = new MessageButton().setCustomId('cancelGif').setLabel('Cancel').setStyle('DANGER');
|
||||||
const actionRow = new MessageActionRow().addComponents(prevButton, confirmButton, nextButton, cancelButton);
|
// 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
|
// Get the query
|
||||||
const query = interaction.options.getString('query');
|
const query = interaction.options.getString('query');
|
||||||
strings.temp.gifName = interaction.options.getString('name').toLowerCase();
|
strings.temp.gifName = interaction.options.getString('name').toLowerCase();
|
||||||
|
|
||||||
// Search Tenor for the GIF
|
// Search Tenor for the GIF
|
||||||
tenor.Search.Query(query, '10').then(res => {
|
tenor.Search.Query(query, '10').then(res => {
|
||||||
strings.temp.gifs = [];
|
strings.temp.gifs = [];
|
||||||
strings.temp.gifIndex = 0;
|
strings.temp.gifIndex = 0;
|
||||||
strings.temp.gifLimit = res.length - 1;
|
strings.temp.gifLimit = res.length - 1;
|
||||||
strings.temp.gifUserId = interaction.user.id;
|
strings.temp.gifUserId = interaction.user.id;
|
||||||
|
|
||||||
if (res[0] == undefined) {
|
if (res[0] == undefined) {
|
||||||
interaction.reply('Sorry I was unable to find a GIF of ' + query);
|
interaction.reply('Sorry I was unable to find a GIF of ' + query);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (const row of res) {
|
for (const row of res) {
|
||||||
strings.temp.gifs.push({
|
strings.temp.gifs.push({
|
||||||
embed_url: row.media[0].gif.url,
|
embed_url: row.media[0].gif.url,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
interaction.reply({ content: strings.temp.gifs[0].embed_url, components: [actionRow], ephemeral: true });
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user