From 3bf374f5ca52c7cdbda14987bbdf71373e7c800a Mon Sep 17 00:00:00 2001 From: Duel <74829708+TheUltimateDuel@users.noreply.github.com> Date: Mon, 1 Aug 2022 16:02:07 -0400 Subject: [PATCH] Added suppor for other languages (#34) * Language Added * changed language to be set before shutdown Closes https://github.com/builder-247/node-autotip/issues/22 Co-authored-by: builder_247 <14019974+builder-247@users.noreply.github.com> --- config.js | 1 + index.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) mode change 100755 => 100644 index.js diff --git a/config.js b/config.js index 7e668f1..bcfcf3e 100644 --- a/config.js +++ b/config.js @@ -12,6 +12,7 @@ const defaults = { HIDE_TIP_MESSAGES: true, // Hide chat spam from tipping HIDE_JOIN_MESSAGES: true, // Hide player join messages HIDE_WATCHDOG_MESSAGES: true, // Hide [WATCHDOG CHEAT DETECTION] messages + CHANGE_LANGUAGE: 'english', // Changes the Language to your preferred language }; // ensure that process.env has all values in defaults, but prefer the process.env value diff --git a/index.js b/index.js old mode 100755 new mode 100644 index ef657fc..d72e0b4 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ /* eslint-disable no-underscore-dangle, no-return-assign */ const mineflayer = require('mineflayer'); +const wait = require('util').promisify(setTimeout); const config = require('./config'); const login = require('./lib/login'); const logger = require('./lib/logger'); @@ -25,6 +26,11 @@ function getUUID() { return bot._client.session.selectedProfile.id; } +function setLang(language = 'english') { + logger.info(`Changing language to ${language}`); + bot.chat(`/lang ${language}`); +} + function sendToLimbo() { logger.info('Sending player to limbo...'); bot._client.write('chat', { message: 'ยง' }); @@ -82,6 +88,7 @@ function chatLogger(message) { function onLogin() { uuid = getUUID(bot); + setLang(); logger.debug(`Logged on ${options.host}:${options.port}`); getLifetimeStats(uuid, (stats) => { logger.info(util.toANSI(stats)); @@ -141,8 +148,14 @@ function onMessage(message) { bot.once('end', () => setTimeout(init, 10000)); }()); -function gracefulShutdown() { +async function gracefulShutdown() { logger.info('Received kill signal, shutting down gracefully.'); + // Change language to a preferred one. Need to leave limbo first to run the command. + bot.chat('/hub'); + await wait(1000); + setLang(config.CHANGE_LANGUAGE); + await wait(1000); + try { autotipSession.logOut(() => { logger.info('Closed out remaining connections.');