"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getEmbed = exports.get = exports.setLang = void 0; const lang_1 = require("./util/lang"); const LANG = { en: { main: { login: 'Logged in as {user}' }, 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', team: { embed: true, title: 'Team', description: '{team}' }, queue: { embed: true, title: 'Active Queue', fields: [ { name: 'Team Size', value: '{teamsize}' }, { name: 'Players Joined', value: '{playercount}' } ], footer: 'type `/join`' } }, api: { player: { embed: true, title: '{name} ({id})', url: 'https://uniteapi.dev/p/{nameEncoded}', timestamp: true, thumbnail: '{avatar}', description: [ 'Level {level}', '{rank} {elo}', '', '**Battles** {battles}', '**Wins** {wins}', '**Win Rate** {winrate}' ] } }, error: { main: { missingToken: 'Missing Discord Token, please enter the bot token into the token file' }, discord: { 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', notMod: 'Member is not a moderator' }, general: { noMember: 'Unable to retrieve guild member information, please try again', noChannel: 'Unable to retrieve text channel information, please try again' }, api: { noUser: 'Unable to find user' } } } }; /* MAIN */ let 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'; } exports.setLang = setLang; /** * reads language json (just strings) * @param id ex: discord.error.noActiveQueue * @param args list of key/value pairs to represent template values * @returns language value, defaults to `id` parameter */ function get(id, args = {}) { const keySpl = id.split('.').map(k => k.trim()).filter(k => k); let finding = LANG[LANGID]; for (const key of keySpl) { if (key in finding) { const found = finding[key]; if (typeof found === 'string') return (0, lang_1.template)(found, args); if (found.embed === true) return (0, lang_1.embedObjStr)(found, id); finding = found; } else break; } return id; } exports.get = get; /** * reads language json as an object (could be embed or just string) * @param id ex: discord.error.noActiveQueue * @param args list of key/value pairs to represent template values * @param otherOptions values to be passed through to the return value * @returns language value, defaults to `id` parameter */ function getEmbed(id, args = {}, otherOptions = {}) { const embedData = { ...otherOptions, embeds: [] }; const keySpl = id.split('.').map(k => k.trim()).filter(k => k); let finding = LANG[LANGID]; for (const key of keySpl) { if (key in finding) { const found = finding[key]; if (typeof found === 'string') { embedData.content = (0, lang_1.template)(found, args); break; } if (found.embed === true) { const embedObj = found, { content } = embedObj, embed = (0, lang_1.embedObjEmbed)(embedObj, args); embedData.embeds.push(embed); if (content !== undefined) embedData.content = content; return embedData; } finding = found; } else break; } return embedData; } exports.getEmbed = getEmbed;