Compare commits
4 Commits
edb786ec04
...
f225bf924a
| Author | SHA1 | Date | |
|---|---|---|---|
| f225bf924a | |||
| 9da9650f92 | |||
| a1a387880c | |||
| 943512d354 |
9
.gitignore
vendored
9
.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
node_modules
|
||||
token.txt
|
||||
queues.json
|
||||
.DS_Store
|
||||
log
|
||||
.vscode
|
||||
log
|
||||
node_modules
|
||||
queues.json
|
||||
token.txt
|
||||
55
dist/lang.js
vendored
Normal file
55
dist/lang.js
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Lang = void 0;
|
||||
const LANG = {
|
||||
en: {
|
||||
discord: {
|
||||
botRestart: 'The bot has just restarted, anybody previously in the queue has been reset',
|
||||
create: 'A queue for teams of {teamsize} has been created',
|
||||
close: 'Queue has been closed',
|
||||
join: 'Joined the queue',
|
||||
leave: 'Left the queue',
|
||||
error: {
|
||||
noQueue: 'There is not an active queue in this channel, type `/open` to create one',
|
||||
noChannel: 'Unable to find channel {channelId} for teams of {teamsize}',
|
||||
noCreate: 'There is already an active queue in this channel for teams of ${teamsize}',
|
||||
inQueue: 'You are already in the queue',
|
||||
notInQueue: 'You aren\'t in the queue'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var Lang;
|
||||
(function (Lang) {
|
||||
var LANGID = 'en';
|
||||
if (!(LANGID in LANG))
|
||||
throw 'language id does not exist';
|
||||
function setLang(langid) {
|
||||
if (langid in LANG)
|
||||
LANGID = langid;
|
||||
else
|
||||
throw 'language id does not exist';
|
||||
}
|
||||
Lang.setLang = setLang;
|
||||
/**
|
||||
* reads language json
|
||||
* @param id ex: discord.error.noActiveQueue
|
||||
* @returns language value, defaults to `id` parameter
|
||||
*/
|
||||
function get(id, args = {}) {
|
||||
let keySpl = id.split('.').map(k => k.trim()).filter(k => k);
|
||||
let finding = LANG[LANGID];
|
||||
for (let key of keySpl) {
|
||||
if (key in finding) {
|
||||
let found = finding[key];
|
||||
if (typeof found === 'string')
|
||||
return found;
|
||||
finding = found;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
Lang.get = get;
|
||||
})(Lang = exports.Lang || (exports.Lang = {}));
|
||||
31
dist/queue.js
vendored
31
dist/queue.js
vendored
@@ -27,6 +27,7 @@ exports.QueueCommands = exports.discordInit = void 0;
|
||||
const discord_js_1 = require("discord.js");
|
||||
const fs = __importStar(require("fs"));
|
||||
const util_1 = require("./util");
|
||||
const lang_1 = require("./lang");
|
||||
//load queues from file
|
||||
if (!fs.existsSync('./queues.json'))
|
||||
fs.writeFileSync('./queues.json', '{}');
|
||||
@@ -52,6 +53,7 @@ async function checkQueue(channel) {
|
||||
return;
|
||||
if (info.players.length >= info.teamsize) {
|
||||
let team = info.players.splice(0, info.teamsize).map(m => m.toString());
|
||||
//TODO add embeds to lang.ts
|
||||
let embed = new discord_js_1.MessageEmbed()
|
||||
.setTitle('Team')
|
||||
.setDescription(team.join('\n'));
|
||||
@@ -96,11 +98,14 @@ async function discordInit(client) {
|
||||
continue;
|
||||
}
|
||||
if (!channel || !(channel instanceof discord_js_1.TextChannel)) {
|
||||
console.error(`Unable to find channel ${channelId} for teams of ${info?.teamsize}`);
|
||||
console.error(lang_1.Lang.get('discord.error.noChannel'), {
|
||||
channelId,
|
||||
teamsize: info.teamsize
|
||||
});
|
||||
Queue.remove(channelId);
|
||||
continue;
|
||||
}
|
||||
channel.send('The bot has just restarted, anybody previously in the queue has been reset');
|
||||
channel.send(lang_1.Lang.get('discord.botRestart'));
|
||||
}
|
||||
}
|
||||
exports.discordInit = discordInit;
|
||||
@@ -115,7 +120,7 @@ var QueueCommands;
|
||||
function getInfo(interaction) {
|
||||
let info = QUEUE.get(interaction.channelId);
|
||||
if (!info)
|
||||
throw (0, util_1.emsg)('There is not an active queue in this channel, type `/open` to create one');
|
||||
throw (0, util_1.emsg)(lang_1.Lang.get('discord.error.noQueue'));
|
||||
return info;
|
||||
}
|
||||
/**
|
||||
@@ -150,9 +155,13 @@ var QueueCommands;
|
||||
(0, util_1.memberIsModThrow)(interaction);
|
||||
let { channelId } = interaction, teamsize = interaction.options.getInteger('teamsize', true);
|
||||
if (QUEUE.has(channelId))
|
||||
throw (0, util_1.emsg)(`There is already an active queue in this channel for teams of ${QUEUE.get(channelId)?.teamsize}`);
|
||||
throw (0, util_1.emsg)(lang_1.Lang.get('discord.error.noCreate', {
|
||||
teamsize: QUEUE.get(channelId)?.teamsize
|
||||
}));
|
||||
Queue.create(channelId, teamsize);
|
||||
interaction.reply(`A queue for teams of ${teamsize} has been started`);
|
||||
interaction.reply(lang_1.Lang.get('discord.create', {
|
||||
teamsize
|
||||
}));
|
||||
}
|
||||
QueueCommands.queueCreate = queueCreate;
|
||||
/**
|
||||
@@ -172,7 +181,7 @@ var QueueCommands;
|
||||
async function close(interaction) {
|
||||
(0, util_1.memberIsModThrow)(interaction);
|
||||
QUEUE.delete(interaction.channelId);
|
||||
await interaction.reply('Queue has been reset');
|
||||
await interaction.reply(lang_1.Lang.get('discord.close'));
|
||||
}
|
||||
QueueCommands.close = close;
|
||||
/**
|
||||
@@ -186,7 +195,7 @@ var QueueCommands;
|
||||
.setTitle('Active Queue')
|
||||
.addField('Team Size', info.teamsize.toString(), true)
|
||||
.addField('Players Joined', info.players.length.toString(), true)
|
||||
.setFooter({ text: 'type /join' });
|
||||
.setFooter({ text: 'type /join' }); //TODO
|
||||
await interaction.reply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
QueueCommands.queue = queue;
|
||||
@@ -198,10 +207,10 @@ var QueueCommands;
|
||||
async function join(interaction) {
|
||||
let { member, info, channel } = getAll(interaction);
|
||||
if (queueContains(interaction))
|
||||
throw (0, util_1.emsg)('You are already in the queue');
|
||||
throw (0, util_1.emsg)(lang_1.Lang.get('discord.error.inQueue'));
|
||||
info.players.push(member);
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
await interaction.reply('Joined the queue');
|
||||
await interaction.reply(lang_1.Lang.get('discord.join'));
|
||||
checkQueue(channel);
|
||||
}
|
||||
QueueCommands.join = join;
|
||||
@@ -213,10 +222,10 @@ var QueueCommands;
|
||||
async function leave(interaction) {
|
||||
let { member, info } = getAll(interaction);
|
||||
if (!queueContains(interaction))
|
||||
throw (0, util_1.emsg)('You aren\'t in the queue');
|
||||
throw (0, util_1.emsg)(lang_1.Lang.get('discord.error.notInQueue'));
|
||||
info.players.splice(info.players.indexOf(member), 1);
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
await interaction.reply('Left the queue');
|
||||
await interaction.reply(lang_1.Lang.get('discord.leave'));
|
||||
}
|
||||
QueueCommands.leave = leave;
|
||||
})(QueueCommands = exports.QueueCommands || (exports.QueueCommands = {}));
|
||||
|
||||
75
package-lock.json
generated
75
package-lock.json
generated
@@ -150,9 +150,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "17.0.13",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.13.tgz",
|
||||
"integrity": "sha512-Y86MAxASe25hNzlDbsviXl8jQHb0RDvKt4c40ZJQ1Don0AAL0STLZSs4N+6gLEO55pedy7r2cLwS+ZDxPm/2Bw=="
|
||||
"version": "17.0.17",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.17.tgz",
|
||||
"integrity": "sha512-e8PUNQy1HgJGV3iU/Bp2+D/DXh3PYeyli8LgIwsQcs1Ar1LoaWHSIT6Rw+H2rNJmiq6SNWiDytfx8+gYj7wDHw=="
|
||||
},
|
||||
"node_modules/@types/node-fetch": {
|
||||
"version": "2.5.12",
|
||||
@@ -662,6 +662,7 @@
|
||||
"version": "0.26.1",
|
||||
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.26.1.tgz",
|
||||
"integrity": "sha512-T5PdMQ+Y1MEECYMV5wmyi9VEYPagEDEi4S0amgsszpWY0VB9JJ/hEvM6BgLhbdnKky4gfmZEXtEEtojN8ZKJQQ==",
|
||||
"deprecated": "No longer supported. Install the latest release!",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
@@ -1211,9 +1212,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/minimatch": {
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.1.tgz",
|
||||
"integrity": "sha512-reLxBcKUPNBnc/sVtAbxgRVFSegoGeLaSjmphNhcwcolhYLRgtJscn5mRl6YRZNQv40Y7P6JM2YhSIsbL9OB5A==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"brace-expansion": "^1.1.7"
|
||||
@@ -1574,9 +1575,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/signal-exit": {
|
||||
"version": "3.0.6",
|
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.6.tgz",
|
||||
"integrity": "sha512-sDl4qMFpijcGw22U5w63KmD3cZJfBuFlVNbVMKje2keoKML7X2UzWbc4XrmEbDwg0NXJc3yv4/ox7b+JWb57kQ==",
|
||||
"version": "3.0.7",
|
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
|
||||
"integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/string_decoder": {
|
||||
@@ -1688,9 +1689,9 @@
|
||||
"integrity": "sha512-nXIb1fvdY5CBSrDIblLn73NW0qRDk5yJ0Sk1qPBF560OdJfQp9jhl+0tzcY09OZ9U+6GpeoI9RjwoIKFIoB9MQ=="
|
||||
},
|
||||
"node_modules/ts-node": {
|
||||
"version": "10.4.0",
|
||||
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.4.0.tgz",
|
||||
"integrity": "sha512-g0FlPvvCXSIO1JDF6S232P5jPYqBkRL9qly81ZgAOSU7rwI0stphCgd2kLiCrU9DjQCrJMWEqcNSjQL02s6d8A==",
|
||||
"version": "10.5.0",
|
||||
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.5.0.tgz",
|
||||
"integrity": "sha512-6kEJKwVxAJ35W4akuiysfKwKmjkbYxwQMTBaAxo9KKAx/Yd26mPUyhGz3ji+EsJoAgrLqVsYHNuuYwQe22lbtw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@cspotcode/source-map-support": "0.7.0",
|
||||
@@ -1704,6 +1705,7 @@
|
||||
"create-require": "^1.1.0",
|
||||
"diff": "^4.0.1",
|
||||
"make-error": "^1.1.1",
|
||||
"v8-compile-cache-lib": "^3.0.0",
|
||||
"yn": "3.1.1"
|
||||
},
|
||||
"bin": {
|
||||
@@ -1846,6 +1848,12 @@
|
||||
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/v8-compile-cache-lib": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.0.tgz",
|
||||
"integrity": "sha512-mpSYqfsFvASnSn5qMiwrr4VKfumbPyONLCOPmsR3A6pTY/r0+tSaVbgPWSAIuzbk3lCTa+FForeTiO+wBQGkjA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/webidl-conversions": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
|
||||
@@ -1908,9 +1916,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/ws": {
|
||||
"version": "8.4.2",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.4.2.tgz",
|
||||
"integrity": "sha512-Kbk4Nxyq7/ZWqr/tarI9yIt/+iNNFOjBXEWgTb4ydaNHBNGgvf2QHbS9fdfsndfjFlFwEd4Al+mw83YkaD10ZA==",
|
||||
"version": "8.5.0",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz",
|
||||
"integrity": "sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
@@ -2056,9 +2064,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "17.0.13",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.13.tgz",
|
||||
"integrity": "sha512-Y86MAxASe25hNzlDbsviXl8jQHb0RDvKt4c40ZJQ1Don0AAL0STLZSs4N+6gLEO55pedy7r2cLwS+ZDxPm/2Bw=="
|
||||
"version": "17.0.17",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.17.tgz",
|
||||
"integrity": "sha512-e8PUNQy1HgJGV3iU/Bp2+D/DXh3PYeyli8LgIwsQcs1Ar1LoaWHSIT6Rw+H2rNJmiq6SNWiDytfx8+gYj7wDHw=="
|
||||
},
|
||||
"@types/node-fetch": {
|
||||
"version": "2.5.12",
|
||||
@@ -2852,9 +2860,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"minimatch": {
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.1.tgz",
|
||||
"integrity": "sha512-reLxBcKUPNBnc/sVtAbxgRVFSegoGeLaSjmphNhcwcolhYLRgtJscn5mRl6YRZNQv40Y7P6JM2YhSIsbL9OB5A==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"brace-expansion": "^1.1.7"
|
||||
@@ -3119,9 +3127,9 @@
|
||||
}
|
||||
},
|
||||
"signal-exit": {
|
||||
"version": "3.0.6",
|
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.6.tgz",
|
||||
"integrity": "sha512-sDl4qMFpijcGw22U5w63KmD3cZJfBuFlVNbVMKje2keoKML7X2UzWbc4XrmEbDwg0NXJc3yv4/ox7b+JWb57kQ==",
|
||||
"version": "3.0.7",
|
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
|
||||
"integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==",
|
||||
"dev": true
|
||||
},
|
||||
"string_decoder": {
|
||||
@@ -3212,9 +3220,9 @@
|
||||
"integrity": "sha512-nXIb1fvdY5CBSrDIblLn73NW0qRDk5yJ0Sk1qPBF560OdJfQp9jhl+0tzcY09OZ9U+6GpeoI9RjwoIKFIoB9MQ=="
|
||||
},
|
||||
"ts-node": {
|
||||
"version": "10.4.0",
|
||||
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.4.0.tgz",
|
||||
"integrity": "sha512-g0FlPvvCXSIO1JDF6S232P5jPYqBkRL9qly81ZgAOSU7rwI0stphCgd2kLiCrU9DjQCrJMWEqcNSjQL02s6d8A==",
|
||||
"version": "10.5.0",
|
||||
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.5.0.tgz",
|
||||
"integrity": "sha512-6kEJKwVxAJ35W4akuiysfKwKmjkbYxwQMTBaAxo9KKAx/Yd26mPUyhGz3ji+EsJoAgrLqVsYHNuuYwQe22lbtw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@cspotcode/source-map-support": "0.7.0",
|
||||
@@ -3228,6 +3236,7 @@
|
||||
"create-require": "^1.1.0",
|
||||
"diff": "^4.0.1",
|
||||
"make-error": "^1.1.1",
|
||||
"v8-compile-cache-lib": "^3.0.0",
|
||||
"yn": "3.1.1"
|
||||
}
|
||||
},
|
||||
@@ -3320,6 +3329,12 @@
|
||||
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=",
|
||||
"dev": true
|
||||
},
|
||||
"v8-compile-cache-lib": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.0.tgz",
|
||||
"integrity": "sha512-mpSYqfsFvASnSn5qMiwrr4VKfumbPyONLCOPmsR3A6pTY/r0+tSaVbgPWSAIuzbk3lCTa+FForeTiO+wBQGkjA==",
|
||||
"dev": true
|
||||
},
|
||||
"webidl-conversions": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
|
||||
@@ -3373,9 +3388,9 @@
|
||||
}
|
||||
},
|
||||
"ws": {
|
||||
"version": "8.4.2",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.4.2.tgz",
|
||||
"integrity": "sha512-Kbk4Nxyq7/ZWqr/tarI9yIt/+iNNFOjBXEWgTb4ydaNHBNGgvf2QHbS9fdfsndfjFlFwEd4Al+mw83YkaD10ZA==",
|
||||
"version": "8.5.0",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz",
|
||||
"integrity": "sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==",
|
||||
"requires": {}
|
||||
},
|
||||
"xdg-basedir": {
|
||||
|
||||
@@ -31,9 +31,9 @@
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node": "^17.0.13",
|
||||
"discord-api-types": "^0.26.1",
|
||||
"npm-watch": "^0.11.0",
|
||||
"ts-node": "^10.4.0",
|
||||
"discord-api-types": "^0.26.1",
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
66
src/lang.ts
Normal file
66
src/lang.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
type LangObj = { [keys:string]: LangObj | string }
|
||||
type LangObjWhold = { [langid:string]: LangObj }
|
||||
|
||||
const LANG: LangObjWhold = {
|
||||
en: {
|
||||
discord: {
|
||||
botRestart: 'The bot has just restarted, anybody previously in the queue has been reset',
|
||||
create: 'A queue for teams of {teamsize} has been created',
|
||||
close: 'Queue has been closed',
|
||||
join: 'Joined the queue',
|
||||
leave: 'Left the queue',
|
||||
error: {
|
||||
noQueue: 'There is not an active queue in this channel, type `/open` to create one',
|
||||
noChannel: 'Unable to find channel {channelId} for teams of {teamsize}',
|
||||
noCreate: 'There is already an active queue in this channel for teams of ${teamsize}',
|
||||
inQueue: 'You are already in the queue',
|
||||
notInQueue: 'You aren\'t in the queue'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export namespace Lang {
|
||||
|
||||
var LANGID = 'en';
|
||||
if (!(LANGID in LANG))
|
||||
throw 'language id does not exist';
|
||||
|
||||
export function setLang(langid: string) {
|
||||
if (langid in LANG)
|
||||
LANGID = langid;
|
||||
else
|
||||
throw 'language id does not exist';
|
||||
}
|
||||
|
||||
/**
|
||||
* reads language json
|
||||
* @param id ex: discord.error.noActiveQueue
|
||||
* @returns language value, defaults to `id` parameter
|
||||
*/
|
||||
export function get(id: string, args: {[keys: string]: any} = {}): string {//discord.error.noActiveQueue
|
||||
|
||||
let keySpl = id.split('.').map(k => k.trim()).filter(k => k);
|
||||
|
||||
let finding = LANG[LANGID];
|
||||
|
||||
for (let key of keySpl) {
|
||||
|
||||
if (key in finding) {
|
||||
|
||||
let found = finding[key];
|
||||
|
||||
if (typeof found === 'string')
|
||||
return found;
|
||||
|
||||
finding = found;
|
||||
|
||||
} else
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
31
src/queue.ts
31
src/queue.ts
@@ -6,6 +6,7 @@ join message should contain your current position in the queue, editing it to ke
|
||||
import { Client, CommandInteraction, GuildMember, MessageEmbed, TextChannel } from "discord.js";
|
||||
import * as fs from 'fs';
|
||||
import { emsg, getChannel, getMember, memberIsModThrow, queueInfo, queueInfoBase } from "./util";
|
||||
import { Lang } from './lang';
|
||||
|
||||
//load queues from file
|
||||
if (!fs.existsSync('./queues.json'))
|
||||
@@ -48,6 +49,7 @@ async function checkQueue(channel: TextChannel) {
|
||||
|
||||
let team = info.players.splice(0, info.teamsize).map(m => m.toString());
|
||||
|
||||
//TODO add embeds to lang.ts
|
||||
let embed = new MessageEmbed()
|
||||
.setTitle('Team')
|
||||
.setDescription(team.join('\n'));
|
||||
@@ -102,12 +104,15 @@ export async function discordInit(client: Client) {
|
||||
}
|
||||
|
||||
if (!channel || !(channel instanceof TextChannel)) {
|
||||
console.error(`Unable to find channel ${channelId} for teams of ${info?.teamsize}`);
|
||||
console.error(Lang.get('discord.error.noChannel'), {
|
||||
channelId,
|
||||
teamsize: info.teamsize
|
||||
});
|
||||
Queue.remove(channelId);
|
||||
continue;
|
||||
}
|
||||
|
||||
channel.send('The bot has just restarted, anybody previously in the queue has been reset');
|
||||
channel.send(Lang.get('discord.botRestart'));
|
||||
|
||||
}
|
||||
|
||||
@@ -124,7 +129,7 @@ export namespace QueueCommands {
|
||||
let info = QUEUE.get(interaction.channelId);
|
||||
|
||||
if (!info)
|
||||
throw emsg('There is not an active queue in this channel, type `/open` to create one');
|
||||
throw emsg(Lang.get('discord.error.noQueue'));
|
||||
|
||||
return info;
|
||||
}
|
||||
@@ -169,11 +174,15 @@ export namespace QueueCommands {
|
||||
teamsize = interaction.options.getInteger('teamsize', true);
|
||||
|
||||
if (QUEUE.has(channelId))
|
||||
throw emsg(`There is already an active queue in this channel for teams of ${QUEUE.get(channelId)?.teamsize}`);
|
||||
throw emsg(Lang.get('discord.error.noCreate', {
|
||||
teamsize: QUEUE.get(channelId)?.teamsize
|
||||
}));
|
||||
|
||||
Queue.create(channelId, teamsize);
|
||||
|
||||
interaction.reply(`A queue for teams of ${teamsize} has been started`)
|
||||
interaction.reply(Lang.get('discord.create', {
|
||||
teamsize
|
||||
}))
|
||||
|
||||
}
|
||||
|
||||
@@ -198,7 +207,7 @@ export namespace QueueCommands {
|
||||
|
||||
QUEUE.delete(interaction.channelId);
|
||||
|
||||
await interaction.reply('Queue has been reset');
|
||||
await interaction.reply(Lang.get('discord.close'));
|
||||
|
||||
}
|
||||
|
||||
@@ -215,7 +224,7 @@ export namespace QueueCommands {
|
||||
.setTitle('Active Queue')
|
||||
.addField('Team Size', info.teamsize.toString(), true)
|
||||
.addField('Players Joined', info.players.length.toString(), true)
|
||||
.setFooter({text: 'type /join'});
|
||||
.setFooter({text: 'type /join'}); //TODO
|
||||
|
||||
await interaction.reply({embeds: [embed], ephemeral: true});
|
||||
|
||||
@@ -231,13 +240,13 @@ export namespace QueueCommands {
|
||||
let {member, info, channel} = getAll(interaction);
|
||||
|
||||
if (queueContains(interaction))
|
||||
throw emsg('You are already in the queue');
|
||||
throw emsg(Lang.get('discord.error.inQueue'));
|
||||
|
||||
info.players.push(member);
|
||||
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
|
||||
await interaction.reply('Joined the queue');
|
||||
await interaction.reply(Lang.get('discord.join'));
|
||||
|
||||
checkQueue(channel);
|
||||
|
||||
@@ -253,13 +262,13 @@ export namespace QueueCommands {
|
||||
let {member, info} = getAll(interaction);
|
||||
|
||||
if (!queueContains(interaction))
|
||||
throw emsg('You aren\'t in the queue');
|
||||
throw emsg(Lang.get('discord.error.notInQueue'));
|
||||
|
||||
info.players.splice(info.players.indexOf(member), 1);
|
||||
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
|
||||
await interaction.reply('Left the queue');
|
||||
await interaction.reply(Lang.get('discord.leave'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user