From 5e914c6f7a6d31d8374cc4ad1bb0a599f5be9aa9 Mon Sep 17 00:00:00 2001 From: ckohen Date: Sat, 12 Dec 2020 00:26:49 -0800 Subject: [PATCH 1/6] fix(Message): #system not all nonzero message types are system --- src/structures/Message.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/structures/Message.js b/src/structures/Message.js index 3f420e322c27..63494f9df500 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -10,7 +10,7 @@ const ReactionCollector = require('./ReactionCollector'); const { Error, TypeError } = require('../errors'); const ReactionManager = require('../managers/ReactionManager'); const Collection = require('../util/Collection'); -const { MessageTypes } = require('../util/Constants'); +const { MessageTypes, SystemMessageTypes } = require('../util/Constants'); const MessageFlags = require('../util/MessageFlags'); const Permissions = require('../util/Permissions'); const SnowflakeUtil = require('../util/Snowflake'); @@ -62,7 +62,7 @@ class Message extends Base { * Whether or not this message was sent by Discord, not actually a user (e.g. pin notifications) * @type {?boolean} */ - this.system = data.type !== 0; + this.system = SystemMessageTypes.includes(this.type); } else if (typeof this.type !== 'string') { this.system = null; this.type = null; From 756f7506429b96d43fd874eb9ae3e4748e935b7f Mon Sep 17 00:00:00 2001 From: ckohen Date: Sat, 12 Dec 2020 00:28:03 -0800 Subject: [PATCH 2/6] feat(Message): introduce system message types --- src/util/Constants.js | 35 +++++++++++++++++++++++++++++++++++ typings/index.d.ts | 16 ++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/util/Constants.js b/src/util/Constants.js index 1d84a51eb200..fe73b28e97de 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -429,6 +429,41 @@ exports.MessageTypes = [ 'REPLY', ]; +/** + * The types of messges that are considered `System`. Here are the available types: + * * RECIPIENT_ADD + * * RECIPIENT_REMOVE + * * CALL + * * CHANNEL_NAME_CHANGE + * * CHANNEL_ICON_CHANGE + * * PINS_ADD + * * GUILD_MEMBER_JOIN + * * USER_PREMIUM_GUILD_SUBSCRIPTION + * * USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1 + * * USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2 + * * USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3 + * * CHANNEL_FOLLOW_ADD + * * GUILD_DISCOVERY_DISQUALIFIED + * * GUILD_DISCOVERY_REQUALIFIED + * @typedef {string} SystemMessageType + */ +exports.SystemMessageTypes = [ + 'RECIPIENT_ADD', + 'RECIPIENT_REMOVE', + 'CALL', + 'CHANNEL_NAME_CHANGE', + 'CHANNEL_ICON_CHANGE', + 'PINS_ADD', + 'GUILD_MEMBER_JOIN', + 'USER_PREMIUM_GUILD_SUBSCRIPTION', + 'USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1', + 'USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2', + 'USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3', + 'CHANNEL_FOLLOW_ADD', + 'GUILD_DISCOVERY_DISQUALIFIED', + 'GUILD_DISCOVERY_REQUALIFIED', +]; + /** * Bots cannot set a `CUSTOM_STATUS`, it is only for custom statuses received from users * The type of an activity of a users presence, e.g. `PLAYING`. Here are the available types: diff --git a/typings/index.d.ts b/typings/index.d.ts index 1f0e39f5ab3e..c402b234df10 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3148,6 +3148,22 @@ declare module 'discord.js' { type SystemChannelFlagsResolvable = BitFieldResolvable; + type SystemMessageType = + | 'RECIPIENT_ADD' + | 'RECIPIENT_REMOVE' + | 'CALL' + | 'CHANNEL_NAME_CHANGE' + | 'CHANNEL_ICON_CHANGE' + | 'PINS_ADD' + | 'GUILD_MEMBER_JOIN' + | 'USER_PREMIUM_GUILD_SUBSCRIPTION' + | 'USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1' + | 'USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2' + | 'USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3' + | 'CHANNEL_FOLLOW_ADD' + | 'GUILD_DISCOVERY_DISQUALIFIED' + | 'GUILD_DISCOVERY_REQUALIFIED'; + type TargetUser = number; interface TypingData { From 59d1a525d6a85833654abd78fbdd43062827c31c Mon Sep 17 00:00:00 2001 From: ckohen Date: Sat, 12 Dec 2020 02:32:25 -0800 Subject: [PATCH 3/6] refactor(Constants): change SystemMessageTypes to be exclusionary --- src/util/Constants.js | 37 ++++++------------------------------- typings/index.d.ts | 16 +--------------- 2 files changed, 7 insertions(+), 46 deletions(-) diff --git a/src/util/Constants.js b/src/util/Constants.js index fe73b28e97de..2e611db26a98 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -430,39 +430,14 @@ exports.MessageTypes = [ ]; /** - * The types of messges that are considered `System`. Here are the available types: - * * RECIPIENT_ADD - * * RECIPIENT_REMOVE - * * CALL - * * CHANNEL_NAME_CHANGE - * * CHANNEL_ICON_CHANGE - * * PINS_ADD - * * GUILD_MEMBER_JOIN - * * USER_PREMIUM_GUILD_SUBSCRIPTION - * * USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1 - * * USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2 - * * USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3 - * * CHANNEL_FOLLOW_ADD - * * GUILD_DISCOVERY_DISQUALIFIED - * * GUILD_DISCOVERY_REQUALIFIED + * The types of messages that are `System`. The available types are `MessageTypes` excluding: + * * DEFAULT + * * REPLY * @typedef {string} SystemMessageType */ -exports.SystemMessageTypes = [ - 'RECIPIENT_ADD', - 'RECIPIENT_REMOVE', - 'CALL', - 'CHANNEL_NAME_CHANGE', - 'CHANNEL_ICON_CHANGE', - 'PINS_ADD', - 'GUILD_MEMBER_JOIN', - 'USER_PREMIUM_GUILD_SUBSCRIPTION', - 'USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1', - 'USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2', - 'USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3', - 'CHANNEL_FOLLOW_ADD', - 'GUILD_DISCOVERY_DISQUALIFIED', - 'GUILD_DISCOVERY_REQUALIFIED', -]; +exports.SystemMessageTypes = module.exports.MessageTypes.filter( + type => type !== null && type !== 'DEFAULT' && type !== 'REPLY', +); /** * Bots cannot set a `CUSTOM_STATUS`, it is only for custom statuses received from users diff --git a/typings/index.d.ts b/typings/index.d.ts index c402b234df10..919fd4b564b9 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3148,21 +3148,7 @@ declare module 'discord.js' { type SystemChannelFlagsResolvable = BitFieldResolvable; - type SystemMessageType = - | 'RECIPIENT_ADD' - | 'RECIPIENT_REMOVE' - | 'CALL' - | 'CHANNEL_NAME_CHANGE' - | 'CHANNEL_ICON_CHANGE' - | 'PINS_ADD' - | 'GUILD_MEMBER_JOIN' - | 'USER_PREMIUM_GUILD_SUBSCRIPTION' - | 'USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1' - | 'USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2' - | 'USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3' - | 'CHANNEL_FOLLOW_ADD' - | 'GUILD_DISCOVERY_DISQUALIFIED' - | 'GUILD_DISCOVERY_REQUALIFIED'; + type SystemMessageType = Exclude; type TargetUser = number; From b2a57a94d1b5d5b19cd110792529637a5eeddf2e Mon Sep 17 00:00:00 2001 From: X-Classified Date: Sat, 12 Dec 2020 02:44:29 -0800 Subject: [PATCH 4/6] fix(Constants): only need to check if type exists Co-authored-by: Jan <66554238+Vaporox@users.noreply.github.com> --- src/util/Constants.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/Constants.js b/src/util/Constants.js index 2e611db26a98..5aac9f4a796c 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -435,8 +435,8 @@ exports.MessageTypes = [ * * REPLY * @typedef {string} SystemMessageType */ -exports.SystemMessageTypes = module.exports.MessageTypes.filter( - type => type !== null && type !== 'DEFAULT' && type !== 'REPLY', +exports.SystemMessageTypes = exports.MessageTypes.filter( + type => type && type !== 'DEFAULT' && type !== 'REPLY', ); /** From d8e1e52cded02a476cafca3e97885955eaeb26f0 Mon Sep 17 00:00:00 2001 From: ckohen Date: Sat, 12 Dec 2020 02:49:11 -0800 Subject: [PATCH 5/6] fix(Constants): lint --- src/util/Constants.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/util/Constants.js b/src/util/Constants.js index 5aac9f4a796c..84a1599f27e5 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -435,9 +435,7 @@ exports.MessageTypes = [ * * REPLY * @typedef {string} SystemMessageType */ -exports.SystemMessageTypes = exports.MessageTypes.filter( - type => type && type !== 'DEFAULT' && type !== 'REPLY', -); +exports.SystemMessageTypes = exports.MessageTypes.filter(type => type && type !== 'DEFAULT' && type !== 'REPLY'); /** * Bots cannot set a `CUSTOM_STATUS`, it is only for custom statuses received from users From 406d3dbecf5d04d2d25c6b2777ddc2d8fc2e67bb Mon Sep 17 00:00:00 2001 From: ckohen Date: Sat, 12 Dec 2020 03:24:39 -0800 Subject: [PATCH 6/6] fix(Typings): add SystemMessageTypees to Constants --- typings/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/typings/index.d.ts b/typings/index.d.ts index 919fd4b564b9..e05929d51d14 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -516,6 +516,7 @@ declare module 'discord.js' { BIG: 2; }; MessageTypes: MessageType[]; + SystemMessageTypes: SystemMessageType[]; ActivityTypes: ActivityType[]; ExplicitContentFilterLevels: ExplicitContentFilterLevel[]; DefaultMessageNotifications: DefaultMessageNotifications[];