Skylar Grant
f1459e9d91
All checks were successful
NodBot PE Dockerization / build (push) Successful in 1m16s
40 lines
1.8 KiB
JavaScript
40 lines
1.8 KiB
JavaScript
const fn = require('../functions');
|
|
const axios = require('axios');
|
|
const dotenv = require('dotenv').config();
|
|
const Tenor = require('tenorjs-v2');
|
|
|
|
const tenor = new Tenor(process.env.TENOR_API_KEY);
|
|
// TODO: Tenor has changed API versions, switch from TenorJS (unmaintained) to axios for
|
|
// general API usage. See: https://github.com/Jinzulen/TenorJS/issues/12
|
|
// see also: https://developers.google.com/tenor/guides/migrate-from-v1
|
|
|
|
module.exports = {
|
|
name: 'gif',
|
|
description: 'Send a GIF',
|
|
usage: '<GIF name or Search Query>.gif',
|
|
async execute(message, commandData) {
|
|
// if (message.deletable) message.delete();
|
|
const client = message.client;
|
|
if (!client.gifs.has(commandData.args)) {
|
|
if (process.env.isDev) console.log('https://tenor.googleapis.com/v2/search?' + `&q=${commandData.args}` + `&key=${process.env.tenorAPIKey}` + '&limit=1&contentfilter=off');
|
|
tenor.search(commandData.args, "1").then(res => {
|
|
if (res[0] == undefined) {
|
|
message.reply('Sorry I was unable to find a GIF of ' + commandData.args);
|
|
return;
|
|
};
|
|
commandData.embed_url = res[0].mediaUrl;
|
|
// message.reply(fn.embeds.gif(commandData));
|
|
// message.channel.send(`> ${commandData.author} - ${commandData.args}.gif`);
|
|
// message.channel.send(commandData.embed_url);
|
|
message.reply(commandData.embed_url);
|
|
}).catch(err => console.error(err));
|
|
} else {
|
|
// message.reply(commandData.args + ' requested by ' + message.author.username + '\n' + client.gifs.get(commandData.args).embed_url);
|
|
commandData.embed_url = client.gifs.get(commandData.args).embed_url;
|
|
// message.reply(fn.embeds.gif(commandData));
|
|
// message.channel.send(`> ${commandData.author} - ${commandData.args}.gif`);
|
|
// message.channel.send(commandData.embed_url);
|
|
message.reply(commandData.embed_url);
|
|
}
|
|
}
|
|
} |