Fix all audio commands

This commit is contained in:
Dragon Fire
2024-03-20 16:42:17 -04:00
parent e09d761463
commit bd6fe1d4d7
16 changed files with 48 additions and 95 deletions
+3 -6
View File
@@ -29,17 +29,14 @@ module.exports = class AirhornCommand extends Command {
}
async run(msg) {
const connection = this.client.voice.connections.get(msg.guild.id);
const connection = this.client.dispatchers.get(msg.guild.id);
if (!connection) {
const usage = this.client.registry.commands.get('join').usage();
return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`);
}
if (this.client.dispatchers.has(msg.guild.id)) return msg.reply('I am already playing audio in this server.');
if (!connection.canPlay) return msg.reply('I am already playing audio in this server.');
const airhorn = sounds[Math.floor(Math.random() * sounds.length)];
const dispatcher = connection.play(path.join(__dirname, '..', '..', 'assets', 'sounds', 'airhorn', airhorn));
this.client.dispatchers.set(msg.guild.id, dispatcher);
dispatcher.once('finish', () => this.client.dispatchers.delete(msg.guild.id));
dispatcher.once('error', () => this.client.dispatchers.delete(msg.guild.id));
connection.play(path.join(__dirname, '..', '..', 'assets', 'sounds', 'airhorn', airhorn));
await reactIfAble(msg, this.client.user, '🔉');
return null;
}
+3 -6
View File
@@ -64,17 +64,14 @@ module.exports = class AnimaleseCommand extends Command {
}
async run(msg, { pitch, text }) {
const connection = this.client.voice.connections.get(msg.guild.id);
const connection = this.client.dispatchers.get(msg.guild.id);
if (!connection) {
const usage = this.client.registry.commands.get('join').usage();
return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`);
}
if (this.client.dispatchers.has(msg.guild.id)) return msg.reply('I am already playing audio in this server.');
if (!connection.canPlay) return msg.reply('I am already playing audio in this server.');
await reactIfAble(msg, this.client.user, LOADING_EMOJI_ID, '💬');
const dispatcher = connection.play(Readable.from([this.animalese(text, pitch)]));
this.client.dispatchers.set(msg.guild.id, dispatcher);
dispatcher.once('finish', () => this.client.dispatchers.delete(msg.guild.id));
dispatcher.once('error', () => this.client.dispatchers.delete(msg.guild.id));
connection.play(Readable.from([this.animalese(text, pitch)]));
await reactIfAble(msg, this.client.user, '🔉');
return null;
}
+3 -6
View File
@@ -47,19 +47,16 @@ module.exports = class DECTalkCommand extends Command {
}
async run(msg, { text }) {
const connection = this.client.voice.connections.get(msg.guild.id);
const connection = this.client.dispatchers.get(msg.guild.id);
if (!connection) {
const usage = this.client.registry.commands.get('join').usage();
return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`);
}
if (this.client.dispatchers.has(msg.guild.id)) return msg.reply('I am already playing audio in this server.');
if (!connection.canPlay) return msg.reply('I am already playing audio in this server.');
try {
await reactIfAble(msg, this.client.user, LOADING_EMOJI_ID, '💬');
const body = await this.tts(msg.guild.id, text);
const dispatcher = connection.play(Readable.from([body]));
this.client.dispatchers.set(msg.guild.id, dispatcher);
dispatcher.once('finish', () => this.client.dispatchers.delete(msg.guild.id));
dispatcher.once('error', () => this.client.dispatchers.delete(msg.guild.id));
connection.play(Readable.from([body]));
await reactIfAble(msg, this.client.user, '🔉');
return null;
} catch (err) {
+3 -6
View File
@@ -29,20 +29,17 @@ module.exports = class MindfulnessCommand extends Command {
}
async run(msg) {
const connection = this.client.voice.connections.get(msg.guild.id);
const connection = this.client.dispatchers.get(msg.guild.id);
if (!connection) {
const usage = this.client.registry.commands.get('join').usage();
return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`);
}
if (this.client.dispatchers.has(msg.guild.id)) return msg.reply('I am already playing audio in this server.');
if (!connection.canPlay) return msg.reply('I am already playing audio in this server.');
try {
await reactIfAble(msg, this.client.user, LOADING_EMOJI_ID, '💬');
const flow = await this.fetchFlow();
const { body } = await request.get(flow.mp3);
const dispatcher = connection.play(Readable.from([body]));
this.client.dispatchers.set(msg.guild.id, dispatcher);
dispatcher.once('finish', () => this.client.dispatchers.delete(msg.guild.id));
dispatcher.once('error', () => this.client.dispatchers.delete(msg.guild.id));
connection.play(Readable.from([body]));
await reactIfAble(msg, this.client.user, '🔉');
for (const item of flow.data) {
if (item.type !== 'quote') continue;
+3 -6
View File
@@ -38,12 +38,12 @@ module.exports = class PlayCommand extends Command {
}
async run(msg, { query }) {
const connection = this.client.voice.connections.get(msg.guild.id);
const connection = this.client.dispatchers.get(msg.guild.id);
if (!connection) {
const usage = this.client.registry.commands.get('join').usage();
return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`);
}
if (this.client.dispatchers.has(msg.guild.id)) return msg.reply('I am already playing audio in this server.');
if (!connection.canPlay) return msg.reply('I am already playing audio in this server.');
const result = await this.searchForVideo(query, msg.channel.nsfw || false);
if (!result) return msg.reply('Could not find any results for your query.');
const data = await ytdl.getInfo(result);
@@ -55,10 +55,7 @@ module.exports = class PlayCommand extends Command {
});
const verification = await verify(msg.channel, msg.author);
if (!verification) return msg.reply('Aborting playback.');
const dispatcher = connection.play(ytdl(result, { filter: 'audioonly' }));
this.client.dispatchers.set(msg.guild.id, dispatcher);
dispatcher.once('finish', () => this.client.dispatchers.delete(msg.guild.id));
dispatcher.once('error', () => this.client.dispatchers.delete(msg.guild.id));
connection.play(ytdl(result, { filter: 'audioonly' }));
return msg.reply(`🔉 Now playing **${shorten(data.videoDetails.title, 70)}**!`);
}
+3 -6
View File
@@ -128,16 +128,13 @@ module.exports = class SoundboardCommand extends Command {
}
async run(msg, { sound }) {
const connection = this.client.voice.connections.get(msg.guild.id);
const connection = this.client.dispatchers.get(msg.guild.id);
if (!connection) {
const usage = this.client.registry.commands.get('join').usage();
return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`);
}
if (this.client.dispatchers.has(msg.guild.id)) return msg.reply('I am already playing audio in this server.');
const dispatcher = connection.play(path.join(__dirname, '..', '..', 'assets', 'sounds', ...sound));
this.client.dispatchers.set(msg.guild.id, dispatcher);
dispatcher.once('finish', () => this.client.dispatchers.delete(msg.guild.id));
dispatcher.once('error', () => this.client.dispatchers.delete(msg.guild.id));
if (!connection.canPlay) return msg.reply('I am already playing audio in this server.');
connection.play(path.join(__dirname, '..', '..', 'assets', 'sounds', ...sound));
await reactIfAble(msg, this.client.user, '🔉');
return null;
}
+3 -6
View File
@@ -45,12 +45,12 @@ module.exports = class TtsCommand extends Command {
}
async run(msg, { accent, text }) {
const connection = this.client.voice.connections.get(msg.guild.id);
const connection = this.client.dispatchers.get(msg.guild.id);
if (!connection) {
const usage = this.client.registry.commands.get('join').usage();
return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`);
}
if (this.client.dispatchers.has(msg.guild.id)) return msg.reply('I am already playing audio in this server.');
if (!connection.canPlay) return msg.reply('I am already playing audio in this server.');
try {
await reactIfAble(msg, this.client.user, LOADING_EMOJI_ID, '💬');
const { body } = await request
@@ -66,10 +66,7 @@ module.exports = class TtsCommand extends Command {
prev: 'input',
ttsspeed: 1
});
const dispatcher = connection.play(Readable.from([body]));
this.client.dispatchers.set(msg.guild.id, dispatcher);
dispatcher.once('finish', () => this.client.dispatchers.delete(msg.guild.id));
dispatcher.once('error', () => this.client.dispatchers.delete(msg.guild.id));
connection.play(Readable.from([body]));
await reactIfAble(msg, this.client.user, '🔉');
return null;
} catch (err) {
+3 -6
View File
@@ -46,12 +46,12 @@ module.exports = class VocodesCommand extends Command {
}
async run(msg, { voice, text }) {
const connection = this.client.voice.connections.get(msg.guild.id);
const connection = this.client.dispatchers.get(msg.guild.id);
if (!connection) {
const usage = this.client.registry.commands.get('join').usage();
return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`);
}
if (this.client.dispatchers.has(msg.guild.id)) return msg.reply('I am already playing audio in this server.');
if (!connection.canPlay) return msg.reply('I am already playing audio in this server.');
try {
await reactIfAble(msg, this.client.user, LOADING_EMOJI_ID, '💬');
const { body } = await request
@@ -60,10 +60,7 @@ module.exports = class VocodesCommand extends Command {
speaker: voice,
text
});
const dispatcher = connection.play(Readable.from([Buffer.from(body.audio_base64, 'base64')]));
this.client.dispatchers.set(msg.guild.id, dispatcher);
dispatcher.once('finish', () => this.client.dispatchers.delete(msg.guild.id));
dispatcher.once('error', () => this.client.dispatchers.delete(msg.guild.id));
connection.play(Readable.from([Buffer.from(body.audio_base64, 'base64')]));
await reactIfAble(msg, this.client.user, '🔉');
return null;
} catch (err) {