mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-18 21:40:49 +02:00
Fix some things
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const request = require('node-superfetch');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const { WORDNIK_KEY } = process.env;
|
||||
|
||||
module.exports = class WordOfTheDayCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'word-of-the-day',
|
||||
aliases: ['wordnik-word-of-the-day'],
|
||||
group: 'events',
|
||||
memberName: 'word-of-the-day',
|
||||
description: 'Responds with today\'s word of the day.',
|
||||
credit: [
|
||||
{
|
||||
name: 'Wordnik API',
|
||||
url: 'https://developer.wordnik.com/'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg) {
|
||||
try {
|
||||
const { body } = await request
|
||||
.get('http://api.wordnik.com/v4/words.json/wordOfTheDay')
|
||||
.query({ api_key: WORDNIK_KEY });
|
||||
return msg.say(stripIndents`
|
||||
**${body.word}**
|
||||
(${body.definitions[0].partOfSpeech || '???'}) ${body.definitions[0].text}
|
||||
`);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -3,7 +3,7 @@ const request = require('node-superfetch');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const { delay, verify } = require('../../util/Util');
|
||||
const startWords = require('../../assets/json/word-list');
|
||||
const { WORDNIK_KEY } = process.env;
|
||||
const { WEBSTER_KEY } = process.env;
|
||||
|
||||
module.exports = class WordChainCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -110,14 +110,9 @@ module.exports = class WordChainCommand extends Command {
|
||||
async verifyWord(word) {
|
||||
try {
|
||||
const { body } = await request
|
||||
.get(`http://api.wordnik.com/v4/word.json/${word}/definitions`)
|
||||
.query({
|
||||
limit: 1,
|
||||
includeRelated: false,
|
||||
useCanonical: false,
|
||||
api_key: WORDNIK_KEY
|
||||
});
|
||||
if (!body.length || body[0].word.toLowerCase() !== word) return false;
|
||||
.get(`https://www.dictionaryapi.com/api/v3/references/collegiate/json/${word}`)
|
||||
.query({ key: WEBSTER_KEY });
|
||||
if (!body.length) return false;
|
||||
return true;
|
||||
} catch (err) {
|
||||
if (err.status === 404) return false;
|
||||
|
||||
@@ -106,18 +106,11 @@ module.exports = class AnimeCommand extends Command {
|
||||
.send({
|
||||
variables: {
|
||||
search: query,
|
||||
type: 'ANIME',
|
||||
isAdult: Boolean(nsfw)
|
||||
type: 'ANIME'
|
||||
},
|
||||
query: searchGraphQL
|
||||
});
|
||||
if (!body.data.anime.results.length) return null;
|
||||
const found = body.data.anime.results.find(anime => {
|
||||
if (anime.title.english && anime.title.english.toLowerCase() === query) return true;
|
||||
if (anime.title.romaji && anime.title.romaji.toLowerCase() === query) return true;
|
||||
return false;
|
||||
});
|
||||
if (found) return found.id;
|
||||
return body.data.anime.results[0].id;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const request = require('node-superfetch');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const { WORDNIK_KEY } = process.env;
|
||||
const { WEBSTER_KEY } = process.env;
|
||||
|
||||
module.exports = class DefineCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'define',
|
||||
aliases: ['dictionary', 'wordnik'],
|
||||
aliases: ['dictionary', 'webster'],
|
||||
group: 'search',
|
||||
memberName: 'define',
|
||||
description: 'Defines a word.',
|
||||
credit: [
|
||||
{
|
||||
name: 'Wordnik API',
|
||||
url: 'https://developer.wordnik.com/'
|
||||
name: 'Merriam-Webster\'s Collegiate® Dictionary',
|
||||
url: 'https://dictionaryapi.com/products/api-collegiate-dictionary'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
@@ -31,18 +31,13 @@ module.exports = class DefineCommand extends Command {
|
||||
async run(msg, { word }) {
|
||||
try {
|
||||
const { body } = await request
|
||||
.get(`http://api.wordnik.com/v4/word.json/${word}/definitions`)
|
||||
.query({
|
||||
limit: 1,
|
||||
includeRelated: false,
|
||||
useCanonical: true,
|
||||
api_key: WORDNIK_KEY
|
||||
});
|
||||
.get(`https://www.dictionaryapi.com/api/v3/references/collegiate/json/${word}`)
|
||||
.query({ key: WEBSTER_KEY });
|
||||
if (!body.length) return msg.say('Could not find any results.');
|
||||
const data = body[0];
|
||||
return msg.say(stripIndents`
|
||||
**${data.word}**
|
||||
(${data.partOfSpeech || 'unknown'}) ${data.text}
|
||||
**${data.stems[0]}** (${data.fl})
|
||||
${data.shortdef.map((definition, i) => `(${i + 1}) ${definition}`).join('\n')}
|
||||
`);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
|
||||
@@ -91,8 +91,7 @@ module.exports = class MangaCommand extends Command {
|
||||
.send({
|
||||
variables: {
|
||||
search: query,
|
||||
type: 'MANGA',
|
||||
isAdult: Boolean(nsfw)
|
||||
type: 'MANGA'
|
||||
},
|
||||
query: searchGraphQL
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user