diff options
Diffstat (limited to '')
-rw-r--r-- | src/MinecraftHandler.ts | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/MinecraftHandler.ts b/src/MinecraftHandler.ts index faf1828..48c30b4 100644 --- a/src/MinecraftHandler.ts +++ b/src/MinecraftHandler.ts @@ -3,7 +3,9 @@ import path from 'path' import { Tail } from 'tail' import express from 'express' -import { Config } from './Config' +import type { Config } from './Config' + +import { fixMinecraftUsername } from './lib/util' export type LogLine = { username: string @@ -22,10 +24,6 @@ class MinecraftHandler { this.config = config } - private static fixMinecraftUsername (username: string) { - return username.replace(/(ยง[A-Z-a-z0-9])/g, '') - } - private parseLogLine (data: string): LogLine { const ignored = new RegExp(this.config.REGEX_IGNORED_CHAT) @@ -58,7 +56,7 @@ class MinecraftHandler { if (logLine.startsWith('<')) { if (this.config.DEBUG){ - console.log('[DEBUG]: A player sent a chat message') + console.log('[DEBUG] A player sent a chat message') } const re = new RegExp(this.config.REGEX_MATCH_CHAT_MC) @@ -69,7 +67,7 @@ class MinecraftHandler { return null } - const username = MinecraftHandler.fixMinecraftUsername(matches[1]) + const username = fixMinecraftUsername(matches[1]) const message = matches[2] if (this.config.DEBUG) { console.log('[DEBUG] Username: ' + matches[1]) @@ -84,18 +82,18 @@ class MinecraftHandler { ) { // handle disconnection etc. if (this.config.DEBUG){ - console.log(`[DEBUG]: A player's connection status changed`) + console.log(`[DEBUG] A player's connection status changed`) } return { username: serverUsername, message: logLine } } else if (this.config.SHOW_SERVER_STATUS && (logLine.includes('Starting minecraft server'))) { if (this.config.DEBUG) { - console.log('[DEBUG]: Server has started') + console.log('[DEBUG] Server has started') } return { username: serverUsername, message: 'Server is online' } } else if (this.config.SHOW_SERVER_STATUS && (logLine.includes('Stopping the server'))) { if (this.config.DEBUG) { - console.log('[DEBUG]: Server has stopped') + console.log('[DEBUG] Server has stopped') } return { username: serverUsername, message: 'Server is offline' } } else if (this.config.SHOW_PLAYER_ADVANCEMENT && logLine.includes('made the advancement')) { @@ -189,7 +187,7 @@ class MinecraftHandler { private initTail (callback: Callback) { if (fs.existsSync(this.config.LOCAL_FILE_PATH)) { console.log(`[INFO] Using configuration for local log file at "${this.config.LOCAL_FILE_PATH}"`) - this.tail = new Tail(this.config.LOCAL_FILE_PATH, {useWatchFile: true}) + this.tail = new Tail(this.config.LOCAL_FILE_PATH, {useWatchFile: this.config.FS_WATCH_FILE ?? true}) } else { throw new Error(`[ERROR] Local log file not found at "${this.config.LOCAL_FILE_PATH}"`) } |