Properly await more functions

This commit is contained in:
Essem 2021-12-13 16:09:12 -06:00
parent c5fc1d0b0f
commit 5acd2b1113
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
7 changed files with 26 additions and 26 deletions

View file

@ -7,7 +7,7 @@ class PauseCommand extends MusicCommand {
if (!this.message.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!"; if (!this.message.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!";
if (this.connection.host !== this.message.author.id && !this.message.member.permissions.has("manageChannels")) return "Only the current voice session host can pause/resume the music!"; if (this.connection.host !== this.message.author.id && !this.message.member.permissions.has("manageChannels")) return "Only the current voice session host can pause/resume the music!";
const player = this.connection.player; const player = this.connection.player;
player.pause(!player.paused ? true : false); await player.pause(!player.paused ? true : false);
return `🔊 The player has been ${!player.paused ? "paused" : "resumed"}.`; return `🔊 The player has been ${!player.paused ? "paused" : "resumed"}.`;
} }

View file

@ -12,7 +12,7 @@ class SeekCommand extends MusicCommand {
if (!track.isSeekable) return "This track isn't seekable!"; if (!track.isSeekable) return "This track isn't seekable!";
const seconds = parseFloat(this.args[0]); const seconds = parseFloat(this.args[0]);
if (isNaN(seconds) || (seconds * 1000) > track.length || (seconds * 1000) < 0) return "That's not a valid position!"; if (isNaN(seconds) || (seconds * 1000) > track.length || (seconds * 1000) < 0) return "That's not a valid position!";
player.seek(seconds * 1000); await player.seek(seconds * 1000);
return `🔊 Seeked track to ${seconds} second(s).`; return `🔊 Seeked track to ${seconds} second(s).`;
} }

View file

@ -16,14 +16,14 @@ class SkipCommand extends MusicCommand {
max: votes.max max: votes.max
}; };
if (votes.count + 1 === votes.max) { if (votes.count + 1 === votes.max) {
player.player.stop(this.message.channel.guild.id); await player.player.stop(this.message.channel.guild.id);
skipVotes.set(this.message.channel.guild.id, { count: 0, ids: [], max: Math.min(3, player.voiceChannel.voiceMembers.filter((i) => i.id !== this.client.user.id && !i.bot).length) }); skipVotes.set(this.message.channel.guild.id, { count: 0, ids: [], max: Math.min(3, player.voiceChannel.voiceMembers.filter((i) => i.id !== this.client.user.id && !i.bot).length) });
} else { } else {
skipVotes.set(this.message.channel.guild.id, newObject); skipVotes.set(this.message.channel.guild.id, newObject);
return `🔊 Voted to skip song (${votes.count + 1}/${votes.max} people have voted).`; return `🔊 Voted to skip song (${votes.count + 1}/${votes.max} people have voted).`;
} }
} else { } else {
player.player.stop(this.message.channel.guild.id); await player.player.stop(this.message.channel.guild.id);
return; return;
} }
} }

View file

