From ff4a9fa8b148da00bff9dd7cb447e9d5321ef84e Mon Sep 17 00:00:00 2001 From: destruc7i0n Date: Wed, 5 Feb 2020 19:32:35 -0500 Subject: More config handling --- src/MinecraftHandler.ts | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src/MinecraftHandler.ts') diff --git a/src/MinecraftHandler.ts b/src/MinecraftHandler.ts index 7ed9d86..20bccf5 100644 --- a/src/MinecraftHandler.ts +++ b/src/MinecraftHandler.ts @@ -1,4 +1,5 @@ import fs from 'fs' +import path from 'path' import { Tail } from 'tail' import express from 'express' @@ -21,7 +22,7 @@ class MinecraftHandler { this.config = config } - private fixMinecraftUsername (username: string) { + private static fixMinecraftUsername (username: string) { return username.replace(/(ยง[A-Z-a-z0-9])/g, '') } @@ -66,7 +67,7 @@ class MinecraftHandler { return null } - const username = this.fixMinecraftUsername(matches[1]) + const username = MinecraftHandler.fixMinecraftUsername(matches[1]) const message = matches[2] if (this.config.DEBUG) { console.log('[DEBUG] Username: ' + matches[1]) @@ -146,10 +147,24 @@ class MinecraftHandler { console.log('[INFO] Bot listening on *:' + port) if (!this.config.IS_LOCAL_FILE && this.config.SHOW_INIT_MESSAGE) { - console.log('[INFO] Please enter the following command on your server running the Minecraft server.') - console.log(' Replace "PATH_TO_MINECRAFT_SERVER_INSTALL" with the path to your Minecraft server install') - console.log(' and "YOUR_URL" with the URL/IP of the server running Shulker!') - console.log(` \`tail -F /PATH_TO_MINECRAFT_SERVER_INSTALL/logs/latest.log | grep --line-buffered ": <" | while read x ; do echo -ne $x | curl -X POST -d @- http://YOUR_URL:${port}${this.config.WEBHOOK} ; done\``) + // in case someone inputs the actual path and url in the config here... + let mcPath: string = this.config.PATH_TO_MINECRAFT_SERVER_INSTALL || 'PATH_TO_MINECRAFT_SERVER_INSTALL' + const url: string = this.config.YOUR_URL || 'YOUR_URL' + + const defaultPath = mcPath === 'PATH_TO_MINECRAFT_SERVER_INSTALL' + const defaultUrl = url === 'YOUR_URL' + + console.log('[INFO] Please enter the following command on your server running the Minecraft server:') + if (defaultPath) { + console.log(' Replace "PATH_TO_MINECRAFT_SERVER_INSTALL" with the path to your Minecraft server install') + if (defaultUrl) console.log(' and "YOUR_URL" with the URL/IP of the server running Shulker!') + } else { + if (defaultUrl) console.log(' Replace "YOUR_URL" with the URL/IP of the server running Shulker') + } + + mcPath = (defaultPath ? '/' : '') + path.join(mcPath, '/logs/latest.log') + + console.log(` \`tail -F ${mcPath} | grep --line-buffered ": <" | while read x ; do echo -ne $x | curl -X POST -d @- http://${url}:${port}${this.config.WEBHOOK} ; done\``) } }) } -- cgit 1.4.1