Show a small note if a user messages the bot with e.g. a Spotify invite

cshd
Dragory 2020-08-16 18:18:32 +03:00
parent 31a5fb55b8
commit 25998fa8a2
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
2 changed files with 38 additions and 2 deletions

View File

@ -10,7 +10,7 @@ const { formatters } = require("../formatters");
const ThreadMessage = require("./ThreadMessage"); 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 * @property {String} id
@ -255,6 +255,7 @@ class Thread {
*/ */
async receiveUserReply(msg) { async receiveUserReply(msg) {
const fullUserName = `${msg.author.username}#${msg.author.discriminator}`; const fullUserName = `${msg.author.username}#${msg.author.discriminator}`;
let messageContent = msg.content || "";
// Prepare attachments // Prepare attachments
const attachments = []; const attachments = [];
@ -274,12 +275,39 @@ class Thread {
attachments.push(savedAttachment.url); 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*<This message contains an invite to ${activityText} on ${applicationName}>*`;
messageContent = messageContent.trim();
}
// Save DB entry // Save DB entry
let threadMessage = new ThreadMessage({ let threadMessage = new ThreadMessage({
message_type: THREAD_MESSAGE_TYPE.FROM_USER, message_type: THREAD_MESSAGE_TYPE.FROM_USER,
user_id: this.user_id, user_id: this.user_id,
user_name: fullUserName, user_name: fullUserName,
body: msg.content || "", body: messageContent,
is_anonymous: 0, is_anonymous: 0,
dm_message_id: msg.id, dm_message_id: msg.id,
attachments, attachments,

View File

@ -26,6 +26,14 @@ module.exports = {
GUILD_STORE: 6, 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: [ ACCIDENTAL_THREAD_MESSAGES: [
"ok", "ok",
"okay", "okay",