Compare commits
2 Commits
1e990abdd5
...
c2c59e53ca
| Author | SHA1 | Date | |
|---|---|---|---|
| c2c59e53ca | |||
| 85d0e833dd |
6
dist/api.js
vendored
6
dist/api.js
vendored
@@ -68,11 +68,10 @@ function getHTML(name) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let result = Buffer.alloc(0);
|
let result = Buffer.alloc(0);
|
||||||
response.on('data', function (chunk) {
|
response.on('data', chunk => {
|
||||||
result = Buffer.concat([result, chunk]);
|
result = Buffer.concat([result, chunk]);
|
||||||
});
|
});
|
||||||
response.on('end', function () {
|
response.on('end', () => {
|
||||||
// result has response body buffer
|
|
||||||
resolve(result.toString());
|
resolve(result.toString());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -212,4 +211,3 @@ async function getPlayerInteraction(interaction) {
|
|||||||
await interaction.editReply('```\n' + JSON.stringify(data, null, 2) + '\n```');
|
await interaction.editReply('```\n' + JSON.stringify(data, null, 2) + '\n```');
|
||||||
}
|
}
|
||||||
exports.getPlayerInteraction = getPlayerInteraction;
|
exports.getPlayerInteraction = getPlayerInteraction;
|
||||||
//await getPlayer('IanWhysp')
|
|
||||||
|
|||||||
20
dist/queue.js
vendored
20
dist/queue.js
vendored
@@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.queueInfo = exports.readyQueue = exports.leaveQueue = exports.joinQueue = exports.createQueue = void 0;
|
exports.queueInfo = exports.readyQueue = exports.leaveQueue = exports.joinQueue = exports.createQueue = exports.queueContains = void 0;
|
||||||
const discord_js_1 = require("discord.js");
|
const discord_js_1 = require("discord.js");
|
||||||
const util_1 = require("./util");
|
const util_1 = require("./util");
|
||||||
//maps ChannelID to QueueInfo
|
//maps ChannelID to QueueInfo
|
||||||
@@ -29,6 +29,18 @@ function getInfo(interaction) {
|
|||||||
throw 'There is not an active queue in this channel, type `/queue` to create one';
|
throw 'There is not an active queue in this channel, type `/queue` to create one';
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* checks if the interaction data is already in the queue
|
||||||
|
* @param interaction
|
||||||
|
* @returns boolean
|
||||||
|
*/
|
||||||
|
function queueContains(interaction) {
|
||||||
|
let member = getMember(interaction), info = getInfo(interaction);
|
||||||
|
if (info.players.map(m => m.id).includes(member.id))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
exports.queueContains = queueContains;
|
||||||
/**
|
/**
|
||||||
* creates a queue from an interaction
|
* creates a queue from an interaction
|
||||||
* @param interaction
|
* @param interaction
|
||||||
@@ -37,7 +49,7 @@ function getInfo(interaction) {
|
|||||||
async function createQueue(interaction) {
|
async function createQueue(interaction) {
|
||||||
let { channelId } = interaction, member = getMember(interaction), teamsize = interaction.options.getInteger('teamsize', true);
|
let { channelId } = interaction, member = getMember(interaction), teamsize = interaction.options.getInteger('teamsize', true);
|
||||||
if (QUEUE.has(channelId))
|
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, {
|
QUEUE.set(channelId, {
|
||||||
players: [
|
players: [
|
||||||
member
|
member
|
||||||
@@ -55,7 +67,7 @@ exports.createQueue = createQueue;
|
|||||||
*/
|
*/
|
||||||
async function joinQueue(interaction) {
|
async function joinQueue(interaction) {
|
||||||
let member = getMember(interaction), info = getInfo(interaction);
|
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';
|
throw 'You are already in the active queue';
|
||||||
info.players.push(member);
|
info.players.push(member);
|
||||||
QUEUE.set(interaction.channelId, info);
|
QUEUE.set(interaction.channelId, info);
|
||||||
@@ -69,7 +81,7 @@ exports.joinQueue = joinQueue;
|
|||||||
*/
|
*/
|
||||||
async function leaveQueue(interaction) {
|
async function leaveQueue(interaction) {
|
||||||
let member = getMember(interaction), info = getInfo(interaction);
|
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';
|
throw 'You aren\'t in the active queue';
|
||||||
info.players.splice(info.players.indexOf(member), 1);
|
info.players.splice(info.players.indexOf(member), 1);
|
||||||
QUEUE.set(interaction.channelId, info);
|
QUEUE.set(interaction.channelId, info);
|
||||||
|
|||||||
@@ -67,12 +67,11 @@ function getHTML(name: string): Promise<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let result = Buffer.alloc(0);
|
let result = Buffer.alloc(0);
|
||||||
response.on('data', function(chunk) {
|
response.on('data', chunk => {
|
||||||
result = Buffer.concat([result, chunk]);
|
result = Buffer.concat([result, chunk]);
|
||||||
});
|
});
|
||||||
|
|
||||||
response.on('end', function() {
|
response.on('end', () => {
|
||||||
// result has response body buffer
|
|
||||||
resolve(result.toString());
|
resolve(result.toString());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -250,5 +249,3 @@ export async function getPlayerInteraction(interaction: CommandInteraction) {
|
|||||||
else
|
else
|
||||||
await interaction.editReply('```\n'+JSON.stringify(data, null, 2)+'\n```');
|
await interaction.editReply('```\n'+JSON.stringify(data, null, 2)+'\n```');
|
||||||
}
|
}
|
||||||
|
|
||||||
//await getPlayer('IanWhysp')
|
|
||||||
23
src/queue.ts
23
src/queue.ts
@@ -41,6 +41,23 @@ function getInfo(interaction: CommandInteraction): queueInfo {
|
|||||||
return info;
|
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
|
* creates a queue from an interaction
|
||||||
* @param interaction
|
* @param interaction
|
||||||
@@ -53,7 +70,7 @@ export async function createQueue(interaction: CommandInteraction) {
|
|||||||
teamsize = interaction.options.getInteger('teamsize', true);
|
teamsize = interaction.options.getInteger('teamsize', true);
|
||||||
|
|
||||||
if (QUEUE.has(channelId))
|
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, {
|
QUEUE.set(channelId, {
|
||||||
players: [
|
players: [
|
||||||
@@ -77,7 +94,7 @@ export async function joinQueue(interaction: CommandInteraction) {
|
|||||||
let member = getMember(interaction),
|
let member = getMember(interaction),
|
||||||
info = getInfo(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';
|
throw 'You are already in the active queue';
|
||||||
|
|
||||||
info.players.push(member);
|
info.players.push(member);
|
||||||
@@ -98,7 +115,7 @@ export async function leaveQueue(interaction: CommandInteraction) {
|
|||||||
let member = getMember(interaction),
|
let member = getMember(interaction),
|
||||||
info = getInfo(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';
|
throw 'You aren\'t in the active queue';
|
||||||
|
|
||||||
info.players.splice(info.players.indexOf(member), 1);
|
info.players.splice(info.players.indexOf(member), 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user