summary refs log tree commit diff homepage
path: root/index.js
diff options
context:
space:
mode:
authorArcensoth <arcensoth@gmail.com>2018-02-23 17:19:41 -0500
committerArcensoth <arcensoth@gmail.com>2018-02-23 17:19:41 -0500
commit012d7e5bcf3a9d4ce3595be8039b89edcf5e847b (patch)
tree3b2d19e09a5f217038c266df2dc2772a25a4ccfb /index.js
parentAllow config file to be passed as a parameter (diff)
downloadshulker-012d7e5bcf3a9d4ce3595be8039b89edcf5e847b.tar.gz
shulker-012d7e5bcf3a9d4ce3595be8039b89edcf5e847b.zip
Allow configurable tellraw format
Diffstat (limited to '')
-rw-r--r--index.js14
1 files changed, 9 insertions, 5 deletions
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
                 });
             });