updated lang strings

This commit is contained in:
2022-02-13 19:15:55 -06:00
parent 9da9650f92
commit f225bf924a
4 changed files with 62 additions and 27 deletions

14
dist/lang.js vendored
View File

@@ -4,8 +4,17 @@ exports.Lang = void 0;
const LANG = { const LANG = {
en: { en: {
discord: { 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: { 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 * @param id ex: discord.error.noActiveQueue
* @returns language value, defaults to `id` parameter * @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 keySpl = id.split('.').map(k => k.trim()).filter(k => k);
let finding = LANG[LANGID]; let finding = LANG[LANGID];
for (let key of keySpl) { for (let key of keySpl) {
@@ -44,4 +53,3 @@ var Lang;
} }
Lang.get = get; Lang.get = get;
})(Lang = exports.Lang || (exports.Lang = {})); })(Lang = exports.Lang || (exports.Lang = {}));
debugger;

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 = {}));

View File

@@ -4,8 +4,17 @@ type LangObjWhold = { [langid:string]: LangObj }
const LANG: LangObjWhold = { const LANG: LangObjWhold = {
en: { en: {
discord: { 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: { 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 * @param id ex: discord.error.noActiveQueue
* @returns language value, defaults to `id` parameter * @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); let keySpl = id.split('.').map(k => k.trim()).filter(k => k);

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'));
} }