From 42e7a234b325af68a5bdec3154f64b33f80ef977 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sun, 25 Sep 2022 02:27:34 -0400 Subject: [PATCH] Adding Dictionary --- .gitignore | 1 + commands/untils/dictionary.js | 88 +++++++++++++++++++++++++++++++++++ commands/untils/qrgen.js | 3 +- package-lock.json | 48 +++++++++++++++++++ package.json | 1 + 5 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 commands/untils/dictionary.js diff --git a/.gitignore b/.gitignore index e9bb675..d9a17f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .env node_modules images +audio diff --git a/commands/untils/dictionary.js b/commands/untils/dictionary.js new file mode 100644 index 0000000..094aed2 --- /dev/null +++ b/commands/untils/dictionary.js @@ -0,0 +1,88 @@ +const { + EmbedBuilder +} = require('discord.js'); +const { + AttachmentBuilder +} = require('discord.js'); +var download = require('download-file') + +var unirest = require('unirest'); +let meaningsArray = [] +module.exports = { + name: "dictionary", + description: "Returns information about a word", + options: [{ + "name": "word", + "description": "The data you would like inside of the QR", + "required": true, + "type": 3 // 6 is type USER + }], + run: async (client, interaction) => { + let rand = Math.floor(Math.random() * 99999).toString(); + let word = interaction.options._hoistedOptions[0].value + + unirest + .get('https://api.dictionaryapi.dev/api/v2/entries/en/' + word) + .headers({ + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }) + .then((response) => { + let data = response.body[0] + let audio = data.phonetics[0].audio + let phonetic = data.phonetics[1].text + + if (!audio) { + const embed = new EmbedBuilder() + .setColor("#FF0000") + .setTitle("Results for " + word + ": " + phonetic) + .addFields(meaningsArray) + .setTimestamp() + .setFooter({ + text: `Requested by ${interaction.user.tag}`, + iconURL: `${interaction.user.displayAvatarURL()}` + }); + interaction.editReply({ + embeds: [embed] + }); + rand = Math.floor(Math.random() * 99999).toString(); + } else { + // Options for Audio Download + var options = { + directory: "./audio/", + filename: rand + ".mp3" + } + + download(audio, options, function(err) { + if (err) throw err + console.log("audio downloaded") + console.log(response.body) + data.meanings.forEach(wordData => { + meaningsArray.push({ + "name": wordData.partOfSpeech, + "value": wordData.definitions[0].definition + }) + }); + + const file = new AttachmentBuilder('./audio/' + rand + ".mp3"); + + const embed = new EmbedBuilder() + .setColor("#FF0000") + .setTitle("Results for " + word + ": " + phonetic) + .addFields(meaningsArray) + .setTimestamp() + .setFooter({ + text: `Requested by ${interaction.user.tag}`, + iconURL: `${interaction.user.displayAvatarURL()}` + }); + interaction.editReply({ + embeds: [embed], + files: [file] + }); + rand = Math.floor(Math.random() * 99999).toString(); + }) + } + }) + + }, +}; \ No newline at end of file diff --git a/commands/untils/qrgen.js b/commands/untils/qrgen.js index e2d5d0d..ce73eae 100644 --- a/commands/untils/qrgen.js +++ b/commands/untils/qrgen.js @@ -36,6 +36,7 @@ module.exports = { url: 'attachment://discordjs.png', }, }; + const embed = new EmbedBuilder() .setColor("#FF0000") .setTitle("Your Generated QR Code") @@ -46,7 +47,5 @@ module.exports = { interaction.editReply({ embeds: [embed], files: [file] }); })(); - - }, }; diff --git a/package-lock.json b/package-lock.json index 2caf0b5..d8f4ca7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "awesome-qr": "^2.1.5-rc.0", "discord.js": "^14.0.3", "dotenv": "^16.0.0", + "download-file": "^0.1.5", "give-me-a-joke": "^0.5.1", "glob": "^7.2.0", "is-not-defined": "^1.0.1", @@ -467,6 +468,25 @@ "node": ">=12" } }, + "node_modules/download-file": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/download-file/-/download-file-0.1.5.tgz", + "integrity": "sha512-cTeC3HGeUdoxKmlWhcNwrCI19kb+WVcJBif1quxIeGmC91FkJzBQuHiQm25uOawV3t33JPthA6yl+f84ofn8UQ==", + "dependencies": { + "mkdirp": "^0.5.0" + } + }, + "node_modules/download-file/node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "dependencies": { + "minimist": "^1.2.6" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, "node_modules/ecc-jsbn": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", @@ -873,6 +893,11 @@ "node": "*" } }, + "node_modules/minimist": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" + }, "node_modules/minipass": { "version": "3.3.4", "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.4.tgz", @@ -1839,6 +1864,24 @@ "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.2.tgz", "integrity": "sha512-JvpYKUmzQhYoIFgK2MOnF3bciIZoItIIoryihy0rIA+H4Jy0FmgyKYAHCTN98P5ybGSJcIFbh6QKeJdtZd1qhA==" }, + "download-file": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/download-file/-/download-file-0.1.5.tgz", + "integrity": "sha512-cTeC3HGeUdoxKmlWhcNwrCI19kb+WVcJBif1quxIeGmC91FkJzBQuHiQm25uOawV3t33JPthA6yl+f84ofn8UQ==", + "requires": { + "mkdirp": "^0.5.0" + }, + "dependencies": { + "mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "requires": { + "minimist": "^1.2.6" + } + } + } + }, "ecc-jsbn": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", @@ -2139,6 +2182,11 @@ "brace-expansion": "^1.1.7" } }, + "minimist": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" + }, "minipass": { "version": "3.3.4", "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.4.tgz", diff --git a/package.json b/package.json index fa0dc90..b32f5e7 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "awesome-qr": "^2.1.5-rc.0", "discord.js": "^14.0.3", "dotenv": "^16.0.0", + "download-file": "^0.1.5", "give-me-a-joke": "^0.5.1", "glob": "^7.2.0", "is-not-defined": "^1.0.1",