From 417dfa990f1b085251bee137a745b4752f3b5dab Mon Sep 17 00:00:00 2001 From: destruc7i0n Date: Wed, 29 Dec 2021 16:06:52 -0500 Subject: added config option for watchFile --- README.md | 11 ++++++++--- config.example.json | 5 +++-- src/Config.ts | 3 ++- src/MinecraftHandler.ts | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 46f7ad6..459acdd 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ tail -F /PATH_TO_MINECRAFT_SERVER_INSTALL/logs/latest.log | grep --line-buffered ```js { "PORT": 8000, /* Port you want to run the webserver for the hook on */ + "DEBUG": false, /* Dev debugging */ "USE_WEBHOOKS": true, /* If you want to use webhooks rather than the Discord bot sending the messages (recommended) */ "WEBHOOK_URL": "DISCORD_WEBHOOK_URL_HERE", /* Be sure to create a webhook in the channel settings and place it here! */ @@ -68,8 +69,9 @@ tail -F /PATH_TO_MINECRAFT_SERVER_INSTALL/logs/latest.log | grep --line-buffered "MINECRAFT_TELLRAW_DOESNT_EXIST": false, /* Minecraft doesn't have the tellraw command (<1.7.2), use say instead. !this may be dangerous! */ "MINECRAFT_TELLRAW_DOESNT_EXIST_SAY_TEMPLATE": "<%username%> %message%", /* used when MINECRAFT_TELLRAW_DOESNT_EXIST is set to true. say template to display on minecraft, same as MINECRAFT_TELLRAW_TEMPLATE. */ - "IS_LOCAL_FILE": false, /* tail the local file specified at `LOCAL_FILE_PATH` */ + "IS_LOCAL_FILE": true, /* tail the local file specified at `LOCAL_FILE_PATH` */ "LOCAL_FILE_PATH": "/usr/home/minecraft_server/logs/latest.log", /* the path to the local file if `IS_LOCAL_FILE` is set */ + "FS_WATCH_FILE": false, /* use node's watchFile rather than watch. see FAQ for more details */ "SHOW_INIT_MESSAGE": true, /* Sends the message on boot if not a local file of what command to run */ @@ -82,13 +84,12 @@ tail -F /PATH_TO_MINECRAFT_SERVER_INSTALL/logs/latest.log | grep --line-buffered "REGEX_SERVER_PREFIX": "\\[Server thread/INFO\\]:", /* What the lines of the log should start with */ "REGEX_MATCH_CHAT_MC": "^<([^>]*)> (.*)", /* What to match for chat (best to leave as default) */ "REGEX_IGNORED_CHAT": "packets too frequently", /* What to ignore, you can put any regex for swear words for example and it will be ignored */ - "DEBUG": false, /* Dev debugging */ "SERVER_NAME": "Shulker", /* The username used when displaying any server information in chat, e.g., Server - Shulker : Server message here*/ "SERVER_IMAGE": "", /* Image for the server when sending such messages (if enabled below). Only for WebHooks. */ "HEAD_IMAGE_URL": "https://mc-heads.net/avatar/%uuid%/256", /* Url to get the heads for the webhook, %uuid% is replaced with the uuid of the player */ "DEFAULT_PLAYER_HEAD": "c06f89064c8a49119c29ea1dbd1aab82", /* UUID of player with the default head to use (currently is MHF_Steve) */ - "SHOW_SERVER_STATUS: false, /* Shows when the server turns on and off e.g., Server - Shulker : Server is online */ + "SHOW_SERVER_STATUS": false, /* Shows when the server turns on and off e.g., Server - Shulker : Server is online */ "SHOW_PLAYER_CONN_STAT": false, /* Shows player connection status in chat, e.g., Server - Shulker : TheMachine joined the game */ "SHOW_PLAYER_ADVANCEMENT": false, /* Shows when players earn advancements in chat, e.g., Server - Shulker : TheMachine has made the advacement [MEME - Machine] */ "SHOW_PLAYER_DEATH": false, /* Shows when players die in chat, e.g., Server - Shulker : TheMachine was blown up by creeper */ @@ -105,6 +106,10 @@ tail -F /PATH_TO_MINECRAFT_SERVER_INSTALL/logs/latest.log | grep --line-buffered - Make sure that you have a role on the server which is put in the array `SLASH_COMMAND_ROLES` case-sensitive. - e.g. `"SLASH_COMMAND_ROLES": ["Admin"]` +* I am using a local file and no messages are being sent! + - Enable `DEBUG` in the config to check for any errors. + - If you are on Windows, try enabling `FS_WATCH_FILE`. + ## Upgrade Instructions From version 2 to version 3: - The main change is that you need to split your `REGEX_MATCH_CHAT_MC` to both `REGEX_MATCH_CHAT_MC` and `REGEX_SERVER_PREFIX`. diff --git a/config.example.json b/config.example.json index 33b0ff6..c7deb0d 100644 --- a/config.example.json +++ b/config.example.json @@ -1,5 +1,6 @@ { "PORT": 8000, + "DEBUG": false, "USE_WEBHOOKS": true, "WEBHOOK_URL": "DISCORD_WEBHOOK_URL_HERE", @@ -16,8 +17,9 @@ "MINECRAFT_TELLRAW_DOESNT_EXIST": false, "MINECRAFT_TELLRAW_DOESNT_EXIST_SAY_TEMPLATE": "<%username%> %message%", - "IS_LOCAL_FILE": false, + "IS_LOCAL_FILE": true, "LOCAL_FILE_PATH": "/usr/home/minecraft_server/logs/latest.log", + "FS_WATCH_FILE": false, "SHOW_INIT_MESSAGE": true, @@ -30,7 +32,6 @@ "REGEX_SERVER_PREFIX": "\\[Server thread/INFO\\]:", "REGEX_MATCH_CHAT_MC": "^<([^>]*)> (.*)", "REGEX_IGNORED_CHAT": "packets too frequently", - "DEBUG": false, "SERVER_NAME": "Shulker", "SERVER_IMAGE": "", diff --git a/src/Config.ts b/src/Config.ts index ee24698..bcc45ef 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -1,5 +1,6 @@ export interface Config { PORT: number + DEBUG: boolean USE_WEBHOOKS: boolean WEBHOOK_URL: string @@ -18,6 +19,7 @@ export interface Config { IS_LOCAL_FILE: boolean LOCAL_FILE_PATH: string + FS_WATCH_FILE: boolean PATH_TO_MINECRAFT_SERVER_INSTALL?: string YOUR_URL?: string @@ -33,7 +35,6 @@ export interface Config { REGEX_SERVER_PREFIX: string REGEX_MATCH_CHAT_MC: string REGEX_IGNORED_CHAT: string - DEBUG: boolean SERVER_NAME: string SERVER_IMAGE: string diff --git a/src/MinecraftHandler.ts b/src/MinecraftHandler.ts index 0882d19..bddc515 100644 --- a/src/MinecraftHandler.ts +++ b/src/MinecraftHandler.ts @@ -190,7 +190,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}"`) } -- cgit 1.4.1