summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authordestruc7i0n <6181960+destruc7i0n@users.noreply.github.com>2020-10-05 09:44:24 -0400
committerGitHub <noreply@github.com>2020-10-05 09:44:24 -0400
commit2fe4b2c3648bc3e1b3c0c229f8cdfa1b8f6bffcb (patch)
treeff00c276d8284656d55691559171e80b4cf0d02c
parentMerge pull request #61 from MarshallOliver/Discord-mentions-regex (diff)
parentnew config stuff (diff)
downloadshulker-2fe4b2c3648bc3e1b3c0c229f8cdfa1b8f6bffcb.tar.gz
shulker-2fe4b2c3648bc3e1b3c0c229f8cdfa1b8f6bffcb.zip
Merge pull request #63 from surepy/master
Add compatibility options MINECRAFT_TELLRAW_DOESNT_EXIST
-rw-r--r--README.md2
-rw-r--r--config.json2
-rw-r--r--src/Config.ts2
-rw-r--r--src/Discord.ts24
4 files changed, 29 insertions, 1 deletions
diff --git a/README.md b/README.md
index 49f017e..5cd0f71 100644
--- a/README.md
+++ b/README.md
@@ -66,6 +66,8 @@ You can also easily Deploy to Heroku and the like, just be sure to edit `YOUR_UR
     "MINECRAFT_SERVER_RCON_IP": "127.0.0.1", /* 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_DOESNT_EXIST": false, /* Minecraft doesn't have the tellraw command (<1.7.2), use say instead. !this may be dangerous! */
+    "MINECRAFT_TELLRAW_DOESNT_EXIST_SAY_TEMPLATE": "<%username%> %message%", /* used when MINECRAFT_TELLRAW_DOESNT_EXIST is set to true. say template to display on minecraft, same as MINECRAFT_TELLRAW_TEMPLATE. */
     "MINECRAFT_TELLRAW_TEMPLATE": "[{\"color\": \"white\", \"text\": \"<%username%> %message%\"}]", /* Tellraw template to display in Minecraft */
     
     "IS_LOCAL_FILE": false, /* should tail the local file, may be a little buggy. please report any you find */
diff --git a/config.json b/config.json
index 2ca92fb..be681e0 100644
--- a/config.json
+++ b/config.json
@@ -12,6 +12,8 @@
     "MINECRAFT_SERVER_RCON_IP": "127.0.0.1",
     "MINECRAFT_SERVER_RCON_PORT": 25575,
     "MINECRAFT_SERVER_RCON_PASSWORD": "password",
+    "MINECRAFT_TELLRAW_DOESNT_EXIST": false,
+    "MINECRAFT_TELLRAW_DOESNT_EXIST_SAY_TEMPLATE": "<%username%> %message%",
     "MINECRAFT_TELLRAW_TEMPLATE": "[{\"color\": \"white\", \"text\": \"<%username%> %message%\"}]",
 
     "IS_LOCAL_FILE": false,
diff --git a/src/Config.ts b/src/Config.ts
index dff0b10..acbab21 100644
--- a/src/Config.ts
+++ b/src/Config.ts
@@ -12,6 +12,8 @@ export interface Config {
   MINECRAFT_SERVER_RCON_IP: string
   MINECRAFT_SERVER_RCON_PORT: number
   MINECRAFT_SERVER_RCON_PASSWORD: string
+  MINECRAFT_TELLRAW_DOESNT_EXIST: boolean
+  MINECRAFT_TELLRAW_DOESNT_EXIST_SAY_TEMPLATE: string
   MINECRAFT_TELLRAW_TEMPLATE: string
 
   IS_LOCAL_FILE: boolean
diff --git a/src/Discord.ts b/src/Discord.ts
index 12ac656..93a99ff 100644
--- a/src/Discord.ts
+++ b/src/Discord.ts
@@ -114,7 +114,13 @@ class Discord {
         console.log('[INFO] User attempted a slash command without a role')
       }
     } else {
-      command = `/tellraw @a ${this.makeMinecraftTellraw(message)}`
+        if (this.config.MINECRAFT_TELLRAW_DOESNT_EXIST) 
+        {
+            command = `/say ${this.makeMinecraftTellraw(message)}`
+        }
+        else {
+            command = `/tellraw @a ${this.makeMinecraftTellraw(message)}`
+        }
     }
 
     if (this.config.DEBUG) console.log(`[DEBUG] Sending command "${command}" to the server`)
@@ -123,6 +129,12 @@ class Discord {
       await rcon.command(command).catch((e) => {
         console.log('[ERROR] Could not send command!')
         if (this.config.DEBUG) console.error(e)
+      }).then((str) => {
+        if (str === 'Unknown command. Try /help for a list of commands') {
+            console.error('[ERROR] Could not send command! (Unknown command)')
+            console.error('if this was a chat message, please look into MINECRAFT_TELLRAW_DOESNT_EXIST!')
+            console.error('command: ' + command)
+        }
       })
     }
     rcon.close()
@@ -139,6 +151,16 @@ class Discord {
     for (const v of Object.keys(variables)) {
       variables[v] = JSON.stringify(variables[v]).slice(1,-1)
     }
+    
+    if (this.config.MINECRAFT_TELLRAW_DOESNT_EXIST)
+    {
+        return this.config.MINECRAFT_TELLRAW_DOESNT_EXIST_SAY_TEMPLATE
+                .replace(/%username%/g, variables.username)
+                .replace(/%nickname%/g, variables.nickname)
+                .replace(/%discriminator%/g, variables.discriminator)
+                .replace(/%message%/g, variables.text)
+    }
+
 
     return this.config.MINECRAFT_TELLRAW_TEMPLATE
       .replace(/%username%/g, variables.username)