separated type definitions and util functions
This commit is contained in:
21
dist/queue.js
vendored
21
dist/queue.js
vendored
@@ -26,9 +26,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.QueueCommands = exports.queueContains = exports.discordInit = exports.queueRemove = exports.queueCreate = void 0;
|
||||
const discord_js_1 = require("discord.js");
|
||||
const fs = __importStar(require("fs"));
|
||||
const util_1 = require("./util");
|
||||
const Lang = __importStar(require("./lang"));
|
||||
//load queues from file
|
||||
const discord_1 = require("./util/discord");
|
||||
const main_1 = require("./util/main");
|
||||
//load queues from file`
|
||||
if (!fs.existsSync('./queues.json'))
|
||||
fs.writeFileSync('./queues.json', '{}');
|
||||
const _QUEUE = fs.readFileSync('./queues.json').toString(), QUEUE = new Map();
|
||||
@@ -101,7 +102,7 @@ exports.discordInit = discordInit;
|
||||
function getInfo(interaction) {
|
||||
const info = QUEUE.get(interaction.channelId);
|
||||
if (!info)
|
||||
throw (0, util_1.emsg)('discord.noQueue');
|
||||
throw (0, main_1.emsg)('discord.noQueue');
|
||||
return info;
|
||||
}
|
||||
/**
|
||||
@@ -111,8 +112,8 @@ function getInfo(interaction) {
|
||||
* @returns object containing each
|
||||
*/
|
||||
const getAll = (interaction) => ({
|
||||
member: (0, util_1.getMember)(interaction),
|
||||
channel: (0, util_1.getChannel)(interaction),
|
||||
member: (0, discord_1.getMember)(interaction),
|
||||
channel: (0, discord_1.getChannel)(interaction),
|
||||
info: getInfo(interaction)
|
||||
});
|
||||
/**
|
||||
@@ -133,11 +134,11 @@ exports.queueContains = queueContains;
|
||||
* @throws errorMessage class if it cannot be left
|
||||
*/
|
||||
function open(interaction) {
|
||||
(0, util_1.memberIsModThrow)(interaction);
|
||||
(0, discord_1.memberIsModThrow)(interaction);
|
||||
const { channelId } = interaction, teamsize = interaction.options.getInteger('teamsize', true);
|
||||
const existing = QUEUE.get(channelId);
|
||||
if (existing)
|
||||
throw (0, util_1.emsg)(Lang.get('error.discord.noCreate', {
|
||||
throw (0, main_1.emsg)(Lang.get('error.discord.noCreate', {
|
||||
teamsize: existing.teamsize.toString()
|
||||
}));
|
||||
queueCreate(channelId, teamsize);
|
||||
@@ -151,7 +152,7 @@ function open(interaction) {
|
||||
* @throws errorMessage class if it cannot be joined
|
||||
*/
|
||||
async function close(interaction) {
|
||||
(0, util_1.memberIsModThrow)(interaction);
|
||||
(0, discord_1.memberIsModThrow)(interaction);
|
||||
QUEUE.delete(interaction.channelId);
|
||||
await interaction.reply(Lang.get('discord.close'));
|
||||
}
|
||||
@@ -177,7 +178,7 @@ async function queue(interaction) {
|
||||
async function join(interaction) {
|
||||
const { member, info, channel } = getAll(interaction);
|
||||
if (queueContains(interaction))
|
||||
throw (0, util_1.emsg)('discord.inQueue');
|
||||
throw (0, main_1.emsg)('discord.inQueue');
|
||||
info.players.push(member);
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
await interaction.reply(Lang.get('discord.join'));
|
||||
@@ -191,7 +192,7 @@ async function join(interaction) {
|
||||
async function leave(interaction) {
|
||||
const { member, info } = getAll(interaction);
|
||||
if (!queueContains(interaction))
|
||||
throw (0, util_1.emsg)('discord.notInQueue');
|
||||
throw (0, main_1.emsg)('discord.notInQueue');
|
||||
info.players.splice(info.players.indexOf(member), 1);
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
await interaction.reply(Lang.get('discord.leave'));
|
||||
|
||||
Reference in New Issue
Block a user