Finish removing "Oh no, an error occurred"

This commit is contained in:
Dragon Fire
2024-03-30 11:59:42 -04:00
parent f6b59c2d46
commit a135cac031
119 changed files with 3418 additions and 4116 deletions
+5 -9
View File
@@ -39,15 +39,11 @@ module.exports = class AnilistCommand extends Command {
}
async run(msg, { query }) {
try {
const data = await this.search(query);
if (!data || !data.id || !data.name) return msg.say('Could not find any results.');
return msg.say(`<https://anilist.co/user/${data.name}>`, {
files: [{ attachment: `https://img.anili.st/user/${data.id}`, name: 'anilist.png' }]
});
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const data = await this.search(query);
if (!data || !data.id || !data.name) return msg.say('Could not find any results.');
return msg.say(`<https://anilist.co/user/${data.name}>`, {
files: [{ attachment: `https://img.anili.st/user/${data.id}`, name: 'anilist.png' }]
});
}
async search(query) {
+15 -19
View File
@@ -71,25 +71,21 @@ module.exports = class AnimeCharacterCommand extends Command {
}
async run(msg, { query }) {
try {
const id = await this.search(query);
if (!id) return msg.say('Could not find any results.');
const character = await this.fetchCharacter(id);
const embed = new MessageEmbed()
.setColor(0x02A9FF)
.setAuthor('AniList', 'https://i.imgur.com/iUIRC7v.png', 'https://anilist.co/')
.setURL(character.siteUrl)
.setThumbnail(character.image.large || character.image.medium || null)
.setTitle(`${character.name.first || ''}${character.name.last ? ` ${character.name.last}` : ''}`)
.setDescription(character.description ? cleanAnilistHTML(character.description, false) : 'No description.')
.addField(' Appearances', trimArray(character.media.edges.map(edge => {
const title = edge.node.title.english || edge.node.title.romaji;
return embedURL(`${title} (${types[edge.node.type]})`, edge.node.siteUrl);
}), 5).join(', '));
return msg.embed(embed);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const id = await this.search(query);
if (!id) return msg.say('Could not find any results.');
const character = await this.fetchCharacter(id);
const embed = new MessageEmbed()
.setColor(0x02A9FF)
.setAuthor('AniList', 'https://i.imgur.com/iUIRC7v.png', 'https://anilist.co/')
.setURL(character.siteUrl)
.setThumbnail(character.image.large || character.image.medium || null)
.setTitle(`${character.name.first || ''}${character.name.last ? ` ${character.name.last}` : ''}`)
.setDescription(character.description ? cleanAnilistHTML(character.description, false) : 'No description.')
.addField(' Appearances', trimArray(character.media.edges.map(edge => {
const title = edge.node.title.english || edge.node.title.romaji;
return embedURL(`${title} (${types[edge.node.type]})`, edge.node.siteUrl);
}), 5).join(', '));
return msg.embed(embed);
}
async search(query) {
+21 -25
View File
@@ -91,31 +91,27 @@ module.exports = class AnimeStaffCommand extends Command {
}
async run(msg, { query }) {
try {
const id = await this.search(query);
if (!id) return msg.say('Could not find any results.');
const staff = await this.fetchStaff(id);
const embed = new MessageEmbed()
.setColor(0x02A9FF)
.setAuthor('AniList', 'https://i.imgur.com/iUIRC7v.png', 'https://anilist.co/')
.setURL(staff.siteUrl)
.setThumbnail(staff.image.large || staff.image.medium || null)
.setTitle(`${staff.name.first || ''}${staff.name.last ? ` ${staff.name.last}` : ''}`)
.setDescription(staff.description ? cleanAnilistHTML(staff.description, false) : 'No description.')
.addField(' Voice Roles',
staff.characterMedia.edges.length ? trimArray(staff.characterMedia.edges.map(edge => {
const title = edge.node.title.english || edge.node.title.romaji;
return embedURL(`${title} (${roles[edge.characterRole]})`, edge.node.siteUrl);
}), 5).join(', ') : 'None')
.addField(' Production Roles',
staff.staffMedia.edges.length ? trimArray(staff.staffMedia.edges.map(edge => {
const title = edge.node.title.english || edge.node.title.romaji;
return embedURL(`${title} (${types[edge.node.type]})`, edge.node.siteUrl);
}), 5).join(', ') : 'None');
return msg.embed(embed);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const id = await this.search(query);
if (!id) return msg.say('Could not find any results.');
const staff = await this.fetchStaff(id);
const embed = new MessageEmbed()
.setColor(0x02A9FF)
.setAuthor('AniList', 'https://i.imgur.com/iUIRC7v.png', 'https://anilist.co/')
.setURL(staff.siteUrl)
.setThumbnail(staff.image.large || staff.image.medium || null)
.setTitle(`${staff.name.first || ''}${staff.name.last ? ` ${staff.name.last}` : ''}`)
.setDescription(staff.description ? cleanAnilistHTML(staff.description, false) : 'No description.')
.addField(' Voice Roles',
staff.characterMedia.edges.length ? trimArray(staff.characterMedia.edges.map(edge => {
const title = edge.node.title.english || edge.node.title.romaji;
return embedURL(`${title} (${roles[edge.characterRole]})`, edge.node.siteUrl);
}), 5).join(', ') : 'None')
.addField(' Production Roles',
staff.staffMedia.edges.length ? trimArray(staff.staffMedia.edges.map(edge => {
const title = edge.node.title.english || edge.node.title.romaji;
return embedURL(`${title} (${types[edge.node.type]})`, edge.node.siteUrl);
}), 5).join(', ') : 'None');
return msg.embed(embed);
}
async search(query) {
+24 -28
View File
@@ -110,34 +110,30 @@ module.exports = class AnimeCommand extends Command {
}
async run(msg, { query }) {
try {
const id = await this.search(query);
if (!id) return msg.say('Could not find any results.');
const anime = await this.fetchAnime(id);
if (!this.personalList) await this.fetchPersonalList();
const entry = this.personalList.find(ani => ani.mediaId === id);
const malScore = await this.fetchMALScore(anime.idMal);
const malURL = `https://myanimelist.net/anime/${anime.idMal}`;
const embed = new MessageEmbed()
.setColor(0x02A9FF)
.setAuthor('AniList', 'https://i.imgur.com/iUIRC7v.png', 'https://anilist.co/')
.setURL(anime.siteUrl)
.setThumbnail(anime.coverImage.large || anime.coverImage.medium || null)
.setTitle(anime.title.english || anime.title.romaji)
.setDescription(anime.description ? cleanAnilistHTML(anime.description) : 'No description.')
.addField(' Status', statuses[anime.status], true)
.addField(' Episodes', anime.episodes?.toString() || '???', true)
.addField(' Season', anime.season ? `${seasons[anime.season]} ${anime.startDate.year}` : '???', true)
.addField(' Average Score', anime.averageScore ? `${anime.averageScore}%` : '???', true)
.addField(` MAL Score`, malScore ? embedURL(malScore, malURL) : '???', true)
.addField(` ${ANILIST_USERNAME}'s Score`, entry && entry.score ? `${entry.score}/10` : '???', true)
.addField(' External Links', anime.externalLinks.length
? anime.externalLinks.map(link => `[${link.site}](${link.url})`).join(', ')
: 'None');
return msg.embed(embed);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const id = await this.search(query);
if (!id) return msg.say('Could not find any results.');
const anime = await this.fetchAnime(id);
if (!this.personalList) await this.fetchPersonalList();
const entry = this.personalList.find(ani => ani.mediaId === id);
const malScore = await this.fetchMALScore(anime.idMal);
const malURL = `https://myanimelist.net/anime/${anime.idMal}`;
const embed = new MessageEmbed()
.setColor(0x02A9FF)
.setAuthor('AniList', 'https://i.imgur.com/iUIRC7v.png', 'https://anilist.co/')
.setURL(anime.siteUrl)
.setThumbnail(anime.coverImage.large || anime.coverImage.medium || null)
.setTitle(anime.title.english || anime.title.romaji)
.setDescription(anime.description ? cleanAnilistHTML(anime.description) : 'No description.')
.addField(' Status', statuses[anime.status], true)
.addField(' Episodes', anime.episodes?.toString() || '???', true)
.addField(' Season', anime.season ? `${seasons[anime.season]} ${anime.startDate.year}` : '???', true)
.addField(' Average Score', anime.averageScore ? `${anime.averageScore}%` : '???', true)
.addField(` MAL Score`, malScore ? embedURL(malScore, malURL) : '???', true)
.addField(` ${ANILIST_USERNAME}'s Score`, entry && entry.score ? `${entry.score}/10` : '???', true)
.addField(' External Links', anime.externalLinks.length
? anime.externalLinks.map(link => `[${link.site}](${link.url})`).join(', ')
: 'None');
return msg.embed(embed);
}
async search(query) {
+10 -14
View File
@@ -30,19 +30,15 @@ module.exports = class DefineCommand extends Command {
}
async run(msg, { word }) {
try {
const { body } = await request
.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];
if (typeof data === 'string') return msg.say(`Could not find any results. Did you mean **${data}**?`);
return msg.say(stripIndents`
**${data.meta.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!`);
}
const { body } = await request
.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];
if (typeof data === 'string') return msg.say(`Could not find any results. Did you mean **${data}**?`);
return msg.say(stripIndents`
**${data.meta.stems[0]}** (${data.fl})
${data.shortdef.map((definition, i) => `(${i + 1}) ${definition}`).join('\n')}
`);
}
};
+20 -24
View File
@@ -28,32 +28,28 @@ module.exports = class FrinkiacCommand extends Command {
}
async run(msg, { query }) {
try {
const search = await this.search(query);
if (!search) return msg.say('Could not find any results.');
const data = await this.fetchCaption(search.Episode, search.Timestamp);
const time = moment.duration(data.Frame.Timestamp).format();
const caption = data.Subtitles.map(sub => sub.Content).join(' ').split(' ');
let url = `https://frinkiac.com/meme/${data.Frame.Episode}/${data.Frame.Timestamp}.jpg`;
const wrapped = [''];
let currentLine = 0;
for (const word of caption) {
if (wrapped[currentLine].length + word.length < 26) {
wrapped[currentLine] += ` ${word}`;
} else {
wrapped.push(` ${word}`);
currentLine++;
}
const search = await this.search(query);
if (!search) return msg.say('Could not find any results.');
const data = await this.fetchCaption(search.Episode, search.Timestamp);
const time = moment.duration(data.Frame.Timestamp).format();
const caption = data.Subtitles.map(sub => sub.Content).join(' ').split(' ');
let url = `https://frinkiac.com/meme/${data.Frame.Episode}/${data.Frame.Timestamp}.jpg`;
const wrapped = [''];
let currentLine = 0;
for (const word of caption) {
if (wrapped[currentLine].length + word.length < 26) {
wrapped[currentLine] += ` ${word}`;
} else {
wrapped.push(` ${word}`);
currentLine++;
}
url += `?b64lines=${base64(wrapped.join('\n')).replace(/\//g, '_')}`;
const seasonEpisode = `S${data.Episode.Season}E${data.Episode.EpisodeNumber}`;
return msg.say(
`This is from **${seasonEpisode} ("${data.Episode.Title}") @ ${time}**.`,
{ files: [url] }
);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
url += `?b64lines=${base64(wrapped.join('\n')).replace(/\//g, '_')}`;
const seasonEpisode = `S${data.Episode.Season}E${data.Episode.EpisodeNumber}`;
return msg.say(
`This is from **${seasonEpisode} ("${data.Episode.Title}") @ ${time}**.`,
{ files: [url] }
);
}
async search(query) {
+9 -13
View File
@@ -26,18 +26,14 @@ module.exports = class GoogleAutofillCommand extends Command {
}
async run(msg, { query }) {
try {
const { text } = await request
.get('https://suggestqueries.google.com/complete/search')
.query({
client: 'firefox',
q: query
});
const data = JSON.parse(text)[1];
if (!data.length) return msg.say('Could not find any results.');
return msg.say(data.join('\n'));
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const { text } = await request
.get('https://suggestqueries.google.com/complete/search')
.query({
client: 'firefox',
q: query
});
const data = JSON.parse(text)[1];
if (!data.length) return msg.say('Could not find any results.');
return msg.say(data.join('\n'));
}
};
+1 -1
View File
@@ -41,7 +41,7 @@ module.exports = class GravatarCommand extends Command {
return msg.say({ files: [{ attachment: body, name: `${emailHash}.jpg` }] });
} catch (err) {
if (err.status === 404) return msg.say('Could not find any results.');
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
throw err;
}
}
};
+1 -1
View File
@@ -32,7 +32,7 @@ module.exports = class HttpCatCommand extends Command {
return msg.say({ files: [{ attachment: body, name: `${code}.jpg` }] });
} catch (err) {
if (err.status === 404) return msg.say('Could not find any results.');
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
throw err;
}
}
};
+11 -15
View File
@@ -30,21 +30,17 @@ module.exports = class KnowYourMemeCommand extends Command {
}
async run(msg, { query }) {
try {
const location = await this.search(query);
if (!location) return msg.say('Could not find any results.');
const data = await this.fetchMeme(location);
const embed = new MessageEmbed()
.setColor(0x12133F)
.setAuthor('Know Your Meme', 'https://i.imgur.com/WvcH4Z2.png', 'https://knowyourmeme.com/')
.setTitle(data.name)
.setDescription(shorten(data.description || 'No description available.'))
.setURL(data.url)
.setThumbnail(data.thumbnail);
return msg.embed(embed);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const location = await this.search(query);
if (!location) return msg.say('Could not find any results.');
const data = await this.fetchMeme(location);
const embed = new MessageEmbed()
.setColor(0x12133F)
.setAuthor('Know Your Meme', 'https://i.imgur.com/WvcH4Z2.png', 'https://knowyourmeme.com/')
.setTitle(data.name)
.setDescription(shorten(data.description || 'No description available.'))
.setURL(data.url)
.setThumbnail(data.thumbnail);
return msg.embed(embed);
}
async search(query) {
+24 -28
View File
@@ -103,34 +103,30 @@ module.exports = class MangaCommand extends Command {
}
async run(msg, { query }) {
try {
const id = await this.search(query);
if (!id) return msg.say('Could not find any results.');
const manga = await this.fetchManga(id);
if (!this.personalList) await this.fetchPersonalList();
const entry = this.personalList.find(ma => ma.mediaId === id);
const malScore = await this.fetchMALScore(manga.idMal);
const malURL = `https://myanimelist.net/manga/${manga.idMal}`;
const embed = new MessageEmbed()
.setColor(0x02A9FF)
.setAuthor('AniList', 'https://i.imgur.com/iUIRC7v.png', 'https://anilist.co/')
.setURL(manga.siteUrl)
.setThumbnail(manga.coverImage.large || manga.coverImage.medium || null)
.setTitle(manga.title.english || manga.title.romaji)
.setDescription(manga.description ? cleanAnilistHTML(manga.description) : 'No description.')
.addField(' Status', statuses[manga.status], true)
.addField(' Chapters / Volumes', `${manga.chapters || '???'}/${manga.volumes || '???'}`, true)
.addField(' Year', manga.startDate.year?.toString() || '???', true)
.addField(' Average Score', manga.averageScore ? `${manga.averageScore}%` : '???', true)
.addField(` MAL Score`, malScore ? embedURL(malScore, malURL) : '???', true)
.addField(` ${ANILIST_USERNAME}'s Score`, entry && entry.score ? `${entry.score}/10` : '???', true)
.addField(' External Links', manga.externalLinks.length
? manga.externalLinks.map(link => `[${link.site}](${link.url})`).join(', ')
: 'None');
return msg.embed(embed);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const id = await this.search(query);
if (!id) return msg.say('Could not find any results.');
const manga = await this.fetchManga(id);
if (!this.personalList) await this.fetchPersonalList();
const entry = this.personalList.find(ma => ma.mediaId === id);
const malScore = await this.fetchMALScore(manga.idMal);
const malURL = `https://myanimelist.net/manga/${manga.idMal}`;
const embed = new MessageEmbed()
.setColor(0x02A9FF)
.setAuthor('AniList', 'https://i.imgur.com/iUIRC7v.png', 'https://anilist.co/')
.setURL(manga.siteUrl)
.setThumbnail(manga.coverImage.large || manga.coverImage.medium || null)
.setTitle(manga.title.english || manga.title.romaji)
.setDescription(manga.description ? cleanAnilistHTML(manga.description) : 'No description.')
.addField(' Status', statuses[manga.status], true)
.addField(' Chapters / Volumes', `${manga.chapters || '???'}/${manga.volumes || '???'}`, true)
.addField(' Year', manga.startDate.year?.toString() || '???', true)
.addField(' Average Score', manga.averageScore ? `${manga.averageScore}%` : '???', true)
.addField(` MAL Score`, malScore ? embedURL(malScore, malURL) : '???', true)
.addField(` ${ANILIST_USERNAME}'s Score`, entry && entry.score ? `${entry.score}/10` : '???', true)
.addField(' External Links', manga.externalLinks.length
? manga.externalLinks.map(link => `[${link.site}](${link.url})`).join(', ')
: 'None');
return msg.embed(embed);
}
async search(query) {
+18 -22
View File
@@ -29,28 +29,24 @@ module.exports = class NASACommand extends Command {
}
async run(msg, { query }) {
try {
const { body } = await request
.get('https://images-api.nasa.gov/search')
.query({
q: query,
media_type: 'image'
});
const images = body.collection.items;
if (!images.length) return msg.say('Could not find any results.');
const data = images[Math.floor(Math.random() * images.length)];
const embed = new MessageEmbed()
.setTitle(shorten(data.data[0].title, 256))
.setDescription(shorten(this.cleanHTML(data.data[0].description)))
.setColor(0x2E528E)
.setAuthor('NASA', 'https://i.imgur.com/Wh8jY9c.png', 'https://www.nasa.gov/multimedia/imagegallery/index.html')
.setImage(`https://images-assets.nasa.gov/image/${data.data[0].nasa_id}/${data.data[0].nasa_id}~thumb.jpg`)
.setFooter(`Image Credits: ${data.data[0].center || 'Public Domain'}`)
.setTimestamp(new Date(data.data[0].date_created));
return msg.embed(embed);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const { body } = await request
.get('https://images-api.nasa.gov/search')
.query({
q: query,
media_type: 'image'
});
const images = body.collection.items;
if (!images.length) return msg.say('Could not find any results.');
const data = images[Math.floor(Math.random() * images.length)];
const embed = new MessageEmbed()
.setTitle(shorten(data.data[0].title, 256))
.setDescription(shorten(this.cleanHTML(data.data[0].description)))
.setColor(0x2E528E)
.setAuthor('NASA', 'https://i.imgur.com/Wh8jY9c.png', 'https://www.nasa.gov/multimedia/imagegallery/index.html')
.setImage(`https://images-assets.nasa.gov/image/${data.data[0].nasa_id}/${data.data[0].nasa_id}~thumb.jpg`)
.setFooter(`Image Credits: ${data.data[0].center || 'Public Domain'}`)
.setTimestamp(new Date(data.data[0].date_created));
return msg.embed(embed);
}
cleanHTML(text) {
+1 -1
View File
@@ -48,7 +48,7 @@ module.exports = class NeopetCommand extends Command {
return msg.say({ files: [{ attachment: body, name: `${pet}-${mood}.png` }] });
} catch (err) {
if (err.status === 404) return msg.say('Could not find any results.');
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
throw err;
}
}
};
+11 -15
View File
@@ -34,21 +34,17 @@ module.exports = class NeopetsItemCommand extends Command {
}
async run(msg, { item }) {
try {
const data = await this.fetchItem(item);
if (!data) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0xFFCE31)
.setAuthor('Neopets', 'https://i.imgur.com/BP8qxJH.png', 'http://www.neopets.com/')
.setTitle(data.name)
.setDescription(data.details)
.setURL(data.url)
.setThumbnail(data.image)
.addField(' Price', data.price ? `${formatNumber(data.price)} ${data.currency}` : 'Not for Sale');
return msg.embed(embed);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const data = await this.fetchItem(item);
if (!data) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0xFFCE31)
.setAuthor('Neopets', 'https://i.imgur.com/BP8qxJH.png', 'http://www.neopets.com/')
.setTitle(data.name)
.setDescription(data.details)
.setURL(data.url)
.setThumbnail(data.image)
.addField(' Price', data.price ? `${formatNumber(data.price)} ${data.currency}` : 'Not for Sale');
return msg.embed(embed);
}
async fetchItem(query) {
+15 -19
View File
@@ -30,24 +30,20 @@ module.exports = class UrbanCommand extends Command {
}
async run(msg, { word }) {
try {
const { body } = await request
.get('http://api.urbandictionary.com/v0/define')
.query({ term: word });
if (!body.list.length) return msg.say('Could not find any results.');
const data = body.list[0];
const embed = new MessageEmbed()
.setColor(0x32A8F0)
.setAuthor('Urban Dictionary', 'https://i.imgur.com/Fo0nRTe.png', 'https://www.urbandictionary.com/')
.setURL(data.permalink)
.setTitle(data.word)
.setDescription(shorten(data.definition.replace(/\[|\]/g, '')))
.setFooter(`👍 ${formatNumber(data.thumbs_up)} 👎 ${formatNumber(data.thumbs_down)}`)
.setTimestamp(new Date(data.written_on))
.addField(' Example', data.example ? shorten(data.example.replace(/\[|\]/g, ''), 1000) : 'None');
return msg.embed(embed);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const { body } = await request
.get('http://api.urbandictionary.com/v0/define')
.query({ term: word });
if (!body.list.length) return msg.say('Could not find any results.');
const data = body.list[0];
const embed = new MessageEmbed()
.setColor(0x32A8F0)
.setAuthor('Urban Dictionary', 'https://i.imgur.com/Fo0nRTe.png', 'https://www.urbandictionary.com/')
.setURL(data.permalink)
.setTitle(data.word)
.setDescription(shorten(data.definition.replace(/\[|\]/g, '')))
.setFooter(`👍 ${formatNumber(data.thumbs_up)} 👎 ${formatNumber(data.thumbs_down)}`)
.setTimestamp(new Date(data.written_on))
.addField(' Example', data.example ? shorten(data.example.replace(/\[|\]/g, ''), 1000) : 'None');
return msg.embed(embed);
}
};
+21 -25
View File
@@ -29,30 +29,26 @@ module.exports = class WikipediaCommand extends Command {
}
async run(msg, { query }) {
try {
const { body } = await request
.get('https://en.wikipedia.org/w/api.php')
.query({
action: 'query',
prop: 'extracts',
format: 'json',
titles: query,
exintro: '',
explaintext: '',
redirects: '',
formatversion: 2
});
const data = body.query.pages[0];
if (data.missing) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0xE7E7E7)
.setTitle(data.title)
.setAuthor('Wikipedia', 'https://i.imgur.com/Z7NJBK2.png', 'https://www.wikipedia.org/')
.setURL(`https://en.wikipedia.org/wiki/${encodeURIComponent(query).replaceAll(')', '%29')}`)
.setDescription(shorten(data.extract.replaceAll('\n', '\n\n')));
return msg.embed(embed);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const { body } = await request
.get('https://en.wikipedia.org/w/api.php')
.query({
action: 'query',
prop: 'extracts',
format: 'json',
titles: query,
exintro: '',
explaintext: '',
redirects: '',
formatversion: 2
});
const data = body.query.pages[0];
if (data.missing) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0xE7E7E7)
.setTitle(data.title)
.setAuthor('Wikipedia', 'https://i.imgur.com/Z7NJBK2.png', 'https://www.wikipedia.org/')
.setURL(`https://en.wikipedia.org/wiki/${encodeURIComponent(query).replaceAll(')', '%29')}`)
.setDescription(shorten(data.extract.replaceAll('\n', '\n\n')));
return msg.embed(embed);
}
};
+23 -27
View File
@@ -38,31 +38,19 @@ module.exports = class XKCDCommand extends Command {
}
async run(msg, { query }) {
try {
const current = await request.get('https://xkcd.com/info.0.json');
if (query === 'today') {
const embed = new MessageEmbed()
.setTitle(`${current.body.num} - ${current.body.title}`)
.setColor(0x9797FF)
.setURL(`https://xkcd.com/${current.body.num}`)
.setImage(current.body.img)
.setFooter(current.body.alt);
return msg.embed(embed);
}
if (query === 'random') {
const random = Math.floor(Math.random() * current.body.num) + 1;
const { body } = await request.get(`https://xkcd.com/${random}/info.0.json`);
const embed = new MessageEmbed()
.setTitle(`${body.num} - ${body.title}`)
.setColor(0x9797FF)
.setURL(`https://xkcd.com/${body.num}`)
.setImage(body.img)
.setFooter(body.alt);
return msg.embed(embed);
}
const choice = Number.parseInt(query, 10);
if (current.body.num < choice) return msg.say('Could not find any results.');
const { body } = await request.get(`https://xkcd.com/${choice}/info.0.json`);
const current = await request.get('https://xkcd.com/info.0.json');
if (query === 'today') {
const embed = new MessageEmbed()
.setTitle(`${current.body.num} - ${current.body.title}`)
.setColor(0x9797FF)
.setURL(`https://xkcd.com/${current.body.num}`)
.setImage(current.body.img)
.setFooter(current.body.alt);
return msg.embed(embed);
}
if (query === 'random') {
const random = Math.floor(Math.random() * current.body.num) + 1;
const { body } = await request.get(`https://xkcd.com/${random}/info.0.json`);
const embed = new MessageEmbed()
.setTitle(`${body.num} - ${body.title}`)
.setColor(0x9797FF)
@@ -70,8 +58,16 @@ module.exports = class XKCDCommand extends Command {
.setImage(body.img)
.setFooter(body.alt);
return msg.embed(embed);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const choice = Number.parseInt(query, 10);
if (current.body.num < choice) return msg.say('Could not find any results.');
const { body } = await request.get(`https://xkcd.com/${choice}/info.0.json`);
const embed = new MessageEmbed()
.setTitle(`${body.num} - ${body.title}`)
.setColor(0x9797FF)
.setURL(`https://xkcd.com/${body.num}`)
.setImage(body.img)
.setFooter(body.alt);
return msg.embed(embed);
}
};
+29 -33
View File
@@ -36,39 +36,35 @@ module.exports = class YuGiOhCommand extends Command {
}
async run(msg, { card }) {
try {
const { body } = await request
.get('https://db.ygoprodeck.com/api/v7/cardinfo.php')
.query({
fname: card,
la: 'english'
});
const data = body.data[0];
const embed = new MessageEmbed()
.setColor(0xBE5F1F)
.setTitle(data.name)
.setURL(`https://db.ygoprodeck.com/card/?search=${data.id}`)
.setDescription(data.type === 'Normal Monster' ? `_${shorten(data.desc)}_` : shorten(data.desc))
.setAuthor('Yu-Gi-Oh!', 'https://i.imgur.com/AJNBflD.png', 'http://www.yugioh-card.com/')
.setThumbnail(data.card_images[0].image_url)
.setFooter(data.id.toString())
.addField(' Type', data.type, true)
.addField(data.type.includes('Monster') ? ' Race' : ' Spell Type', data.race, true);
if (data.type.includes('Monster')) {
embed
.addField(' Attribute', data.attribute, true)
.addField(' Level', data.level?.toString() || 'N/A', true)
.addField(' ATK', formatNumber(data.atk).toString(), true)
.addField(
data.type === 'Link Monster' ? ' Link Value' : ' DEF',
formatNumber(data.type === 'Link Monster' ? data.linkval : data.def).toString(),
true
);
}
embed.addField(' TCGPlayer Price', `$${data.card_prices[0].tcgplayer_price}`);
return msg.embed(embed);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
const { body } = await request
.get('https://db.ygoprodeck.com/api/v7/cardinfo.php')
.query({
fname: card,
la: 'english'
});
const data = body.data[0];
const embed = new MessageEmbed()
.setColor(0xBE5F1F)
.setTitle(data.name)
.setURL(`https://db.ygoprodeck.com/card/?search=${data.id}`)
.setDescription(data.type === 'Normal Monster' ? `_${shorten(data.desc)}_` : shorten(data.desc))
.setAuthor('Yu-Gi-Oh!', 'https://i.imgur.com/AJNBflD.png', 'http://www.yugioh-card.com/')
.setThumbnail(data.card_images[0].image_url)
.setFooter(data.id.toString())
.addField(' Type', data.type, true)
.addField(data.type.includes('Monster') ? ' Race' : ' Spell Type', data.race, true);
if (data.type.includes('Monster')) {
embed
.addField(' Attribute', data.attribute, true)
.addField(' Level', data.level?.toString() || 'N/A', true)
.addField(' ATK', formatNumber(data.atk).toString(), true)
.addField(
data.type === 'Link Monster' ? ' Link Value' : ' DEF',
formatNumber(data.type === 'Link Monster' ? data.linkval : data.def).toString(),
true
);
}
embed.addField(' TCGPlayer Price', `$${data.card_prices[0].tcgplayer_price}`);
return msg.embed(embed);
}
};