From 25998fa8a297645fc2e7c8a83a45d2c26439b7de Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sun, 16 Aug 2020 18:18:32 +0300 Subject: [PATCH] Show a small note if a user messages the bot with e.g. a Spotify invite --- src/data/Thread.js | 32 ++++++++++++++++++++++++++++++-- src/data/constants.js | 8 ++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/data/Thread.js b/src/data/Thread.js index 42f0b41..2912b11 100644 --- a/src/data/Thread.js +++ b/src/data/Thread.js @@ -10,7 +10,7 @@ const { formatters } = require("../formatters"); const ThreadMessage = require("./ThreadMessage"); -const {THREAD_MESSAGE_TYPE, THREAD_STATUS} = require("./constants"); +const {THREAD_MESSAGE_TYPE, THREAD_STATUS, DISCORD_MESSAGE_ACTIVITY_TYPES} = require("./constants"); /** * @property {String} id @@ -255,6 +255,7 @@ class Thread { */ async receiveUserReply(msg) { const fullUserName = `${msg.author.username}#${msg.author.discriminator}`; + let messageContent = msg.content || ""; // Prepare attachments const attachments = []; @@ -274,12 +275,39 @@ class Thread { attachments.push(savedAttachment.url); } + // Handle special embeds (listening party invites etc.) + if (msg.activity) { + let applicationName = msg.application && msg.application.name; + + if (! applicationName && msg.activity.party_id.startsWith("spotify:")) { + applicationName = "Spotify"; + } + + if (! applicationName) { + applicationName = "Unknown Application"; + } + + let activityText; + if (msg.activity.type === DISCORD_MESSAGE_ACTIVITY_TYPES.JOIN || msg.activity.type === DISCORD_MESSAGE_ACTIVITY_TYPES.JOIN_REQUEST) { + activityText = "join a game"; + } else if (msg.activity.type === DISCORD_MESSAGE_ACTIVITY_TYPES.SPECTATE) { + activityText = "spectate"; + } else if (msg.activity.type === DISCORD_MESSAGE_ACTIVITY_TYPES.LISTEN) { + activityText = "listen along"; + } else { + activityText = "do something"; + } + + messageContent += `\n\n**`; + messageContent = messageContent.trim(); + } + // Save DB entry let threadMessage = new ThreadMessage({ message_type: THREAD_MESSAGE_TYPE.FROM_USER, user_id: this.user_id, user_name: fullUserName, - body: msg.content || "", + body: messageContent, is_anonymous: 0, dm_message_id: msg.id, attachments, diff --git a/src/data/constants.js b/src/data/constants.js index 067cb06..221becd 100644 --- a/src/data/constants.js +++ b/src/data/constants.js @@ -26,6 +26,14 @@ module.exports = { GUILD_STORE: 6, }, + // https://discord.com/developers/docs/resources/channel#message-object-message-activity-types + DISCORD_MESSAGE_ACTIVITY_TYPES: { + JOIN: 1, + SPECTATE: 2, + LISTEN: 3, + JOIN_REQUEST: 5, + }, + ACCIDENTAL_THREAD_MESSAGES: [ "ok", "okay",