From b6d2a539762cec69c226e0eb7de2bd273df90b9b Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Fri, 2 Dec 2022 12:55:05 -0500 Subject: [PATCH 1/3] Tenor search is FUBAR --- dot-commands/gif.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dot-commands/gif.js b/dot-commands/gif.js index 4b8f556..03ea658 100644 --- a/dot-commands/gif.js +++ b/dot-commands/gif.js @@ -7,6 +7,10 @@ const tenor = require('tenorjs').client({ "DateFormat": "D/MM/YYYY - H:mm:ss A" // Change this accordingly }); +// 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', From 6872397c58c3b6e7d079c3cd1a5881c6fc507cb9 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Fri, 2 Dec 2022 13:16:54 -0500 Subject: [PATCH 2/3] Modified workflow for dev environment --- .github/workflows/docker-image.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 76eb4f4..d5fc425 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -2,9 +2,9 @@ name: Docker Image CI on: push: - branches: [ "main" ] + branches: [ "3.0.1-dev" ] pull_request: - branches: [ "main" ] + branches: [ "3.0.1-dev" ] env: DHUB_UNAME: ${{ secrets.DHUB_UNAME }} @@ -19,8 +19,8 @@ jobs: steps: - uses: actions/checkout@v3 - name: Build the Docker image - run: docker build . --file Dockerfile --tag v0idf1sh/nodbot + run: docker build . --file Dockerfile --tag v0idf1sh/nodbot-dev - name: Log into Docker Hub run: docker login -u $DHUB_UNAME -p $DHUB_PWORD - name: Push image to Docker Hub - run: docker push v0idf1sh/nodbot + run: docker push v0idf1sh/nodbot-dev From 7bc2d388021b679da50416c9224855f00e58011e Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Fri, 2 Dec 2022 13:46:26 -0500 Subject: [PATCH 3/3] Migrate from TenorJS to axios --- dot-commands/gif.js | 39 +++++++++++++++++++++++++-------------- package.json | 4 ++-- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/dot-commands/gif.js b/dot-commands/gif.js index 03ea658..c7dedd7 100644 --- a/dot-commands/gif.js +++ b/dot-commands/gif.js @@ -1,11 +1,6 @@ const fn = require('../functions'); -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 axios = require('axios'); +const dotenv = require('dotenv').config(); // TODO: Tenor has changed API versions, switch from TenorJS (unmaintained) to axios for // general API usage. See: https://github.com/Jinzulen/TenorJS/issues/12 @@ -15,21 +10,37 @@ module.exports = { name: 'gif', description: 'Send a GIF', usage: '.gif', - execute(message, commandData) { + async execute(message, commandData) { // if (message.deletable) message.delete(); const client = message.client; if (!client.gifs.has(commandData.args)) { - tenor.Search.Query(commandData.args, 1).then(res => { - if (res[0] == undefined) { + if (process.env.isDev) console.log('https://tenor.googleapis.com/v2/search?' + `&q=${commandData.args}` + `&key=${process.env.tenorAPIKey}` + '&limit=1&contentfilter=off'); + const q = await axios.get( + 'https://tenor.googleapis.com/v2/search?' + + `&q=${commandData.args}` + + `&key=${process.env.tenorAPIKey}` + + '&limit=1' + + `&contentfilter=off` + ).then(res => { + if (process.env.isDev) console.log(res.data.results); + if (res.data.results[0] == undefined) { message.reply('Sorry I was unable to find a GIF of ' + commandData.args); return; }; - commandData.embed_url = res[0].media[0].gif.url; - // message.reply(fn.embeds.gif(commandData)); - // message.channel.send(`> ${commandData.author} - ${commandData.args}.gif`); - // message.channel.send(commandData.embed_url); + commandData.embed_url = res.data.results[0].url; message.reply(commandData.embed_url); }).catch(err => console.error(err)); + // tenor.Search.Query(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].media[0].gif.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); + // }).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; diff --git a/package.json b/package.json index 87f9215..7e600d7 100644 --- a/package.json +++ b/package.json @@ -6,13 +6,13 @@ "dependencies": { "@discordjs/builders": "^0.6.0", "@discordjs/rest": "^0.1.0-canary.0", - "axios": "^0.21.1", + "axios": "^0.21.4", "discord-api-types": "^0.22.0", "discord.js": "^13.1.0", "dotenv": "^10.0.0", "fuzzy-search": "^3.2.1", "mysql": "^2.18.1", - "tenorjs": "^1.0.8" + "tenorjs": "^1.0.10" }, "engines": { "node": "16.x"