feat: v13 safety alerts channel and mention raid protection

#9073 djs
This commit is contained in:
Elysia
2023-02-12 15:30:49 +07:00
parent 779fc7a5f4
commit f28ea5c031
4 changed files with 63 additions and 0 deletions

View File

@@ -73,6 +73,7 @@ class AutoModerationRule extends Base {
* @property {string[]} allowList The substrings that will be exempt from triggering
* {@link AutoModerationRuleTriggerTypes.KEYWORD} and {@link AutoModerationRuleTriggerTypes.KEYWORD_PRESET}
* @property {?number} mentionTotalLimit The total number of role & user mentions allowed per message
* @property {boolean} mentionRaidProtectionEnabled Whether mention raid protection is enabled
*/
/**
@@ -85,6 +86,7 @@ class AutoModerationRule extends Base {
presets: data.trigger_metadata.presets?.map(preset => AutoModerationRuleKeywordPresetTypes[preset]) ?? [],
allowList: data.trigger_metadata.allow_list ?? [],
mentionTotalLimit: data.trigger_metadata.mention_total_limit ?? null,
mentionRaidProtectionEnabled: data.trigger_metadata.mention_raid_protection_enabled ?? false,
};
}
@@ -234,6 +236,17 @@ class AutoModerationRule extends Base {
return this.edit({ triggerMetadata: { mentionTotalLimit }, reason });
}
/**
* Sets whether to enable mention raid protection for this auto moderation rule.
* @param {boolean} mentionRaidProtectionEnabled
* Whether to enable mention raid protection for this auto moderation rule
* @param {string} [reason] The reason for changing the mention raid protection of this auto moderation rule
* @returns {Promise<AutoModerationRule>}
*/
setMentionRaidProtectionEnabled(mentionRaidProtectionEnabled, reason) {
return this.edit({ triggerMetadata: { ...this.triggerMetadata, mentionRaidProtectionEnabled }, reason });
}
/**
* Sets the actions for this auto moderation rule.
* @param {AutoModerationActionOptions[]} actions The actions of this auto moderation rule

View File

@@ -450,6 +450,16 @@ class Guild extends AnonymousGuild {
this.preferredLocale = data.preferred_locale;
}
if ('safety_alerts_channel_id' in data) {
/**
* The safety alerts channel's id for the guild
* @type {?Snowflake}
*/
this.safetyAlertsChannelId = data.safety_alerts_channel_id;
} else {
this.safetyAlertsChannelId ??= null;
}
if (data.channels) {
this.channels.cache.clear();
for (const rawChannel of data.channels) {
@@ -585,6 +595,15 @@ class Guild extends AnonymousGuild {
return this.client.channels.resolve(this.systemChannelId);
}
/**
* Safety alerts channel for this guild
* @type {?TextChannel}
* @readonly
*/
get safetyAlertsChannel() {
return this.client.channels.resolve(this.safetyAlertsChannelId);
}
/**
* Widget channel for this guild.
* @type {?(TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel)}
@@ -877,6 +896,7 @@ class Guild extends AnonymousGuild {
* @property {?TextChannelResolvable} [rulesChannel] The rules channel of the guild
* @property {?TextChannelResolvable} [publicUpdatesChannel] The community updates channel of the guild
* @property {?string} [preferredLocale] The preferred locale of the guild
* @property {?TextChannelResolvable} [safetyAlertsChannel] The safety alerts channel of the guild
* @property {boolean} [premiumProgressBarEnabled] Whether the guild's premium progress bar is enabled
* @property {?string} [description] The discovery description of the guild
* @property {Features[]} [features] The features of the guild
@@ -966,6 +986,9 @@ class Guild extends AnonymousGuild {
_data.description = data.description;
}
if (typeof data.preferredLocale !== 'undefined') _data.preferred_locale = data.preferredLocale;
if (typeof data.safetyAlertsChannel !== 'undefined') {
_data.safety_alerts_channel_id = this.client.channels.resolveId(data.safetyAlertsChannel);
}
if ('premiumProgressBarEnabled' in data) {
_data.premium_progress_bar_enabled = data.premiumProgressBarEnabled;
}
@@ -1311,6 +1334,21 @@ class Guild extends AnonymousGuild {
return this.edit({ preferredLocale }, reason);
}
/**
* Edits the safety alerts channel of the guild.
* @param {?TextChannelResolvable} safetyAlertsChannel The new safety alerts channel
* @param {string} [reason] Reason for changing the guild's safety alerts channel
* @returns {Promise<Guild>}
* @example
* // Edit the guild safety alerts channel
* guild.setSafetyAlertsChannel(channel)
* .then(updated => console.log(`Updated guild safety alerts channel to ${guild.safetyAlertsChannel.name}`))
* .catch(console.error);
*/
setSafetyAlertsChannel(safetyAlertsChannel, reason) {
return this.edit({ safetyAlertsChannel }, reason);
}
/**
* Edits the enabled state of the guild's premium progress bar.
* @param {boolean} [enabled=true] The new enabled state of the guild's premium progress bar