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 { Command } = require('discord-akairo');
|
||||||
const util = require('util');
|
const { execFile } = require('child_process');
|
||||||
const exec = util.promisify(require('child_process').exec);
|
const os = require('os');
|
||||||
const rand = require('../../../rand.js');
|
const rand = require('../../../rand.js');
|
||||||
|
|
||||||
class dectalkCommand extends Command {
|
class dectalkCommand extends Command {
|
||||||
|
@ -29,31 +29,36 @@ 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);
|
||||||
args.decMessage = args.decMessage.replace('\n', ' ');
|
let output = `${os.tmpdir()}/${message.id}_dectalk.wav`;
|
||||||
let decMessage = '[:phoneme on] ' + args.decMessage.replace(/(["'$`\\])/g,'\\$1');
|
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') {
|
if (process.platform === 'win32') {
|
||||||
exec(`cd .\\dectalk && .\\say.exe -w ${message.id}_dectalk.wav "${decMessage}"`)
|
execFile('say.exe', ['-w', output, `${decMessage}`], {cwd: './dectalk/'}, (error, stdout, stderr) => {
|
||||||
.catch(err => {
|
if (error) {
|
||||||
console.error(err);
|
loadingmsg.delete();
|
||||||
|
console.error(stdout);
|
||||||
|
console.error(stderr);
|
||||||
|
console.error(error);
|
||||||
return message.channel.send('Oh no! an error has occurred!');
|
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}"`)
|
loadingmsg.delete();
|
||||||
.catch(err => {
|
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();
|
loadingmsg.delete();
|
||||||
console.error(err);
|
console.error(stdout);
|
||||||
|
console.error(stderr);
|
||||||
|
console.error(error);
|
||||||
return message.channel.send('Oh no! an error has occurred!');
|
return message.channel.send('Oh no! an error has occurred!');
|
||||||
})
|
}
|
||||||
.then(() => {
|
|
||||||
loadingmsg.delete();
|
loadingmsg.delete();
|
||||||
return message.channel.send({files: [`./dectalk/${message.id}_dectalk.wav`]});
|
return message.channel.send({files: [output]});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const { Command } = require('discord-akairo');
|
const { Command } = require('discord-akairo');
|
||||||
const util = require('util');
|
const { execFile } = require('child_process');
|
||||||
const exec = util.promisify(require('child_process').exec);
|
const os = require('os');
|
||||||
const rand = require('../../../rand.js');
|
const rand = require('../../../rand.js');
|
||||||
|
|
||||||
class dectalkvcCommand extends Command {
|
class dectalkvcCommand extends Command {
|
||||||
|
@ -29,58 +29,53 @@ 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);
|
||||||
args.decMessage = args.decMessage.replace('\n', ' ');
|
let output = `${os.tmpdir()}/${message.id}_dectalk.wav`;
|
||||||
let decMessage = '[:phoneme on] ' + args.decMessage.replace(/(["'$`\\])/g,'\\$1');
|
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') {
|
if (process.platform === 'win32') {
|
||||||
exec(`cd .\\dectalk && .\\say.exe -w ${message.id}_dectalk.wav "${decMessage}"`)
|
execFile('say.exe', ['-w', output, `${decMessage}`], {cwd: './dectalk/'}, async (error, stdout, stderr) => {
|
||||||
.catch(err => {
|
if (error) {
|
||||||
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 => {
|
|
||||||
loadingmsg.delete();
|
loadingmsg.delete();
|
||||||
console.error(err);
|
console.error(stdout);
|
||||||
|
console.error(stderr);
|
||||||
|
console.error(error);
|
||||||
return message.channel.send('Oh no! an error has occurred!');
|
return message.channel.send('Oh no! an error has occurred!');
|
||||||
})
|
}
|
||||||
.then(async () => {
|
|
||||||
const voiceChannel = message.member.voice.channel;
|
loadingmsg.delete();
|
||||||
if (!voiceChannel) return message.channel.send('Please enter a voice channel first.');
|
playinVC(output);
|
||||||
try {
|
});
|
||||||
loadingmsg.delete();
|
|
||||||
const connection = await voiceChannel.join();
|
} else if (process.platform === 'linux' || process.platform === 'darwin') {
|
||||||
const dispatcher = connection.play(`./dectalk/${message.id}_dectalk.wav`);
|
execFile('wine', ['say.exe', '-w', output, `${decMessage}`], {cwd: './dectalk/'}, async (error, stdout, stderr) => {
|
||||||
dispatcher.once('finish', () => voiceChannel.leave());
|
if (error) {
|
||||||
dispatcher.once('error', () => voiceChannel.leave());
|
loadingmsg.delete();
|
||||||
return null;
|
console.error(stdout);
|
||||||
} catch (err) {
|
console.error(stderr);
|
||||||
voiceChannel.leave();
|
console.error(error);
|
||||||
loadingmsg.delete();
|
return message.channel.send('Oh no! an error has occurred!');
|
||||||
return message.reply(`Oh no, an error occurred: \`${err.message}\`.`);
|
}
|
||||||
}
|
|
||||||
});
|
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