diff --git a/.env.example b/.env.example index 6bac0e90..c6f22050 100644 --- a/.env.example +++ b/.env.example @@ -51,7 +51,6 @@ WEBSTER_KEY= WHATANIME_KEY= XIAO_GITHUB_REPO_NAME= XIAO_GITHUB_REPO_USERNAME= -YODA_KEY= # Imgur album IDs BLUSH_ALBUM_ID= diff --git a/commands/text-edit/yoda.js b/commands/text-edit/yoda.js index 46de4dcc..89765f94 100644 --- a/commands/text-edit/yoda.js +++ b/commands/text-edit/yoda.js @@ -1,6 +1,5 @@ const Command = require('../../structures/Command'); -const request = require('node-superfetch'); -const { YODA_KEY } = process.env; +const soap = require('soap'); module.exports = class YodaCommand extends Command { constructor(client) { @@ -25,20 +24,24 @@ module.exports = class YodaCommand extends Command { } ] }); + + this.soapClient = null; } async run(msg, { sentence }) { try { - const { body } = await request - .get('https://yoda-speak-api.herokuapp.com/speak') - .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); + if (!this.soapClient) await this.setUpClient(); + const response = await this.soapClient.yodaTalkAsync({ inputText: sentence }); + const text = response[0].return; + if (!text) return msg.reply('Empty, this message is. Try again later, you must.'); + return msg.say(text); } catch (err) { return msg.reply(`Being a jerk again, Yoda is: \`${err.message}\`. Try again later, you must.`); } } + + async setUpClient() { + this.soapClient = await soap.createClientAsync('https://www.yodaspeak.co.uk/webservice/yodatalk.php?wsdl'); + return this.soapClient; + } }; diff --git a/package.json b/package.json index e1466df6..c5acff20 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "109.0.1", + "version": "109.0.2", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { @@ -46,6 +46,7 @@ "moment-timezone": "^0.5.27", "node-superfetch": "^0.1.9", "random-js": "^2.1.0", + "soap": "^0.30.0", "winston": "^3.2.1" }, "devDependencies": {