waaay better
Signed-off-by: loicbersier <loic.bersier1@gmail.com>
This commit is contained in:
parent
1b3fa24062
commit
265757e2f5
2 changed files with 71 additions and 71 deletions
|
@ -1,6 +1,6 @@
|
|||
const { Command } = require('discord-akairo');
|
||||
const util = require('util');
|
||||
const exec = util.promisify(require('child_process').exec);
|
||||
const { execFile } = require('child_process');
|
||||
const os = require('os');
|
||||
const rand = require('../../../rand.js');
|
||||
|
||||
class dectalkCommand extends Command {
|
||||
|
@ -29,31 +29,36 @@ class dectalkCommand extends Command {
|
|||
|
||||
async exec(message, args) {
|
||||
args.decMessage = rand.random(args.decMessage, message);
|
||||
args.decMessage = args.decMessage.replace('\n', ' ');
|
||||
let decMessage = '[:phoneme on] ' + args.decMessage.replace(/(["'$`\\])/g,'\\$1');
|
||||
let output = `${os.tmpdir()}/${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>');
|
||||
|
||||
if (process.platform == 'win32') {
|
||||
exec(`cd .\\dectalk && .\\say.exe -w ${message.id}_dectalk.wav "${decMessage}"`)
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
if (process.platform === 'win32') {
|
||||
execFile('say.exe', ['-w', output, `${decMessage}`], {cwd: './dectalk/'}, (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!');
|
||||
})
|
||||
.then(() => {
|
||||
return message.channel.send({files: [`./dectalk/${message.id}_dectalk.wav`]});
|
||||
});
|
||||
} else if (process.platform == 'linux' || process.platform == 'darwin') {
|
||||
let loadingmsg = await message.channel.send('Processing ( this can take some time ) <a:loadingmin:527579785212329984>');
|
||||
}
|
||||
|
||||
exec(`cd dectalk && DISPLAY=:0.0 wine say.exe -w ${message.id}_dectalk.wav "${decMessage}"`)
|
||||
.catch(err => {
|
||||
loadingmsg.delete();
|
||||
return message.channel.send({files: [output]});
|
||||
});
|
||||
} else if (process.platform === 'linux' || process.platform === 'darwin') {
|
||||
execFile('wine', ['say.exe', '-w', output, `${decMessage}`], {cwd: './dectalk/'}, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
loadingmsg.delete();
|
||||
console.error(err);
|
||||
console.error(stdout);
|
||||
console.error(stderr);
|
||||
console.error(error);
|
||||
return message.channel.send('Oh no! an error has occurred!');
|
||||
})
|
||||
.then(() => {
|
||||
loadingmsg.delete();
|
||||
return message.channel.send({files: [`./dectalk/${message.id}_dectalk.wav`]});
|
||||
});
|
||||
}
|
||||
|
||||
loadingmsg.delete();
|
||||
return message.channel.send({files: [output]});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const { Command } = require('discord-akairo');
|
||||
const util = require('util');
|
||||
const exec = util.promisify(require('child_process').exec);
|
||||
const { execFile } = require('child_process');
|
||||
const os = require('os');
|
||||
const rand = require('../../../rand.js');
|
||||
|
||||
class dectalkvcCommand extends Command {
|
||||
|
@ -29,58 +29,53 @@ class dectalkvcCommand extends Command {
|
|||
|
||||
async exec(message, args) {
|
||||
args.decMessage = rand.random(args.decMessage, message);
|
||||
args.decMessage = args.decMessage.replace('\n', ' ');
|
||||
let decMessage = '[:phoneme on] ' + args.decMessage.replace(/(["'$`\\])/g,'\\$1');
|
||||
let output = `${os.tmpdir()}/${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>');
|
||||
|
||||
if (process.platform == 'win32') {
|
||||
exec(`cd .\\dectalk && .\\say.exe -w ${message.id}_dectalk.wav "${decMessage}"`)
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
return message.channel.send('Oh no! an error has occurred!');
|
||||
})
|
||||
.then(async () => {
|
||||
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(`./dectalk/${message.id}_dectalk.wav`);
|
||||
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}\`.`);
|
||||
}
|
||||
});
|
||||
|
||||
} else if (process.platform == 'linux' || process.platform == 'darwin') {
|
||||
let loadingmsg = await message.channel.send('Processing ( this can take some time ) <a:loadingmin:527579785212329984>');
|
||||
|
||||
exec(`cd dectalk && DISPLAY=:0.0 wine say.exe -w ${message.id}_dectalk.wav "${decMessage}"`)
|
||||
.catch(err => {
|
||||
if (process.platform === 'win32') {
|
||||
execFile('say.exe', ['-w', output, `${decMessage}`], {cwd: './dectalk/'}, async (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
loadingmsg.delete();
|
||||
console.error(err);
|
||||
console.error(stdout);
|
||||
console.error(stderr);
|
||||
console.error(error);
|
||||
return message.channel.send('Oh no! an error has occurred!');
|
||||
})
|
||||
.then(async () => {
|
||||
const voiceChannel = message.member.voice.channel;
|
||||
if (!voiceChannel) return message.channel.send('Please enter a voice channel first.');
|
||||
try {
|
||||
loadingmsg.delete();
|
||||
const connection = await voiceChannel.join();
|
||||
const dispatcher = connection.play(`./dectalk/${message.id}_dectalk.wav`);
|
||||
dispatcher.once('finish', () => voiceChannel.leave());
|
||||
dispatcher.once('error', () => voiceChannel.leave());
|
||||
return null;
|
||||
} catch (err) {
|
||||
voiceChannel.leave();
|
||||
loadingmsg.delete();
|
||||
return message.reply(`Oh no, an error occurred: \`${err.message}\`.`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
loadingmsg.delete();
|
||||
playinVC(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!');
|
||||
}
|
||||
|
||||
loadingmsg.delete();
|
||||
playinVC(output);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
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}\`.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue