queue create/join
This commit is contained in:
69
dist/queue.js
vendored
69
dist/queue.js
vendored
@@ -1,6 +1,73 @@
|
|||||||
"use strict";
|
"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 });
|
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) {
|
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;
|
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;
|
||||||
|
|||||||
85
src/queue.ts
85
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<string, queueInfo>();
|
||||||
|
|
||||||
|
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}
|
||||||
|
`+'```')
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user