diff --git a/dist/lang.js b/dist/lang.js index 5f378de..b908234 100644 --- a/dist/lang.js +++ b/dist/lang.js @@ -4,8 +4,17 @@ 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: { - noActiveQueue: 'There is not an active queue in this channel, type `/open` to create one' + 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' } } } @@ -27,7 +36,7 @@ var Lang; * @param id ex: discord.error.noActiveQueue * @returns language value, defaults to `id` parameter */ - function get(id) { + function get(id, args = {}) { let keySpl = id.split('.').map(k => k.trim()).filter(k => k); let finding = LANG[LANGID]; for (let key of keySpl) { @@ -44,4 +53,3 @@ var Lang; } Lang.get = get; })(Lang = exports.Lang || (exports.Lang = {})); -debugger; diff --git a/dist/queue.js b/dist/queue.js index b7d5190..af574d1 100644 --- a/dist/queue.js +++ b/dist/queue.js @@ -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 = {})); diff --git a/src/lang.ts b/src/lang.ts index a0edb15..a42585e 100644 --- a/src/lang.ts +++ b/src/lang.ts @@ -4,8 +4,17 @@ 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: { - noActiveQueue: 'There is not an active queue in this channel, type `/open` to create one' + 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' } } } @@ -29,7 +38,7 @@ export namespace Lang { * @param id ex: discord.error.noActiveQueue * @returns language value, defaults to `id` parameter */ - export function get(id: string): string {//discord.error.noActiveQueue + export function get(id: string, args: {[keys: string]: any} = {}): string {//discord.error.noActiveQueue let keySpl = id.split('.').map(k => k.trim()).filter(k => k); diff --git a/src/queue.ts b/src/queue.ts index fa2af61..4ad4e6f 100644 --- a/src/queue.ts +++ b/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')); }