summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--config.json1
-rw-r--r--index.js16
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": "<your 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
                 });
             });