feat(Guild): add support for system channel flags (#3793)

This commit is contained in:
SpaceEEC
2020-02-22 12:36:59 +01:00
committed by GitHub
parent ab866d6b2e
commit 330c410796
4 changed files with 65 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ module.exports = {
Permissions: require('./util/Permissions'),
Snowflake: require('./util/Snowflake'),
SnowflakeUtil: require('./util/Snowflake'),
SystemChannelFlags: require('./util/SystemChannelFlags'),
Util: Util,
util: Util,
version: require('../package').version,

View File

@@ -10,6 +10,7 @@ const Constants = require('../util/Constants');
const Collection = require('../util/Collection');
const Util = require('../util/Util');
const Snowflake = require('../util/Snowflake');
const SystemChannelFlags = require('../util/SystemChannelFlags');
/**
* Represents a guild (or a server) on Discord.
@@ -185,6 +186,12 @@ class Guild {
this.defaultMessageNotifications = Constants.DefaultMessageNotifications[data.default_message_notifications] ||
data.default_message_notifications;
/**
* The value for the guild's system channel flags
* @type {Readonly<SystemChannelFlags>}
*/
this.systemChannelFlags = new SystemChannelFlags(data.system_channel_flags).freeze();
/**
* The type of premium tier:
* * 0: NONE
@@ -891,6 +898,7 @@ class Guild {
* @property {Base64Resolvable} [banner] The banner of the guild
* @property {GuildMemberResolvable} [owner] The owner of the guild
* @property {Base64Resolvable} [splash] The splash screen of the guild
* @property {SystemChannelFlagsResolvable} [systemChannelFlags] The system channel flags of the guild
*/
/**
@@ -931,6 +939,9 @@ class Guild {
Constants.DefaultMessageNotifications.indexOf(data.defaultMessageNotifications) :
Number(data.defaultMessageNotifications);
}
if (typeof data.systemChannelFlags !== 'undefined') {
_data.system_channel_flags = SystemChannelFlags.resolve(data.systemChannelFlags);
}
return this.client.rest.methods.updateGuild(this, _data, reason);
}
@@ -965,6 +976,16 @@ class Guild {
return this.edit({ defaultMessageNotifications }, reason);
}
/**
* Edits the flags of the default message notifications of the guild.
* @param {SystemChannelFlagsResolvable} systemChannelFlags The new flags for the default message notifications
* @param {string} [reason] Reason for changing the flags of the default message notifications
* @returns {Promise<Guild>}
*/
setSystemChannelFlags(systemChannelFlags, reason) {
return this.edit({ systemChannelFlags }, reason);
}
/**
* Edit the name of the guild.
* @param {string} name The new name of the guild

View File

@@ -0,0 +1,31 @@
const BitField = require('./BitField');
/**
* Data structure that makes it easy to interact with a {@link Guild#systemChannelFlags} bitfield.
* <info>Note that all event message types are enabled by default,
* and by setting their corresponding flags you are disabling them</info>
* @extends {BitField}
*/
class SystemChannelFlags extends BitField {}
/**
* Data that can be resolved to give a sytem channel flag bitfield. This can be:
* * A string (see {@link SystemChannelFlags.FLAGS})
* * A sytem channel flag
* * An instance of SystemChannelFlags
* * An Array of SystemChannelFlagsResolvable
* @typedef {string|number|SystemChannelFlags|SystemChannelFlagsResolvable[]} SystemChannelFlagsResolvable
*/
/**
* Numeric system channel flags. All available properties:
* * `WELCOME_MESSAGE_DISABLED`
* * `BOOST_MESSAGE_DISABLED`
* @type {Object}
*/
SystemChannelFlags.FLAGS = {
WELCOME_MESSAGE_DISABLED: 1 << 0,
BOOST_MESSAGE_DISABLED: 1 << 1,
};
module.exports = SystemChannelFlags;