mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-18 21:40:49 +02:00
Can I please do Dectalk without saving files? PLEASE
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
const { Command } = require('discord.js-commando');
|
const { Command } = require('discord.js-commando');
|
||||||
const snekfetch = require('snekfetch');
|
const snekfetch = require('snekfetch');
|
||||||
const path = require('path');
|
|
||||||
const { promisifyAll } = require('../../util/Util');
|
|
||||||
const fs = promisifyAll(require('fs'));
|
|
||||||
|
|
||||||
module.exports = class DECTalkCommand extends Command {
|
module.exports = class DECTalkCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
@@ -36,28 +33,18 @@ module.exports = class DECTalkCommand extends Command {
|
|||||||
}
|
}
|
||||||
if (!channel.joinable) return msg.say('Your voice channel is not joinable.');
|
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.');
|
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 {
|
try {
|
||||||
const connection = await channel.join();
|
const connection = await channel.join();
|
||||||
const { body } = await snekfetch
|
const data = await snekfetch
|
||||||
.get('http://tts.cyzon.us/tts')
|
.get('http://tts.cyzon.us/tts', { followRedirects: false })
|
||||||
.query({ text });
|
.query({ text });
|
||||||
await fs.writeFileAsync(file, body, { encoding: 'binary' });
|
const dispatcher = connection.playArbitraryInput(`http://tts.cyzon.us${data.headers.location}`);
|
||||||
const dispatcher = connection.playFile(file);
|
dispatcher.once('end', () => channel.leave());
|
||||||
dispatcher.once('end', () => this.finish(file, channel));
|
dispatcher.once('error', () => channel.leave());
|
||||||
dispatcher.once('error', () => this.finish(file, channel));
|
|
||||||
return null;
|
return null;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await this.finish(file, channel);
|
channel.leave();
|
||||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
return msg.reply(`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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiaobot",
|
"name": "xiaobot",
|
||||||
"version": "55.0.0",
|
"version": "55.0.1",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "XiaoBot.js",
|
"main": "XiaoBot.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user