summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--src/Config.ts3
-rw-r--r--src/MinecraftHandler.ts27
2 files changed, 24 insertions, 6 deletions
diff --git a/src/Config.ts b/src/Config.ts
index 036e057..5688f2e 100644
--- a/src/Config.ts
+++ b/src/Config.ts
@@ -15,6 +15,9 @@ export interface Config {
   IS_LOCAL_FILE: boolean
   LOCAL_FILE_PATH: string
 
+  PATH_TO_MINECRAFT_SERVER_INSTALL?: string
+  YOUR_URL?: string
+
   SHOW_INIT_MESSAGE: boolean
 
   ALLOW_USER_MENTIONS: boolean
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\``)
       }
     })
   }