From 2d91b78179757d588718ce9013316dc91a5ffec2 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sun, 15 Jul 2018 03:22:47 +0000 Subject: [PATCH] DECTalk is back! --- README.md | 3 ++- commands/voice/dec-talk.js | 50 ++++++++++++++++++++++++++++++++++++++ package.json | 4 +-- 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 commands/voice/dec-talk.js diff --git a/README.md b/README.md index 15b69067..e4ae09c4 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ You can invite the bot to your server using Be sure to also join the [home server](https://discord.gg/sbMe32W) for information and support. -## Commands (295) +## Commands (296) ### Utility: * **prefix**: Shows or sets the command prefix. @@ -220,6 +220,7 @@ information and support. ### Voice Channel: +* **dec-talk**: The world's best Text-to-Speech. * **leave-voice-channel**: Leaves a voice channel, in case the bot gets stuck. * **soundboard**: Plays a sound in your voice channel. diff --git a/commands/voice/dec-talk.js b/commands/voice/dec-talk.js new file mode 100644 index 00000000..491e3f8a --- /dev/null +++ b/commands/voice/dec-talk.js @@ -0,0 +1,50 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); + +module.exports = class DECTalkCommand extends Command { + constructor(client) { + super(client, { + name: 'dec-talk', + aliases: ['moon-base-alpha', 'text-to-speech', 'tts'], + group: 'voice', + memberName: 'dec-talk', + description: 'The world\'s best Text-to-Speech.', + guildOnly: true, + throttling: { + usages: 1, + duration: 10 + }, + args: [ + { + key: 'text', + prompt: 'What text do you want to say?', + type: 'string', + max: 1024 + } + ] + }); + } + + async run(msg, { text }) { + const channel = msg.member.voiceChannel; + if (!channel) return msg.say('Please enter a voice channel first.'); + if (!channel.permissionsFor(this.client.user).has(['CONNECT', 'SPEAK'])) { + return msg.say('Missing the "Connect" or "Speak" permission for the voice channel.'); + } + if (!channel.joinable) return msg.say('Your voice channel is not joinable.'); + if (this.client.voiceConnections.has(channel.guild.id)) return msg.say('I am already playing a sound.'); + try { + const connection = await channel.join(); + const { url } = await request + .get('http://tts.cyzon.us/tts') + .query({ text }); + const dispatcher = connection.play(url); + dispatcher.once('finish', () => channel.leave()); + dispatcher.once('error', () => channel.leave()); + return null; + } catch (err) { + channel.leave(); + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index 595285ca..7b13253a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "84.5.0", + "version": "84.6.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { @@ -40,7 +40,7 @@ "erlpack": "github:discordapp/erlpack", "mathjs": "^5.0.2", "node-opus": "^0.3.0", - "node-superfetch": "^0.1.2", + "node-superfetch": "^0.1.3", "pg": "^6.4.2", "pg-hstore": "^2.3.2", "random-js": "^1.0.8",