diff --git a/src/index.js b/src/index.js index 2d776e7c..cbc0d5a7 100644 --- a/src/index.js +++ b/src/index.js @@ -26,6 +26,7 @@ module.exports = { Snowflake: require('./util/Snowflake'), SnowflakeUtil: require('./util/Snowflake'), Structures: require('./util/Structures'), + SystemChannelFlags: require('./util/SystemChannelFlags'), Util: Util, util: Util, version: require('../package.json').version, diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 75925663..987fa38f 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -10,6 +10,7 @@ const Collection = require('../util/Collection'); const Util = require('../util/Util'); const DataResolver = require('../util/DataResolver'); const Snowflake = require('../util/Snowflake'); +const SystemChannelFlags = require('../util/SystemChannelFlags'); const GuildMemberStore = require('../stores/GuildMemberStore'); const RoleStore = require('../stores/RoleStore'); const GuildEmojiStore = require('../stores/GuildEmojiStore'); @@ -275,6 +276,12 @@ class Guild extends Base { this.defaultMessageNotifications = DefaultMessageNotifications[data.default_message_notifications] || data.default_message_notifications; + /** + * The value set for the guild's system channel flags + * @type {Readonly} + */ + this.systemChannelFlags = new SystemChannelFlags(data.system_channel_flags).freeze(); + /** * The maximum amount of members the guild can have * You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter @@ -773,6 +780,7 @@ class Guild extends Base { * @property {Base64Resolvable} [splash] The splash screen of the guild * @property {Base64Resolvable} [banner] The banner of the guild * @property {DefaultMessageNotifications|number} [defaultMessageNotifications] The default message notifications + * @property {SystemChannelFlagsResolvable} [systemChannelFlags] The system channel flags of the guild */ /** @@ -813,6 +821,9 @@ class Guild extends Base { DefaultMessageNotifications.indexOf(data.defaultMessageNotifications) : Number(data.defaultMessageNotifications); } + if (typeof data.systemChannelFlags !== 'undefined') { + _data.systemChannelFlags = SystemChannelFlags.resolve(data.systemChannelFlags); + } return this.client.api.guilds(this.id).patch({ data: _data, reason }) .then(newData => this.client.actions.GuildUpdate.handle(newData).updated); } @@ -839,6 +850,16 @@ class Guild extends Base { } /* eslint-enable max-len */ + /** + * 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} + */ + setSystemChannelFlags(systemChannelFlags, reason) { + return this.edit({ systemChannelFlags }, reason); + } + /** * Edits the name of the guild. * @param {string} name The new name of the guild diff --git a/src/util/SystemChannelFlags.js b/src/util/SystemChannelFlags.js new file mode 100644 index 00000000..14e8fd4f --- /dev/null +++ b/src/util/SystemChannelFlags.js @@ -0,0 +1,33 @@ +'use strict'; + +const BitField = require('./BitField'); + +/** + * Data structure that makes it easy to interact with a {@link Guild#systemChannelFlags} bitfield. + * Note that all event message types are enabled by default, + * and by setting their corresponding flags you are disabling them + * @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; diff --git a/typings/index.d.ts b/typings/index.d.ts index d26160fe..7ab448e7 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -714,6 +714,7 @@ declare module 'discord.js' { public shardID: number; public splash: string | null; public readonly systemChannel: TextChannel | null; + public systemChannelFlags: Readonly; public systemChannelID: Snowflake | null; public vanityURLCode: string | null; public verificationLevel: number; @@ -755,6 +756,7 @@ declare module 'discord.js' { public setRolePositions(rolePositions: RolePosition[]): Promise; public setSplash(splash: Base64Resolvable | null, reason?: string): Promise; public setSystemChannel(systemChannel: ChannelResolvable | null, reason?: string): Promise; + public setSystemChannelFlags(systemChannelFlags: SystemChannelFlagsResolvable, reason?: string): Promise; public setVerificationLevel(verificationLevel: number, reason?: string): Promise; public splashURL(options?: AvatarOptions): string | null; public toJSON(): object; @@ -1368,6 +1370,11 @@ declare module 'discord.js' { static extend(structure: string, extender: (baseClass: typeof Function) => T): T; } + export class SystemChannelFlags extends BitField { + public static FLAGS: Record; + public static resolve(bit?: BitFieldResolvable): number; + } + export class TextChannel extends TextBasedChannel(GuildChannel) { constructor(guild: Guild, data?: object); public messages: MessageStore; @@ -2285,6 +2292,7 @@ declare module 'discord.js' { defaultMessageNotifications?: DefaultMessageNotifications | number; afkChannel?: ChannelResolvable; systemChannel?: ChannelResolvable; + systemChannelFlags?: SystemChannelFlags; afkTimeout?: number; icon?: Base64Resolvable; owner?: GuildMemberResolvable; @@ -2613,6 +2621,11 @@ declare module 'discord.js' { type StringResolvable = string | string[] | any; + type SystemChannelFlagsString = 'WELCOME_MESSAGE_DISABLED' + | 'BOOST_MESSAGE_DISABLED'; + + type SystemChannelFlagsResolvable = BitFieldResolvable; + type TargetUser = number; type UserResolvable = User | Snowflake | Message | GuildMember;