Catch every API

This commit is contained in:
Daniel Odendahl Jr
2017-08-27 22:04:58 +00:00
parent 75422711c3
commit eed39c5ec1
63 changed files with 785 additions and 631 deletions
+1 -1
View File
@@ -43,7 +43,7 @@ module.exports = class YearsCommand extends Command {
ctx.drawImage(avatar, 461, 127, 200, 200);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: '3000-years.png' }] });
} catch (err) {
return msg.say(`Oh no, the image generation failed: \`${err.message}\`. Try again later!`);
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -43,7 +43,7 @@ module.exports = class ApprovedCommand extends Command {
ctx.drawImage(base, 0, 0, 256, 256);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'approved.png' }] });
} catch (err) {
return msg.say(`Oh no, the image generation failed: \`${err.message}\`. Try again later!`);
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -44,7 +44,7 @@ module.exports = class BeautifulCommand extends Command {
ctx.drawImage(avatar, 343, 301, 117, 135);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'beautiful.png' }] });
} catch (err) {
return msg.say(`Oh no, the image generation failed: \`${err.message}\`. Try again later!`);
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -47,7 +47,7 @@ module.exports = class BobRossCommand extends Command {
ctx.drawImage(base, 0, 0);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'bob-ross.png' }] });
} catch (err) {
return msg.say(`Oh no, the image generation failed: \`${err.message}\`. Try again later!`);
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -67,7 +67,7 @@ module.exports = class CardCommand extends Command {
ctx.fillText(`#${member.user.discriminator}`, 313, 355);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'card.png' }] });
} catch (err) {
return msg.say(`Oh no, the image generation failed: \`${err.message}\`. Try again later!`);
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -42,7 +42,7 @@ module.exports = class ChallengerCommand extends Command {
ctx.drawImage(avatar, 484, 98, 256, 256);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'challenger.png' }] });
} catch (err) {
return msg.say(`Oh no, the image generation failed: \`${err.message}\`. Try again later!`);
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -44,7 +44,7 @@ module.exports = class DexterCommand extends Command {
ctx.rotate(11 * Math.PI / 180);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'dexter.png' }] });
} catch (err) {
return msg.say(`Oh no, the image generation failed: \`${err.message}\`. Try again later!`);
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -49,7 +49,7 @@ module.exports = class GreyscaleCommand extends Command {
ctx.putImageData(imgData, 0, 0);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'greyscale.png' }] });
} catch (err) {
return msg.say(`Oh no, the image generation failed: \`${err.message}\`. Try again later!`);
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -47,7 +47,7 @@ module.exports = class InvertCommand extends Command {
ctx.putImageData(imgData, 0, 0);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'invert.png' }] });
} catch (err) {
return msg.say(`Oh no, the image generation failed: \`${err.message}\`. Try again later!`);
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -43,7 +43,7 @@ module.exports = class RejctedCommand extends Command {
ctx.drawImage(base, 0, 0, 256, 256);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'rejected.png' }] });
} catch (err) {
return msg.say(`Oh no, the image generation failed: \`${err.message}\`. Try again later!`);
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -52,7 +52,7 @@ module.exports = class RIPCommand extends Command {
ctx.putImageData(imgData, 158, 51);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'rip.png' }] });
} catch (err) {
return msg.say(`Oh no, the image generation failed: \`${err.message}\`. Try again later!`);
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -44,7 +44,7 @@ module.exports = class SimbaCommand extends Command {
ctx.rotate(24 * Math.PI / 180);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'simba.png' }] });
} catch (err) {
return msg.say(`Oh no, the image generation failed: \`${err.message}\`. Try again later!`);
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -48,7 +48,7 @@ module.exports = class SteamCardCommand extends Command {
ctx.fillText(member.displayName, 35, 48);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'steam-card.png' }] });
} catch (err) {
return msg.say(`Oh no, the image generation failed: \`${err.message}\`. Try again later!`);
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -51,7 +51,7 @@ module.exports = class ThugLifeCommand extends Command {
ctx.putImageData(imgData, 0, 0);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'thug-life.png' }] });
} catch (err) {
return msg.say(`Oh no, the image generation failed: \`${err.message}\`. Try again later!`);
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -48,7 +48,7 @@ module.exports = class TriggeredCommand extends Command {
ctx.drawImage(base, 0, 0);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'triggered.png' }] });
} catch (err) {
return msg.say(`Oh no, the image generation failed: \`${err.message}\`. Try again later!`);
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -42,7 +42,7 @@ module.exports = class WantedCommand extends Command {
ctx.drawImage(avatar, 150, 360, 430, 430);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'wanted.png' }] });
} catch (err) {
return msg.say(`Oh no, the image generation failed: \`${err.message}\`. Try again later!`);
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+31 -27
View File
@@ -43,33 +43,37 @@ module.exports = class QuizCommand extends Command {
async run(msg, args) {
const { type, difficulty } = args;
const { body } = await snekfetch
.get('https://opentdb.com/api.php')
.query({
amount: 1,
type,
encode: 'url3986',
difficulty
try {
const { body } = await snekfetch
.get('https://opentdb.com/api.php')
.query({
amount: 1,
type,
encode: 'url3986',
difficulty
});
if (!body.results) return msg.say('Oh no, a question could not be fetched. Try again later!');
const answers = body.results[0].incorrect_answers.map(answer => decodeURIComponent(answer.toLowerCase()));
const correct = decodeURIComponent(body.results[0].correct_answer.toLowerCase());
answers.push(correct);
const embed = new MessageEmbed()
.setTitle('You have 15 seconds to answer this question:')
.setColor(0x9797FF)
.setDescription(stripIndents`
**${decodeURIComponent(body.results[0].category)}**
${type === 'boolean' ? '**True or False:** ' : ''}${decodeURIComponent(body.results[0].question)}
${type === 'multiple' ? `**Choices:** ${list(shuffle(answers), 'or')}` : ''}
`);
await msg.embed(embed);
const msgs = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, {
max: 1,
time: 15000
});
if (!body.results) return msg.say('Oh no, a question could not be fetched. Try again later!');
const answers = body.results[0].incorrect_answers.map(answer => decodeURIComponent(answer.toLowerCase()));
const correct = decodeURIComponent(body.results[0].correct_answer.toLowerCase());
answers.push(correct);
const embed = new MessageEmbed()
.setTitle('You have 15 seconds to answer this question:')
.setColor(0x9797FF)
.setDescription(stripIndents`
**${decodeURIComponent(body.results[0].category)}**
${type === 'boolean' ? '**True or False:** ' : ''}${decodeURIComponent(body.results[0].question)}
${type === 'multiple' ? `**Choices:** ${list(shuffle(answers), 'or')}` : ''}
`);
await msg.embed(embed);
const msgs = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, {
max: 1,
time: 15000
});
if (!msgs.size) return msg.say(`Time! It was ${correct}, sorry!`);
if (msgs.first().content.toLowerCase() !== correct) return msg.say(`Nope, sorry, it's ${correct}.`);
return msg.say('Nice job! 10/10! You deserve some cake!');
if (!msgs.size) return msg.say(`Time! It was ${correct}, sorry!`);
if (msgs.first().content.toLowerCase() !== correct) return msg.say(`Nope, sorry, it's ${correct}.`);
return msg.say('Nice job! 10/10! You deserve some cake!');
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+21 -17
View File
@@ -17,22 +17,26 @@ module.exports = class WhosThatPokemonCommand extends Command {
async run(msg) {
const pokemon = Math.floor(Math.random() * 721) + 1;
const { body } = await snekfetch
.get(`https://pokeapi.co/api/v2/pokemon-species/${pokemon}`);
const names = body.names.map(name => name.name.toLowerCase());
const name = filterPkmn(body.names).name;
const id = `${'000'.slice(body.id.toString().length)}${body.id}`;
const embed = new MessageEmbed()
.setTitle('You have 15 seconds, who\'s that Pokémon?')
.setColor(0xED1C24)
.setImage(`https://www.serebii.net/sunmoon/pokemon/${id}.png`);
await msg.embed(embed);
const msgs = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, {
max: 1,
time: 15000
});
if (!msgs.size) return msg.say(`Time! It was ${name}, sorry!`);
if (!names.includes(msgs.first().content.toLowerCase())) return msg.say(`Nope, sorry, it's ${name}.`);
return msg.say('Nice job! 10/10! You deserve some cake!');
try {
const { body } = await snekfetch
.get(`https://pokeapi.co/api/v2/pokemon-species/${pokemon}`);
const names = body.names.map(name => name.name.toLowerCase());
const name = filterPkmn(body.names).name;
const id = `${'000'.slice(body.id.toString().length)}${body.id}`;
const embed = new MessageEmbed()
.setTitle('You have 15 seconds, who\'s that Pokémon?')
.setColor(0xED1C24)
.setImage(`https://www.serebii.net/sunmoon/pokemon/${id}.png`);
await msg.embed(embed);
const msgs = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, {
max: 1,
time: 15000
});
if (!msgs.size) return msg.say(`Time! It was ${name}, sorry!`);
if (!names.includes(msgs.first().content.toLowerCase())) return msg.say(`Nope, sorry, it's ${name}.`);
return msg.say('Nice job! 10/10! You deserve some cake!');
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+12 -8
View File
@@ -25,14 +25,18 @@ module.exports = class AchievementCommand extends Command {
async run(msg, args) {
const { text } = args;
const { body } = await snekfetch
.get('https://www.minecraftskinstealer.com/achievement/a.php')
.query({
i: 1,
h: 'Achievement Get!',
t: text
});
return msg.say({ files: [{ attachment: body, name: 'achievement.png' }] });
try {
const { body } = await snekfetch
.get('https://www.minecraftskinstealer.com/achievement/a.php')
.query({
i: 1,
h: 'Achievement Get!',
t: text
});
return msg.say({ files: [{ attachment: body, name: 'achievement.png' }] });
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+11 -4
View File
@@ -1,4 +1,5 @@
const Command = require('../../structures/Command');
const snekfetch = require('snekfetch');
const { list } = require('../../structures/Util');
const codes = require('../../assets/json/meme');
@@ -30,7 +31,7 @@ module.exports = class MemeCommand extends Command {
if (top.length < 200) return true;
return 'Please keep the top text under 200 characters.';
},
parse: top => encodeURIComponent(top.replace(/ /g, '-'))
parse: top => encodeURIComponent(top)
},
{
key: 'bottom',
@@ -40,14 +41,20 @@ module.exports = class MemeCommand extends Command {
if (bottom.length < 200) return true;
return 'Please keep the bottom text under 200 characters.';
},
parse: bottom => encodeURIComponent(bottom.replace(/ /g, '-'))
parse: bottom => encodeURIComponent(bottom)
}
]
});
}
run(msg, args) {
async run(msg, args) {
const { type, top, bottom } = args;
return msg.say({ files: [`https://memegen.link/${type}/${top}/${bottom}.jpg`] });
try {
const { body } = await snekfetch
.get(`https://memegen.link/api/templates/${type}/${top}/${bottom}`);
return msg.say({ files: [body.direct.visible] });
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+11 -7
View File
@@ -44,12 +44,16 @@ module.exports = class CurrencyCommand extends Command {
async run(msg, args) {
const { base, target, amount } = args;
if (base === target) return msg.say(`Converting ${base} to ${target} is the same value, dummy.`);
const { body } = await snekfetch
.get('http://api.fixer.io/latest')
.query({
base,
symbols: target
});
return msg.say(`${amount} ${base} is ${amount * body.rates[target]} ${target}.`);
try {
const { body } = await snekfetch
.get('http://api.fixer.io/latest')
.query({
base,
symbols: target
});
return msg.say(`${amount} ${base} is ${amount * body.rates[target]} ${target}.`);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+2 -2
View File
@@ -22,9 +22,9 @@ module.exports = class MathCommand extends Command {
const { expression } = args;
try {
const solved = math.eval(expression).toString();
return msg.say(solved).catch(() => msg.say('Invalid Statement'));
return msg.say(solved).catch(() => msg.say('Invalid statement.'));
} catch (err) {
return msg.say('Invalid Statement');
return msg.say('Invalid statement.');
}
}
};
+7 -3
View File
@@ -13,8 +13,12 @@ module.exports = class CatCommand extends Command {
}
async run(msg) {
const { body } = await snekfetch
.get('http://random.cat/meow');
return msg.say(body.file);
try {
const { body } = await snekfetch
.get('http://random.cat/meow');
return msg.say(body.file);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+7 -3
View File
@@ -12,8 +12,12 @@ module.exports = class DogCommand extends Command {
}
async run(msg) {
const { body } = await snekfetch
.get('https://random.dog/woof.json');
return msg.say(body.url);
try {
const { body } = await snekfetch
.get('https://random.dog/woof.json');
return msg.say(body.url);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+11 -7
View File
@@ -22,12 +22,16 @@ module.exports = class ChuckNorrisCommand extends Command {
async run(msg, args) {
const { name } = args;
const { body } = await snekfetch
.get('http://api.icndb.com/jokes/random')
.query({
escape: 'javascript',
firstName: name
});
return msg.say(body.value.joke);
try {
const { body } = await snekfetch
.get('http://api.icndb.com/jokes/random')
.query({
escape: 'javascript',
firstName: name
});
return msg.say(body.value.joke);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+12 -8
View File
@@ -14,13 +14,17 @@ module.exports = class FortuneCommand extends Command {
}
async run(msg) {
const { body } = await snekfetch
.get('http://fortunecookieapi.herokuapp.com/v1/cookie')
.query({ limit: 1 });
return msg.say(stripIndents`
${body[0].fortune.message}
${body[0].lotto.numbers.join(', ')}
${body[0].lesson.chinese} (${body[0].lesson.pronunciation}): ${body[0].lesson.english}
`);
try {
const { body } = await snekfetch
.get('http://fortunecookieapi.herokuapp.com/v1/cookie')
.query({ limit: 1 });
return msg.say(stripIndents`
${body[0].fortune.message}
${body[0].lotto.numbers.join(', ')}
${body[0].lesson.chinese} (${body[0].lesson.pronunciation}): ${body[0].lesson.english}
`);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+8 -4
View File
@@ -12,9 +12,13 @@ module.exports = class JokeCommand extends Command {
}
async run(msg) {
const { body } = await snekfetch
.get('https://icanhazdadjoke.com/')
.set({ Accept: 'application/json' });
return msg.say(body.joke);
try {
const { body } = await snekfetch
.get('https://icanhazdadjoke.com/')
.set({ Accept: 'application/json' });
return msg.say(body.joke);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+12 -8
View File
@@ -28,13 +28,17 @@ module.exports = class NameCommand extends Command {
async run(msg, args) {
const { gender } = args;
const { body } = await snekfetch
.get('http://namey.muffinlabs.com/name.json')
.query({
with_surname: true,
type: gender,
frequency: 'all'
});
return msg.say(body[0]);
try {
const { body } = await snekfetch
.get('http://namey.muffinlabs.com/name.json')
.query({
with_surname: true,
type: gender,
frequency: 'all'
});
return msg.say(body[0]);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+7 -3
View File
@@ -12,8 +12,12 @@ module.exports = class QuoteCommand extends Command {
}
async run(msg) {
const { body } = await snekfetch
.get('https://talaikis.com/api/quotes/random/');
return msg.say(`${body.quote} - _${body.author}_`);
try {
const { body } = await snekfetch
.get('https://talaikis.com/api/quotes/random/');
return msg.say(`${body.quote} - _${body.author}_`);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -39,7 +39,7 @@ module.exports = class TodayCommand extends Command {
return msg.embed(embed);
} catch (err) {
if (err.status === 404 || err.status === 500) return msg.say('Invalid date.');
throw err;
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+12 -8
View File
@@ -15,13 +15,17 @@ module.exports = class WouldYouRatherCommand extends Command {
}
async run(msg) {
const { body } = await snekfetch
.get('http://www.rrrather.com/botapi');
const embed = new MessageEmbed()
.setTitle(`${body.title}...`)
.setURL(body.link)
.setColor(0x9797FF)
.setDescription(`${body.choicea} OR ${body.choiceb}?`);
return msg.embed(embed);
try {
const { body } = await snekfetch
.get('http://www.rrrather.com/botapi');
const embed = new MessageEmbed()
.setTitle(`${body.title}...`)
.setURL(body.link)
.setColor(0x9797FF)
.setDescription(`${body.choicea} OR ${body.choiceb}?`);
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+19 -15
View File
@@ -30,20 +30,24 @@ module.exports = class HoroscopeCommand extends Command {
async run(msg, args) {
const { sign } = args;
const { text } = await snekfetch
.get(`http://sandipbgt.com/theastrologer/api/horoscope/${sign}/today`);
const body = JSON.parse(text);
const embed = new MessageEmbed()
.setColor(0x9797FF)
.setTitle(`Horoscope for ${body.sunsign}...`)
.setTimestamp()
.setDescription(body.horoscope)
.addField(' Mood',
body.meta.mood, true)
.addField(' Intensity',
body.meta.intensity, true)
.addField(' Date',
body.date, true);
return msg.embed(embed);
try {
const { text } = await snekfetch
.get(`http://sandipbgt.com/theastrologer/api/horoscope/${sign}/today`);
const body = JSON.parse(text);
const embed = new MessageEmbed()
.setColor(0x9797FF)
.setTitle(`Horoscope for ${body.sunsign}...`)
.setTimestamp()
.setDescription(body.horoscope)
.addField(' Mood',
body.meta.mood, true)
.addField(' Intensity',
body.meta.intensity, true)
.addField(' Date',
body.date, true);
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+11 -7
View File
@@ -38,12 +38,16 @@ module.exports = class StrawpollCommand extends Command {
const { title, options } = args;
if (options.length < 2) return msg.say('Please provide more than one choice.');
if (options.length > 31) return msg.say('Please provide thirty or less choices.');
const { body } = await snekfetch
.post('https://strawpoll.me/api/v2/polls')
.send({ title, options });
return msg.say(stripIndents`
${body.title}
http://www.strawpoll.me/${body.id}
`);
try {
const { body } = await snekfetch
.post('https://strawpoll.me/api/v2/polls')
.send({ title, options });
return msg.say(stripIndents`
${body.title}
http://www.strawpoll.me/${body.id}
`);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+29 -25
View File
@@ -25,21 +25,34 @@ module.exports = class XKCDCommand extends Command {
async run(msg, args) {
const { type } = args;
const current = await snekfetch
.get('https://xkcd.com/info.0.json');
if (type === '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 (type === 'random') {
const random = Math.floor(Math.random() * current.body.num) + 1;
try {
const current = await snekfetch
.get('https://xkcd.com/info.0.json');
if (type === '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 (type === 'random') {
const random = Math.floor(Math.random() * current.body.num) + 1;
const { body } = await snekfetch
.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 = parseInt(type, 10);
if (isNaN(choice) || current.body.num < choice || choice < 1) return msg.say('Invalid number.');
const { body } = await snekfetch
.get(`https://xkcd.com/${random}/info.0.json`);
.get(`https://xkcd.com/${choice}/info.0.json`);
const embed = new MessageEmbed()
.setTitle(`${body.num} - ${body.title}`)
.setColor(0x9797FF)
@@ -47,17 +60,8 @@ module.exports = class XKCDCommand extends Command {
.setImage(body.img)
.setFooter(body.alt);
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const choice = parseInt(type, 10);
if (isNaN(choice) || current.body.num < choice || choice < 1) return msg.say('Invalid number.');
const { body } = await snekfetch
.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);
}
};
+1 -1
View File
@@ -50,7 +50,7 @@ module.exports = class AnimeCommand extends Command {
return msg.embed(embed);
} catch (err) {
if (err.message === 'Parse Error') return msg.say('Could not find any results.');
throw err;
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -42,7 +42,7 @@ module.exports = class BotSearchCommand extends Command {
return msg.embed(embed);
} catch (err) {
if (err.status === 404) return msg.say('Could not find any results.');
throw err;
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+23 -19
View File
@@ -24,24 +24,28 @@ module.exports = class BulbapediaCommand extends Command {
async run(msg, args) {
const { query } = args;
const { body } = await snekfetch
.get('http://bulbapedia.bulbagarden.net/w/api.php')
.query({
action: 'query',
prop: 'extracts',
format: 'json',
titles: query,
exintro: '',
explaintext: '',
redirects: '',
formatversion: 2
});
if (body.query.pages[0].missing) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0x3E7614)
.setTitle(body.query.pages[0].title)
.setAuthor('Bulbapedia', 'https://i.imgur.com/09eYo5T.png')
.setDescription(shorten(body.query.pages[0].extract.replace(/\n/g, '\n\n')));
return msg.embed(embed);
try {
const { body } = await snekfetch
.get('http://bulbapedia.bulbagarden.net/w/api.php')
.query({
action: 'query',
prop: 'extracts',
format: 'json',
titles: query,
exintro: '',
explaintext: '',
redirects: '',
formatversion: 2
});
if (body.query.pages[0].missing) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0x3E7614)
.setTitle(body.query.pages[0].title)
.setAuthor('Bulbapedia', 'https://i.imgur.com/09eYo5T.png')
.setDescription(shorten(body.query.pages[0].extract.replace(/\n/g, '\n\n')));
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+18 -14
View File
@@ -24,19 +24,23 @@ module.exports = class DefineCommand extends Command {
async run(msg, args) {
const { query } = args;
const { body } = await snekfetch
.get(`http://api.wordnik.com:80/v4/word.json/${query}/definitions`)
.query({
limit: 1,
includeRelated: false,
useCanonical: false,
api_key: WORDNIK_KEY
});
if (!body.length) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0x9797FF)
.setTitle(body[0].word)
.setDescription(body[0].text);
return msg.embed(embed);
try {
const { body } = await snekfetch
.get(`http://api.wordnik.com:80/v4/word.json/${query}/definitions`)
.query({
limit: 1,
includeRelated: false,
useCanonical: false,
api_key: WORDNIK_KEY
});
if (!body.length) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0x9797FF)
.setTitle(body[0].word)
.setDescription(body[0].text);
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+60 -56
View File
@@ -23,61 +23,65 @@ module.exports = class ForecastCommand extends Command {
async run(msg, args) {
const { query } = args;
const { body } = await snekfetch
.get('https://query.yahooapis.com/v1/public/yql')
.query({
q: `select * from weather.forecast where u='f' AND woeid in (select woeid from geo.places(1) where text="${query}")`, // eslint-disable-line max-len
format: 'json'
});
if (!body.query.count) return msg.say('Could not find any results.');
const forecasts = body.query.results.channel.item.forecast;
const embed = new MessageEmbed()
.setColor(0x0000FF)
.setAuthor(body.query.results.channel.title, 'https://i.imgur.com/2MT0ViC.png')
.setURL(body.query.results.channel.link)
.setTimestamp()
.addField(` ${forecasts[0].day} - ${forecasts[0].date}`,
stripIndents`
**High:** ${forecasts[0].high}°F
**Low:** ${forecasts[0].low}°F
**Condition:** ${forecasts[0].text}
`)
.addField(` ${forecasts[1].day} - ${forecasts[1].date}`,
stripIndents`
**High:** ${forecasts[1].high}°F
**Low:** ${forecasts[1].low}°F
**Condition:** ${forecasts[1].text}
`)
.addField(` ${forecasts[2].day} - ${forecasts[2].date}`,
stripIndents`
**High:** ${forecasts[2].high}°F
**Low:** ${forecasts[2].low}°F
**Condition:** ${forecasts[2].text}
`)
.addField(` ${forecasts[3].day} - ${forecasts[3].date}`,
stripIndents`
**High:** ${forecasts[3].high}°F
**Low:** ${forecasts[3].low}°F
**Condition:** ${forecasts[3].text}
`)
.addField(` ${forecasts[4].day} - ${forecasts[4].date}`,
stripIndents`
**High:** ${forecasts[4].high}°F
**Low:** ${forecasts[4].low}°F
**Condition:** ${forecasts[4].text}
`)
.addField(` ${forecasts[5].day} - ${forecasts[5].date}`,
stripIndents`
**High:** ${forecasts[5].high}°F
**Low:** ${forecasts[5].low}°F
**Condition:** ${forecasts[5].text}
`)
.addField(` ${forecasts[6].day} - ${forecasts[6].date}`,
stripIndents`
**High:** ${forecasts[6].high}°F
**Low:** ${forecasts[6].low}°F
**Condition:** ${forecasts[6].text}
`);
return msg.embed(embed);
try {
const { body } = await snekfetch
.get('https://query.yahooapis.com/v1/public/yql')
.query({
q: `select * from weather.forecast where u='f' AND woeid in (select woeid from geo.places(1) where text="${query}")`, // eslint-disable-line max-len
format: 'json'
});
if (!body.query.count) return msg.say('Could not find any results.');
const forecasts = body.query.results.channel.item.forecast;
const embed = new MessageEmbed()
.setColor(0x0000FF)
.setAuthor(body.query.results.channel.title, 'https://i.imgur.com/2MT0ViC.png')
.setURL(body.query.results.channel.link)
.setTimestamp()
.addField(` ${forecasts[0].day} - ${forecasts[0].date}`,
stripIndents`
**High:** ${forecasts[0].high}°F
**Low:** ${forecasts[0].low}°F
**Condition:** ${forecasts[0].text}
`)
.addField(` ${forecasts[1].day} - ${forecasts[1].date}`,
stripIndents`
**High:** ${forecasts[1].high}°F
**Low:** ${forecasts[1].low}°F
**Condition:** ${forecasts[1].text}
`)
.addField(` ${forecasts[2].day} - ${forecasts[2].date}`,
stripIndents`
**High:** ${forecasts[2].high}°F
**Low:** ${forecasts[2].low}°F
**Condition:** ${forecasts[2].text}
`)
.addField(` ${forecasts[3].day} - ${forecasts[3].date}`,
stripIndents`
**High:** ${forecasts[3].high}°F
**Low:** ${forecasts[3].low}°F
**Condition:** ${forecasts[3].text}
`)
.addField(` ${forecasts[4].day} - ${forecasts[4].date}`,
stripIndents`
**High:** ${forecasts[4].high}°F
**Low:** ${forecasts[4].low}°F
**Condition:** ${forecasts[4].text}
`)
.addField(` ${forecasts[5].day} - ${forecasts[5].date}`,
stripIndents`
**High:** ${forecasts[5].high}°F
**Low:** ${forecasts[5].low}°F
**Condition:** ${forecasts[5].text}
`)
.addField(` ${forecasts[6].day} - ${forecasts[6].date}`,
stripIndents`
**High:** ${forecasts[6].high}°F
**Low:** ${forecasts[6].low}°F
**Condition:** ${forecasts[6].text}
`);
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+13 -9
View File
@@ -21,14 +21,18 @@ module.exports = class GiphyCommand extends Command {
async run(msg, args) {
const { query } = args;
const { body } = await snekfetch
.get('http://api.giphy.com/v1/gifs/search')
.query({
q: query,
api_key: GIPHY_KEY,
rating: msg.channel.nsfw ? 'r' : 'pg'
});
if (!body.data.length) return msg.say('No Results.');
return msg.say(body.data[Math.floor(Math.random() * body.data.length)].images.original.url);
try {
const { body } = await snekfetch
.get('http://api.giphy.com/v1/gifs/search')
.query({
q: query,
api_key: GIPHY_KEY,
rating: msg.channel.nsfw ? 'r' : 'pg'
});
if (!body.data.length) return msg.say('Could not find any results.');
return msg.say(body.data[Math.floor(Math.random() * body.data.length)].images.original.url);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+2 -2
View File
@@ -53,8 +53,8 @@ module.exports = class GitHubCommand extends Command {
moment(body.updated_at).format('MMMM Do YYYY'), true);
return msg.embed(embed);
} catch (err) {
if (err.status === 404) return msg.say('Could not find the repository.');
throw err;
if (err.status === 404) return msg.say('Could not find any results.');
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -50,7 +50,7 @@ module.exports = class MangaCommand extends Command {
return msg.embed(embed);
} catch (err) {
if (err.message === 'Parse Error') return msg.say('Could not find any results.');
throw err;
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+13 -9
View File
@@ -32,14 +32,18 @@ module.exports = class MapCommand extends Command {
async run(msg, args) {
const { zoom, query } = args;
const { body } = await snekfetch
.get('https://maps.googleapis.com/maps/api/staticmap')
.query({
center: query,
zoom,
size: '500x500',
key: GOOGLE_KEY
});
return msg.say({ files: [{ attachment: body, name: 'map.png' }] });
try {
const { body } = await snekfetch
.get('https://maps.googleapis.com/maps/api/staticmap')
.query({
center: query,
zoom,
size: '500x500',
key: GOOGLE_KEY
});
return msg.say({ files: [{ attachment: body, name: 'map.png' }] });
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+31 -27
View File
@@ -25,32 +25,36 @@ module.exports = class MovieCommand extends Command {
async run(msg, args) {
const { query } = args;
const search = await snekfetch
.get('http://api.themoviedb.org/3/search/movie')
.query({
api_key: TMDB_KEY,
include_adult: msg.channel.nsfw || false,
query
});
if (!search.body.results.length) return msg.say('Could not find any results.');
const { body } = await snekfetch
.get(`https://api.themoviedb.org/3/movie/${search.body.results[0].id}`)
.query({ api_key: TMDB_KEY });
const embed = new MessageEmbed()
.setColor(0x00D474)
.setTitle(body.title)
.setURL(`https://www.themoviedb.org/movie/${body.id}`)
.setAuthor('TMDB', 'https://i.imgur.com/G9q4DF1.png')
.setDescription(body.overview ? shorten(body.overview) : 'No description available.')
.setThumbnail(body.poster_path ? `https://image.tmdb.org/t/p/w500${body.poster_path}` : null)
.addField(' Runtime',
body.runtime ? `${body.runtime} mins.` : 'N/A', true)
.addField(' Release Date',
body.release_date || 'N/A', true)
.addField(' Genres',
body.genres.length ? body.genres.map(genre => genre.name).join(', ') : 'N/A')
.addField(' Production Companies',
body.production_companies.length ? body.production_companies.map(company => company.name).join(', ') : 'N/A');
return msg.embed(embed);
try {
const search = await snekfetch
.get('http://api.themoviedb.org/3/search/movie')
.query({
api_key: TMDB_KEY,
include_adult: msg.channel.nsfw || false,
query
});
if (!search.body.results.length) return msg.say('Could not find any results.');
const { body } = await snekfetch
.get(`https://api.themoviedb.org/3/movie/${search.body.results[0].id}`)
.query({ api_key: TMDB_KEY });
const embed = new MessageEmbed()
.setColor(0x00D474)
.setTitle(body.title)
.setURL(`https://www.themoviedb.org/movie/${body.id}`)
.setAuthor('TMDB', 'https://i.imgur.com/G9q4DF1.png')
.setDescription(body.overview ? shorten(body.overview) : 'No description available.')
.setThumbnail(body.poster_path ? `https://image.tmdb.org/t/p/w500${body.poster_path}` : null)
.addField(' Runtime',
body.runtime ? `${body.runtime} mins.` : 'N/A', true)
.addField(' Release Date',
body.release_date || 'N/A', true)
.addField(' Genres',
body.genres.length ? body.genres.map(genre => genre.name).join(', ') : 'N/A')
.addField(' Production Companies',
body.production_companies.length ? body.production_companies.map(c => c.name).join(', ') : 'N/A');
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+14 -10
View File
@@ -20,15 +20,19 @@ module.exports = class NeopetCommand extends Command {
async run(msg, args) {
const { query } = args;
const { text } = await snekfetch
.get('http://www.sunnyneo.com/petimagefinder.php')
.query({
name: query,
size: 5,
mood: 1
});
const link = text.match(/http:\/\/pets\.neopets\.com\/cp\/.+\.png/);
if (!link) return msg.say('Could not find any results.');
return msg.say(link[0]);
try {
const { text } = await snekfetch
.get('http://www.sunnyneo.com/petimagefinder.php')
.query({
name: query,
size: 5,
mood: 1
});
const link = text.match(/http:\/\/pets\.neopets\.com\/cp\/.+\.png/);
if (!link) return msg.say('Could not find any results.');
return msg.say(link[0]);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -52,7 +52,7 @@ module.exports = class NPMCommand extends Command {
return msg.embed(embed);
} catch (err) {
if (err.status === 404) return msg.say('Could not find any results.');
throw err;
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+41 -37
View File
@@ -23,42 +23,46 @@ module.exports = class OsuCommand extends Command {
async run(msg, args) {
const { query } = args;
const { body } = await snekfetch
.get('https://osu.ppy.sh/api/get_user')
.query({
k: OSU_KEY,
u: query,
type: 'string'
});
if (!body.length) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0xFF66AA)
.setAuthor('osu!', 'https://i.imgur.com/EmnUp00.png')
.setURL('https://osu.ppy.sh/')
.addField(' Username',
body[0].username, true)
.addField(' ID',
body[0].user_id, true)
.addField(' Level',
body[0].level || 'N/A', true)
.addField(' Accuracy',
body[0].accuracy || 'N/A', true)
.addField(' Rank',
body[0].pp_rank || 'N/A', true)
.addField(' Play Count',
body[0].playcount || 'N/A', true)
.addField(' Country',
body[0].country || 'N/A', true)
.addField(' Ranked Score',
body[0].ranked_score || 'N/A', true)
.addField(' Total Score',
body[0].total_score || 'N/A', true)
.addField(' SS',
body[0].count_rank_ss || 'N/A', true)
.addField(' S',
body[0].count_rank_s || 'N/A', true)
.addField(' A',
body[0].count_rank_a || 'N/A', true);
return msg.embed(embed);
try {
const { body } = await snekfetch
.get('https://osu.ppy.sh/api/get_user')
.query({
k: OSU_KEY,
u: query,
type: 'string'
});
if (!body.length) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0xFF66AA)
.setAuthor('osu!', 'https://i.imgur.com/EmnUp00.png')
.setURL('https://osu.ppy.sh/')
.addField(' Username',
body[0].username, true)
.addField(' ID',
body[0].user_id, true)
.addField(' Level',
body[0].level || 'N/A', true)
.addField(' Accuracy',
body[0].accuracy || 'N/A', true)
.addField(' Rank',
body[0].pp_rank || 'N/A', true)
.addField(' Play Count',
body[0].playcount || 'N/A', true)
.addField(' Country',
body[0].country || 'N/A', true)
.addField(' Ranked Score',
body[0].ranked_score || 'N/A', true)
.addField(' Total Score',
body[0].total_score || 'N/A', true)
.addField(' SS',
body[0].count_rank_ss || 'N/A', true)
.addField(' S',
body[0].count_rank_s || 'N/A', true)
.addField(' A',
body[0].count_rank_a || 'N/A', true);
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -42,7 +42,7 @@ module.exports = class PokedexCommand extends Command {
return msg.embed(embed);
} catch (err) {
if (err.status === 404) return msg.say('Could not find any results.');
throw err;
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+2 -2
View File
@@ -46,8 +46,8 @@ module.exports = class RedditCommand extends Command {
return msg.embed(embed);
} catch (err) {
if (err.status === 403) return msg.say('This subreddit is private.');
if (err.status === 404) return msg.say('Could not find the subreddit.');
throw err;
if (err.status === 404) return msg.say('Could not find any results.');
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+28 -24
View File
@@ -23,29 +23,33 @@ module.exports = class SoundCloudCommand extends Command {
async run(msg, args) {
const { query } = args;
const { body } = await snekfetch
.get('https://api.soundcloud.com/tracks')
.query({
q: query,
client_id: SOUNDCLOUD_KEY
});
if (!body.length) return msg.say('No Results.');
const embed = new MessageEmbed()
.setColor(0xF15A22)
.setAuthor('SoundCloud', 'https://i.imgur.com/lFIz7RU.png')
.setTitle(body[0].title)
.setURL(body[0].permalink_url)
.setThumbnail(body[0].artwork_url)
.addField(' Artist',
body[0].user.username)
.addField(' Download Count',
body[0].download_count, true)
.addField(' Comment Count',
body[0].comment_count, true)
.addField(' Playback Count',
body[0].playback_count, true)
.addField(' Favorited Count',
body[0].favoritings_count, true);
return msg.embed(embed);
try {
const { body } = await snekfetch
.get('https://api.soundcloud.com/tracks')
.query({
q: query,
client_id: SOUNDCLOUD_KEY
});
if (!body.length) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0xF15A22)
.setAuthor('SoundCloud', 'https://i.imgur.com/lFIz7RU.png')
.setTitle(body[0].title)
.setURL(body[0].permalink_url)
.setThumbnail(body[0].artwork_url)
.addField(' Artist',
body[0].user.username)
.addField(' Download Count',
body[0].download_count, true)
.addField(' Comment Count',
body[0].comment_count, true)
.addField(' Playback Count',
body[0].playback_count, true)
.addField(' Favorited Count',
body[0].favoritings_count, true);
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+26 -22
View File
@@ -22,27 +22,31 @@ module.exports = class SteamCommand extends Command {
async run(msg, args) {
const { query } = args;
const { body } = await snekfetch
.get('https://store.steampowered.com/api/storesearch')
.query({
cc: 'us',
l: 'en',
term: query
});
if (!body.total) return msg.say('Could not find any results.');
const current = body.items[0].price ? body.items[0].price.final / 100 : 0.00;
const original = body.items[0].price ? body.items[0].price.initial / 100 : 0.00;
const price = current === original ? `$${current}` : `~~$${original}~~ $${current}`;
const embed = new MessageEmbed()
.setColor(0x101D2F)
.setAuthor('Steam', 'https://i.imgur.com/vL8b4D5.png')
.setTitle(body.items[0].name)
.setURL(`http://store.steampowered.com/app/${body.items[0].id}`)
.setImage(body.items[0].tiny_image)
.addField(' Price',
price, true)
.addField(' Metascore',
body.items[0].metascore || 'N/A', true);
return msg.embed(embed);
try {
const { body } = await snekfetch
.get('https://store.steampowered.com/api/storesearch')
.query({
cc: 'us',
l: 'en',
term: query
});
if (!body.total) return msg.say('Could not find any results.');
const current = body.items[0].price ? body.items[0].price.final / 100 : 0.00;
const original = body.items[0].price ? body.items[0].price.initial / 100 : 0.00;
const price = current === original ? `$${current}` : `~~$${original}~~ $${current}`;
const embed = new MessageEmbed()
.setColor(0x101D2F)
.setAuthor('Steam', 'https://i.imgur.com/vL8b4D5.png')
.setTitle(body.items[0].name)
.setURL(`http://store.steampowered.com/app/${body.items[0].id}`)
.setImage(body.items[0].tiny_image)
.addField(' Price',
price, true)
.addField(' Metascore',
body.items[0].metascore || 'N/A', true);
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+35 -31
View File
@@ -25,36 +25,40 @@ module.exports = class TVShowCommand extends Command {
async run(msg, args) {
const { query } = args;
const search = await snekfetch
.get('http://api.themoviedb.org/3/search/tv')
.query({
api_key: TMDB_KEY,
include_adult: msg.channel.nsfw || false,
query
});
if (!search.body.results.length) return msg.say('Could not find any results.');
const { body } = await snekfetch
.get(`https://api.themoviedb.org/3/tv/${search.body.results[0].id}`)
.query({ api_key: TMDB_KEY });
const embed = new MessageEmbed()
.setColor(0x00D474)
.setTitle(body.name)
.setURL(`https://www.themoviedb.org/tv/${body.id}`)
.setAuthor('TMDB', 'https://i.imgur.com/G9q4DF1.png')
.setDescription(body.overview ? shorten(body.overview) : 'No description available.')
.setThumbnail(body.poster_path ? `https://image.tmdb.org/t/p/w500${body.poster_path}` : null)
.addField(' First Air Date',
body.first_air_date || 'N/A', true)
.addField(' Last Air Date',
body.last_air_date || 'N/A', true)
.addField(' Seasons',
body.number_of_seasons || 'N/A', true)
.addField(' Episodes',
body.number_of_episodes || 'N/A', true)
.addField(' Genres',
body.genres.length ? body.genres.map(genre => genre.name).join(', ') : 'N/A')
.addField(' Production Companies',
body.production_companies.length ? body.production_companies.map(company => company.name).join(', ') : 'N/A');
return msg.embed(embed);
try {
const search = await snekfetch
.get('http://api.themoviedb.org/3/search/tv')
.query({
api_key: TMDB_KEY,
include_adult: msg.channel.nsfw || false,
query
});
if (!search.body.results.length) return msg.say('Could not find any results.');
const { body } = await snekfetch
.get(`https://api.themoviedb.org/3/tv/${search.body.results[0].id}`)
.query({ api_key: TMDB_KEY });
const embed = new MessageEmbed()
.setColor(0x00D474)
.setTitle(body.name)
.setURL(`https://www.themoviedb.org/tv/${body.id}`)
.setAuthor('TMDB', 'https://i.imgur.com/G9q4DF1.png')
.setDescription(body.overview ? shorten(body.overview) : 'No description available.')
.setThumbnail(body.poster_path ? `https://image.tmdb.org/t/p/w500${body.poster_path}` : null)
.addField(' First Air Date',
body.first_air_date || 'N/A', true)
.addField(' Last Air Date',
body.last_air_date || 'N/A', true)
.addField(' Seasons',
body.number_of_seasons || 'N/A', true)
.addField(' Episodes',
body.number_of_episodes || 'N/A', true)
.addField(' Genres',
body.genres.length ? body.genres.map(genre => genre.name).join(', ') : 'N/A')
.addField(' Production Companies',
body.production_companies.length ? body.production_companies.map(c => c.name).join(', ') : 'N/A');
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+17 -13
View File
@@ -23,18 +23,22 @@ module.exports = class UrbanCommand extends Command {
async run(msg, args) {
const { query } = args;
const { body } = await snekfetch
.get('http://api.urbandictionary.com/v0/define')
.query({ term: query });
if (!body.list.length) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0x32A8F0)
.setAuthor('Urban Dictionary', 'https://i.imgur.com/fzFuuL7.png')
.setURL(body.list[0].permalink)
.setTitle(body.list[0].word)
.setDescription(shorten(body.list[0].definition))
.addField(' Example',
shorten(body.list[0].example, 1000) || 'None');
return msg.embed(embed);
try {
const { body } = await snekfetch
.get('http://api.urbandictionary.com/v0/define')
.query({ term: query });
if (!body.list.length) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0x32A8F0)
.setAuthor('Urban Dictionary', 'https://i.imgur.com/fzFuuL7.png')
.setURL(body.list[0].permalink)
.setTitle(body.list[0].word)
.setDescription(shorten(body.list[0].definition))
.addField(' Example',
shorten(body.list[0].example, 1000) || 'None');
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+30 -26
View File
@@ -24,31 +24,35 @@ module.exports = class VocaloidCommand extends Command {
async run(msg, args) {
const { query } = args;
const { body } = await snekfetch
.get('http://vocadb.net/api/songs')
.query({
query,
maxResults: 1,
getTotalCount: true,
sort: 'FavoritedTimes',
preferAccurateMatches: true,
nameMatchMode: 'Words',
fields: 'ThumbUrl,Lyrics'
});
if (!body.totalCount) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0x86D2D0)
.setAuthor('VocaDB', 'https://i.imgur.com/9Tx9UIc.jpg')
.setTitle(body.items[0].name)
.setURL(`http://vocadb.net/S/${body.items[0].id}`)
.setDescription(body.items[0].lyrics.length ? shorten(body.items[0].lyrics[0].value) : 'No lyrics available.')
.setThumbnail(body.items[0].thumbUrl)
.addField(' Artist',
body.items[0].artistString)
.addField(' Publish Date',
moment(body.items[0].publishDate).format('MMMM Do YYYY'), true)
.addField(' Length',
moment.duration(body.items[0].lengthSeconds, 's').format(), true);
return msg.embed(embed);
try {
const { body } = await snekfetch
.get('http://vocadb.net/api/songs')
.query({
query,
maxResults: 1,
getTotalCount: true,
sort: 'FavoritedTimes',
preferAccurateMatches: true,
nameMatchMode: 'Words',
fields: 'ThumbUrl,Lyrics'
});
if (!body.totalCount) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0x86D2D0)
.setAuthor('VocaDB', 'https://i.imgur.com/9Tx9UIc.jpg')
.setTitle(body.items[0].name)
.setURL(`http://vocadb.net/S/${body.items[0].id}`)
.setDescription(body.items[0].lyrics.length ? shorten(body.items[0].lyrics[0].value) : 'N/A')
.setThumbnail(body.items[0].thumbUrl)
.addField(' Artist',
body.items[0].artistString)
.addField(' Publish Date',
moment(body.items[0].publishDate).format('MMMM Do YYYY'), true)
.addField(' Length',
moment.duration(body.items[0].lengthSeconds, 's').format(), true);
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+32 -28
View File
@@ -25,33 +25,37 @@ module.exports = class WattpadCommand extends Command {
async run(msg, args) {
const { query } = args;
const { body } = await snekfetch
.get('https://api.wattpad.com:443/v4/stories')
.query({
query,
limit: 1
})
.set({ Authorization: `Basic ${WATTPAD_KEY}` });
if (!body.stories.length) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0xF89C34)
.setAuthor('Wattpad', 'https://i.imgur.com/Rw9vRQB.png')
.setURL(body.stories[0].url)
.setTitle(body.stories[0].title)
.setDescription(shorten(body.stories[0].description))
.setThumbnail(body.stories[0].cover)
.addField(' Created On',
moment(body.stories[0].createDate).format('MMMM Do YYYY'), true)
.addField(' Author',
body.stories[0].user, true)
.addField(' Parts',
body.stories[0].numParts, true)
.addField(' Reads',
body.stories[0].readCount, true)
.addField(' Votes',
body.stories[0].voteCount, true)
.addField(' Comments',
body.stories[0].commentCount, true);
return msg.embed(embed);
try {
const { body } = await snekfetch
.get('https://api.wattpad.com:443/v4/stories')
.query({
query,
limit: 1
})
.set({ Authorization: `Basic ${WATTPAD_KEY}` });
if (!body.stories.length) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0xF89C34)
.setAuthor('Wattpad', 'https://i.imgur.com/Rw9vRQB.png')
.setURL(body.stories[0].url)
.setTitle(body.stories[0].title)
.setDescription(shorten(body.stories[0].description))
.setThumbnail(body.stories[0].cover)
.addField(' Created On',
moment(body.stories[0].createDate).format('MMMM Do YYYY'), true)
.addField(' Author',
body.stories[0].user, true)
.addField(' Parts',
body.stories[0].numParts, true)
.addField(' Reads',
body.stories[0].readCount, true)
.addField(' Votes',
body.stories[0].voteCount, true)
.addField(' Comments',
body.stories[0].commentCount, true);
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+41 -37
View File
@@ -22,42 +22,46 @@ module.exports = class WeatherCommand extends Command {
async run(msg, args) {
const { query } = args;
const { body } = await snekfetch
.get('https://query.yahooapis.com/v1/public/yql')
.query({
q: `select * from weather.forecast where u='f' AND woeid in (select woeid from geo.places(1) where text="${query}")`, // eslint-disable-line max-len
format: 'json'
});
if (!body.query.count) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0x0000FF)
.setAuthor(body.query.results.channel.title, 'https://i.imgur.com/2MT0ViC.png')
.setURL(body.query.results.channel.link)
.setTimestamp()
.addField(' City',
body.query.results.channel.location.city, true)
.addField(' Country',
body.query.results.channel.location.country, true)
.addField(' Region',
body.query.results.channel.location.region, true)
.addField(' Condition',
body.query.results.channel.item.condition.text, true)
.addField(' Temperature',
`${body.query.results.channel.item.condition.temp}°F`, true)
.addField(' Humidity',
body.query.results.channel.atmosphere.humidity, true)
.addField(' Pressure',
body.query.results.channel.atmosphere.pressure, true)
.addField(' Rising',
body.query.results.channel.atmosphere.rising, true)
.addField(' Visibility',
body.query.results.channel.atmosphere.visibility, true)
.addField(' Wind Chill',
body.query.results.channel.wind.chill, true)
.addField(' Wind Direction',
body.query.results.channel.wind.direction, true)
.addField(' Wind Speed',
body.query.results.channel.wind.speed, true);
return msg.embed(embed);
try {
const { body } = await snekfetch
.get('https://query.yahooapis.com/v1/public/yql')
.query({
q: `select * from weather.forecast where u='f' AND woeid in (select woeid from geo.places(1) where text="${query}")`, // eslint-disable-line max-len
format: 'json'
});
if (!body.query.count) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0x0000FF)
.setAuthor(body.query.results.channel.title, 'https://i.imgur.com/2MT0ViC.png')
.setURL(body.query.results.channel.link)
.setTimestamp()
.addField(' City',
body.query.results.channel.location.city, true)
.addField(' Country',
body.query.results.channel.location.country, true)
.addField(' Region',
body.query.results.channel.location.region, true)
.addField(' Condition',
body.query.results.channel.item.condition.text, true)
.addField(' Temperature',
`${body.query.results.channel.item.condition.temp}°F`, true)
.addField(' Humidity',
body.query.results.channel.atmosphere.humidity, true)
.addField(' Pressure',
body.query.results.channel.atmosphere.pressure, true)
.addField(' Rising',
body.query.results.channel.atmosphere.rising, true)
.addField(' Visibility',
body.query.results.channel.atmosphere.visibility, true)
.addField(' Wind Chill',
body.query.results.channel.wind.chill, true)
.addField(' Wind Direction',
body.query.results.channel.wind.direction, true)
.addField(' Wind Speed',
body.query.results.channel.wind.speed, true);
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+23 -19
View File
@@ -23,24 +23,28 @@ module.exports = class WikipediaCommand extends Command {
async run(msg, args) {
const { query } = args;
const { body } = await snekfetch
.get('https://en.wikipedia.org/w/api.php')
.query({
action: 'query',
prop: 'extracts',
format: 'json',
titles: query,
exintro: '',
explaintext: '',
redirects: '',
formatversion: 2
});
if (body.query.pages[0].missing) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0xE7E7E7)
.setTitle(body.query.pages[0].title)
.setAuthor('Wikipedia', 'https://i.imgur.com/a4eeEhh.png')
.setDescription(shorten(body.query.pages[0].extract.replace(/\n/g, '\n\n')));
return msg.embed(embed);
try {
const { body } = await snekfetch
.get('https://en.wikipedia.org/w/api.php')
.query({
action: 'query',
prop: 'extracts',
format: 'json',
titles: query,
exintro: '',
explaintext: '',
redirects: '',
formatversion: 2
});
if (body.query.pages[0].missing) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0xE7E7E7)
.setTitle(body.query.pages[0].title)
.setAuthor('Wikipedia', 'https://i.imgur.com/a4eeEhh.png')
.setDescription(shorten(body.query.pages[0].extract.replace(/\n/g, '\n\n')));
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+22 -18
View File
@@ -23,23 +23,27 @@ module.exports = class YouTubeCommand extends Command {
async run(msg, args) {
const { query } = args;
const { body } = await snekfetch
.get('https://www.googleapis.com/youtube/v3/search')
.query({
part: 'snippet',
type: 'video',
maxResults: 1,
q: query,
key: GOOGLE_KEY
});
if (!body.items.length) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0xDD2825)
.setTitle(body.items[0].snippet.title)
.setDescription(body.items[0].snippet.description)
.setAuthor(`YouTube - ${body.items[0].snippet.channelTitle}`, 'https://i.imgur.com/hkUafwu.png')
.setURL(`https://www.youtube.com/watch?v=${body.items[0].id.videoId}`)
.setThumbnail(body.items[0].snippet.thumbnails.default.url);
return msg.embed(embed);
try {
const { body } = await snekfetch
.get('https://www.googleapis.com/youtube/v3/search')
.query({
part: 'snippet',
type: 'video',
maxResults: 1,
q: query,
key: GOOGLE_KEY
});
if (!body.items.length) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0xDD2825)
.setTitle(body.items[0].snippet.title)
.setDescription(body.items[0].snippet.description)
.setAuthor(`YouTube - ${body.items[0].snippet.channelTitle}`, 'https://i.imgur.com/hkUafwu.png')
.setURL(`https://www.youtube.com/watch?v=${body.items[0].id.videoId}`)
.setThumbnail(body.items[0].snippet.thumbnails.default.url);
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+27 -23
View File
@@ -23,29 +23,33 @@ module.exports = class YuGiOhCommand extends Command {
async run(msg, args) {
const { query } = args;
const { body } = await snekfetch
.get(`http://yugiohprices.com/api/card_data/${query}`);
if (body.status === 'fail') return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0xBE5F1F)
.setTitle(body.data.name)
.setDescription(body.data.text)
.setAuthor('Yu-Gi-Oh!', 'https://i.imgur.com/7gPm9Rr.png')
.addField(' Card Type',
body.data.card_type, true);
if (body.data.card_type === 'monster') {
embed
.addField(' Type',
body.data.type, true)
.addField(' Attribute',
body.data.family, true)
.addField(' ATK',
body.data.atk, true)
.addField(' DEF',
body.data.def, true)
.addField(' Level',
body.data.level, true);
try {
const { body } = await snekfetch
.get(`http://yugiohprices.com/api/card_data/${query}`);
if (body.status === 'fail') return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setColor(0xBE5F1F)
.setTitle(body.data.name)
.setDescription(body.data.text)
.setAuthor('Yu-Gi-Oh!', 'https://i.imgur.com/7gPm9Rr.png')
.addField(' Card Type',
body.data.card_type, true);
if (body.data.card_type === 'monster') {
embed
.addField(' Type',
body.data.type, true)
.addField(' Attribute',
body.data.family, true)
.addField(' ATK',
body.data.atk, true)
.addField(' DEF',
body.data.def, true)
.addField(' Level',
body.data.level, true);
}
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
return msg.embed(embed);
}
};
+19 -15
View File
@@ -51,20 +51,24 @@ module.exports = class TranslateCommand extends Command {
async run(msg, args) {
const { text, target, original } = args;
const { body } = await snekfetch
.get('https://translate.yandex.net/api/v1.5/tr.json/translate')
.query({
key: YANDEX_KEY,
text,
lang: original ? `${original}-${target}` : target
});
const lang = body.lang.split('-');
const embed = new MessageEmbed()
.setColor(0x00AE86)
.addField(` From: ${codes[lang[0]]}`,
text)
.addField(` To: ${codes[lang[1]]}`,
body.text[0]);
return msg.embed(embed);
try {
const { body } = await snekfetch
.get('https://translate.yandex.net/api/v1.5/tr.json/translate')
.query({
key: YANDEX_KEY,
text,
lang: original ? `${original}-${target}` : target
});
const lang = body.lang.split('-');
const embed = new MessageEmbed()
.setColor(0x00AE86)
.addField(` From: ${codes[lang[0]]}`,
text)
.addField(` To: ${codes[lang[1]]}`,
body.text[0]);
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+8 -4
View File
@@ -24,9 +24,13 @@ module.exports = class WebhookCommand extends Command {
async run(msg, args) {
const { content } = args;
if (msg.guild && msg.channel.permissionsFor(this.client.user).has('MANAGE_MESSAGES')) await msg.delete();
await snekfetch
.post(WEBHOOK_URL)
.send({ content });
return null;
try {
await snekfetch
.post(WEBHOOK_URL)
.send({ content });
return null;
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+14 -7
View File
@@ -16,12 +16,19 @@ module.exports = class UpvoteCommand extends Command {
}
async run(msg) {
const { body } = await snekfetch
.get(`https://discordbots.org/api/bots/${this.client.user.id}/votes`)
.set({ Authorization: DBOTSORG_KEY });
return msg.say(stripIndents`
Upvote Xiao and get rewards while joining ${body.length} others!
<https://discordbots.org/bot/xiaobot>
`);
try {
const { body } = await snekfetch
.get(`https://discordbots.org/api/bots/${this.client.user.id}/votes`)
.set({ Authorization: DBOTSORG_KEY });
return msg.say(stripIndents`
Upvote Xiao and get rewards while joining ${body.length} others!
<https://discordbots.org/bot/xiaobot>
`);
} catch (err) {
return msg.say(stripIndents`
Upvote Xiao and get rewards!
<https://discordbots.org/bot/xiaobot>
`);
}
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "31.2.5",
"version": "31.2.6",
"description": "Your personal server companion.",
"main": "Shard.js",
"scripts": {