Files
xiao/commands/voice/dec-talk.js
T
2020-05-05 20:59:58 -04:00

68 lines
1.8 KiB
JavaScript

const Command = require('../../structures/Command');
const request = require('node-superfetch');
module.exports = class DECTalkCommand extends Command {
constructor(client) {
super(client, {
name: 'dec-talk',
aliases: ['text-to-speech', 'tts'],
group: 'voice',
memberName: 'dec-talk',
description: 'The world\'s best Text-to-Speech.',
guildOnly: true,
throttling: {
usages: 1,
duration: 10
},
userPermissions: ['CONNECT', 'SPEAK'],
credit: [
{
name: 'calzoneman',
url: 'https://github.com/calzoneman',
reason: 'API',
reasonURL: 'https://github.com/calzoneman/aeiou'
},
{
name: 'Digital Equipment Corporation',
url: 'http://gordonbell.azurewebsites.net/digital/timeline/tmlnhome.htm',
reason: 'Original DECTalk Software'
},
{
name: 'NASA',
url: 'https://www.nasa.gov/',
reason: 'Original "Moonbase Alpha" Game',
reasonURL: 'https://store.steampowered.com/app/39000/Moonbase_Alpha/'
}
],
args: [
{
key: 'text',
prompt: 'What text do you want to say?',
type: 'string',
max: 1024
}
]
});
}
async run(msg, { text }) {
const inGuild = msg.guild ? undefined : null;
const connection = this.client.voice.connections.get(msg.guild.id);
if (!connection) {
return msg.reply(`I am not in a voice channel. Use ${msg.anyUsage('join', inGuild, inGuild)} to fix that!`);
}
try {
const { url } = await request
.get('http://tts.cyzon.us/tts')
.query({ text });
connection.play(url);
if (msg.channel.permissionsFor(this.client.user).has(['ADD_REACTIONS', 'READ_MESSAGE_HISTORY'])) {
await msg.react('🔉');
}
return null;
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};