diff options
author | Arcensoth <arcensoth@gmail.com> | 2018-02-23 18:05:28 -0500 |
---|---|---|
committer | Arcensoth <arcensoth@gmail.com> | 2018-02-23 18:05:28 -0500 |
commit | d76da4a3d2542f42ff0aa1ef761558fa0b93a350 (patch) | |
tree | 7b8cee8403ce5d8c0aea68149d46ee58efaa2c0d /index.js | |
parent | Revert example tellraw format to mimic the original (diff) | |
download | shulker-d76da4a3d2542f42ff0aa1ef761558fa0b93a350.tar.gz shulker-d76da4a3d2542f42ff0aa1ef761558fa0b93a350.zip |
Allow configurable discord format
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 16 |
1 files changed, 11 insertions, 5 deletions
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 }); }); |