added more strings

This commit is contained in:
2022-02-14 14:56:47 -06:00
parent 458d3f3d76
commit 513a9d1582
4 changed files with 84 additions and 41 deletions

34
dist/lang.js vendored
View File

@@ -105,7 +105,27 @@ const LANG = {
create: 'A queue for teams of {teamsize} has been created', create: 'A queue for teams of {teamsize} has been created',
close: 'Queue has been closed', close: 'Queue has been closed',
join: 'Joined the queue', join: 'Joined the queue',
leave: 'Left 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: { api: {
player: { player: {
@@ -160,6 +180,7 @@ exports.setLang = setLang;
/** /**
* reads language json (just strings) * reads language json (just strings)
* @param id ex: discord.error.noActiveQueue * @param id ex: discord.error.noActiveQueue
* @param args list of key/value pairs to represent template values
* @returns language value, defaults to `id` parameter * @returns language value, defaults to `id` parameter
*/ */
function get(id, args = {}) { function get(id, args = {}) {
@@ -183,10 +204,13 @@ exports.get = get;
/** /**
* reads language json as an object (could be embed or just string) * reads language json as an object (could be embed or just string)
* @param id ex: discord.error.noActiveQueue * @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 * @returns language value, defaults to `id` parameter
*/ */
function getEmbed(id, args = {}) { function getEmbed(id, args = {}, otherOptions = {}) {
const embedData = { const embedData = {
...otherOptions,
embeds: [] embeds: []
}; };
const keySpl = id.split('.').map(k => k.trim()).filter(k => k); const keySpl = id.split('.').map(k => k.trim()).filter(k => k);
@@ -199,9 +223,8 @@ function getEmbed(id, args = {}) {
break; break;
} }
if (found.embed === true) { if (found.embed === true) {
const embedObj = found, { content } = embedObj, embed = embedObjEmbed(embedObj, args), embedData = { const embedObj = found, { content } = embedObj, embed = embedObjEmbed(embedObj, args);
embeds: [embed] embedData.embeds.push(embed);
};
if (content !== undefined) if (content !== undefined)
embedData.content = content; embedData.content = content;
return embedData; return embedData;
@@ -214,3 +237,4 @@ function getEmbed(id, args = {}) {
return embedData; return embedData;
} }
exports.getEmbed = getEmbed; exports.getEmbed = getEmbed;
debugger;

20
dist/queue.js vendored
View File

@@ -55,11 +55,7 @@ async function checkQueue(channel) {
return; return;
if (info.players.length >= info.teamsize) { if (info.players.length >= info.teamsize) {
const team = info.players.splice(0, info.teamsize).map(m => m.toString()); const team = info.players.splice(0, info.teamsize).map(m => m.toString());
//TODO add embeds to lang.ts await channel.send(Lang.getEmbed('discord.team', { team: team.join('\n') }));
const embed = new discord_js_1.MessageEmbed()
.setTitle('Team')
.setDescription(team.join('\n'));
await channel.send({ embeds: [embed] });
} }
} }
function queueCreate(channelId, teamsize) { function queueCreate(channelId, teamsize) {
@@ -80,7 +76,7 @@ SaveQueue();
async function discordInit(client) { async function discordInit(client) {
for (const channelId of QUEUE.keys()) { for (const channelId of QUEUE.keys()) {
const info = QUEUE.get(channelId), channel = await client.channels.fetch(channelId); const info = QUEUE.get(channelId), channel = await client.channels.fetch(channelId);
if (!info) { //no idea what could cause this but TS complains if (!info) {
queueRemove(channelId); queueRemove(channelId);
continue; continue;
} }
@@ -166,12 +162,12 @@ async function close(interaction) {
*/ */
async function queue(interaction) { async function queue(interaction) {
const info = getInfo(interaction); const info = getInfo(interaction);
const embed = new discord_js_1.MessageEmbed() await interaction.reply(Lang.getEmbed('discord.queue', {
.setTitle('Active Queue') teamsize: info.teamsize.toString(),
.addField('Team Size', info.teamsize.toString(), true) playercount: info.players.length.toString(),
.addField('Players Joined', info.players.length.toString(), true) }, {
.setFooter({ text: 'type /join' }); //TODO ephemeral: true
await interaction.reply({ embeds: [embed], ephemeral: true }); }));
} }
/** /**
* joins a queue * joins a queue

View File

@@ -2,7 +2,10 @@ import { MessageEmbed } from 'discord.js';
/* TYPES */ /* TYPES */
type basicObject = {[keys: string]: string}; //this is a generic type, and needs 'any'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type basicObject = {[keys: string]: any};
type basicObjectStr = {[keys: string]: string};
type URL = string; type URL = string;
@@ -99,7 +102,7 @@ function embedObjStr(embedData: embedObj, fallback = ''): string {
return fallback; return fallback;
} }
function embedObjEmbed(embedObj: embedObj, args: basicObject = {}): MessageEmbed { function embedObjEmbed(embedObj: embedObj, args: basicObjectStr = {}): MessageEmbed {
const embed = new MessageEmbed(), const embed = new MessageEmbed(),
{ author, color, description, fields, footer, image, thumbnail, timestamp, title, url } = embedObj; { author, color, description, fields, footer, image, thumbnail, timestamp, title, url } = embedObj;
@@ -205,7 +208,28 @@ const LANG: LangObjWhole = {
create: 'A queue for teams of {teamsize} has been created', create: 'A queue for teams of {teamsize} has been created',
close: 'Queue has been closed', close: 'Queue has been closed',
join: 'Joined the queue', join: 'Joined the queue',
leave: 'Left 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: { api: {
@@ -272,9 +296,10 @@ export function setLang(langid: string) {
/** /**
* reads language json (just strings) * reads language json (just strings)
* @param id ex: discord.error.noActiveQueue * @param id ex: discord.error.noActiveQueue
* @param args list of key/value pairs to represent template values
* @returns language value, defaults to `id` parameter * @returns language value, defaults to `id` parameter
*/ */
export function get(id: string, args: basicObject = {}): string { export function get(id: string, args: basicObjectStr = {}): string {
const keySpl = id.split('.').map(k => k.trim()).filter(k => k); const keySpl = id.split('.').map(k => k.trim()).filter(k => k);
@@ -305,11 +330,14 @@ export function get(id: string, args: basicObject = {}): string {
/** /**
* reads language json as an object (could be embed or just string) * reads language json as an object (could be embed or just string)
* @param id ex: discord.error.noActiveQueue * @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 * @returns language value, defaults to `id` parameter
*/ */
export function getEmbed(id: string, args: basicObject = {}): embedData { export function getEmbed(id: string, args: basicObjectStr = {}, otherOptions: basicObject = {}): embedData {
const embedData: embedData = { const embedData: embedData = {
...otherOptions,
embeds: [] embeds: []
}; };
@@ -331,10 +359,9 @@ export function getEmbed(id: string, args: basicObject = {}): embedData {
if (found.embed === true) { if (found.embed === true) {
const embedObj = found as embedObj, const embedObj = found as embedObj,
{content} = embedObj, {content} = embedObj,
embed = embedObjEmbed(embedObj, args), embed = embedObjEmbed(embedObj, args);
embedData: embedData = {
embeds: [embed] embedData.embeds.push(embed);
};
if (content !== undefined) if (content !== undefined)
embedData.content = content; embedData.content = content;
@@ -351,3 +378,5 @@ export function getEmbed(id: string, args: basicObject = {}): embedData {
return embedData; return embedData;
} }
debugger;

View File

@@ -3,7 +3,7 @@
join message should contain your current position in the queue, editing it to keep it current join message should contain your current position in the queue, editing it to keep it current
*/ */
import { Client, CommandInteraction, MessageEmbed, TextChannel } from 'discord.js'; import { Client, CommandInteraction, 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 * as Lang from './lang'; import * as Lang from './lang';
@@ -51,12 +51,7 @@ async function checkQueue(channel: TextChannel) {
const team = info.players.splice(0, info.teamsize).map(m => m.toString()); const team = info.players.splice(0, info.teamsize).map(m => m.toString());
//TODO add embeds to lang.ts await channel.send(Lang.getEmbed('discord.team', { team: team.join('\n') }));
const embed = new MessageEmbed()
.setTitle('Team')
.setDescription(team.join('\n'));
await channel.send({embeds: [embed]});
} }
@@ -86,7 +81,7 @@ export async function discordInit(client: Client) {
const info = QUEUE.get(channelId), const info = QUEUE.get(channelId),
channel = await client.channels.fetch(channelId); channel = await client.channels.fetch(channelId);
if (!info) { //no idea what could cause this but TS complains if (!info) {
queueRemove(channelId); queueRemove(channelId);
continue; continue;
} }
@@ -198,13 +193,12 @@ async function queue(interaction: CommandInteraction) {
const info = getInfo(interaction); const info = getInfo(interaction);
const embed = new MessageEmbed() await interaction.reply(Lang.getEmbed('discord.queue', {
.setTitle('Active Queue') teamsize: info.teamsize.toString(),
.addField('Team Size', info.teamsize.toString(), true) playercount: info.players.length.toString(),
.addField('Players Joined', info.players.length.toString(), true) }, {
.setFooter({text: 'type /join'}); //TODO ephemeral: true
}));
await interaction.reply({embeds: [embed], ephemeral: true});
} }