2022-09-25 02:27:34 -04:00
|
|
|
const {
|
|
|
|
EmbedBuilder
|
|
|
|
} = require('discord.js');
|
|
|
|
const {
|
|
|
|
AttachmentBuilder
|
|
|
|
} = require('discord.js');
|
|
|
|
var download = require('download-file')
|
2022-10-17 00:38:56 -04:00
|
|
|
const notDefined = require("is-not-defined");
|
2022-09-25 02:50:27 -04:00
|
|
|
let phonetic
|
2022-09-25 02:27:34 -04:00
|
|
|
var unirest = require('unirest');
|
|
|
|
let meaningsArray = []
|
2022-09-25 02:50:27 -04:00
|
|
|
|
2022-09-25 02:27:34 -04:00
|
|
|
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) => {
|
2022-09-25 02:51:42 -04:00
|
|
|
let data = response.body[0]
|
2022-10-17 00:38:56 -04:00
|
|
|
if (notDefined(data)) {
|
2022-09-25 02:51:42 -04:00
|
|
|
return interaction.editReply("Sorry, nothing was found!")
|
2022-09-25 02:50:27 -04:00
|
|
|
}
|
2022-09-25 02:27:34 -04:00
|
|
|
|
2022-10-17 00:38:56 -04:00
|
|
|
if (notDefined(data.phonetics[1])) {
|
2022-09-25 02:51:42 -04:00
|
|
|
phonetic = ""
|
2022-09-25 02:50:27 -04:00
|
|
|
} else {
|
2022-09-25 02:51:42 -04:00
|
|
|
phonetic = data.phonetics[1].text
|
2022-09-25 02:50:27 -04:00
|
|
|
}
|
2022-09-25 02:51:42 -04:00
|
|
|
|
2022-09-25 02:50:27 -04:00
|
|
|
let audio = data.phonetics[0].audio
|
2022-09-25 02:27:34 -04:00
|
|
|
if (!audio) {
|
2022-09-25 06:27:01 -04:00
|
|
|
|
|
|
|
data.meanings.forEach(wordData => {
|
|
|
|
|
|
|
|
if (wordData.definitions[0].example) {
|
|
|
|
meaningsArray.push({
|
|
|
|
"name": wordData.partOfSpeech,
|
|
|
|
"value": wordData.definitions[0].definition + "\nExample: " + wordData.definitions[0].example
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
meaningsArray.push({
|
|
|
|
"name": wordData.partOfSpeech,
|
|
|
|
"value": wordData.definitions[0].definition
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-09-25 02:27:34 -04:00
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
.setColor("#FF0000")
|
2022-09-25 06:45:06 -04:00
|
|
|
.setTitle(word + ": " + phonetic)
|
2022-09-25 02:27:34 -04:00
|
|
|
.addFields(meaningsArray)
|
|
|
|
.setTimestamp()
|
|
|
|
.setFooter({
|
|
|
|
text: `Requested by ${interaction.user.tag}`,
|
|
|
|
iconURL: `${interaction.user.displayAvatarURL()}`
|
|
|
|
});
|
|
|
|
interaction.editReply({
|
|
|
|
embeds: [embed]
|
|
|
|
});
|
2022-09-25 02:58:27 -04:00
|
|
|
meaningsArray = []
|
2022-09-25 02:27:34 -04:00
|
|
|
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")
|
2022-09-25 06:27:01 -04:00
|
|
|
console.log(data.meanings)
|
2022-09-25 02:27:34 -04:00
|
|
|
data.meanings.forEach(wordData => {
|
2022-09-25 06:15:26 -04:00
|
|
|
|
|
|
|
if (wordData.definitions[0].example) {
|
|
|
|
meaningsArray.push({
|
|
|
|
"name": wordData.partOfSpeech,
|
|
|
|
"value": wordData.definitions[0].definition + "\nExample: " + wordData.definitions[0].example
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
meaningsArray.push({
|
|
|
|
"name": wordData.partOfSpeech,
|
|
|
|
"value": wordData.definitions[0].definition
|
|
|
|
})
|
|
|
|
}
|
2022-09-25 02:27:34 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
const file = new AttachmentBuilder('./audio/' + rand + ".mp3");
|
|
|
|
|
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
.setColor("#FF0000")
|
2022-09-25 06:45:06 -04:00
|
|
|
.setTitle(word + ": " + phonetic)
|
2022-09-25 02:27:34 -04:00
|
|
|
.addFields(meaningsArray)
|
|
|
|
.setTimestamp()
|
|
|
|
.setFooter({
|
|
|
|
text: `Requested by ${interaction.user.tag}`,
|
|
|
|
iconURL: `${interaction.user.displayAvatarURL()}`
|
|
|
|
});
|
|
|
|
interaction.editReply({
|
|
|
|
embeds: [embed],
|
|
|
|
files: [file]
|
|
|
|
});
|
2022-09-25 02:58:27 -04:00
|
|
|
meaningsArray = []
|
2022-09-25 02:27:34 -04:00
|
|
|
rand = Math.floor(Math.random() * 99999).toString();
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
},
|
|
|
|
};
|