Haha-Yes/commands/fun/tts/dectalkvc.js

81 lines
2.4 KiB
JavaScript
Raw Normal View History

2019-05-18 00:49:20 +02:00
const { Command } = require('discord-akairo');
const { execFile } = require('child_process');
2019-05-19 21:36:42 +02:00
const rand = require('../../../rand.js');
2019-05-18 00:49:20 +02:00
class dectalkvcCommand extends Command {
constructor() {
super('dectalkvc', {
aliases: ['dectalkvc', 'decvc'],
category: 'fun',
2019-11-22 20:56:54 +01:00
clientPermissions: ['SPEAK'],
2019-05-18 00:49:20 +02:00
args: [
{
id: 'decMessage',
type: 'string',
2019-06-23 03:41:59 +02:00
prompt: {
start: 'Write something so i can say it back in dectalk',
},
2019-05-18 00:49:20 +02:00
match: 'rest'
}
],
description: {
2019-05-18 03:01:57 +02:00
content: 'Repeat what you sent in the voice chat you are currently in',
usage: '[text]',
examples: ['This command is very epic']
2019-05-18 00:49:20 +02:00
}
});
}
async exec(message, args) {
2019-05-19 20:41:58 +02:00
args.decMessage = rand.random(args.decMessage, message);
let output = `${message.id}_dectalk.wav`;
let decMessage = '[:phoneme on] ' + args.decMessage;
let loadingmsg = await message.channel.send('Processing ( this can take some time ) <a:loadingmin:527579785212329984>');
2019-05-18 00:49:20 +02:00
if (process.platform === 'win32') {
execFile('say.exe', ['-w', output, `${decMessage}`], {cwd: './dectalk/'}, async (error, stdout, stderr) => {
if (error) {
loadingmsg.delete();
console.error(stdout);
console.error(stderr);
console.error(error);
return message.channel.send('Oh no! an error has occurred!');
}
loadingmsg.delete();
playinVC(`./dectalk/${output}`);
});
} else if (process.platform === 'linux' || process.platform === 'darwin') {
execFile('wine', ['say.exe', '-w', output, `${decMessage}`], {cwd: './dectalk/'}, async (error, stdout, stderr) => {
if (error) {
loadingmsg.delete();
console.error(stdout);
console.error(stderr);
console.error(error);
return message.channel.send('Oh no! an error has occurred!');
}
2019-07-17 23:31:08 +02:00
loadingmsg.delete();
playinVC(`./dectalk/${output}`);
});
}
2019-05-18 00:49:20 +02:00
async function playinVC(file) {
const voiceChannel = message.member.voice.channel;
if (!voiceChannel) return message.channel.send('Please enter a voice channel first.');
try {
const connection = await voiceChannel.join();
const dispatcher = connection.play(file);
dispatcher.once('finish', () => voiceChannel.leave());
dispatcher.once('error', () => voiceChannel.leave());
return null;
} catch (err) {
voiceChannel.leave();
return message.reply(`Oh no, an error occurred: \`${err.message}\`.`);
}
}
2019-05-18 00:49:20 +02:00
}
}
module.exports = dectalkvcCommand;