You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Haha-Yes/commands/fun/tts/dectalk.js

63 lines
1.8 KiB
JavaScript

5 years ago
const { Command } = require('discord-akairo');
const util = require('util');
const exec = util.promisify(require('child_process').exec);
4 years ago
const os = require('os');
const rand = require('../../../rand.js');
5 years ago
class dectalkCommand extends Command {
constructor() {
super('dectalk', {
aliases: ['dectalk', 'dec'],
category: 'fun',
5 years ago
clientPermissions: ['ATTACH_FILES'],
5 years ago
args: [
{
id: 'decMessage',
type: 'string',
5 years ago
prompt: {
start: 'Write something so i can say it back in dectalk',
},
5 years ago
match: 'rest'
}
],
description: {
content: 'Send a wav of what you wrote into .wav with dectalk',
usage: '[text]',
examples: ['This command is very epic']
5 years ago
}
});
}
async exec(message, args) {
4 years ago
let output = `${os.tmpdir()}/${message.id}_dectalk.wav`;
args.decMessage = rand.random(args.decMessage, message);
args.decMessage = args.decMessage.replace('\n', ' ');
4 years ago
let decMessage = '[:phoneme on] ' + args.decMessage.replace(/(["'$`\\])/g,'\\$1');
5 years ago
if (process.platform == 'win32') {
4 years ago
exec(`cd .\\dectalk && .\\say.exe -w ${output} "${decMessage}"`)
.catch(err => {
console.error(err);
return message.channel.send('Oh no! an error has occurred!');
})
.then(() => {
4 years ago
return message.channel.send({files: [output]});
});
5 years ago
} else if (process.platform == 'linux' || process.platform == 'darwin') {
let loadingmsg = await message.channel.send('Processing ( this can take some time ) <a:loadingmin:527579785212329984>');
4 years ago
exec(`cd dectalk && DISPLAY=:0.0 wine say.exe -w ${output} "${decMessage}"`)
.catch(err => {
loadingmsg.delete();
console.error(err);
return message.channel.send('Oh no! an error has occurred!');
})
.then(() => {
loadingmsg.delete();
4 years ago
return message.channel.send({files: [output]});
});
}
5 years ago
}
}
module.exports = dectalkCommand;