cleaned up queue code
This commit is contained in:
23
src/queue.ts
23
src/queue.ts
@@ -41,6 +41,23 @@ function getInfo(interaction: CommandInteraction): queueInfo {
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the interaction data is already in the queue
|
||||
* @param interaction
|
||||
* @returns boolean
|
||||
*/
|
||||
export function queueContains(interaction: CommandInteraction): boolean {
|
||||
|
||||
let member = getMember(interaction),
|
||||
info = getInfo(interaction);
|
||||
|
||||
if (info.players.map(m=>m.id).includes(member.id))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a queue from an interaction
|
||||
* @param interaction
|
||||
@@ -53,7 +70,7 @@ export async function createQueue(interaction: CommandInteraction) {
|
||||
teamsize = interaction.options.getInteger('teamsize', true);
|
||||
|
||||
if (QUEUE.has(channelId))
|
||||
throw 'There is already an active queue in this channel, type `/join` to join'; //and you are already in it
|
||||
throw 'There is already an active queue in this channel, ' + (queueContains(interaction) ? 'and you are already in it' : 'type `/join` to join'); //and you are already in it
|
||||
|
||||
QUEUE.set(channelId, {
|
||||
players: [
|
||||
@@ -77,7 +94,7 @@ export async function joinQueue(interaction: CommandInteraction) {
|
||||
let member = getMember(interaction),
|
||||
info = getInfo(interaction);
|
||||
|
||||
if (info.players.map(m=>m.id).includes(member.id))
|
||||
if (queueContains(interaction))
|
||||
throw 'You are already in the active queue';
|
||||
|
||||
info.players.push(member);
|
||||
@@ -98,7 +115,7 @@ export async function leaveQueue(interaction: CommandInteraction) {
|
||||
let member = getMember(interaction),
|
||||
info = getInfo(interaction);
|
||||
|
||||
if (!info.players.map(m=>m.id).includes(member.id))
|
||||
if (!queueContains(interaction))
|
||||
throw 'You aren\'t in the active queue';
|
||||
|
||||
info.players.splice(info.players.indexOf(member), 1);
|
||||
|
||||
Reference in New Issue
Block a user