summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authordestruc7i0n <destruc7i0n@users.noreply.github.com>2021-12-03 23:53:33 -0500
committerdestruc7i0n <destruc7i0n@users.noreply.github.com>2021-12-03 23:53:33 -0500
commit314506bb942af8784865d513a62f080083bc30b6 (patch)
tree88c1090aa247a7afba5cd2fd2271750488f839bd
parentonly allow text messages to be handled (diff)
downloadshulker-314506bb942af8784865d513a62f080083bc30b6.tar.gz
shulker-314506bb942af8784865d513a62f080083bc30b6.zip
ability to specify custom avatar provider
closes #74
-rw-r--r--README.md2
-rw-r--r--config.example.json101
-rw-r--r--src/Config.ts2
-rw-r--r--src/Discord.ts9
4 files changed, 77 insertions, 37 deletions
diff --git a/README.md b/README.md
index 34a99b1..7ac771a 100644
--- a/README.md
+++ b/README.md
@@ -84,6 +84,8 @@ tail -F /PATH_TO_MINECRAFT_SERVER_INSTALL/logs/latest.log | grep --line-buffered
 
     "SERVER_NAME": "Shulker", /* The username used when displaying any server information in chat, e.g., Server - Shulker : Server message here*/
     "SERVER_IMAGE": "", /* Image for the server when sending such messages (if enabled below). Only for WebHooks. */
+    "HEAD_IMAGE_URL": "https://minotar.net/helm/%uuid%/256.png", /* Url to get the heads for the webhook, %uuid% is replaced with the uuid of the player */
+    "DEFAULT_PLAYER_HEAD": "c06f89064c8a49119c29ea1dbd1aab82", /* UUID of player with the default head to use (currently is MHF_Steve) */
     "SHOW_SERVER_STATUS: false, /* Shows when the server turns on and off e.g., Server - Shulker : Server is online */
     "SHOW_PLAYER_CONN_STAT": false, /* Shows player connection status in chat, e.g., Server - Shulker : TheMachine joined the game */
     "SHOW_PLAYER_ADVANCEMENT": false, /* Shows when players earn advancements in chat, e.g., Server - Shulker : TheMachine has made the advacement [MEME - Machine] */
