mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-04 07:46:43 +02:00
I don't understand
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { Readable } = require('stream');
|
||||
// const path = require('path');
|
||||
// const { promisifyAll } = require('tsubaki');
|
||||
// const fs = promisifyAll(require('fs'));
|
||||
const path = require('path');
|
||||
const { promisifyAll } = require('tsubaki');
|
||||
const fs = promisifyAll(require('fs'));
|
||||
|
||||
module.exports = class DECTalkCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -40,21 +39,28 @@ module.exports = class DECTalkCommand extends Command {
|
||||
}
|
||||
if (!channel.joinable) return msg.say('Your voice channel is not joinable.');
|
||||
if (this.client.voiceConnections.has(channel.guild.id)) return msg.say('I am already playing a sound.');
|
||||
const file = path.join(__dirname, '..', '..', 'assets', `dec-talk ${channel.guild.id}.wav`);
|
||||
try {
|
||||
const connection = await channel.join();
|
||||
const { body } = await snekfetch
|
||||
.get('http://tts.cyzon.us/tts')
|
||||
.query({ text });
|
||||
const stream = new Readable();
|
||||
stream.read = function () {};
|
||||
stream.push(body);
|
||||
const dispatcher = connection.playStream(stream);
|
||||
dispatcher.once('end', () => channel.leave());
|
||||
dispatcher.once('error', () => channel.leave());
|
||||
await fs.writeFileAsync(file, body, { encoding: 'binary' });
|
||||
const dispatcher = connection.playFile(file);
|
||||
dispatcher.once('end', () => this.finish(file, channel));
|
||||
dispatcher.once('error', () => this.finish(file, channel));
|
||||
return null;
|
||||
} catch (err) {
|
||||
channel.leave();
|
||||
await this.finish(file, channel);
|
||||
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
async finish(file, channel) {
|
||||
try {
|
||||
if (fs.existsSync(file)) await fs.unlinkAsync(file);
|
||||
} finally {
|
||||
channel.leave();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user