Skip to content

Commit

Permalink
fix(Message): #system non-zero message types are not guaranteed to be…
Browse files Browse the repository at this point in the history
… system (#5108)

* fix(Message): #system not all nonzero message types are system

* feat(Message): introduce system message types

* refactor(Constants): change SystemMessageTypes to be exclusionary

* fix(Constants): only need to check if type exists

Co-authored-by: Jan <66554238+Vaporox@users.noreply.github.com>

* fix(Constants): lint

* fix(Typings): add SystemMessageTypees to Constants

Co-authored-by: Jan <66554238+Vaporox@users.noreply.github.com>
  • Loading branch information
ckohen and vaporoxx committed Dec 12, 2020
1 parent 5b51392 commit bb78120
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/structures/Message.js
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/util/Constants.js
Expand Up @@ -429,6 +429,14 @@ exports.MessageTypes = [
'REPLY',
];

/**
* The types of messages that are `System`. The available types are `MessageTypes` excluding:
* * DEFAULT
* * REPLY
* @typedef {string} SystemMessageType
*/
exports.SystemMessageTypes = exports.MessageTypes.filter(type => type && type !== 'DEFAULT' && type !== 'REPLY');

/**
* <info>Bots cannot set a `CUSTOM_STATUS`, it is only for custom statuses received from users</info>
* The type of an activity of a users presence, e.g. `PLAYING`. Here are the available types:
Expand Down
3 changes: 3 additions & 0 deletions typings/index.d.ts
Expand Up @@ -516,6 +516,7 @@ declare module 'discord.js' {
BIG: 2;
};
MessageTypes: MessageType[];
SystemMessageTypes: SystemMessageType[];
ActivityTypes: ActivityType[];
ExplicitContentFilterLevels: ExplicitContentFilterLevel[];
DefaultMessageNotifications: DefaultMessageNotifications[];
Expand Down Expand Up @@ -3147,6 +3148,8 @@ declare module 'discord.js' {

type SystemChannelFlagsResolvable = BitFieldResolvable<SystemChannelFlagsString>;

type SystemMessageType = Exclude<MessageType, 'DEFAULT' | 'REPLY'>;

type TargetUser = number;

interface TypingData {
Expand Down

0 comments on commit bb78120

Please sign in to comment.