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
+4 -9
View File
@@ -52,24 +52,21 @@ module.exports = class GuessSongCommand extends Command {
}
async run(msg, { chart }) {
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!`);
}
const current = this.client.games.get(msg.channel.id);
if (current) return msg.reply(`Please wait until the current game of \`${current.name}\` is finished.`);
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.');
this.client.games.set(msg.channel.id, { name: this.name });
let songID;
try {
if (!this.token) await this.fetchToken();
const data = await this.fetchRandomSong(chart);
const { body: previewBody } = await request.get(data.preview);
const dispatcher = connection.play(Readable.from([previewBody]));
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([previewBody]));
await reactIfAble(msg, this.client.user, '🔉');
await msg.reply('**You have 30 seconds, what song is this?**');
const msgs = await msg.channel.awaitMessages({
@@ -78,8 +75,7 @@ module.exports = class GuessSongCommand extends Command {
time: 30000
});
this.client.games.delete(msg.channel.id);
dispatcher.end();
this.client.dispatchers.delete(msg.guild.id);
connection.stop();
if (!msgs.size) return msg.reply(`Time! It's **${data.name}** by **${data.artist}**!`);
const guess = msgs.first().content.toLowerCase();
if (!guess.includes(data.name.toLowerCase()) && !guess.includes(data.shortName.toLowerCase())) {
@@ -87,7 +83,6 @@ module.exports = class GuessSongCommand extends Command {
}
return msg.reply(`Nice! It's **${data.name}** by **${data.artist}**!`);
} catch (err) {
this.client.dispatchers.delete(msg.guild.id);
this.client.games.delete(msg.channel.id);
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Song ID: \`${songID}\`.`);
}
+2 -1
View File
@@ -30,11 +30,12 @@ module.exports = class HearingTestCommand 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 (!connection.canPlay) return msg.reply('I am already playing audio in this server.');
try {
let age;
let range;
+4 -7
View File
@@ -44,14 +44,11 @@ module.exports = class JeopardyCommand extends Command {
this.client.games.set(msg.channel.id, { name: this.name });
const question = await this.fetchQuestion();
const clueCard = await this.generateClueCard(question.question.replace(/<\/?i>/gi, ''));
const connection = msg.guild ? this.client.voice.connections.get(msg.guild.id) : null;
const connection = msg.guild ? this.client.dispatchers.get(msg.guild.id) : null;
let playing = false;
if (msg.guild && connection && !this.client.dispatchers.has(msg.guild.id)) {
if (msg.guild && connection && connection.canPlay) {
playing = true;
const dispatcher = connection.play(path.join(__dirname, '..', '..', 'assets', 'sounds', 'jeopardy.mp3'));
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', 'jeopardy.mp3'));
await reactIfAble(msg, this.client.user, '🔉');
}
const category = question.category ? question.category.title.toUpperCase() : '';
@@ -63,7 +60,7 @@ module.exports = class JeopardyCommand extends Command {
max: 1,
time: 30000
});
if (playing) connection.dispatcher.end();
if (playing) connection.stop();
const answer = question.answer.replace(/<\/?i>/gi, '*');
this.client.games.delete(msg.channel.id);
if (!msgs.size) return msg.reply(`Time's up, the answer was **${answer}**.`);
+3 -7
View File
@@ -78,23 +78,20 @@ module.exports = class WhosThatPokemonCryCommand extends Command {
}
async run(msg, { pokemon }) {
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!`);
}
const current = this.client.games.get(msg.channel.id);
if (current) return msg.reply(`Please wait until the current game of \`${current.name}\` is finished.`);
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.');
this.client.games.set(msg.channel.id, { name: this.name });
try {
const data = await this.client.pokemon.fetch(pokemon.toString());
const names = data.names.map(name => name.name.toLowerCase());
const attachment = await this.client.registry.commands.get('whos-that-pokemon').createImage(data, false);
const dispatcher = connection.play(data.cry);
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(data.cry);
await reactIfAble(msg, this.client.user, '🔉');
await msg.reply('**You have 15 seconds, who\'s that Pokémon?**');
const msgs = await msg.channel.awaitMessages({
@@ -112,7 +109,6 @@ module.exports = class WhosThatPokemonCryCommand extends Command {
}
return msg.reply(`Nice! It's **${data.name}**!`, { files: [attachment] });
} catch (err) {
this.client.dispatchers.delete(msg.guild.id);
this.client.games.delete(msg.channel.id);
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}