From 8f635bd0b0d47bf8ee68e2208d4407eaa0c95f84 Mon Sep 17 00:00:00 2001 From: destruc7i0n Date: Sat, 26 Jun 2021 15:50:27 -0400 Subject: only allow text messages to be handled * move config.json to config.example.json * update packages --- src/Discord.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src') 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, } -- cgit 1.4.1