From 4b14e5e050b5e43eb850a3e2dfdb3194baadf768 Mon Sep 17 00:00:00 2001 From: ashley zomo Date: Thu, 27 Jan 2022 18:49:52 -0600 Subject: [PATCH] queue create/join --- dist/queue.js | 69 ++++++++++++++++++++++++++++++++++++++++- src/queue.ts | 85 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 151 insertions(+), 3 deletions(-) diff --git a/dist/queue.js b/dist/queue.js index 8b56744..dac7532 100644 --- a/dist/queue.js +++ b/dist/queue.js @@ -1,6 +1,73 @@ "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.createQueue = void 0; +exports.queueInfo = exports.joinQueue = exports.createQueue = void 0; +const discord_js_1 = require("discord.js"); +//maps ChannelID to QueueInfo +const QUEUE = new Map(); function createQueue(interaction) { + return __awaiter(this, void 0, void 0, function* () { + console.log('COMMAND createQueue'); + let member = interaction.member; + if (!(member instanceof discord_js_1.GuildMember)) { + yield interaction.reply('Unable to retrieve guild member information, please try again'); + return; + } + let channelId = interaction.channelId; + if (QUEUE.has(channelId)) { + yield interaction.reply('There is already an active queue in this channel, type `/join` to join'); + return; + } + QUEUE.set(channelId, { + players: [], + initiator: member, + teamsize: interaction.options.getInteger('teamsize', true) + }); + yield interaction.reply('Queue has been created, type `/join` to join'); + }); } exports.createQueue = createQueue; +function joinQueue(interaction) { + return __awaiter(this, void 0, void 0, function* () { + console.log('COMMAND joinQueue'); + let member = interaction.member; + if (!(member instanceof discord_js_1.GuildMember)) { + yield interaction.reply('Unable to retrieve guild member information, please try again'); + return; + } + let channelId = interaction.channelId; + let info = QUEUE.get(channelId); + if (!info) { + yield interaction.reply('There is not an active queue in this channel, type `/queue` to create one'); + return; + } + info.players.push(member); + QUEUE.set(channelId, info); + yield interaction.reply('Joined the queue'); + }); +} +exports.joinQueue = joinQueue; +function queueInfo(interaction) { + return __awaiter(this, void 0, void 0, function* () { + console.log('COMMAND queueInfo'); + let channelId = interaction.channelId, info = QUEUE.get(channelId); + if (!info) { + yield interaction.reply('There is not an active queue in this channel, type `/queue` to create one'); + return; + } + yield interaction.reply('```' + ` +players: ${info.players.map(p => p.user.tag).join('\n ')} +initiator: ${info.initiator.user.tag} +teamsize: ${info.teamsize} +` + '```'); + }); +} +exports.queueInfo = queueInfo; diff --git a/src/queue.ts b/src/queue.ts index d4fc8bf..a9b5781 100644 --- a/src/queue.ts +++ b/src/queue.ts @@ -1,5 +1,86 @@ -import { CommandInteraction } from "discord.js"; +import { CommandInteraction, GuildMember } from "discord.js"; -export function createQueue(interaction: CommandInteraction) { +type queueInfo = { + players: GuildMember[], + initiator: GuildMember, + teamsize: number +} + +//maps ChannelID to QueueInfo +const QUEUE = new Map(); + +export async function createQueue(interaction: CommandInteraction) { + + console.log('COMMAND createQueue') + + let member = interaction.member; + + if (!(member instanceof GuildMember)) { + await interaction.reply('Unable to retrieve guild member information, please try again'); + return; + } + + let channelId = interaction.channelId; + + if (QUEUE.has(channelId)) { + await interaction.reply('There is already an active queue in this channel, type `/join` to join'); + return; + } + + QUEUE.set(channelId, { + players: [], + initiator: member, + teamsize: interaction.options.getInteger('teamsize', true) + }); + + await interaction.reply('Queue has been created, type `/join` to join'); + +} + +export async function joinQueue(interaction: CommandInteraction) { + + console.log('COMMAND joinQueue') + + let member = interaction.member; + + if (!(member instanceof GuildMember)) { + await interaction.reply('Unable to retrieve guild member information, please try again'); + return; + } + + let channelId = interaction.channelId; + + let info = QUEUE.get(channelId); + + if (!info) { + await interaction.reply('There is not an active queue in this channel, type `/queue` to create one'); + return; + } + + info.players.push(member); + + QUEUE.set(channelId, info); + + await interaction.reply('Joined the queue'); + +} + +export async function queueInfo(interaction: CommandInteraction) { + + console.log('COMMAND queueInfo') + + let channelId = interaction.channelId, + info = QUEUE.get(channelId); + + if (!info) { + await interaction.reply('There is not an active queue in this channel, type `/queue` to create one'); + return; + } + + await interaction.reply('```'+` +players: ${info.players.map(p => p.user.tag).join('\n ')} +initiator: ${info.initiator.user.tag} +teamsize: ${info.teamsize} +`+'```') } \ No newline at end of file