2019-05-18 00:49:20 +02:00
|
|
|
const { Command } = require('discord-akairo');
|
2019-07-17 23:31:08 +02:00
|
|
|
const util = require('util');
|
|
|
|
const exec = util.promisify(require('child_process').exec);
|
2020-04-11 20:02:45 +02:00
|
|
|
const os = require('os');
|
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) {
|
2020-04-11 20:02:45 +02:00
|
|
|
let output = `${os.tmpdir()}/${message.id}_dectalk.wav`;
|
2019-05-19 20:41:58 +02:00
|
|
|
args.decMessage = rand.random(args.decMessage, message);
|
2019-05-18 00:49:20 +02:00
|
|
|
args.decMessage = args.decMessage.replace('\n', ' ');
|
2020-02-01 02:06:16 +01:00
|
|
|
let decMessage = '[:phoneme on] ' + args.decMessage.replace(/(["'$`\\])/g,'\\$1');
|
2019-05-18 00:49:20 +02:00
|
|
|
|
2019-07-17 23:31:08 +02:00
|
|
|
if (process.platform == 'win32') {
|
2020-04-11 20:02:45 +02:00
|
|
|
exec(`cd .\\dectalk && .\\say.exe -w ${output} "${decMessage}"`)
|
2019-07-17 23:31:08 +02:00
|
|
|
.catch(err => {
|
2019-10-26 00:01:17 +02:00
|
|
|
console.error(err);
|
2020-07-16 09:42:07 +02:00
|
|
|
return message.channel.send('Oh no! an error has occurred!');
|
2019-07-17 23:31:08 +02:00
|
|
|
})
|
|
|
|
.then(async () => {
|
|
|
|
const voiceChannel = message.member.voice.channel;
|
2020-04-10 16:30:43 +02:00
|
|
|
if (!voiceChannel) return message.channel.send('Please enter a voice channel first.');
|
2019-07-17 23:31:08 +02:00
|
|
|
try {
|
|
|
|
const connection = await voiceChannel.join();
|
2020-04-11 20:02:45 +02:00
|
|
|
const dispatcher = connection.play(output);
|
2019-07-17 23:31:08 +02:00
|
|
|
dispatcher.once('finish', () => voiceChannel.leave());
|
|
|
|
dispatcher.once('error', () => voiceChannel.leave());
|
|
|
|
return null;
|
|
|
|
} catch (err) {
|
|
|
|
voiceChannel.leave();
|
2019-11-09 13:36:56 +01:00
|
|
|
return message.reply(`Oh no, an error occurred: \`${err.message}\`.`);
|
2019-07-17 23:31:08 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-07-18 04:21:19 +02:00
|
|
|
} else if (process.platform == 'linux' || process.platform == 'darwin') {
|
2019-10-26 00:01:17 +02:00
|
|
|
let loadingmsg = await message.channel.send('Processing ( this can take some time ) <a:loadingmin:527579785212329984>');
|
|
|
|
|
2020-04-11 20:02:45 +02:00
|
|
|
exec(`cd dectalk && DISPLAY=:0.0 wine say.exe -w ${output} "${decMessage}"`)
|
2019-07-17 23:31:08 +02:00
|
|
|
.catch(err => {
|
2019-10-26 00:01:17 +02:00
|
|
|
loadingmsg.delete();
|
|
|
|
console.error(err);
|
2020-07-16 09:42:07 +02:00
|
|
|
return message.channel.send('Oh no! an error has occurred!');
|
2019-07-17 23:31:08 +02:00
|
|
|
})
|
|
|
|
.then(async () => {
|
|
|
|
const voiceChannel = message.member.voice.channel;
|
2020-04-10 16:30:43 +02:00
|
|
|
if (!voiceChannel) return message.channel.send('Please enter a voice channel first.');
|
2019-07-17 23:31:08 +02:00
|
|
|
try {
|
2019-10-26 00:01:17 +02:00
|
|
|
loadingmsg.delete();
|
2019-07-17 23:31:08 +02:00
|
|
|
const connection = await voiceChannel.join();
|
2020-04-11 20:02:45 +02:00
|
|
|
const dispatcher = connection.play(output);
|
2019-07-17 23:31:08 +02:00
|
|
|
dispatcher.once('finish', () => voiceChannel.leave());
|
|
|
|
dispatcher.once('error', () => voiceChannel.leave());
|
|
|
|
return null;
|
|
|
|
} catch (err) {
|
|
|
|
voiceChannel.leave();
|
2019-10-26 00:01:17 +02:00
|
|
|
loadingmsg.delete();
|
2019-11-09 13:36:56 +01:00
|
|
|
return message.reply(`Oh no, an error occurred: \`${err.message}\`.`);
|
2019-07-17 23:31:08 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-05-18 00:49:20 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = dectalkvcCommand;
|