queue create/join
This commit is contained in:
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