Don't use tmpdir as it apparently doesn't like that

Signed-off-by: loicbersier <loic.bersier1@gmail.com>
This commit is contained in:
loicbersier 2020-09-04 13:52:25 +02:00
parent 265757e2f5
commit aba72cac11
2 changed files with 18 additions and 26 deletions

View file

@ -1,6 +1,5 @@
const { Command } = require('discord-akairo');
const { execFile } = require('child_process');
const os = require('os');
const rand = require('../../../rand.js');
class dectalkCommand extends Command {
@ -29,37 +28,31 @@ class dectalkCommand extends Command {
async exec(message, args) {
args.decMessage = rand.random(args.decMessage, message);
let output = `${os.tmpdir()}/${message.id}_dectalk.wav`;
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>');
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!');
}
loadingmsg.delete();
return message.channel.send({files: [output]});
sendMessage(output, error, stdout, stderr);
});
} 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(stdout);
console.error(stderr);
console.error(error);
return message.channel.send('Oh no! an error has occurred!');
}
loadingmsg.delete();
return message.channel.send({files: [output]});
sendMessage(`./dectalk/${output}`, error, stdout, stderr);
});
}
async function sendMessage(file, error, stdout, stderr) {
console.error(stdout);
loadingmsg.delete();
if (error) {
console.error(stderr);
console.error(error);
return message.channel.send('Oh no! an error has occurred!');
}
return message.channel.send({files: [file]});
}
}
}

View file

@ -1,6 +1,5 @@
const { Command } = require('discord-akairo');
const { execFile } = require('child_process');
const os = require('os');
const rand = require('../../../rand.js');
class dectalkvcCommand extends Command {
@ -29,7 +28,7 @@ class dectalkvcCommand extends Command {
async exec(message, args) {
args.decMessage = rand.random(args.decMessage, message);
let output = `${os.tmpdir()}/${message.id}_dectalk.wav`;
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>');
@ -44,7 +43,7 @@ class dectalkvcCommand extends Command {
}
loadingmsg.delete();
playinVC(output);
playinVC(`./dectalk/${output}`);
});
} else if (process.platform === 'linux' || process.platform === 'darwin') {
@ -58,7 +57,7 @@ class dectalkvcCommand extends Command {
}
loadingmsg.delete();
playinVC(output);
playinVC(`./dectalk/${output}`);
});
}