@ -7,9 +7,9 @@ class StopCommand extends MusicCommand {
if (!this.message.member.voiceState.channelID) return "You need to be in a voice channel first!"; if (!this.message.member.voiceState.channelID) return "You need to be in a voice channel first!";
if (!this.message.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!"; if (!this.message.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!";
if (this.connection.host !== this.message.author.id && !this.message.member.permissions.has("manageChannels")) return "Only the current voice session host can stop the music!"; if (this.connection.host !== this.message.author.id && !this.message.member.permissions.has("manageChannels")) return "Only the current voice session host can stop the music!";
manager.leave(this.message.channel.guild.id); await manager.leave(this.message.channel.guild.id);
const connection = this.connection.player; const connection = this.connection.player;
connection.destroy(); await connection.destroy();
players.delete(this.message.channel.guild.id); players.delete(this.message.channel.guild.id);
queues.delete(this.message.channel.guild.id); queues.delete(this.message.channel.guild.id);
return "🔊 The current voice channel session has ended."; return "🔊 The current voice channel session has ended.";

View file

@ -7,12 +7,12 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
const connection = players.get(oldChannel.guild.id); const connection = players.get(oldChannel.guild.id);
if (connection && oldChannel.id === connection.voiceChannel.id) { if (connection && oldChannel.id === connection.voiceChannel.id) {
if (oldChannel.voiceMembers.filter((i) => i.id !== client.user.id && !i.bot).length === 0) { if (oldChannel.voiceMembers.filter((i) => i.id !== client.user.id && !i.bot).length === 0) {
connection.player.pause(true); await connection.player.pause(true);
const waitMessage = await client.createMessage(connection.originalChannel.id, "🔊 Waiting 10 seconds for someone to return..."); const waitMessage = await client.createMessage(connection.originalChannel.id, "🔊 Waiting 10 seconds for someone to return...");
const awaitRejoin = new AwaitRejoin(oldChannel, true); const awaitRejoin = new AwaitRejoin(oldChannel, true);
awaitRejoin.on("end", async (rejoined, member) => { awaitRejoin.on("end", async (rejoined, member) => {
if (rejoined) { if (rejoined) {
connection.player.pause(false); await connection.player.pause(false);
players.set(connection.voiceChannel.guild.id, { player: connection.player, type: connection.type, host: member.id, voiceChannel: connection.voiceChannel, originalChannel: connection.originalChannel, loop: connection.loop, shuffle: connection.shuffle, playMessage: connection.playMessage }); players.set(connection.voiceChannel.guild.id, { player: connection.player, type: connection.type, host: member.id, voiceChannel: connection.voiceChannel, originalChannel: connection.originalChannel, loop: connection.loop, shuffle: connection.shuffle, playMessage: connection.playMessage });
waitMessage.edit(`🔊 ${member.mention} is the new voice channel host.`); waitMessage.edit(`🔊 ${member.mention} is the new voice channel host.`);
} else { } else {
@ -21,9 +21,9 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
} catch { } catch {
// no-op // no-op
} }
connection.player.stop(connection.originalChannel.guild.id); await connection.player.stop(connection.originalChannel.guild.id);
manager.leave(connection.originalChannel.guild.id); await manager.leave(connection.originalChannel.guild.id);
connection.player.destroy(); await connection.player.destroy();
players.delete(connection.originalChannel.guild.id); players.delete(connection.originalChannel.guild.id);
queues.delete(connection.originalChannel.guild.id); queues.delete(connection.originalChannel.guild.id);
skipVotes.delete(connection.originalChannel.guild.id); skipVotes.delete(connection.originalChannel.guild.id);
@ -48,9 +48,9 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
} catch { } catch {
// no-op // no-op
} }
connection.player.stop(connection.originalChannel.guild.id); await connection.player.stop(connection.originalChannel.guild.id);
manager.leave(connection.originalChannel.guild.id); await manager.leave(connection.originalChannel.guild.id);
connection.player.destroy(); await connection.player.destroy();
players.delete(connection.originalChannel.guild.id); players.delete(connection.originalChannel.guild.id);
queues.delete(connection.originalChannel.guild.id); queues.delete(connection.originalChannel.guild.id);
skipVotes.delete(connection.originalChannel.guild.id); skipVotes.delete(connection.originalChannel.guild.id);
@ -63,9 +63,9 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
} }
}); });
} else if (member.id === client.user.id) { } else if (member.id === client.user.id) {
connection.player.stop(connection.originalChannel.guild.id); await connection.player.stop(connection.originalChannel.guild.id);
manager.leave(connection.originalChannel.guild.id); await manager.leave(connection.originalChannel.guild.id);
connection.player.destroy(); await connection.player.destroy();
players.delete(connection.originalChannel.guild.id); players.delete(connection.originalChannel.guild.id);
queues.delete(connection.originalChannel.guild.id); queues.delete(connection.originalChannel.guild.id);
skipVotes.delete(connection.originalChannel.guild.id); skipVotes.delete(connection.originalChannel.guild.id);

View file

@ -140,9 +140,9 @@ export async function nextSong(client, message, connection, track, info, music,
} catch { } catch {
// no-op // no-op
} }
manager.leave(voiceChannel.guild.id); await manager.leave(voiceChannel.guild.id);
connection.removeAllListeners("end"); connection.removeAllListeners("end");
connection.destroy(); await connection.destroy();
players.delete(voiceChannel.guild.id); players.delete(voiceChannel.guild.id);
queues.delete(voiceChannel.guild.id); queues.delete(voiceChannel.guild.id);
logger.error(error); logger.error(error);
@ -181,8 +181,8 @@ export async function nextSong(client, message, connection, track, info, music,
// no-op // no-op
} }
} else if (process.env.STAYVC !== "true") { } else if (process.env.STAYVC !== "true") {
manager.leave(voiceChannel.guild.id); await manager.leave(voiceChannel.guild.id);
connection.destroy(); await connection.destroy();
players.delete(voiceChannel.guild.id); players.delete(voiceChannel.guild.id);
queues.delete(voiceChannel.guild.id); queues.delete(voiceChannel.guild.id);
skipVotes.delete(voiceChannel.guild.id); skipVotes.delete(voiceChannel.guild.id);