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 support for incident actions #3079

Draft
wants to merge 2 commits into
base: current
Choose a base branch
from
Draft
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
50 changes: 50 additions & 0 deletions src/builder/edit_guild_incident_actions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#[cfg(feature = "http")]
use crate::http::Http;
#[cfg(feature = "http")]
use crate::internal::prelude::*;
use crate::model::prelude::*;

/// A builder for editing guild incident actions.
///
/// [Discord's docs]: https://github.com/discord/discord-api-docs/pull/6396
#[derive(Clone, Debug, Default, Serialize)]
#[must_use]
pub struct EditGuildIncidentActions {
invites_disabled_until: Option<Timestamp>,
dms_disabled_until: Option<Timestamp>,
}

impl EditGuildIncidentActions {
pub fn new() -> Self {
Self::default()
}

/// Sets the time invites to the guild will be disabled until. Must be no further than 1 day in
/// the future.
pub fn invites_disabled_until(mut self, timestamp: Timestamp) -> Self {
self.invites_disabled_until = Some(timestamp);
self
}

/// Sets the time dms for users within the guild will be disabled until. Must be no further
/// than 1 day in the future.
pub fn dms_disabled_until(mut self, timestamp: Timestamp) -> Self {
self.dms_disabled_until = Some(timestamp);
self
}

/// Modifies the guild's incident actions.
///
///
/// # Errors
///
/// Returns [`Error::Http`] if invalid data is given. See [Discord's docs] for more details.
///
/// May also return [`Error::Json`] if there is an error in deserializing the API response.
///
/// [Discord's docs]: https://github.com/discord/discord-api-docs/pull/6396
#[cfg(feature = "http")]
pub async fn execute(self, http: &Http, guild_id: GuildId) -> Result<IncidentsData> {
http.edit_guild_incident_actions(guild_id, &self).await
}
}
4 changes: 4 additions & 0 deletions src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ mod create_webhook;
mod edit_automod_rule;
mod edit_channel;
mod edit_guild;
#[cfg(feature = "unstable_discord_api")]
mod edit_guild_incident_actions;
mod edit_guild_welcome_screen;
mod edit_guild_widget;
mod edit_interaction_response;
Expand Down Expand Up @@ -102,6 +104,8 @@ pub use create_webhook::*;
pub use edit_automod_rule::*;
pub use edit_channel::*;
pub use edit_guild::*;
#[cfg(feature = "unstable_discord_api")]
pub use edit_guild_incident_actions::*;
pub use edit_guild_welcome_screen::*;
pub use edit_guild_widget::*;
pub use edit_interaction_response::*;
Expand Down
20 changes: 20 additions & 0 deletions src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4779,6 +4779,26 @@ impl Http {
.await
}

/// Modify the guild's incident actions.
#[cfg(feature = "unstable_discord_api")]
pub async fn edit_guild_incident_actions(
&self,
guild_id: GuildId,
map: &impl serde::Serialize,
) -> Result<IncidentsData> {
self.fire(Request {
body: Some(to_vec(map)?),
multipart: None,
headers: None,
method: LightMethod::Put,
route: Route::GuildIncidentActions {
guild_id,
},
params: None,
})
.await
}

