updated to es2020
This commit is contained in:
115
dist/queue.js
vendored
115
dist/queue.js
vendored
@@ -1,13 +1,4 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.queueInfo = exports.readyQueue = exports.leaveQueue = exports.joinQueue = exports.createQueue = void 0;
|
||||
const discord_js_1 = require("discord.js");
|
||||
@@ -43,20 +34,18 @@ function getInfo(interaction) {
|
||||
* @param interaction
|
||||
* @throws string message if it cannot be created
|
||||
*/
|
||||
function createQueue(interaction) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let { channelId } = interaction, member = getMember(interaction), 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
|
||||
QUEUE.set(channelId, {
|
||||
players: [
|
||||
member
|
||||
],
|
||||
initiator: member,
|
||||
teamsize: teamsize
|
||||
});
|
||||
yield interaction.reply(`Queue for teams of ${teamsize} has been created, and you have joined`);
|
||||
async function createQueue(interaction) {
|
||||
let { channelId } = interaction, member = getMember(interaction), 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
|
||||
QUEUE.set(channelId, {
|
||||
players: [
|
||||
member
|
||||
],
|
||||
initiator: member,
|
||||
teamsize: teamsize
|
||||
});
|
||||
await interaction.reply(`Queue for teams of ${teamsize} has been created, and you have joined`);
|
||||
}
|
||||
exports.createQueue = createQueue;
|
||||
/**
|
||||
@@ -64,15 +53,13 @@ exports.createQueue = createQueue;
|
||||
* @param interaction
|
||||
* @throws string message if it cannot be joined
|
||||
*/
|
||||
function joinQueue(interaction) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let member = getMember(interaction), info = getInfo(interaction);
|
||||
if (info.players.map(m => m.id).includes(member.id))
|
||||
throw 'You are already in the active queue';
|
||||
info.players.push(member);
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
yield interaction.reply('Joined the queue');
|
||||
});
|
||||
async function joinQueue(interaction) {
|
||||
let member = getMember(interaction), info = getInfo(interaction);
|
||||
if (info.players.map(m => m.id).includes(member.id))
|
||||
throw 'You are already in the active queue';
|
||||
info.players.push(member);
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
await interaction.reply('Joined the queue');
|
||||
}
|
||||
exports.joinQueue = joinQueue;
|
||||
/**
|
||||
@@ -80,15 +67,13 @@ exports.joinQueue = joinQueue;
|
||||
* @param interaction
|
||||
* @throws string message if it cannot be left
|
||||
*/
|
||||
function leaveQueue(interaction) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let member = getMember(interaction), info = getInfo(interaction);
|
||||
if (!info.players.map(m => m.id).includes(member.id))
|
||||
throw 'You aren\'t in the active queue';
|
||||
info.players.splice(info.players.indexOf(member), 1);
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
yield interaction.reply('Left the queue');
|
||||
});
|
||||
async function leaveQueue(interaction) {
|
||||
let member = getMember(interaction), info = getInfo(interaction);
|
||||
if (!info.players.map(m => m.id).includes(member.id))
|
||||
throw 'You aren\'t in the active queue';
|
||||
info.players.splice(info.players.indexOf(member), 1);
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
await interaction.reply('Left the queue');
|
||||
}
|
||||
exports.leaveQueue = leaveQueue;
|
||||
/**
|
||||
@@ -96,29 +81,27 @@ exports.leaveQueue = leaveQueue;
|
||||
* @param interaction
|
||||
* @throws string message if it cannot be readied
|
||||
*/
|
||||
function readyQueue(interaction) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let member = getMember(interaction), info = getInfo(interaction), { initiator } = info;
|
||||
if (member.id !== initiator.id)
|
||||
throw 'Only the queue initiator can ready the queue';
|
||||
//reset queue
|
||||
QUEUE.delete(interaction.channelId);
|
||||
if (info.players.filter(m => m.id !== initiator.id).length === 0)
|
||||
throw 'Nobody signed up for the queue, the queue has been reset';
|
||||
//team data
|
||||
let playerlist = (0, util_1.shuffle)(info.players), teams = [];
|
||||
//fill team data
|
||||
for (let i = 0; i < playerlist.length; i += info.teamsize)
|
||||
teams.push(playerlist.slice(i, i + info.teamsize));
|
||||
//convert teams to strings
|
||||
let teamsStr = [];
|
||||
teams.forEach((team, i) => {
|
||||
let str = [`Team ${i + 1}`];
|
||||
team.forEach(m => str.push(` ${m.user.tag}`));
|
||||
teamsStr.push(str.join('\n'));
|
||||
});
|
||||
yield interaction.reply('```\n' + teamsStr.join('\n\n') + '\n```');
|
||||
async function readyQueue(interaction) {
|
||||
let member = getMember(interaction), info = getInfo(interaction), { initiator } = info;
|
||||
if (member.id !== initiator.id)
|
||||
throw 'Only the queue initiator can ready the queue';
|
||||
//reset queue
|
||||
QUEUE.delete(interaction.channelId);
|
||||
if (info.players.filter(m => m.id !== initiator.id).length === 0)
|
||||
throw 'Nobody signed up for the queue, the queue has been reset';
|
||||
//team data
|
||||
let playerlist = (0, util_1.shuffle)(info.players), teams = [];
|
||||
//fill team data
|
||||
for (let i = 0; i < playerlist.length; i += info.teamsize)
|
||||
teams.push(playerlist.slice(i, i + info.teamsize));
|
||||
//convert teams to strings
|
||||
let teamsStr = [];
|
||||
teams.forEach((team, i) => {
|
||||
let str = [`Team ${i + 1}`];
|
||||
team.forEach(m => str.push(` ${m.user.tag}`));
|
||||
teamsStr.push(str.join('\n'));
|
||||
});
|
||||
await interaction.reply('```\n' + teamsStr.join('\n\n') + '\n```');
|
||||
}
|
||||
exports.readyQueue = readyQueue;
|
||||
/**
|
||||
@@ -126,14 +109,12 @@ exports.readyQueue = readyQueue;
|
||||
* @param interaction
|
||||
* @throws string message if it cannot be read
|
||||
*/
|
||||
function queueInfo(interaction) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let info = getInfo(interaction);
|
||||
yield interaction.reply('```' + `
|
||||
async function queueInfo(interaction) {
|
||||
let info = getInfo(interaction);
|
||||
await interaction.reply('```' + `
|
||||
players: ${info.players.map(p => p.user.tag).join('\n ')}
|
||||
initiator: ${info.initiator.user.tag}
|
||||
teamsize: ${info.teamsize}
|
||||
` + '```');
|
||||
});
|
||||
}
|
||||
exports.queueInfo = queueInfo;
|
||||
|
||||
Reference in New Issue
Block a user