Skip to content
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
17 changes: 15 additions & 2 deletions twilight-model/src/oauth/application.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{
ApplicationFlags, InstallParams,
ApplicationFlags, EventWebhookStatus, InstallParams,
application_integration_type::{ApplicationIntegrationMap, ApplicationIntegrationTypeConfig},
team::Team,
};
Expand Down Expand Up @@ -38,6 +38,11 @@ pub struct Application {
pub custom_install_url: Option<String>,
/// Description of the application.
pub description: String,
/// If webhook events are enabled for the app.
pub event_webhooks_status: EventWebhookStatus,
/// Event webhooks URL for the app to receive webhook events.
#[serde(skip_serializing_if = "Option::is_none")]
pub event_webhooks_url: Option<String>,
/// Public flags of the application.
pub flags: Option<ApplicationFlags>,
/// Partial object of the associated guild.
Expand Down Expand Up @@ -98,6 +103,7 @@ pub struct Application {
#[cfg(test)]
mod tests {
use super::{Application, ApplicationFlags, Team, User};
use crate::oauth::EventWebhookStatus;
use crate::{id::Id, test::image_hash};
use serde::{Deserialize, Serialize};
use serde_test::Token;
Expand Down Expand Up @@ -149,6 +155,8 @@ mod tests {
cover_image: Some(image_hash::COVER),
custom_install_url: None,
description: "a pretty cool application".to_owned(),
event_webhooks_url: Some("https://eventwebhooks".into()),
event_webhooks_status: EventWebhookStatus::Enabled,
flags: Some(ApplicationFlags::EMBEDDED),
guild: None,
guild_id: Some(Id::new(1)),
Expand Down Expand Up @@ -207,7 +215,7 @@ mod tests {
&[
Token::Struct {
name: "Application",
len: 22,
len: 24,
},
Token::Str("approximate_guild_count"),
Token::Some,
Expand All @@ -224,6 +232,11 @@ mod tests {
Token::Str(image_hash::COVER_INPUT),
Token::Str("description"),
Token::Str("a pretty cool application"),
Token::Str("event_webhooks_status"),
Token::U8(2),
Token::Str("event_webhooks_url"),
Token::Some,
Token::Str("https://eventwebhooks"),
Token::Str("flags"),
Token::Some,
Token::U64(131_072),
Expand Down
8 changes: 6 additions & 2 deletions twilight-model/src/oauth/current_authorization_information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct CurrentAuthorizationInformation {
mod tests {
use crate::{
id::Id,
oauth::{Application, scope},
oauth::{Application, EventWebhookStatus, scope},
test::image_hash,
util::{Timestamp, datetime::TimestampParseError},
};
Expand Down Expand Up @@ -79,6 +79,8 @@ mod tests {
cover_image: None,
custom_install_url: None,
description: DESCRIPTION.to_owned(),
event_webhooks_url: None,
event_webhooks_status: EventWebhookStatus::Disabled,
flags: None,
guild: None,
guild_id: None,
Expand Down Expand Up @@ -115,7 +117,7 @@ mod tests {
Token::Str("application"),
Token::Struct {
name: "Application",
len: 12,
len: 13,
},
Token::Str("approximate_guild_count"),
Token::Some,
Expand All @@ -129,6 +131,8 @@ mod tests {
Token::Bool(true),
Token::Str("description"),
Token::Str(DESCRIPTION),
Token::Str("event_webhooks_status"),
Token::U8(1),
Token::Str("flags"),
Token::None,
Token::Str("icon"),
Expand Down
38 changes: 38 additions & 0 deletions twilight-model/src/oauth/event_webhook.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use serde::{Deserialize, Serialize};

/// Status indicating whether event webhooks are enabled or disabled for an application.
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[non_exhaustive]
#[serde(from = "u8", into = "u8")]
pub enum EventWebhookStatus {
/// Event webhooks are disabled.
Disabled,
/// Event webhooks are enabled.
Enabled,
/// Event webhooks have been disabled by Discord due to inactivity.
DisabledByDiscord,
/// Variant value is unknown to the library.
Unknown(u8),
}

impl From<u8> for EventWebhookStatus {
fn from(value: u8) -> Self {
match value {
1 => Self::Disabled,
2 => Self::Enabled,
3 => Self::DisabledByDiscord,
_ => Self::Unknown(value),
}
}
}

impl From<EventWebhookStatus> for u8 {
fn from(value: EventWebhookStatus) -> Self {
match value {
EventWebhookStatus::Disabled => 1,
EventWebhookStatus::Enabled => 2,
EventWebhookStatus::DisabledByDiscord => 3,
EventWebhookStatus::Unknown(v) => v,
}
}
}
2 changes: 2 additions & 0 deletions twilight-model/src/oauth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod application;
mod application_flags;
mod application_integration_type;
mod current_authorization_information;
mod event_webhook;
mod install_params;
mod partial_application;

Expand All @@ -15,6 +16,7 @@ pub use self::{
ApplicationIntegrationMap, ApplicationIntegrationType, ApplicationIntegrationTypeConfig,
},
current_authorization_information::CurrentAuthorizationInformation,
event_webhook::EventWebhookStatus,
install_params::InstallParams,
partial_application::PartialApplication,
};