backport: DefaultMessageNotifications

This commit is contained in:
Lewdcario
2018-07-17 21:32:24 -05:00
parent 1d9edec567
commit 0702a0fcda
2 changed files with 35 additions and 0 deletions

View File

@@ -74,6 +74,7 @@ class Guild {
}
}
/* eslint-disable complexity */
/**
* Sets up the guild.
* @param {*} data The raw data of the guild
@@ -176,6 +177,13 @@ class Guild {
*/
this.joinedTimestamp = data.joined_at ? new Date(data.joined_at).getTime() : this.joinedTimestamp;
/**
* The value set for a guild's default message notifications
* @type {DefaultMessageNotifications|number}
*/
this.defaultMessageNotifications = Constants.DefaultMessageNotifications[data.default_message_notifications] ||
data.default_message_notifications;
this.id = data.id;
this.available = !data.unavailable;
this.features = data.features || this.features || [];
@@ -688,6 +696,11 @@ class Guild {
if (typeof data.explicitContentFilter !== 'undefined') {
_data.explicit_content_filter = Number(data.explicitContentFilter);
}
if (typeof data.defaultMessageNotifications !== 'undefined') {
_data.default_message_notifications = typeof data.defaultMessageNotifications === 'string' ?
Constants.DefaultMessageNotifications.indexOf(data.defaultMessageNotifications) :
Number(data.defaultMessageNotifications);
}
return this.client.rest.methods.updateGuild(this, _data, reason);
}
@@ -701,6 +714,17 @@ class Guild {
return this.edit({ explicitContentFilter }, reason);
}
/* eslint-disable max-len */
/**
* Edits the setting of the default message notifications of the guild.
* @param {DefaultMessageNotifications|number} defaultMessageNotifications The new setting for the default message notifications
* @param {string} [reason] Reason for changing the setting of the default message notifications
* @returns {Promise<Guild>}
*/
setDefaultMessageNotifications(defaultMessageNotifications, reason) {
return this.edit({ defaultMessageNotifications }, reason);
}
/**
* Edit the name of the guild.
* @param {string} name The new name of the guild

View File

@@ -815,3 +815,14 @@ exports.APIErrors = {
INVITE_ACCEPTED_TO_GUILD_NOT_CONTANING_BOT: 50036,
REACTION_BLOCKED: 90001,
};
/**
* The value set for a guild's default message notifications, e.g. `ALL`. Here are the available types:
* * ALL
* * MENTIONS
* @typedef {string} DefaultMessageNotifications
*/
exports.DefaultMessageNotifications = [
'ALL',
'MENTIONS',
];