From 343ed640ae1c7b156a4fa0a19988b23707a4da04 Mon Sep 17 00:00:00 2001 From: ashley zomo Date: Sun, 13 Feb 2022 19:35:16 -0600 Subject: [PATCH] updated lang strings --- dist/api.js | 2 +- dist/discord.js | 1 - dist/index.js | 11 +++++++++-- dist/lang.js | 9 +++++++++ dist/queue.js | 7 ++++--- src/api.ts | 2 +- src/discord.ts | 1 - src/index.ts | 7 +++++-- src/lang.ts | 11 ++++++++++- src/queue.ts | 7 ++++--- 10 files changed, 43 insertions(+), 15 deletions(-) diff --git a/dist/api.js b/dist/api.js index 98f16eb..fec131a 100644 --- a/dist/api.js +++ b/dist/api.js @@ -204,7 +204,7 @@ async function getPlayerInteraction(interaction) { await interaction.deferReply(); let data = await getPlayer(username); if (data === null) - throw (0, util_1.emsg)('Unable to find user'); + throw (0, util_1.emsg)('api.noUser'); else sendPlayerEmbed(interaction, data); } diff --git a/dist/discord.js b/dist/discord.js index b953c3e..1480287 100644 --- a/dist/discord.js +++ b/dist/discord.js @@ -60,7 +60,6 @@ async function registerCommands(token, clientId, guildIds) { for (let i = 0; i < guildIds.length; i++) { try { await rest.put(v9_1.Routes.applicationGuildCommands(clientId, guildIds[i]), { body: commands }); - console.log(`[${guildIds[i]}] registered command`); } catch (error) { console.error(error); diff --git a/dist/index.js b/dist/index.js index c23ab25..ac6f00e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -23,6 +23,7 @@ const discord_js_1 = require("discord.js"); const fs = __importStar(require("fs")); const api_1 = require("./api"); const discord_1 = require("./discord"); +const lang_1 = require("./lang"); const queue_1 = require("./queue"); const util_1 = require("./util"); const CLIENT = new discord_js_1.Client({ intents: [discord_js_1.Intents.FLAGS.GUILDS] }); @@ -31,16 +32,22 @@ console.log(new Date().toISOString() + '\n\n'); //get token if (!fs.existsSync('./token.txt')) { fs.writeFileSync('./token.txt', ''); - console.error('Missing Discord Token, please enter the bot token into the token file'); + console.error(lang_1.Lang.get('error.main.missingToken')); process.exit(1); } const TOKEN = fs.readFileSync('./token.txt').toString(); //discord connections CLIENT.on('ready', client => { - console.log(`Logged in as ${client.user.tag}`); + console.log(lang_1.Lang.get('main.login', { + user: client.user.tag + })); client.guilds.fetch().then(guilds => (0, discord_1.registerCommands)(TOKEN, client.user.id, guilds.map(g => g.id))); (0, queue_1.discordInit)(client); }); +CLIENT.on('guildCreate', guild => { + if (guild.client.user) + (0, discord_1.registerCommands)(TOKEN, guild.client.user.id, guild.id); +}); CLIENT.on('interactionCreate', async (interaction) => { if (!interaction.isCommand()) return; diff --git a/dist/lang.js b/dist/lang.js index 201a6b9..ed531a8 100644 --- a/dist/lang.js +++ b/dist/lang.js @@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.Lang = void 0; 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', @@ -11,6 +14,9 @@ const LANG = { leave: 'Left the queue' }, 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}', @@ -22,6 +28,9 @@ const LANG = { 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' } } } diff --git a/dist/queue.js b/dist/queue.js index 697574b..7e482e8 100644 --- a/dist/queue.js +++ b/dist/queue.js @@ -154,13 +154,14 @@ var QueueCommands; function queueCreate(interaction) { (0, util_1.memberIsModThrow)(interaction); let { channelId } = interaction, teamsize = interaction.options.getInteger('teamsize', true); - if (QUEUE.has(channelId)) + let existing = QUEUE.get(channelId); + if (existing) throw (0, util_1.emsg)(lang_1.Lang.get('error.discord.noCreate', { - teamsize: QUEUE.get(channelId)?.teamsize + teamsize: existing.teamsize.toString() })); Queue.create(channelId, teamsize); interaction.reply(lang_1.Lang.get('discord.create', { - teamsize + teamsize: teamsize.toString() })); } QueueCommands.queueCreate = queueCreate; diff --git a/src/api.ts b/src/api.ts index ae7cc96..8ad0e77 100644 --- a/src/api.ts +++ b/src/api.ts @@ -245,7 +245,7 @@ export async function getPlayerInteraction(interaction: CommandInteraction) { let data = await getPlayer(username); if (data === null) - throw emsg('Unable to find user'); + throw emsg('api.noUser'); else sendPlayerEmbed(interaction, data); } diff --git a/src/discord.ts b/src/discord.ts index ad5102d..696af3f 100644 --- a/src/discord.ts +++ b/src/discord.ts @@ -67,7 +67,6 @@ export async function registerCommands(token: string, clientId: string, guildIds Routes.applicationGuildCommands(clientId, guildIds[i]), { body: commands }, ); - console.log(`[${guildIds[i]}] registered command`); } catch (error) { console.error(error); } diff --git a/src/index.ts b/src/index.ts index 48805a9..a76c30c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,7 @@ import { Client, Intents } from 'discord.js'; import * as fs from 'fs'; import { getPlayerInteraction } from './api'; import { registerCommands } from './discord'; +import { Lang } from './lang'; import { discordInit, QueueCommands } from './queue'; import { errorMessage } from './util'; const CLIENT = new Client({ intents: [Intents.FLAGS.GUILDS] }); @@ -13,14 +14,16 @@ console.log(new Date().toISOString()+'\n\n'); //get token if (!fs.existsSync('./token.txt')) { fs.writeFileSync('./token.txt', ''); - console.error('Missing Discord Token, please enter the bot token into the token file'); + console.error(Lang.get('error.main.missingToken')); process.exit(1); } const TOKEN = fs.readFileSync('./token.txt').toString(); //discord connections CLIENT.on('ready', client => { - console.log(`Logged in as ${client.user.tag}`); + console.log(Lang.get('main.login', { + user: client.user.tag + })); client.guilds.fetch().then(guilds => registerCommands(TOKEN, client.user.id, guilds.map(g => g.id))); discordInit(client); diff --git a/src/lang.ts b/src/lang.ts index 438d43b..c7a5282 100644 --- a/src/lang.ts +++ b/src/lang.ts @@ -3,6 +3,9 @@ type LangObjWhold = { [langid:string]: LangObj } const LANG: LangObjWhold = { 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', @@ -11,6 +14,9 @@ const LANG: LangObjWhold = { leave: 'Left the queue' }, 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}', @@ -22,6 +28,9 @@ const LANG: LangObjWhold = { 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' } } } @@ -45,7 +54,7 @@ export namespace Lang { * @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 + export function get(id: string, args: {[keys: string]: string} = {}): 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 e0ea0bd..773e988 100644 --- a/src/queue.ts +++ b/src/queue.ts @@ -173,15 +173,16 @@ export namespace QueueCommands { let {channelId} = interaction, teamsize = interaction.options.getInteger('teamsize', true); - if (QUEUE.has(channelId)) + let existing = QUEUE.get(channelId) + if (existing) throw emsg(Lang.get('error.discord.noCreate', { - teamsize: QUEUE.get(channelId)?.teamsize + teamsize: existing.teamsize.toString() })); Queue.create(channelId, teamsize); interaction.reply(Lang.get('discord.create', { - teamsize + teamsize: teamsize.toString() })) }