/// Starts typing in the specified [`Channel`] for an indefinite period of time.
///
/// Returns [`Typing`] that is used to trigger the typing. [`Typing::stop`] must be called on
Expand Down
4 changes: 4 additions & 0 deletions src/http/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ routes! ('a, {
api!("/guilds/{}/threads/active", guild_id),
Some(RatelimitingKind::PathAndId(guild_id.into()));

GuildIncidentActions { guild_id: GuildId },
api!("/guilds/{}/incident-actions", guild_id),
Some(RatelimitingKind::PathAndId(guild_id.into()));

Guilds,
api!("/guilds"),
Some(RatelimitingKind::Path);
Expand Down
21 changes: 21 additions & 0 deletions src/model/guild/guild_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::fmt;
#[cfg(feature = "model")]
use futures::stream::Stream;

#[cfg(all(feature = "unstable_discord_api", feature = "model"))]
use crate::builder::EditGuildIncidentActions;
#[cfg(feature = "model")]
use crate::builder::{
AddMember,
Expand Down Expand Up @@ -1695,6 +1697,25 @@ impl GuildId {
pub async fn get_active_threads(self, http: impl AsRef<Http>) -> Result<ThreadsData> {
http.as_ref().get_guild_active_threads(self).await
}

/// Edits the guild incident actions
///
/// # Errors
///
/// Returns [`Error::Http`] if invalid data is given. See [Discord's docs] for more details.
///
/// May also return [`Error::Json`] if there is an error in deserializing the API response.
///
/// [Discord's docs]: https://github.com/discord/discord-api-docs/pull/6396
#[cfg(feature = "unstable_discord_api")]
pub async fn edit_guild_incident_actions(
self,
http: &Http,
guild_id: GuildId,
builder: EditGuildIncidentActions,
) -> Result<IncidentsData> {
builder.execute(http, guild_id).await
}
}

impl From<PartialGuild> for GuildId {
Expand Down
44 changes: 44 additions & 0 deletions src/model/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub use self::role::*;
pub use self::scheduled_event::*;
pub use self::system_channel::*;
pub use self::welcome_screen::*;
#[cfg(all(feature = "unstable_discord_api", feature = "model"))]
use crate::builder::EditGuildIncidentActions;
#[cfg(feature = "model")]
use crate::builder::{
AddMember,
Expand Down Expand Up @@ -288,6 +290,11 @@ pub struct Guild {
/// The stage instances in this guild.
#[serde(rename = "guild_scheduled_events")]
pub scheduled_events: Vec<ScheduledEvent>,
/// the id of the channel where this guild will recieve safety alerts.
pub safety_alerts_channel_id: Option<ChannelId>,
/// The incidents data for this guild, if any.
#[cfg(feature = "unstable_discord_api")]
pub incidents_data: Option<IncidentsData>,
}

#[cfg(feature = "model")]
Expand Down Expand Up @@ -2541,6 +2548,25 @@ impl Guild {
pub async fn get_active_threads(&self, http: impl AsRef<Http>) -> Result<ThreadsData> {
self.id.get_active_threads(http).await
}

/// Edits the guild incident actions
///
/// # Errors
///
/// Returns [`Error::Http`] if invalid data is given. See [Discord's docs] for more details.
///
/// May also return [`Error::Json`] if there is an error in deserializing the API response.
///
/// [Discord's docs]: https://github.com/discord/discord-api-docs/pull/6396
#[cfg(feature = "unstable_discord_api")]
pub async fn edit_guild_incident_actions(
self,
http: &Http,
guild_id: GuildId,
builder: EditGuildIncidentActions,
) -> Result<IncidentsData> {
builder.execute(http, guild_id).await
}
}

#[cfg(feature = "model")]
Expand Down Expand Up @@ -2862,6 +2888,24 @@ enum_number! {
}
}

/// The [`Guild`]'s incident's data.
///
/// [Discord docs](https://github.com/discord/discord-api-docs/pull/6396).
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[cfg(feature = "unstable_discord_api")]
#[non_exhaustive]
pub struct IncidentsData {
/// The time that invites get enabled again.
pub invites_disabled_until: Option<Timestamp>,
/// The time that dms get enabled again.
pub dms_disabled_until: Option<Timestamp>,
/// The time when elevated dm activity was triggered.
pub dm_spam_detected_at: Option<Timestamp>,
/// The time when raid alerts were triggered.
pub raid_detected_at: Option<Timestamp>,
}

#[cfg(test)]
mod test {
#[cfg(feature = "model")]
Expand Down
10 changes: 10 additions & 0 deletions src/model/guild/partial_guild.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use serde::Serialize;

#[cfg(feature = "unstable_discord_api")]
use super::IncidentsData;
#[cfg(feature = "model")]
use crate::builder::{
CreateChannel,
Expand Down Expand Up @@ -174,6 +176,11 @@ pub struct PartialGuild {
pub stickers: HashMap<StickerId, Sticker>,
/// Whether the guild has the boost progress bar enabled
pub premium_progress_bar_enabled: bool,
/// the id of the channel where this guild will recieve safety alerts.
pub safety_alerts_channel_id: Option<ChannelId>,
/// The incidents data for this guild, if any.
#[cfg(feature = "unstable_discord_api")]
pub incidents_data: Option<IncidentsData>,
}

#[cfg(feature = "model")]
Expand Down Expand Up @@ -1618,6 +1625,9 @@ impl From<Guild> for PartialGuild {
preferred_locale: guild.preferred_locale,
max_stage_video_channel_users: guild.max_stage_video_channel_users,
premium_progress_bar_enabled: guild.premium_progress_bar_enabled,
safety_alerts_channel_id: guild.safety_alerts_channel_id,
#[cfg(feature = "unstable_discord_api")]
incidents_data: guild.incidents_data,
}
}
}
Loading