From 16016776c992c92f19102dcec2ea257041817e66 Mon Sep 17 00:00:00 2001 From: Arcensoth Date: Fri, 23 Feb 2018 15:49:26 -0500 Subject: Change the in-game message format --- index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 2c21524..9f22887 100644 --- a/index.js +++ b/index.js @@ -48,9 +48,10 @@ shulker.on("ready", function() { shulker.on("message", function(message) { if (message.channel.id === shulker.channels.get(c.DISCORD_CHANNEL_ID).id) { if (message.author.id !== shulker.user.id) { - var data = { - text: "<" + message.author.username + "> " + message.cleanContent - }; + var data = [ + {color: "gray", text: "[" + message.author.username + "#" + message.author.discriminator + "] "}, + {color: "white", text: message.cleanContent} + ]; var client = new Rcon(c.MINECRAFT_SERVER_RCON_IP, c.MINECRAFT_SERVER_RCON_PORT); // create rcon client client.auth(c.MINECRAFT_SERVER_RCON_PASSWORD, function(err){ // only authenticate when needed client.command('tellraw @a ["",' + JSON.stringify(data) + ']', function(err, resp) { -- cgit 1.4.1 From 37b8cfc92c275dbdc12f3a1dcb7112cf5326b335 Mon Sep 17 00:00:00 2001 From: Arcensoth Date: Fri, 23 Feb 2018 15:55:15 -0500 Subject: Ignore node installation files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..504afef --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +package-lock.json -- cgit 1.4.1 From e865b399823174cc73ea480c661994a3ea3e736b Mon Sep 17 00:00:00 2001 From: Arcensoth Date: Fri, 23 Feb 2018 16:18:13 -0500 Subject: Allow config file to be passed as a parameter --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 9f22887..0d5aed4 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,13 @@ var Rcon = require("./lib/rcon.js"); var express = require("express"); var app = express(); var http = require("http").Server(app); -var c = require("./config.json"); + +var cfile = (process.argv.length > 2) ? process.argv[2] : "./config.json" + +console.log("[INFO] Using configuration file:", cfile); + +var c = require(cfile); + var debug = c.DEBUG; var shulker = new Discord.Client(); -- cgit 1.4.1 From 012d7e5bcf3a9d4ce3595be8039b89edcf5e847b Mon Sep 17 00:00:00 2001 From: Arcensoth Date: Fri, 23 Feb 2018 17:19:41 -0500 Subject: Allow configurable tellraw format --- config.json | 3 ++- index.js | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/config.json b/config.json index d34d46a..0713beb 100644 --- a/config.json +++ b/config.json @@ -5,9 +5,10 @@ "MINECRAFT_SERVER_RCON_IP": "example.com", "MINECRAFT_SERVER_RCON_PORT": 25575, "MINECRAFT_SERVER_RCON_PASSWORD": "password", + "MINECRAFT_TELLRAW_TEMPLATE": "[{\"color\": \"gray\", \"text\": \"[%username%#%discriminator%] \"},{\"color\": \"white\", \"text\": \"%message%\"}]", "WEBHOOK": "/minecraft/hook", "REGEX_MATCH_CHAT_MC": "\\[Server thread/INFO\\]: <([^>]*)> (.*)", "REGEX_IGNORED_CHAT": "packets too frequently", "RCON_RECONNECT_DELAY": 10, "DEBUG": false -} \ No newline at end of file +} diff --git a/index.js b/index.js index 0d5aed4..bcb7bd5 100644 --- a/index.js +++ b/index.js @@ -13,6 +13,14 @@ console.log("[INFO] Using configuration file:", cfile); var c = require(cfile); +function makeTellraw(message) { + // make a tellraw string by formatting the configured template with the given message + return c.MINECRAFT_TELLRAW_TEMPLATE + .replace("%username%", message.author.username) + .replace("%discriminator%", message.author.discriminator) + .replace("%message%", message.cleanContent); +} + var debug = c.DEBUG; var shulker = new Discord.Client(); @@ -54,13 +62,9 @@ shulker.on("ready", function() { shulker.on("message", function(message) { if (message.channel.id === shulker.channels.get(c.DISCORD_CHANNEL_ID).id) { if (message.author.id !== shulker.user.id) { - var data = [ - {color: "gray", text: "[" + message.author.username + "#" + message.author.discriminator + "] "}, - {color: "white", text: message.cleanContent} - ]; var client = new Rcon(c.MINECRAFT_SERVER_RCON_IP, c.MINECRAFT_SERVER_RCON_PORT); // create rcon client client.auth(c.MINECRAFT_SERVER_RCON_PASSWORD, function(err){ // only authenticate when needed - client.command('tellraw @a ["",' + JSON.stringify(data) + ']', function(err, resp) { + client.command('tellraw @a ' + makeTellraw(message), function(err, resp) { client.close(); // close the rcon connection }); }); -- cgit 1.4.1 From 7a1986349648631552aa393a03c4942fc5629f7b Mon Sep 17 00:00:00 2001 From: Arcensoth Date: Fri, 23 Feb 2018 17:28:37 -0500 Subject: Update readme with new tellraw config option --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3518e9d..5828a3d 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ You can also easily Deploy to Heroku or Bluemix, just be sure to edit `YOUR_URL` "MINECRAFT_SERVER_RCON_IP": "example.com", /* Minecraft server IP (make sure you have enabled rcon) */ "MINECRAFT_SERVER_RCON_PORT": <1-65535>, /* Minecraft server rcon port */ "MINECRAFT_SERVER_RCON_PASSWORD": "", /* Minecraft server rcon password */ + "MINECRAFT_TELLRAW_TEMPLATE": "[{\"color\": \"gray\", \"text\": \"[%username%#%discriminator%] \"},{\"color\": \"white\", \"text\": \"%message%\"}]", /* Tellraw command format to display in-game */ "WEBHOOK": "/minecraft/hook", /* Web hook, where to send the log to */ "REGEX_MATCH_CHAT_MC": "\\[Server thread/INFO\\]: <(.*)> (.*)", /* 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 */ -- cgit 1.4.1 From 1ca7e040e8968e30d2be5d420abd7f3a76c08989 Mon Sep 17 00:00:00 2001 From: Arcensoth Date: Fri, 23 Feb 2018 18:01:35 -0500 Subject: Revert example tellraw format to mimic the original --- README.md | 2 +- config.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5828a3d..f56d6ca 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ You can also easily Deploy to Heroku or Bluemix, just be sure to edit `YOUR_URL` "MINECRAFT_SERVER_RCON_IP": "example.com", /* Minecraft server IP (make sure you have enabled rcon) */ "MINECRAFT_SERVER_RCON_PORT": <1-65535>, /* Minecraft server rcon port */ "MINECRAFT_SERVER_RCON_PASSWORD": "", /* Minecraft server rcon password */ - "MINECRAFT_TELLRAW_TEMPLATE": "[{\"color\": \"gray\", \"text\": \"[%username%#%discriminator%] \"},{\"color\": \"white\", \"text\": \"%message%\"}]", /* Tellraw command format to display in-game */ + "MINECRAFT_TELLRAW_TEMPLATE": "[{\"color\": \"white\", \"text\": \"<%username%> %message%\"}]", /* Tellraw command format to display in-game */ "WEBHOOK": "/minecraft/hook", /* Web hook, where to send the log to */ "REGEX_MATCH_CHAT_MC": "\\[Server thread/INFO\\]: <(.*)> (.*)", /* 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 */ diff --git a/config.json b/config.json index 0713beb..8d5a709 100644 --- a/config.json +++ b/config.json @@ -5,7 +5,7 @@ "MINECRAFT_SERVER_RCON_IP": "example.com", "MINECRAFT_SERVER_RCON_PORT": 25575, "MINECRAFT_SERVER_RCON_PASSWORD": "password", - "MINECRAFT_TELLRAW_TEMPLATE": "[{\"color\": \"gray\", \"text\": \"[%username%#%discriminator%] \"},{\"color\": \"white\", \"text\": \"%message%\"}]", + "MINECRAFT_TELLRAW_TEMPLATE": "[{\"color\": \"white\", \"text\": \"<%username%> %message%\"}]", "WEBHOOK": "/minecraft/hook", "REGEX_MATCH_CHAT_MC": "\\[Server thread/INFO\\]: <([^>]*)> (.*)", "REGEX_IGNORED_CHAT": "packets too frequently", -- cgit 1.4.1 From d76da4a3d2542f42ff0aa1ef761558fa0b93a350 Mon Sep 17 00:00:00 2001 From: Arcensoth Date: Fri, 23 Feb 2018 18:05:28 -0500 Subject: Allow configurable discord format --- README.md | 3 ++- config.json | 1 + index.js | 16 +++++++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f56d6ca..e655bf1 100644 --- a/README.md +++ b/README.md @@ -38,10 +38,11 @@ You can also easily Deploy to Heroku or Bluemix, just be sure to edit `YOUR_URL` "PORT": 8000, /* Port you want to run the webserver for the hook on */ "DISCORD_TOKEN": "<12345>", /* Discord bot token. [Click here](https://discordapp.com/developers/applications/me) to create you application and add a bot to it. */ "DISCORD_CHANNEL_ID": "<12345>", /* Discord channel ID for for the discord bot. Enable developer mode in your Discord client, then right click channel and select "Copy ID". */ + "DISCORD_MESSAGE_TEMPLATE": "`%username%`:%message%", /* Message template to display in Discord */ "MINECRAFT_SERVER_RCON_IP": "example.com", /* Minecraft server IP (make sure you have enabled rcon) */ "MINECRAFT_SERVER_RCON_PORT": <1-65535>, /* Minecraft server rcon port */ "MINECRAFT_SERVER_RCON_PASSWORD": "", /* Minecraft server rcon password */ - "MINECRAFT_TELLRAW_TEMPLATE": "[{\"color\": \"white\", \"text\": \"<%username%> %message%\"}]", /* Tellraw command format to display in-game */ + "MINECRAFT_TELLRAW_TEMPLATE": "[{\"color\": \"white\", \"text\": \"<%username%> %message%\"}]", /* Tellraw template to display in Minecraft */ "WEBHOOK": "/minecraft/hook", /* Web hook, where to send the log to */ "REGEX_MATCH_CHAT_MC": "\\[Server thread/INFO\\]: <(.*)> (.*)", /* 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 */ diff --git a/config.json b/config.json index 8d5a709..ddf8cd8 100644 --- a/config.json +++ b/config.json @@ -2,6 +2,7 @@ "PORT": 8000, "DISCORD_TOKEN": "TOKEN_HERE", "DISCORD_CHANNEL_ID": "general", + "DISCORD_MESSAGE_TEMPLATE": "`%username%`:%message%", "MINECRAFT_SERVER_RCON_IP": "example.com", "MINECRAFT_SERVER_RCON_PORT": 25575, "MINECRAFT_SERVER_RCON_PASSWORD": "password", diff --git a/index.js b/index.js index bcb7bd5..82d5694 100644 --- a/index.js +++ b/index.js @@ -13,8 +13,15 @@ console.log("[INFO] Using configuration file:", cfile); var c = require(cfile); -function makeTellraw(message) { - // make a tellraw string by formatting the configured template with the given message +function makeDiscordMessage(bodymatch) { + // make a discord message string by formatting the configured template with the given parameters + return c.DISCORD_MESSAGE_TEMPLATE + .replace("%username%", bodymatch[1].replace(/(\§[A-Z-a-z-0-9])/g, "")) + .replace("%message%", bodymatch[2]); +} + +function makeMinecraftTellraw(message) { + // same as the discord side but with discord message parameters return c.MINECRAFT_TELLRAW_TEMPLATE .replace("%username%", message.author.username) .replace("%discriminator%", message.author.discriminator) @@ -52,8 +59,7 @@ shulker.on("ready", function() { console.log("[DEBUG] Username: " + bodymatch[1]); console.log("[DEBUG] Text: " + bodymatch[2]); } - var message = "`" + bodymatch[1].replace(/(\§[A-Z-a-z-0-9])/g, "") + "`:" + bodymatch[2]; - shulker.channels.get(channel).sendMessage(message); + shulker.channels.get(channel).sendMessage(makeDiscordMessage(bodymatch)); } response.send(""); }); @@ -64,7 +70,7 @@ shulker.on("message", function(message) { if (message.author.id !== shulker.user.id) { var client = new Rcon(c.MINECRAFT_SERVER_RCON_IP, c.MINECRAFT_SERVER_RCON_PORT); // create rcon client client.auth(c.MINECRAFT_SERVER_RCON_PASSWORD, function(err){ // only authenticate when needed - client.command('tellraw @a ' + makeTellraw(message), function(err, resp) { + client.command('tellraw @a ' + makeMinecraftTellraw(message), function(err, resp) { client.close(); // close the rcon connection }); }); -- cgit 1.4.1