Compare commits

..

4 Commits

Author SHA1 Message Date
f225bf924a updated lang strings 2022-02-13 19:15:55 -06:00
9da9650f92 created lang file 2022-02-13 18:56:12 -06:00
a1a387880c updated gitignore 2022-02-13 18:55:47 -06:00
943512d354 updated packages 2022-02-13 18:50:24 -06:00
7 changed files with 212 additions and 57 deletions

7
.gitignore vendored
View File

@@ -1,5 +1,6 @@
node_modules
token.txt
queues.json
.DS_Store .DS_Store
.vscode
log log
node_modules
queues.json
token.txt

55
dist/lang.js vendored Normal file
View 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
View File

@@ -27,6 +27,7 @@ exports.QueueCommands = exports.discordInit = void 0;
const discord_js_1 = require("discord.js"); const discord_js_1 = require("discord.js");
const fs = __importStar(require("fs")); const fs = __importStar(require("fs"));
const util_1 = require("./util"); const util_1 = require("./util");
const lang_1 = require("./lang");
//load queues from file //load queues from file
if (!fs.existsSync('./queues.json')) if (!fs.existsSync('./queues.json'))
fs.writeFileSync('./queues.json', '{}'); fs.writeFileSync('./queues.json', '{}');
@@ -52,6 +53,7 @@ async function checkQueue(channel) {
return; return;
if (info.players.length >= info.teamsize) { if (info.players.length >= info.teamsize) {
let team = info.players.splice(0, info.teamsize).map(m => m.toString()); 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() let embed = new discord_js_1.MessageEmbed()
.setTitle('Team') .setTitle('Team')
.setDescription(team.join('\n')); .setDescription(team.join('\n'));
@@ -96,11 +98,14 @@ async function discordInit(client) {
continue; continue;
} }
if (!channel || !(channel instanceof discord_js_1.TextChannel)) { 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); Queue.remove(channelId);
continue; 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; exports.discordInit = discordInit;
@@ -115,7 +120,7 @@ var QueueCommands;
function getInfo(interaction) { function getInfo(interaction) {
let info = QUEUE.get(interaction.channelId); let info = QUEUE.get(interaction.channelId);
if (!info) 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; return info;
} }
/** /**
@@ -150,9 +155,13 @@ var QueueCommands;
(0, util_1.memberIsModThrow)(interaction); (0, util_1.memberIsModThrow)(interaction);
let { channelId } = interaction, teamsize = interaction.options.getInteger('teamsize', true); let { channelId } = interaction, teamsize = interaction.options.getInteger('teamsize', true);
if (QUEUE.has(channelId)) 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); 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; QueueCommands.queueCreate = queueCreate;
/** /**
@@ -172,7 +181,7 @@ var QueueCommands;
async function close(interaction) { async function close(interaction) {
(0, util_1.memberIsModThrow)(interaction); (0, util_1.memberIsModThrow)(interaction);
QUEUE.delete(interaction.channelId); QUEUE.delete(interaction.channelId);
await interaction.reply('Queue has been reset'); await interaction.reply(lang_1.Lang.get('discord.close'));
} }
QueueCommands.close = close; QueueCommands.close = close;
/** /**
@@ -186,7 +195,7 @@ var QueueCommands;
.setTitle('Active Queue') .setTitle('Active Queue')
.addField('Team Size', info.teamsize.toString(), true) .addField('Team Size', info.teamsize.toString(), true)
.addField('Players Joined', info.players.length.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 }); await interaction.reply({ embeds: [embed], ephemeral: true });
} }
QueueCommands.queue = queue; QueueCommands.queue = queue;
@@ -198,10 +207,10 @@ var QueueCommands;
async function join(interaction) { async function join(interaction) {
let { member, info, channel } = getAll(interaction); let { member, info, channel } = getAll(interaction);
if (queueContains(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); info.players.push(member);
QUEUE.set(interaction.channelId, info); QUEUE.set(interaction.channelId, info);
await interaction.reply('Joined the queue'); await interaction.reply(lang_1.Lang.get('discord.join'));
checkQueue(channel); checkQueue(channel);
} }
QueueCommands.join = join; QueueCommands.join = join;
@@ -213,10 +222,10 @@ var QueueCommands;
async function leave(interaction) { async function leave(interaction) {
let { member, info } = getAll(interaction); let { member, info } = getAll(interaction);
if (!queueContains(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); info.players.splice(info.players.indexOf(member), 1);
QUEUE.set(interaction.channelId, info); QUEUE.set(interaction.channelId, info);
await interaction.reply('Left the queue'); await interaction.reply(lang_1.Lang.get('discord.leave'));
} }
QueueCommands.leave = leave; QueueCommands.leave = leave;
})(QueueCommands = exports.QueueCommands || (exports.QueueCommands = {})); })(QueueCommands = exports.QueueCommands || (exports.QueueCommands = {}));

75
package-lock.json generated
View File

@@ -150,9 +150,9 @@
"dev": true "dev": true
}, },
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "17.0.13", "version": "17.0.17",
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.13.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.17.tgz",
"integrity": "sha512-Y86MAxASe25hNzlDbsviXl8jQHb0RDvKt4c40ZJQ1Don0AAL0STLZSs4N+6gLEO55pedy7r2cLwS+ZDxPm/2Bw==" "integrity": "sha512-e8PUNQy1HgJGV3iU/Bp2+D/DXh3PYeyli8LgIwsQcs1Ar1LoaWHSIT6Rw+H2rNJmiq6SNWiDytfx8+gYj7wDHw=="
}, },
"node_modules/@types/node-fetch": { "node_modules/@types/node-fetch": {
"version": "2.5.12", "version": "2.5.12",
@@ -662,6 +662,7 @@
"version": "0.26.1", "version": "0.26.1",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.26.1.tgz", "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.26.1.tgz",
"integrity": "sha512-T5PdMQ+Y1MEECYMV5wmyi9VEYPagEDEi4S0amgsszpWY0VB9JJ/hEvM6BgLhbdnKky4gfmZEXtEEtojN8ZKJQQ==", "integrity": "sha512-T5PdMQ+Y1MEECYMV5wmyi9VEYPagEDEi4S0amgsszpWY0VB9JJ/hEvM6BgLhbdnKky4gfmZEXtEEtojN8ZKJQQ==",
"deprecated": "No longer supported. Install the latest release!",
"engines": { "engines": {
"node": ">=12" "node": ">=12"
} }
@@ -1211,9 +1212,9 @@
} }
}, },
"node_modules/minimatch": { "node_modules/minimatch": {
"version": "3.0.4", "version": "3.1.1",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.1.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "integrity": "sha512-reLxBcKUPNBnc/sVtAbxgRVFSegoGeLaSjmphNhcwcolhYLRgtJscn5mRl6YRZNQv40Y7P6JM2YhSIsbL9OB5A==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
@@ -1574,9 +1575,9 @@
} }
}, },
"node_modules/signal-exit": { "node_modules/signal-exit": {
"version": "3.0.6", "version": "3.0.7",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.6.tgz", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
"integrity": "sha512-sDl4qMFpijcGw22U5w63KmD3cZJfBuFlVNbVMKje2keoKML7X2UzWbc4XrmEbDwg0NXJc3yv4/ox7b+JWb57kQ==", "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==",
"dev": true "dev": true
}, },
"node_modules/string_decoder": { "node_modules/string_decoder": {
@@ -1688,9 +1689,9 @@
"integrity": "sha512-nXIb1fvdY5CBSrDIblLn73NW0qRDk5yJ0Sk1qPBF560OdJfQp9jhl+0tzcY09OZ9U+6GpeoI9RjwoIKFIoB9MQ==" "integrity": "sha512-nXIb1fvdY5CBSrDIblLn73NW0qRDk5yJ0Sk1qPBF560OdJfQp9jhl+0tzcY09OZ9U+6GpeoI9RjwoIKFIoB9MQ=="
}, },
"node_modules/ts-node": { "node_modules/ts-node": {
"version": "10.4.0", "version": "10.5.0",
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.4.0.tgz", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.5.0.tgz",
"integrity": "sha512-g0FlPvvCXSIO1JDF6S232P5jPYqBkRL9qly81ZgAOSU7rwI0stphCgd2kLiCrU9DjQCrJMWEqcNSjQL02s6d8A==", "integrity": "sha512-6kEJKwVxAJ35W4akuiysfKwKmjkbYxwQMTBaAxo9KKAx/Yd26mPUyhGz3ji+EsJoAgrLqVsYHNuuYwQe22lbtw==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@cspotcode/source-map-support": "0.7.0", "@cspotcode/source-map-support": "0.7.0",
@@ -1704,6 +1705,7 @@
"create-require": "^1.1.0", "create-require": "^1.1.0",
"diff": "^4.0.1", "diff": "^4.0.1",
"make-error": "^1.1.1", "make-error": "^1.1.1",
"v8-compile-cache-lib": "^3.0.0",
"yn": "3.1.1" "yn": "3.1.1"
}, },
"bin": { "bin": {
@@ -1846,6 +1848,12 @@
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=",
"dev": true "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": { "node_modules/webidl-conversions": {
"version": "3.0.1", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
@@ -1908,9 +1916,9 @@
} }
}, },
"node_modules/ws": { "node_modules/ws": {
"version": "8.4.2", "version": "8.5.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.4.2.tgz", "resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz",
"integrity": "sha512-Kbk4Nxyq7/ZWqr/tarI9yIt/+iNNFOjBXEWgTb4ydaNHBNGgvf2QHbS9fdfsndfjFlFwEd4Al+mw83YkaD10ZA==", "integrity": "sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==",
"engines": { "engines": {
"node": ">=10.0.0" "node": ">=10.0.0"
}, },
@@ -2056,9 +2064,9 @@
"dev": true "dev": true
}, },
"@types/node": { "@types/node": {
"version": "17.0.13", "version": "17.0.17",
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.13.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.17.tgz",
"integrity": "sha512-Y86MAxASe25hNzlDbsviXl8jQHb0RDvKt4c40ZJQ1Don0AAL0STLZSs4N+6gLEO55pedy7r2cLwS+ZDxPm/2Bw==" "integrity": "sha512-e8PUNQy1HgJGV3iU/Bp2+D/DXh3PYeyli8LgIwsQcs1Ar1LoaWHSIT6Rw+H2rNJmiq6SNWiDytfx8+gYj7wDHw=="
}, },
"@types/node-fetch": { "@types/node-fetch": {
"version": "2.5.12", "version": "2.5.12",
@@ -2852,9 +2860,9 @@
"dev": true "dev": true
}, },
"minimatch": { "minimatch": {
"version": "3.0.4", "version": "3.1.1",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.1.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "integrity": "sha512-reLxBcKUPNBnc/sVtAbxgRVFSegoGeLaSjmphNhcwcolhYLRgtJscn5mRl6YRZNQv40Y7P6JM2YhSIsbL9OB5A==",
"dev": true, "dev": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
@@ -3119,9 +3127,9 @@
} }
}, },
"signal-exit": { "signal-exit": {
"version": "3.0.6", "version": "3.0.7",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.6.tgz", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
"integrity": "sha512-sDl4qMFpijcGw22U5w63KmD3cZJfBuFlVNbVMKje2keoKML7X2UzWbc4XrmEbDwg0NXJc3yv4/ox7b+JWb57kQ==", "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==",
"dev": true "dev": true
}, },
"string_decoder": { "string_decoder": {
@@ -3212,9 +3220,9 @@
"integrity": "sha512-nXIb1fvdY5CBSrDIblLn73NW0qRDk5yJ0Sk1qPBF560OdJfQp9jhl+0tzcY09OZ9U+6GpeoI9RjwoIKFIoB9MQ==" "integrity": "sha512-nXIb1fvdY5CBSrDIblLn73NW0qRDk5yJ0Sk1qPBF560OdJfQp9jhl+0tzcY09OZ9U+6GpeoI9RjwoIKFIoB9MQ=="
}, },
"ts-node": { "ts-node": {
"version": "10.4.0", "version": "10.5.0",
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.4.0.tgz", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.5.0.tgz",
"integrity": "sha512-g0FlPvvCXSIO1JDF6S232P5jPYqBkRL9qly81ZgAOSU7rwI0stphCgd2kLiCrU9DjQCrJMWEqcNSjQL02s6d8A==", "integrity": "sha512-6kEJKwVxAJ35W4akuiysfKwKmjkbYxwQMTBaAxo9KKAx/Yd26mPUyhGz3ji+EsJoAgrLqVsYHNuuYwQe22lbtw==",
"dev": true, "dev": true,
"requires": { "requires": {
"@cspotcode/source-map-support": "0.7.0", "@cspotcode/source-map-support": "0.7.0",
@@ -3228,6 +3236,7 @@
"create-require": "^1.1.0", "create-require": "^1.1.0",
"diff": "^4.0.1", "diff": "^4.0.1",
"make-error": "^1.1.1", "make-error": "^1.1.1",
"v8-compile-cache-lib": "^3.0.0",
"yn": "3.1.1" "yn": "3.1.1"
} }
}, },
@@ -3320,6 +3329,12 @@
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=",
"dev": true "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": { "webidl-conversions": {
"version": "3.0.1", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
@@ -3373,9 +3388,9 @@
} }
}, },
"ws": { "ws": {
"version": "8.4.2", "version": "8.5.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.4.2.tgz", "resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz",
"integrity": "sha512-Kbk4Nxyq7/ZWqr/tarI9yIt/+iNNFOjBXEWgTb4ydaNHBNGgvf2QHbS9fdfsndfjFlFwEd4Al+mw83YkaD10ZA==", "integrity": "sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==",
"requires": {} "requires": {}
}, },
"xdg-basedir": { "xdg-basedir": {

View File

@@ -31,9 +31,9 @@
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/node": "^17.0.13", "@types/node": "^17.0.13",
"discord-api-types": "^0.26.1",
"npm-watch": "^0.11.0", "npm-watch": "^0.11.0",
"ts-node": "^10.4.0", "ts-node": "^10.4.0",
"discord-api-types": "^0.26.1",
"typescript": "^4.5.5" "typescript": "^4.5.5"
}, },
"dependencies": { "dependencies": {

66
src/lang.ts Normal file
View 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;
}
}

View File

@@ -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 { Client, CommandInteraction, GuildMember, MessageEmbed, TextChannel } from "discord.js";
import * as fs from 'fs'; import * as fs from 'fs';
import { emsg, getChannel, getMember, memberIsModThrow, queueInfo, queueInfoBase } from "./util"; import { emsg, getChannel, getMember, memberIsModThrow, queueInfo, queueInfoBase } from "./util";
import { Lang } from './lang';
//load queues from file //load queues from file
if (!fs.existsSync('./queues.json')) 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()); let team = info.players.splice(0, info.teamsize).map(m => m.toString());
//TODO add embeds to lang.ts
let embed = new MessageEmbed() let embed = new MessageEmbed()
.setTitle('Team') .setTitle('Team')
.setDescription(team.join('\n')); .setDescription(team.join('\n'));
@@ -102,12 +104,15 @@ export async function discordInit(client: Client) {
} }
if (!channel || !(channel instanceof TextChannel)) { 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); Queue.remove(channelId);
continue; 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); let info = QUEUE.get(interaction.channelId);
if (!info) 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; return info;
} }
@@ -169,11 +174,15 @@ export namespace QueueCommands {
teamsize = interaction.options.getInteger('teamsize', true); teamsize = interaction.options.getInteger('teamsize', true);
if (QUEUE.has(channelId)) 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); 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); 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') .setTitle('Active Queue')
.addField('Team Size', info.teamsize.toString(), true) .addField('Team Size', info.teamsize.toString(), true)
.addField('Players Joined', info.players.length.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}); await interaction.reply({embeds: [embed], ephemeral: true});
@@ -231,13 +240,13 @@ export namespace QueueCommands {
let {member, info, channel} = getAll(interaction); let {member, info, channel} = getAll(interaction);
if (queueContains(interaction)) if (queueContains(interaction))
throw emsg('You are already in the queue'); throw emsg(Lang.get('discord.error.inQueue'));
info.players.push(member); info.players.push(member);
QUEUE.set(interaction.channelId, info); QUEUE.set(interaction.channelId, info);
await interaction.reply('Joined the queue'); await interaction.reply(Lang.get('discord.join'));
checkQueue(channel); checkQueue(channel);
@@ -253,13 +262,13 @@ export namespace QueueCommands {
let {member, info} = getAll(interaction); let {member, info} = getAll(interaction);
if (!queueContains(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); info.players.splice(info.players.indexOf(member), 1);
QUEUE.set(interaction.channelId, info); QUEUE.set(interaction.channelId, info);
await interaction.reply('Left the queue'); await interaction.reply(Lang.get('discord.leave'));
} }