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 { Command } = require('discord-akairo');
const { execFile } = require('child_process'); const { execFile } = require('child_process');
const os = require('os');
const rand = require('../../../rand.js'); const rand = require('../../../rand.js');
class dectalkCommand extends Command { class dectalkCommand extends Command {
@ -29,37 +28,31 @@ class dectalkCommand extends Command {
async exec(message, args) { async exec(message, args) {
args.decMessage = rand.random(args.decMessage, message); 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 decMessage = '[:phoneme on]' + args.decMessage;
let loadingmsg = await message.channel.send('Processing ( this can take some time ) <a:loadingmin:527579785212329984>'); let loadingmsg = await message.channel.send('Processing ( this can take some time ) <a:loadingmin:527579785212329984>');
if (process.platform === 'win32') { if (process.platform === 'win32') {
execFile('say.exe', ['-w', output, `${decMessage}`], {cwd: './dectalk/'}, (error, stdout, stderr) => { execFile('say.exe', ['-w', output, `${decMessage}`], {cwd: './dectalk/'}, (error, stdout, stderr) => {
if (error) { sendMessage(output, error, stdout, stderr);
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]});
}); });
} else if (process.platform === 'linux' || process.platform === 'darwin') { } else if (process.platform === 'linux' || process.platform === 'darwin') {
execFile('wine', ['say.exe', '-w', output, `${decMessage}`], {cwd: './dectalk/'}, (error, stdout, stderr) => { execFile('wine', ['say.exe', '-w', output, `${decMessage}`], {cwd: './dectalk/'}, (error, stdout, stderr) => {
if (error) { sendMessage(`./dectalk/${output}`, error, stdout, stderr);
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]});
}); });
} }
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 { Command } = require('discord-akairo');
const { execFile } = require('child_process'); const { execFile } = require('child_process');
const os = require('os');
const rand = require('../../../rand.js'); const rand = require('../../../rand.js');
class dectalkvcCommand extends Command { class dectalkvcCommand extends Command {
@ -29,7 +28,7 @@ class dectalkvcCommand extends Command {
async exec(message, args) { async exec(message, args) {
args.decMessage = rand.random(args.decMessage, message); 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 decMessage = '[:phoneme on] ' + args.decMessage;
let loadingmsg = await message.channel.send('Processing ( this can take some time ) <a:loadingmin:527579785212329984>'); 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(); loadingmsg.delete();
playinVC(output); playinVC(`./dectalk/${output}`);
}); });
} else if (process.platform === 'linux' || process.platform === 'darwin') { } else if (process.platform === 'linux' || process.platform === 'darwin') {
@ -58,7 +57,7 @@ class dectalkvcCommand extends Command {
} }
loadingmsg.delete(); loadingmsg.delete();
playinVC(output); playinVC(`./dectalk/${output}`);
}); });
} }