mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-13 15:58:06 +02:00
Added Yoda Command
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
const commando = require('discord.js-commando');
|
||||
const request = require('request-promise');
|
||||
const config = require('../../config.json');
|
||||
|
||||
class YodaCommand extends commando.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.']
|
||||
});
|
||||
}
|
||||
|
||||
async run(message, args) {
|
||||
if(message.channel.type !== 'dm') {
|
||||
if(!message.channel.permissionsFor(this.client.user).hasPermission('SEND_MESSAGES')) return;
|
||||
if(!message.channel.permissionsFor(this.client.user).hasPermission('READ_MESSAGES')) return;
|
||||
}
|
||||
console.log("[Command] " + message.content);
|
||||
let yodaspeak = message.content.split(" ").slice(1).join("-");
|
||||
const options = {
|
||||
method: 'GET',
|
||||
uri: 'https://yoda.p.mashape.com/yoda',
|
||||
qs: {
|
||||
sentence: yodaspeak
|
||||
},
|
||||
headers: {
|
||||
'X-Mashape-Key': config.mashapekey,
|
||||
'Accept': "text/plain"
|
||||
},
|
||||
json: true
|
||||
}
|
||||
request(options).then(function (response) {
|
||||
if(response === undefined) {
|
||||
message.channel.sendMessage(':x: Error! Something went wrong! Keep it simple to avoid this error.');
|
||||
} else {
|
||||
let translated = response.split('-').join(" ");
|
||||
message.channel.sendMessage(translated);
|
||||
}
|
||||
}).catch(function (err) {
|
||||
message.channel.sendMessage(":x: Error!");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = YodaCommand;
|
||||
Reference in New Issue
Block a user