Files
xiao/commands/textedit/yoda.js
T
Daniel Odendahl Jr 8074fe51bd Move to snekfetch 🐍
2017-04-16 01:12:22 +00:00

39 lines
1.3 KiB
JavaScript

const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
module.exports = class YodaCommand extends Command {
constructor(client) {
super(client, {
name: 'yoda',
group: 'textedit',
memberName: 'yoda',
description: 'Converts text to Yoda Speak. (;yoda This is Yoda.)',
examples: [';yoda This is Yoda.'],
args: [{
key: 'text',
prompt: 'What text would you like to convert to Yoda speak?',
type: 'string'
}]
});
}
async run(message, args) {
if (message.channel.type !== 'dm') {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
}
const text = encodeURIComponent(args.text);
try {
const response = await snekfetch
.get(`https://yoda.p.mashape.com/yoda?sentence=${text}`)
.set({
'X-Mashape-Key': process.env.MASHAPE_KEY,
'Accept': 'text/plain'
});
return message.say(`\u180E${response.text}`);
}
catch (err) {
return message.say(':x: Error! Something went wrong!');
}
}
};