Switching to Tenor for GIFs
This commit is contained in:
parent
b66c545500
commit
c99662723b
@ -1,5 +1,11 @@
|
||||
const functions = require('../functions');
|
||||
const giphy = require('giphy-api')(process.env.giphyAPIKey);
|
||||
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", // Your locale here, case-sensitivity depends on input
|
||||
"MediaFilter": "minimal", // either minimal or basic, not case sensitive
|
||||
"DateFormat": "D/MM/YYYY - H:mm:ss A" // Change this accordingly
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
name: 'gif',
|
||||
@ -7,17 +13,13 @@ module.exports = {
|
||||
execute(message, file) {
|
||||
const client = message.client;
|
||||
if (!client.gifs.has(file.name)) {
|
||||
giphy.search(file.name).then(function (res) {
|
||||
if (res.data[0] != undefined) {
|
||||
// message.channel.send(file.name + ' requested by ' + message.author.username + '\n' + res.data[0].embed_url).then().catch(console.error);
|
||||
tenor.Search.Query(file.name, 1).then(res => {
|
||||
if (res[0] == undefined) return;
|
||||
const gifInfo = {
|
||||
'name': file.name,
|
||||
'embed_url': res.data[0].images.original.url
|
||||
'embed_url': res[0].media[0].gif.url
|
||||
};
|
||||
message.channel.send(functions.createGifEmbed(gifInfo, message.author, `${file.name}.${file.extension}`));
|
||||
} else {
|
||||
message.channel.send('I was unable to find a gif of ' + file.name);
|
||||
}
|
||||
})
|
||||
.catch(err => console.error(err));
|
||||
} else {
|
||||
|
@ -1,4 +1,10 @@
|
||||
const giphy = require('giphy-api')(process.env.giphyAPIKey);
|
||||
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", // Your locale here, case-sensitivity depends on input
|
||||
"MediaFilter": "minimal", // either minimal or basic, not case sensitive
|
||||
"DateFormat": "D/MM/YYYY - H:mm:ss A" // Change this accordingly
|
||||
});
|
||||
const functions = require('../functions');
|
||||
const { emoji } = require('../config.json');
|
||||
|
||||
@ -9,17 +15,16 @@ module.exports = {
|
||||
execute(message, file) {
|
||||
const channel = message.channel;
|
||||
const query = file.name;
|
||||
giphy.search(query)
|
||||
tenor.Search.Query(query, 20)
|
||||
.then(res => {
|
||||
if (res.data == undefined) return;
|
||||
if (res.data[0] == undefined) {
|
||||
if (res[0] == undefined) {
|
||||
channel.send('Sorry, I wasn\'t able to find a GIF of ' + file.name);
|
||||
return;
|
||||
}
|
||||
let i = 0;
|
||||
const data = {
|
||||
"name": file.name,
|
||||
"embed_url": res.data[i].images.original.url,
|
||||
"embed_url": res[0].media[0].gif.url,
|
||||
"author": message.author
|
||||
};
|
||||
let embed = functions.createGifEmbed(data, message.author, `${Object.values(file).join('.')}`);
|
||||
@ -42,8 +47,13 @@ module.exports = {
|
||||
collector.on('collect', (reaction, user) => {
|
||||
switch (reaction.emoji.name) {
|
||||
case emoji.next:
|
||||
if (i < res.length) {
|
||||
i++;
|
||||
data.embed_url = res.data[i].images.original.url;
|
||||
} else {
|
||||
selfMessage.channel.send('That\'s the last GIF, sorry!');
|
||||
break;
|
||||
}
|
||||
data.embed_url = res[i].media[0].gif.url;
|
||||
embed = functions.createGifEmbed(data, message.author, `${file.name}.${file.extension}`);
|
||||
if (selfMessage.editable) {
|
||||
selfMessage.edit(embed);
|
||||
@ -60,11 +70,15 @@ module.exports = {
|
||||
functions.saveGif(message, nameMessage.content, data.embed_url);
|
||||
});
|
||||
});
|
||||
|
||||
break;
|
||||
case emoji.previous:
|
||||
if (i > 0) {
|
||||
i--;
|
||||
data.embed_url = res.data[i].images.original.url;
|
||||
} else {
|
||||
selfMessage.channel.send('That\'s the first GIF, can\'t go back any further!');
|
||||
break;
|
||||
}
|
||||
data.embed_url = res[i].media[0].gif.url;
|
||||
embed = functions.createGifEmbed(data, message.author, `${file.name}.${file.extension}`);
|
||||
if (selfMessage.editable) {
|
||||
selfMessage.edit(embed);
|
||||
|
4
gifs/psh.js
Normal file
4
gifs/psh.js
Normal file
@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
name: 'psh',
|
||||
embed_url: 'https://media.tenor.com/images/c88d8cdde582c01cb1396db7f01023eb/tenor.gif'
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
module.exports = {
|
||||
name: 'unreal',
|
||||
embed_url: 'https://media1.giphy.com/media/Q8hDlkzBrcrdz200GC/giphy.gif'
|
||||
embed_url: 'https://media.tenor.com/images/5ff1d1ef874429a81db93a15d49f208c/tenor.gif'
|
||||
}
|
25
package-lock.json
generated
25
package-lock.json
generated
@ -440,6 +440,11 @@
|
||||
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
||||
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
|
||||
},
|
||||
"colors": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
|
||||
"integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA=="
|
||||
},
|
||||
"combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
@ -1263,6 +1268,11 @@
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
||||
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
|
||||
},
|
||||
"moment": {
|
||||
"version": "2.29.1",
|
||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz",
|
||||
"integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ=="
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||
@ -1505,6 +1515,11 @@
|
||||
"glob": "^7.1.3"
|
||||
}
|
||||
},
|
||||
"roi": {
|
||||
"version": "0.18.0",
|
||||
"resolved": "https://registry.npmjs.org/roi/-/roi-0.18.0.tgz",
|
||||
"integrity": "sha512-nRUZ5fJxnU9SUAc30Pul10O4LlWqdpXh1xunb3zsR7FA/NJ4yPNzL2ViTgAB7H70YqLsfGQRghvaff8ZcV/7Ug=="
|
||||
},
|
||||
"semver": {
|
||||
"version": "5.7.1",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz",
|
||||
@ -1680,6 +1695,16 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"tenorjs": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/tenorjs/-/tenorjs-1.0.8.tgz",
|
||||
"integrity": "sha512-rPN3AVJYK7M3fRrELV4YC5Iw+FyEy+BAgsj9iRg9KujATLlT0lPtnE3btC2fuWUA7evSwqFc1t17g/vPhL7EyA==",
|
||||
"requires": {
|
||||
"colors": "^1.3.3",
|
||||
"moment": "^2.24.0",
|
||||
"roi": "^0.18.0"
|
||||
}
|
||||
},
|
||||
"term-size": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/term-size/-/term-size-2.2.1.tgz",
|
||||
|
@ -8,7 +8,8 @@
|
||||
"discord.js": "^12.5.3",
|
||||
"dotenv": "^10.0.0",
|
||||
"giphy-api": "^2.0.2",
|
||||
"nodemon": "^2.0.9"
|
||||
"nodemon": "^2.0.9",
|
||||
"tenorjs": "^1.0.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^7.29.0"
|
||||
|
Loading…
Reference in New Issue
Block a user