Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Guild join raid and Moderation rule mention raid protection #1031

Merged
merged 3 commits into from
Dec 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Discord/Parts/Guild/AutoModeration/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @property-read User|null $creator The user which first created this rule.
* @property int $event_type The rule event type.
* @property int $trigger_type The rule trigger type.
* @property object $trigger_metadata The rule trigger metadata (may contain `keyword_filter`, `regex_patterns`, `presets`, `allow_list` and `mention_total_limit`).
* @property object $trigger_metadata The rule trigger metadata (may contain `keyword_filter`, `regex_patterns`, `presets`, `allow_list`, `mention_total_limit` and `mention_raid_protection_enabled`).
* @property Collection|Action[] $actions The actions which will execute when the rule is triggered.
* @property bool $enabled Whether the rule is enabled.
* @property Collection|Roles[] $exempt_roles The role ids that should not be affected by the rule (Maximum of 20).
Expand Down
18 changes: 14 additions & 4 deletions src/Discord/Parts/Guild/Guild.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
* @property-read bool $feature_partnered Guild is partnered.
* @property-read bool $feature_preview_enabled Guild can be previewed before joining via membership screening or the directory.
* @property-read bool $feature_private_threads Guild has access to create private threads.
* @property-read bool $feature_raid_alerts_enabled Guild has enabled alerts for join raids in the configured safety alerts channel.
* @property-read bool $feature_role_icons Guild is able to set role icons.
* @property-read bool $feature_role_subscriptions_available_for_purchase Guild has role subscriptions that can be purchased.
* @property-read bool $feature_role_subscriptions_enabled Guild has enabled role subscriptions.
Expand Down Expand Up @@ -128,6 +129,7 @@
* @property int $nsfw_level The guild NSFW level.
* @property StickerRepository $stickers Custom guild stickers.
* @property bool $premium_progress_bar_enabled Whether the guild has the boost progress bar enabled.
* @property string|null $safety_alerts_channel_id The id of the channel where admins and moderators of Community guilds receive safety alerts from Discord.
*
* @property Carbon|null $joined_at A timestamp of when the current user joined the guild.
* @property bool|null $large Whether the guild is considered 'large' (over 250 members).
Expand Down Expand Up @@ -225,6 +227,7 @@ class Guild extends Part
'welcome_screen',
'nsfw_level',
'premium_progress_bar_enabled',
'safety_alerts_channel_id',

// events
'joined_at',
Expand Down Expand Up @@ -263,6 +266,7 @@ class Guild extends Part
'feature_partnered',
'feature_preview_enabled',
'feature_private_threads',
'feature_raid_alerts_enabled',
'feature_role_icons',
'feature_role_subscriptions_available_for_purchase',
'feature_role_subscriptions_enabled',
Expand Down Expand Up @@ -665,6 +669,11 @@ protected function getFeaturePrivateThreadsAttribute(): bool
return in_array('PRIVATE_THREADS', $this->features);
}

protected function getFeatureRaidAlertsEnabledAttribute(): bool
{
return in_array('RAID_ALERTS_ENABLED', $this->features);
}

protected function getFeatureRoleIconsAttribute(): bool
{
return in_array('ROLE_ICONS', $this->features);
Expand Down Expand Up @@ -1508,7 +1517,7 @@ public function updateMFALevel(int $level, ?string $reason = null): ExtendedProm
* @throws \RuntimeException Guild feature is already set.
* @throws NoPermissionsException Missing various permissions:
* administrator for COMMUNITY or DISCOVERABLE.
* manage_guild for INVITES_DISABLED.
* manage_guild for INVITES_DISABLED or RAID_ALERTS_ENABLED.
*
* @return ExtendedPromiseInterface<self> This guild.
*/
Expand All @@ -1518,14 +1527,14 @@ public function setFeatures(array $features, ?string $reason = null): ExtendedPr
if ((isset($features['COMMUNITY']) || isset($features['DISCOVERABLE'])) && ! $botperms->administrator) {
return reject(new NoPermissionsException('You do not have administrator permission to modify the guild feature COMMUNITY or DISCOVERABLE.'));
}
if (isset($features['INVITES_DISABLED']) && ! $botperms->manage_guild) {
return reject(new NoPermissionsException('You do not have manage guild permission to modify the guild feature INVITES_DISABLED.'));
if ((isset($features['INVITES_DISABLED']) || isset($features['RAID_ALERTS_ENABLED'])) && ! $botperms->manage_guild) {
return reject(new NoPermissionsException('You do not have manage guild permission to modify the guild feature INVITES_DISABLED or RAID_ALERTS_ENABLED.'));
}
}

$setFeatures = $this->features;
foreach ($features as $feature => $set) {
if (! in_array($feature, ['COMMUNITY', 'INVITES_DISABLED', 'DISCOVERABLE'])) {
if (! in_array($feature, ['COMMUNITY', 'INVITES_DISABLED', 'DISCOVERABLE', 'RAID_ALERTS_ENABLED'])) {
return reject(new \OutOfRangeException("Guild feature {$feature} is not mutable"));
}
$featureIdx = array_search($feature, $setFeatures);
Expand Down Expand Up @@ -1605,6 +1614,7 @@ public function getUpdatableAttributes(): array
'preferred_locale' => $this->preferred_locale ?? null,
'description' => $this->description ?? null,
'premium_progress_bar_enabled' => $this->premium_progress_bar_enabled,
'safety_alerts_channel_id' => $this->safety_alerts_channel_id,
];
}

Expand Down