diff --git a/config.example.json b/config.example.json
index 78de668..2aef660 100644
--- a/config.example.json
+++ b/config.example.json
@@ -1,44 +1,75 @@
 {
-    "PORT": 8000,
+  "PORT": 8000,
 
-    "USE_WEBHOOKS": true,
-    "WEBHOOK_URL": "DISCORD_WEBHOOK_URL_HERE",
-    "IGNORE_WEBHOOKS": true,
-    "DISCORD_TOKEN": "TOKEN_HERE",
-    "DISCORD_CHANNEL_ID": "",
-    "DISCORD_CHANNEL_NAME": "#bot",
-    "DISCORD_MESSAGE_TEMPLATE": "`%username%`: %message%",
+  "USE_WEBHOOKS": true,
+  "WEBHOOK_URL": "DISCORD_WEBHOOK_URL_HERE",
+  "IGNORE_WEBHOOKS": true,
+  "DISCORD_TOKEN": "TOKEN_HERE",
+  "DISCORD_CHANNEL_ID": "",
+  "DISCORD_CHANNEL_NAME": "#bot",
+  "DISCORD_MESSAGE_TEMPLATE": "`%username%`: %message%",
 
-    "MINECRAFT_SERVER_RCON_IP": "127.0.0.1",
-    "MINECRAFT_SERVER_RCON_PORT": 25575,
-    "MINECRAFT_SERVER_RCON_PASSWORD": "password",
-    "MINECRAFT_TELLRAW_TEMPLATE": "[{\"color\": \"white\", \"text\": \"<%username%> %message%\"}]",
-    "MINECRAFT_TELLRAW_DOESNT_EXIST": false,
-    "MINECRAFT_TELLRAW_DOESNT_EXIST_SAY_TEMPLATE": "<%username%> %message%",
+  "MINECRAFT_SERVER_RCON_IP": "127.0.0.1",
+  "MINECRAFT_SERVER_RCON_PORT": 25575,
+  "MINECRAFT_SERVER_RCON_PASSWORD": "password",
+  "MINECRAFT_TELLRAW_TEMPLATE": "[{\"color\": \"white\", \"text\": \"<%username%> %message%\"}]",
+  "MINECRAFT_TELLRAW_DOESNT_EXIST": false,
+  "MINECRAFT_TELLRAW_DOESNT_EXIST_SAY_TEMPLATE": "<%username%> %message%",
 
-    "IS_LOCAL_FILE": false,
-    "LOCAL_FILE_PATH": "/usr/home/minecraft_server/logs/latest.log",
+  "IS_LOCAL_FILE": false,
+  "LOCAL_FILE_PATH": "/usr/home/minecraft_server/logs/latest.log",
 
-    "SHOW_INIT_MESSAGE": true,
+  "SHOW_INIT_MESSAGE": true,
 
-    "ALLOW_USER_MENTIONS": false,
-    "ALLOW_HERE_EVERYONE_MENTIONS": false,
-    "ALLOW_SLASH_COMMANDS": false,
-    "SLASH_COMMAND_ROLES": [],
+  "ALLOW_USER_MENTIONS": false,
+  "ALLOW_HERE_EVERYONE_MENTIONS": false,
+  "ALLOW_SLASH_COMMANDS": false,
+  "SLASH_COMMAND_ROLES": [],
 
-    "WEBHOOK": "/minecraft/hook",
-    "REGEX_SERVER_PREFIX": "\\[Server thread/INFO\\]:",
-    "REGEX_MATCH_CHAT_MC": "^<([^>]*)> (.*)",
-    "REGEX_IGNORED_CHAT": "packets too frequently",
-    "DEBUG": false,
+  "WEBHOOK": "/minecraft/hook",
+  "REGEX_SERVER_PREFIX": "\\[Server thread/INFO\\]:",
+  "REGEX_MATCH_CHAT_MC": "^<([^>]*)> (.*)",
+  "REGEX_IGNORED_CHAT": "packets too frequently",
+  "DEBUG": false,
 
-    "SERVER_NAME": "Shulker",
-    "SERVER_IMAGE": "",
-    "SHOW_SERVER_STATUS": false,
-    "SHOW_PLAYER_CONN_STAT": false,
-    "SHOW_PLAYER_ADVANCEMENT": false,
-    "SHOW_PLAYER_DEATH": false,
-    "SHOW_PLAYER_ME": false,
-    "DEATH_KEY_WORDS": ["shot", "fell", "death", "died", "doomed", "pummeled", "removed", "didn't want", "withered", "squashed", "flames", "burnt", "walked into", "bang", "roasted", "squished", "drowned", "killed", "slain", "blown", "blew", "suffocated", "struck", "lava", "impaled", "speared", "fireballed", "finished", "kinetic"]
+  "SERVER_NAME": "Shulker",
+  "SERVER_IMAGE": "",
+  "HEAD_IMAGE_URL": "https://minotar.net/helm/%uuid%/256.png",
+  "DEFAULT_PLAYER_HEAD": "c06f89064c8a49119c29ea1dbd1aab82",
+  "SHOW_SERVER_STATUS": false,
+  "SHOW_PLAYER_CONN_STAT": false,
+  "SHOW_PLAYER_ADVANCEMENT": false,
+  "SHOW_PLAYER_DEATH": false,
+  "SHOW_PLAYER_ME": false,
+  "DEATH_KEY_WORDS": [
+    "shot",
+    "fell",
+    "death",
+    "died",
+    "doomed",
+    "pummeled",
+    "removed",
+    "didn't want",
+    "withered",
+    "squashed",
+    "flames",
+    "burnt",
+    "walked into",
+    "bang",
+    "roasted",
+    "squished",
+    "drowned",
+    "killed",
+    "slain",
+    "blown",
+    "blew",
+    "suffocated",
+    "struck",
+    "lava",
+    "impaled",
+    "speared",
+    "fireballed",
+    "finished",
+    "kinetic"
+  ]
 }
-
diff --git a/src/Config.ts b/src/Config.ts
index 5a1417d..ee24698 100644
--- a/src/Config.ts
+++ b/src/Config.ts
@@ -37,6 +37,8 @@ export interface Config {
 
   SERVER_NAME: string
   SERVER_IMAGE: string
+  HEAD_IMAGE_URL: string
+  DEFAULT_PLAYER_HEAD: string
   SHOW_SERVER_STATUS: boolean
   SHOW_PLAYER_CONN_STAT: boolean
   SHOW_PLAYER_ADVANCEMENT: boolean
diff --git a/src/Discord.ts b/src/Discord.ts
index e1a7903..b001c8c 100644
--- a/src/Discord.ts
+++ b/src/Discord.ts
@@ -219,17 +219,22 @@ class Discord {
     }
   }
 
+  private getHeadUrl(uuid: string): string {
+    const url = this.config.HEAD_IMAGE_URL || 'https://minotar.net/helm/%uuid%/256.png'
+    return url.replace(/%uuid%/, uuid)
+  }
+
   private async makeDiscordWebhook (username: string, message: string) {
     message = this.replaceDiscordMentions(message)
 
-    const defaultHead = 'https://minotar.net/helm/c06f89064c8a49119c29ea1dbd1aab82/256.png' // MHF_Steve
+    const defaultHead = this.getHeadUrl(this.config.DEFAULT_PLAYER_HEAD || 'c06f89064c8a49119c29ea1dbd1aab82') // MHF_Steve
 
     let avatarURL
     if (username === this.config.SERVER_NAME + ' - Server') { // use avatar for the server
       avatarURL = this.config.SERVER_IMAGE || defaultHead
     } else { // use avatar for player
       const uuid = await this.getUUIDFromUsername(username)
-      avatarURL = !!uuid ? `https://minotar.net/helm/${uuid}/256.png` : defaultHead
+      avatarURL = !!uuid ? this.getHeadUrl(uuid) : defaultHead
     }
 
     return {