Change Yoda API, Security Key

This commit is contained in:
Daniel Odendahl Jr
2017-12-18 22:33:54 +00:00
parent dae319c85b
commit 55c0f6a571
2 changed files with 28 additions and 9 deletions
+18
View File
@@ -0,0 +1,18 @@
const { Command } = require('discord.js-commando');
const crypto = require('crypto');
module.exports = class SecurityKeyCommand extends Command {
constructor(client) {
super(client, {
name: 'security-key',
aliases: ['crypto', 'random-bytes'],
group: 'random',
memberName: 'security-key',
description: 'Responds with a random security key.'
});
}
run(msg) {
return msg.say(crypto.randomBytes(15).toString('hex'));
}
};
+10 -9
View File
@@ -1,6 +1,6 @@
const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
const { MASHAPE_KEY } = process.env;
const { YODA_KEY } = process.env;
module.exports = class YodaCommand extends Command {
constructor(client) {
@@ -13,8 +13,7 @@ module.exports = class YodaCommand extends Command {
args: [
{
key: 'sentence',
label: 'text',
prompt: 'What text would you like to convert to Yoda speak?',
prompt: 'What sentence would you like to convert to Yoda speak?',
type: 'string',
max: 500
}
@@ -24,12 +23,14 @@ module.exports = class YodaCommand extends Command {
async run(msg, { sentence }) {
try {
const { text } = await snekfetch
.get('https://yoda.p.mashape.com/yoda')
.query({ sentence })
.set({ 'X-Mashape-Key': MASHAPE_KEY });
if (!text) return msg.reply('Empty, this message is. Try again later, you must.');
return msg.say(text);
const { body } = await snekfetch
.get('https://yoda-speak-api.herokuapp.com/')
.query({
text: sentence,
token: YODA_KEY
});
if (!body.response) return msg.reply('Empty, this message is. Try again later, you must.');
return msg.say(body.response);
} catch (err) {
return msg.reply(`Being a jerk again, Yoda is: \`${err.message}\`. Try again later, you must.`);
}