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

feat(model, http): Add support for guild onboarding #2130

Merged
merged 30 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
82b7cbb
feat(model, http): Add support for guild onboarding
suneettipirneni Feb 9, 2023
3da10d5
fix: make requested changes
suneettipirneni Feb 10, 2023
37d2a44
fix: test
suneettipirneni Feb 10, 2023
18fad87
refactor(gateway, http, model)!: remove deprecated apis (#2132)
zeylahellyer Feb 17, 2023
27b4272
feat(http-ratelimiting)!: hide `http` dependency (#2163)
vilgotf Mar 11, 2023
7b9c602
feat(model)!: reduce size of gateway rest models (#2168)
vilgotf Mar 20, 2023
7057e38
refactor(model)!: remove user profile (#2131)
zeylahellyer Mar 25, 2023
d0876f7
feat(http)!: return errors at finalization (#2171)
zeylahellyer Mar 25, 2023
0b6eea6
Merge branch 'main' into next
itohatweb Apr 24, 2023
97bb9da
fix merge issues
itohatweb Apr 24, 2023
62e2763
Merge branch 'main' of https://github.com/twilight-rs/twilight into f…
suneettipirneni Apr 25, 2023
44b7d80
refactor emoji to be all options
suneettipirneni Apr 25, 2023
9df0721
fix return types and tests
suneettipirneni Apr 25, 2023
d237656
Merge branch 'next' of https://github.com/twilight-rs/twilight into f…
suneettipirneni Apr 25, 2023
aff775f
fix doc
suneettipirneni Apr 25, 2023
3378617
refactor(model, cache, gateway)!: update bitflags crate to v2 (#2199)
Apr 25, 2023
9043358
Revert "refactor emoji to be all options"
suneettipirneni Apr 25, 2023
bebaeb5
fix test
suneettipirneni Apr 25, 2023
a0e7ec0
Merge branch 'next' of https://github.com/twilight-rs/twilight into f…
suneettipirneni Apr 25, 2023
1aa3c7a
remove unrelated changes from main
suneettipirneni Apr 25, 2023
5329961
missed one file
suneettipirneni Apr 25, 2023
e1b5b18
fix test
suneettipirneni Apr 25, 2023
995c697
Revert "Merge branch 'next' of https://github.com/twilight-rs/twiligh…
suneettipirneni Apr 25, 2023
38a56c9
Revert "Merge branch 'next' of https://github.com/twilight-rs/twiligh…
suneettipirneni Apr 25, 2023
82453da
remove unrelated changes
suneettipirneni Apr 25, 2023
e5f2a14
make requested changes
suneettipirneni Apr 26, 2023
1d52d1d
Merge branch 'main' of https://github.com/twilight-rs/twilight into f…
suneettipirneni May 22, 2023
de0c840
make requested changes
suneettipirneni May 22, 2023
9216514
remove conversion
suneettipirneni Jul 1, 2023
bb65a7a
Merge branch 'main' of https://github.com/twilight-rs/twilight into f…
suneettipirneni Jul 1, 2023
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
3 changes: 3 additions & 0 deletions twilight-http-ratelimiting/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ pub enum Path {
GuildsIdMembersSearch(u64),
/// Operating on one of the user's guilds' MFA level.
GuildsIdMfa(u64),
/// Operating on one of the user's guilds' onboarding.
GuildsIdOnboarding(u64),
/// Operating on one of the user's guilds' by previewing it.
GuildsIdPreview(u64),
/// Operating on one of the user's guilds' by pruning members.
Expand Down Expand Up @@ -400,6 +402,7 @@ impl FromStr for Path {
["guilds", id, "members", _] => GuildsIdMembersId(parse_id(id)?),
["guilds", id, "members", _, "roles", _] => GuildsIdMembersIdRolesId(parse_id(id)?),
["guilds", id, "members", "@me", "nick"] => GuildsIdMembersMeNick(parse_id(id)?),
["guilds", id, "onboarding"] => GuildsIdOnboarding(parse_id(id)?),
["guilds", id, "preview"] => GuildsIdPreview(parse_id(id)?),
["guilds", id, "prune"] => GuildsIdPrune(parse_id(id)?),
["guilds", id, "regions"] => GuildsIdRegions(parse_id(id)?),
Expand Down
7 changes: 6 additions & 1 deletion twilight-http/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod interaction;

pub use self::{builder::ClientBuilder, interaction::InteractionClient};

use crate::request::GetCurrentAuthorizationInformation;
use crate::request::{guild::GetGuildOnboarding, GetCurrentAuthorizationInformation};
#[allow(deprecated)]
use crate::{
client::connector::Connector,
Expand Down Expand Up @@ -1231,6 +1231,11 @@ impl Client {
RemoveRoleFromMember::new(self, guild_id, user_id, role_id)
}

/// Retrieves the onboarding data for a guild.
pub const fn guild_onboarding(&self, guild_id: Id<GuildMarker>) -> GetGuildOnboarding<'_> {
GetGuildOnboarding::new(self, guild_id)
}

/// For public guilds, get the guild preview.
///
/// This works even if the user is not in the guild.
Expand Down
69 changes: 69 additions & 0 deletions twilight-http/src/request/guild/get_guild_onboarding.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use std::future::IntoFuture;

use twilight_model::{
guild::onboarding::Onboarding,
id::{marker::GuildMarker, Id},
};

use crate::{
request::{Request, TryIntoRequest},
response::ResponseFuture,
routing::Route,
Client, Error, Response,
};

/// Get the onboarding information for a guild.
///
/// # Examples
///
/// ```no_run
/// use twilight_http::Client;
/// use twilight_model::id::Id;
///
/// # #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let client = Client::new("token".to_owned());
///
/// let guild_id = Id::new(101);
/// let onboarding = client.guild_onboarding(guild_id).await?.model().await?;
///
/// for prompt in onboarding.prompts {
/// println!("Prompt: {}", prompt.title);
/// }
/// # Ok(()) }
/// ```
pub struct GetGuildOnboarding<'a> {
guild_id: Id<GuildMarker>,
http: &'a Client,
}

impl<'a> GetGuildOnboarding<'a> {
pub(crate) const fn new(http: &'a Client, guild_id: Id<GuildMarker>) -> Self {
Self { guild_id, http }
}
}

impl IntoFuture for GetGuildOnboarding<'_> {
type Output = Result<Response<Onboarding>, Error>;

type IntoFuture = ResponseFuture<Onboarding>;

fn into_future(self) -> Self::IntoFuture {
let http = self.http;

match self.try_into_request() {
Ok(request) => http.request(request),
Err(source) => ResponseFuture::error(source),
}
}
}

impl TryIntoRequest for GetGuildOnboarding<'_> {
fn try_into_request(self) -> Result<Request, Error> {
let request = Request::from_route(&Route::GetGuildOnboarding {
guild_id: self.guild_id.get(),
});

Ok(request)
}
}
15 changes: 8 additions & 7 deletions twilight-http/src/request/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod get_audit_log;
mod get_guild;
mod get_guild_channels;
mod get_guild_invites;
mod get_guild_onboarding;
mod get_guild_preview;
mod get_guild_prune_count;
mod get_guild_vanity_url;
Expand All @@ -36,12 +37,12 @@ pub use self::{
create_guild_prune::CreateGuildPrune, delete_guild::DeleteGuild,
get_active_threads::GetActiveThreads, get_audit_log::GetAuditLog, get_guild::GetGuild,
get_guild_channels::GetGuildChannels, get_guild_invites::GetGuildInvites,
get_guild_preview::GetGuildPreview, get_guild_prune_count::GetGuildPruneCount,
get_guild_vanity_url::GetGuildVanityUrl, get_guild_voice_regions::GetGuildVoiceRegions,
get_guild_webhooks::GetGuildWebhooks, get_guild_welcome_screen::GetGuildWelcomeScreen,
get_guild_widget::GetGuildWidget, get_guild_widget_settings::GetGuildWidgetSettings,
update_current_member::UpdateCurrentMember, update_guild::UpdateGuild,
update_guild_channel_positions::UpdateGuildChannelPositions, update_guild_mfa::UpdateGuildMfa,
update_guild_welcome_screen::UpdateGuildWelcomeScreen,
get_guild_onboarding::GetGuildOnboarding, get_guild_preview::GetGuildPreview,
get_guild_prune_count::GetGuildPruneCount, get_guild_vanity_url::GetGuildVanityUrl,
get_guild_voice_regions::GetGuildVoiceRegions, get_guild_webhooks::GetGuildWebhooks,
get_guild_welcome_screen::GetGuildWelcomeScreen, get_guild_widget::GetGuildWidget,
get_guild_widget_settings::GetGuildWidgetSettings, update_current_member::UpdateCurrentMember,
update_guild::UpdateGuild, update_guild_channel_positions::UpdateGuildChannelPositions,
update_guild_mfa::UpdateGuildMfa, update_guild_welcome_screen::UpdateGuildWelcomeScreen,
update_guild_widget_settings::UpdateGuildWidgetSettings,
};
11 changes: 6 additions & 5 deletions twilight-http/src/request/try_into_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ mod private {
},
user::{UpdateCurrentUserVoiceState, UpdateUserVoiceState},
CreateGuild, CreateGuildChannel, CreateGuildPrune, DeleteGuild, GetActiveThreads,
GetAuditLog, GetGuild, GetGuildChannels, GetGuildInvites, GetGuildPreview,
GetGuildPruneCount, GetGuildVanityUrl, GetGuildVoiceRegions, GetGuildWebhooks,
GetGuildWelcomeScreen, GetGuildWidget, GetGuildWidgetSettings, UpdateCurrentMember,
UpdateGuild, UpdateGuildChannelPositions, UpdateGuildMfa, UpdateGuildWelcomeScreen,
UpdateGuildWidgetSettings,
GetAuditLog, GetGuild, GetGuildChannels, GetGuildInvites, GetGuildOnboarding,
GetGuildPreview, GetGuildPruneCount, GetGuildVanityUrl, GetGuildVoiceRegions,
GetGuildWebhooks, GetGuildWelcomeScreen, GetGuildWidget, GetGuildWidgetSettings,
UpdateCurrentMember, UpdateGuild, UpdateGuildChannelPositions, UpdateGuildMfa,
UpdateGuildWelcomeScreen, UpdateGuildWidgetSettings,
},
scheduled_event::{
CreateGuildExternalScheduledEvent, CreateGuildStageInstanceScheduledEvent,
Expand Down Expand Up @@ -191,6 +191,7 @@ mod private {
impl Sealed for GetGuildIntegrations<'_> {}
impl Sealed for GetGuildInvites<'_> {}
impl Sealed for GetGuildMembers<'_> {}
impl Sealed for GetGuildOnboarding<'_> {}
impl Sealed for GetGuildPreview<'_> {}
impl Sealed for GetGuildPruneCount<'_> {}
impl Sealed for GetGuildRoles<'_> {}
Expand Down
19 changes: 19 additions & 0 deletions twilight-http/src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,11 @@ pub enum Route<'a> {
/// The maximum number of members to get.
limit: Option<u16>,
},
/// Route information to get a guild's onboarding information.
GetGuildOnboarding {
/// The ID of the guild to get onboarding information for.
guild_id: u64,
},
/// Route information to get a guild's preview.
GetGuildPreview {
/// The ID of the guild.
Expand Down Expand Up @@ -1176,6 +1181,7 @@ impl<'a> Route<'a> {
| Self::GetGuildIntegrations { .. }
| Self::GetGuildInvites { .. }
| Self::GetGuildMembers { .. }
| Self::GetGuildOnboarding { .. }
| Self::GetGuildPreview { .. }
| Self::GetGuildPruneCount { .. }
| Self::GetGuildRoles { .. }
Expand Down Expand Up @@ -1547,6 +1553,7 @@ impl<'a> Route<'a> {
Self::GetGuildMembers { guild_id, .. } | Self::UpdateCurrentMember { guild_id, .. } => {
Path::GuildsIdMembers(guild_id)
}
Self::GetGuildOnboarding { guild_id } => Path::GuildsIdOnboarding(guild_id),
Self::CreateGuildScheduledEvent { guild_id, .. }
| Self::GetGuildScheduledEvents { guild_id, .. } => {
Path::GuildsIdScheduledEvents(guild_id)
Expand Down Expand Up @@ -2406,6 +2413,12 @@ impl Display for Route<'_> {

Ok(())
}
Route::GetGuildOnboarding { guild_id } => {
f.write_str("guilds/")?;
Display::fmt(guild_id, f)?;

f.write_str("/onboarding")
}
Route::GetGuildPreview { guild_id } => {
f.write_str("guilds/")?;
Display::fmt(guild_id, f)?;
Expand Down Expand Up @@ -4672,4 +4685,10 @@ mod tests {
format!("guilds/{GUILD_ID}/auto-moderation/rules/{AUTO_MODERATION_RULE_ID}")
);
}

#[test]
fn get_guild_onboarding() {
let route = Route::GetGuildOnboarding { guild_id: GUILD_ID };
assert_eq!(route.to_string(), format!("guilds/{GUILD_ID}/onboarding"));
}
}
1 change: 1 addition & 0 deletions twilight-model/src/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
pub mod audit_log;
pub mod auto_moderation;
pub mod invite;
pub mod onboarding;
pub mod scheduled_event;
pub mod template;
pub mod widget;
Expand Down
65 changes: 65 additions & 0 deletions twilight-model/src/guild/onboarding/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//! Types for guild onboarding.

mod option;
mod prompt;
mod prompt_type;

suneettipirneni marked this conversation as resolved.
Show resolved Hide resolved
use crate::id::marker::GuildMarker;
use crate::id::{marker::ChannelMarker, Id};
suneettipirneni marked this conversation as resolved.
Show resolved Hide resolved
use serde::{Deserialize, Serialize};

pub use self::{
option::OnboardingPromptOption, prompt::OnboardingPrompt, prompt_type::OnboardingPromptType,
};

/// The onboarding data for a guild.
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct Onboarding {
/// Channel ids that new members get opted into automatically
suneettipirneni marked this conversation as resolved.
Show resolved Hide resolved
pub default_channel_ids: Vec<Id<ChannelMarker>>,
/// Whether the guild has enabled onboarding
suneettipirneni marked this conversation as resolved.
Show resolved Hide resolved
pub enabled: bool,
/// The id of the guild this onboarding is a part of.
suneettipirneni marked this conversation as resolved.
Show resolved Hide resolved
pub guild_id: Id<GuildMarker>,
/// The array of [`OnboardingPrompt`]s for the guild onboarding flow.
suneettipirneni marked this conversation as resolved.
Show resolved Hide resolved
pub prompts: Vec<OnboardingPrompt>,
}

#[cfg(test)]
mod tests {
use super::Onboarding;
use crate::id::{marker::GuildMarker, Id};
use serde_test::Token;

#[test]
fn onboarding() {
let onboarding = Onboarding {
default_channel_ids: Vec::new(),
enabled: true,
guild_id: Id::<GuildMarker>::new(123_456_789),
suneettipirneni marked this conversation as resolved.
Show resolved Hide resolved
prompts: Vec::new(),
};

serde_test::assert_tokens(
&onboarding,
&[
Token::Struct {
name: "Onboarding",
len: 4,
},
Token::Str("default_channel_ids"),
Token::Seq { len: Some(0) },
Token::SeqEnd,
Token::Str("enabled"),
Token::Bool(true),
Token::Str("guild_id"),
Token::NewtypeStruct { name: "Id" },
Token::Str("123456789"),
Token::Str("prompts"),
Token::Seq { len: Some(0) },
Token::SeqEnd,
Token::StructEnd,
],
)
}
}
Loading