summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorArcensoth <arcensoth@gmail.com>2018-02-23 18:05:28 -0500
committerArcensoth <arcensoth@gmail.com>2018-02-23 18:05:28 -0500
commitd76da4a3d2542f42ff0aa1ef761558fa0b93a350 (patch)
tree7b8cee8403ce5d8c0aea68149d46ee58efaa2c0d
parentRevert example tellraw format to mimic the original (diff)
downloadshulker-d76da4a3d2542f42ff0aa1ef761558fa0b93a350.tar.gz
shulker-d76da4a3d2542f42ff0aa1ef761558fa0b93a350.zip
Allow configurable discord format
Diffstat (limited to '')
-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
                 });
             });
class='logheader'>2018-08-07Hack clang into checking uiFmt format stringsJune McEnroe 2018-08-07Handle PART and QUIT without messagesJune McEnroe 2018-08-07Make safe filling the who bufferJune McEnroe 2018-08-07Add reverse and reset IRC formatting codesJune McEnroe 2018-08-06Rewrite line editing again, add formattingJune McEnroe 2018-08-06Fix allocation size in vaswprintfJune McEnroe This is so embarrassing. It only started crashing once it had strings that were long enough, and then it took me so long to notice this mistake. I was worried I was still doing va_list wrong somehow. 2018-08-06Implement word wrappingJune McEnroe 2018-08-06Use wchar_t strings for all of UIJune McEnroe vaswprintf is a nightmare. 2018-08-06Rename line editing functionsJune McEnroe 2018-08-05Initialize all possible color pairsJune McEnroe This is actually possible with use_default_colors! 2018-08-05Refactor color initializationJune McEnroe 2018-08-05Add ^L redrawJune McEnroe 2018-08-05Use 16 colors if availableJune McEnroe Fall back to using bold if there are only 8 colors. This also allowed bright background colors in 16-color terminals. I must port this system to torus. I'll be able to remove the awful termcap patch hack. 2018-08-05Limit parsed colors to number of mIRC colorsJune McEnroe Oh boy that's embarrassing. 2018-08-04Show source link on exitJune McEnroe 2018-08-04Implement line editing, scrollingJune McEnroe Don't really have a way to implement the M-* keys, and currently missing C-w. 2018-08-04Handle /topicJune McEnroe