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 --- index.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'index.js') 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