Skip to content

Commit

Permalink
Added suppor for other languages (#34)
Browse files Browse the repository at this point in the history
* Language Added

* changed language to be set before shutdown

Closes #22

Co-authored-by: builder_247 <[email protected]>
  • Loading branch information
Dueel-Dev and builder-247 authored Aug 1, 2022
1 parent 862f8f4 commit 3bf374f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion index.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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: '§' });
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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.');
Expand Down

0 comments on commit 3bf374f

Please sign in to comment.