Skip to content
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
4 changes: 2 additions & 2 deletions examples/testing/src/model_type_sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ pub fn print_ranking() {
("InviteCreateEvent", std::mem::size_of::<InviteCreateEvent>()),
("InviteDeleteEvent", std::mem::size_of::<InviteDeleteEvent>()),
("InviteGuild", std::mem::size_of::<InviteGuild>()),
("InviteStageInstance", std::mem::size_of::<InviteStageInstance>()),
("InviteMetadata", std::mem::size_of::<InviteMetadata>()),
("InviteRole", std::mem::size_of::<InviteRole>()),
("Maintenance", std::mem::size_of::<Maintenance>()),
("Member", std::mem::size_of::<Member>()),
("Message", std::mem::size_of::<Message>()),
Expand Down Expand Up @@ -154,7 +155,6 @@ pub fn print_ranking() {
("ReadyEvent", std::mem::size_of::<ReadyEvent>()),
("ResolvedOption", std::mem::size_of::<ResolvedOption>()),
("ResumedEvent", std::mem::size_of::<ResumedEvent>()),
("RichInvite", std::mem::size_of::<RichInvite>()),
("Role", std::mem::size_of::<Role>()),
("RoleId", std::mem::size_of::<RoleId>()),
("RoleTags", std::mem::size_of::<RoleTags>()),
Expand Down
54 changes: 28 additions & 26 deletions src/builder/create_invite.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::borrow::Cow;

#[cfg(feature = "http")]
use crate::http::Http;
#[cfg(feature = "http")]
use crate::internal::prelude::*;
use crate::model::prelude::*;

/// A builder to create a [`RichInvite`] for use via [`ChannelId::create_invite`].
/// A builder to create an [`Invite`] for use via [`ChannelId::create_invite`].
///
/// This is a structured and cleaner way of creating an invite, as all parameters are optional.
///
Expand Down Expand Up @@ -41,6 +43,8 @@ pub struct CreateInvite<'a> {
target_user_id: Option<UserId>,
#[serde(skip_serializing_if = "Option::is_none")]
target_application_id: Option<ApplicationId>,
#[serde(skip_serializing_if = "Option::is_none")]
role_ids: Option<Cow<'a, [RoleId]>>,

#[serde(skip)]
audit_log_reason: Option<&'a str>,
Expand All @@ -52,27 +56,23 @@ impl<'a> CreateInvite<'a> {
Self::default()
}

/// The duration that the invite will be valid for.
///
/// Set to `0` for an invite which does not expire after an amount of time.
/// The duration of the invite in seconds before expiry.
///
/// Defaults to `86400`, or 24 hours.
/// Between `0` (never) and `604800` (7 days). Defaults to `86400` (24 hours).
pub fn max_age(mut self, max_age: u32) -> Self {
self.max_age = Some(max_age);
self
}

/// The number of uses that the invite will be valid for.
/// The maximum number of uses for the invite.
///
/// Set to `0` for an invite which does not expire after a number of uses.
///
/// Defaults to `0`.
/// Between `0` (unlimited) and `100`. Defaults to `0`.
pub fn max_uses(mut self, max_uses: u8) -> Self {
self.max_uses = Some(max_uses);
self
}

/// Whether an invite grants a temporary membership.
/// Whether the invite only grants temporary membership.
///
/// Defaults to `false`.
pub fn temporary(mut self, temporary: bool) -> Self {
Expand All @@ -94,34 +94,36 @@ impl<'a> CreateInvite<'a> {
self
}

/// The ID of the user whose stream to display for this invite, required if `target_type` is
/// `Stream`
/// The user must be streaming in the channel.
/// The [`UserId`] of the user whose stream to display for this invite.
///
/// Required if `target_type` is `Stream`. The user must be streaming in the channel.
pub fn target_user_id(mut self, target_user_id: UserId) -> Self {
self.target_user_id = Some(target_user_id);
self
}

/// The ID of the embedded application to open for this invite, required if `target_type` is
/// `EmmbeddedApplication`.
/// The ID of the embedded application to open for this invite.
///
/// The application must have the `EMBEDDED` flag.
/// Required if `target_type` is `EmmbeddedApplication`. The application must have the
/// [`ApplicationFlags::EMBEDDED`] flag.
///
/// When sending an invite with this value, the first user to use the invite will have to click
/// on the URL, that will enable the buttons in the embed.
/// Some examples of popular embedded applications:
///
/// These are some of the known applications which have the flag:
///
/// betrayal: `773336526917861400`
/// youtube: `755600276941176913`
/// fishing: `814288819477020702`
/// poker: `755827207812677713`
/// chess: `832012774040141894`
/// Watch Together: `880218394199220334`
/// Wordle: `1211781489931452447`
/// Poker Night: `755827207812677713`
/// Chess in the Park: `832012774040141894`
pub fn target_application_id(mut self, target_application_id: ApplicationId) -> Self {
self.target_application_id = Some(target_application_id);
self
}

/// The [`RoleId`]s for roles in the guild given to the users that accept this invite.
pub fn role_ids(mut self, role_ids: impl Into<Cow<'a, [RoleId]>>) -> Self {
self.role_ids = Some(role_ids.into());
self
}

/// Sets the request's audit log reason.
pub fn audit_log_reason(mut self, reason: &'a str) -> Self {
self.audit_log_reason = Some(reason);
Expand All @@ -139,7 +141,7 @@ impl<'a> CreateInvite<'a> {
///
/// [Create Instant Invite]: Permissions::CREATE_INSTANT_INVITE
#[cfg(feature = "http")]
pub async fn execute(self, http: &Http, channel_id: ChannelId) -> Result<RichInvite> {
pub async fn execute(self, http: &Http, channel_id: ChannelId) -> Result<Invite> {
http.create_invite(channel_id, &self, self.audit_log_reason).await
}
}
16 changes: 6 additions & 10 deletions src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,13 +722,13 @@ impl Http {
self.wind(request).await
}

/// Creates a [`RichInvite`] for the given [channel][`GuildChannel`].
/// Creates an [`Invite`] for the given [channel][`GuildChannel`].
pub async fn create_invite(
&self,
channel_id: ChannelId,
map: &impl serde::Serialize,
audit_log_reason: Option<&str>,
) -> Result<RichInvite> {
) -> Result<Invite> {
let body = to_vec(map)?;

self.fire(Request {
Expand Down Expand Up @@ -2621,7 +2621,7 @@ impl Http {
}

/// Gets all invites for a channel.
pub async fn get_channel_invites(&self, channel_id: ChannelId) -> Result<Vec<RichInvite>> {
pub async fn get_channel_invites(&self, channel_id: ChannelId) -> Result<Vec<Invite>> {
self.fire(Request {
body: None,
multipart: None,
Expand Down Expand Up @@ -3401,7 +3401,7 @@ impl Http {
}

/// Gets all invites to a guild.
pub async fn get_guild_invites(&self, guild_id: GuildId) -> Result<Vec<RichInvite>> {
pub async fn get_guild_invites(&self, guild_id: GuildId) -> Result<Vec<Invite>> {
self.fire(Request {
body: None,
multipart: None,
Expand Down Expand Up @@ -3801,18 +3801,14 @@ impl Http {
&self,
code: &str,
member_counts: bool,
expiration: bool,
event_id: Option<ScheduledEventId>,
) -> Result<Invite> {
let (member_counts_str, expiration_str, event_id_str);
let mut params = ArrayVec::<_, 3>::new();
let (member_counts_str, event_id_str);
let mut params = ArrayVec::<_, 2>::new();

member_counts_str = member_counts.to_arraystring();
params.push(("with_counts", member_counts_str.as_str()));

expiration_str = expiration.to_arraystring();
params.push(("with_expiration", &expiration_str));

if let Some(event_id) = event_id {
event_id_str = event_id.to_arraystring();
params.push(("guild_scheduled_event_id", &event_id_str));
Expand Down
4 changes: 2 additions & 2 deletions src/model/channel/channel_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl ChannelId {
/// Returns [`Error::Http`] if the current user lacks permission or if invalid data is given.
///
/// [Create Instant Invite]: Permissions::CREATE_INSTANT_INVITE
pub async fn create_invite(self, http: &Http, builder: CreateInvite<'_>) -> Result<RichInvite> {
pub async fn create_invite(self, http: &Http, builder: CreateInvite<'_>) -> Result<Invite> {
builder.execute(http, self).await
}

Expand Down Expand Up @@ -215,7 +215,7 @@ impl ChannelId {
/// Returns [`Error::Http`] if the current user lacks permission.
///
/// [Manage Channels]: Permissions::MANAGE_CHANNELS
pub async fn invites(self, http: &Http) -> Result<Vec<RichInvite>> {
pub async fn invites(self, http: &Http) -> Result<Vec<Invite>> {
http.get_channel_invites(self).await
}

Expand Down
6 changes: 4 additions & 2 deletions src/model/guild/guild_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,15 +1016,17 @@ impl GuildId {

/// Gets all of the guild's invites.
///
/// Requires the [Manage Guild] permission.
/// Requires the [Manage Guild] or [View Audit Log] permission. [`InviteMetadata`] is only
/// included with the [Manage Guild] permission.
///
/// # Errors
///
/// Returns [`Error::Http`] if the current user lacks permission, also may return
/// [`Error::Json`] if there is an error in deserializing the API response.
///
/// [Manage Guild]: Permissions::MANAGE_GUILD
pub async fn invites(self, http: &Http) -> Result<Vec<RichInvite>> {
/// [View Audit Log]: Permissions::VIEW_AUDIT_LOG
pub async fn invites(self, http: &Http) -> Result<Vec<Invite>> {
http.get_guild_invites(self).await
}

Expand Down
Loading
Loading