summary refs log tree commit diff homepage
path: root/src/Discord.ts
diff options
context:
space:
mode:
authordestruc7i0n <destruc7i0n@users.noreply.github.com>2021-06-26 15:50:27 -0400
committerdestruc7i0n <destruc7i0n@users.noreply.github.com>2021-06-26 15:50:27 -0400
commit8f635bd0b0d47bf8ee68e2208d4407eaa0c95f84 (patch)
tree07db8177b1c29dbb7a17bf4e31a9234990bbf7bb /src/Discord.ts
parentuse uuids for avatar requests with webhooks (diff)
downloadshulker-8f635bd0b0d47bf8ee68e2208d4407eaa0c95f84.tar.gz
shulker-8f635bd0b0d47bf8ee68e2208d4407eaa0c95f84.zip
only allow text messages to be handled
* move config.json to config.example.json
* update packages
Diffstat (limited to '')
-rw-r--r--src/Discord.ts14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/Discord.ts b/src/Discord.ts
index 4debee9..e1a7903 100644
--- a/src/Discord.ts
+++ b/src/Discord.ts
@@ -95,6 +95,10 @@ class Discord {
         }
       }
     }
+    // ensure that the message has a sender
+    if (!message.author) return
+    // ensure that the message is a text message
+    if (message.type !== 'DEFAULT') return
     // if the same user as the bot, ignore
     if (message.author.id === this.client.user.id) return
     // ignore any attachments
@@ -143,9 +147,10 @@ class Discord {
   }
 
   private makeMinecraftTellraw(message: Message): string {
+    const username = emojiStrip(message.author.username)
     const variables: {[index: string]: string} = {
-      username: emojiStrip(message.author.username),
-      nickname: message.member.nickname ? emojiStrip(message.member.nickname) : emojiStrip(message.author.username),
+      username,
+      nickname: !!message.member?.nickname ? emojiStrip(message.member.nickname) : username,
       discriminator: message.author.discriminator,
       text: emojiStrip(message.cleanContent)
     }
@@ -219,17 +224,16 @@ class Discord {
 
     const defaultHead = 'https://minotar.net/helm/c06f89064c8a49119c29ea1dbd1aab82/256.png' // MHF_Steve
 
-    const uuid = await this.getUUIDFromUsername(username)
-
     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
     }
 
     return {
-      username: username,
+      username,
       content: message,
       'avatar_url': avatarURL,
     }