Skip to content

Commit

Permalink
Updates for discord 2020-05-27 (#173)
Browse files Browse the repository at this point in the history
* Update the model with the newest changes.

- Document optional Connection object fields.
discord/discord-api-docs#1466

- Update invite create event fields and example invite object.
discord/discord-api-docs#1438

- New member count fields on get guilds
discord/discord-api-docs#1528

- Add support for `include_roles` when pruning.
discord/discord-api-docs#1563

- Add `max_video_channel_users` to guilds.
discord/discord-api-docs#1512


- Rename guild embed to guild widget.
discord/discord-api-docs#1536

Signed-off-by: Valdemar Erk <valdemar@erk.io>
  • Loading branch information
Erk- authored May 28, 2020
1 parent 5d8f770 commit 09b6e7e
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 60 deletions.
3 changes: 3 additions & 0 deletions cache/in-memory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,9 @@ mod tests {
vanity_url_code: None,
widget_channel_id: None,
widget_enabled: None,
max_video_channel_users: None,
approximate_member_count: None,
approximate_presence_count: None,
};

let cache = InMemoryCache::new();
Expand Down
8 changes: 4 additions & 4 deletions http/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,12 @@ impl Client {
UpdateGuildChannelPositions::new(self, guild_id, channel_positions)
}

pub fn guild_embed(&self, guild_id: GuildId) -> GetGuildEmbed<'_> {
GetGuildEmbed::new(self, guild_id)
pub fn guild_widget(&self, guild_id: GuildId) -> GetGuildWidget<'_> {
GetGuildWidget::new(self, guild_id)
}

pub fn update_guild_embed(&self, guild_id: GuildId) -> UpdateGuildEmbed<'_> {
UpdateGuildEmbed::new(self, guild_id)
pub fn update_guild_widget(&self, guild_id: GuildId) -> UpdateGuildWidget<'_> {
UpdateGuildWidget::new(self, guild_id)
}

pub fn guild_integrations(&self, guild_id: GuildId) -> GetGuildIntegrations<'_> {
Expand Down
17 changes: 16 additions & 1 deletion http/src/request/guild/create_guild_prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use std::{
error::Error,
fmt::{Display, Formatter, Result as FmtResult},
};
use twilight_model::{guild::GuildPrune, id::GuildId};
use twilight_model::{
guild::GuildPrune,
id::{GuildId, RoleId},
};

#[derive(Clone, Debug)]
pub enum CreateGuildPruneError {
Expand All @@ -25,6 +28,7 @@ impl Error for CreateGuildPruneError {}
struct CreateGuildPruneFields {
compute_prune_count: Option<bool>,
days: Option<u64>,
include_roles: Vec<u64>,
}

pub struct CreateGuildPrune<'a> {
Expand All @@ -46,6 +50,15 @@ impl<'a> CreateGuildPrune<'a> {
}
}

/// List of roles to include when pruning.
pub fn include_roles(mut self, roles: impl Iterator<Item = RoleId>) -> Self {
let roles = roles.map(|e| e.0).collect::<Vec<_>>();

self.fields.include_roles = roles;

self
}

pub fn compute_prune_count(mut self, compute_prune_count: bool) -> Self {
self.fields.compute_prune_count.replace(compute_prune_count);

Expand Down Expand Up @@ -88,13 +101,15 @@ impl<'a> CreateGuildPrune<'a> {
compute_prune_count: self.fields.compute_prune_count,
days: self.fields.days,
guild_id: self.guild_id.0,
include_roles: self.fields.include_roles.clone(),
},
))
} else {
Request::from(Route::CreateGuildPrune {
compute_prune_count: self.fields.compute_prune_count,
days: self.fields.days,
guild_id: self.guild_id.0,
include_roles: self.fields.include_roles.clone(),
})
};

Expand Down
16 changes: 16 additions & 0 deletions http/src/request/guild/get_guild.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
use crate::request::prelude::*;
use twilight_model::{guild::Guild, id::GuildId};

#[derive(Default)]
struct GetGuildFields {
with_counts: bool,
}

pub struct GetGuild<'a> {
fields: GetGuildFields,
fut: Option<Pending<'a, Option<Guild>>>,
guild_id: GuildId,
http: &'a Client,
Expand All @@ -10,16 +16,26 @@ pub struct GetGuild<'a> {
impl<'a> GetGuild<'a> {
pub(crate) fn new(http: &'a Client, guild_id: GuildId) -> Self {
Self {
fields: GetGuildFields::default(),
fut: None,
guild_id,
http,
}
}

/// Sets if you want to receive `approximate_member_count` and
/// `approximate_presence_count` in the guld structure.
pub fn with_counts(mut self, with: bool) -> Self {
self.fields.with_counts = with;

self
}

fn start(&mut self) -> Result<()> {
self.fut.replace(Box::pin(self.http.request(Request::from(
Route::GetGuild {
guild_id: self.guild_id.0,
with_counts: self.fields.with_counts,
},
))));

Expand Down
16 changes: 15 additions & 1 deletion http/src/request/guild/get_guild_prune_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use std::{
error::Error,
fmt::{Display, Formatter, Result as FmtResult},
};
use twilight_model::{guild::GuildPrune, id::GuildId};
use twilight_model::{
guild::GuildPrune,
id::{GuildId, RoleId},
};

#[derive(Clone, Debug)]
pub enum GetGuildPruneCountError {
Expand All @@ -24,6 +27,7 @@ impl Error for GetGuildPruneCountError {}
#[derive(Default)]
struct GetGuildPruneCountFields {
days: Option<u64>,
include_roles: Vec<u64>,
}

pub struct GetGuildPruneCount<'a> {
Expand Down Expand Up @@ -64,11 +68,21 @@ impl<'a> GetGuildPruneCount<'a> {
Ok(self)
}

/// List of roles to include when calculating prune count
pub fn include_roles(mut self, roles: impl Iterator<Item = RoleId>) -> Self {
let roles = roles.map(|e| e.0).collect::<Vec<_>>();

self.fields.include_roles = roles;

self
}

fn start(&mut self) -> Result<()> {
self.fut.replace(Box::pin(self.http.request(Request::from(
Route::GetGuildPruneCount {
days: self.fields.days,
guild_id: self.guild_id.0,
include_roles: self.fields.include_roles.clone(),
},
))));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::request::prelude::*;
use twilight_model::{guild::GuildEmbed, id::GuildId};
use twilight_model::{guild::GuildWidget, id::GuildId};

pub struct GetGuildEmbed<'a> {
fut: Option<Pending<'a, Option<GuildEmbed>>>,
pub struct GetGuildWidget<'a> {
fut: Option<Pending<'a, Option<GuildWidget>>>,
guild_id: GuildId,
http: &'a Client,
}

impl<'a> GetGuildEmbed<'a> {
impl<'a> GetGuildWidget<'a> {
pub(crate) fn new(http: &'a Client, guild_id: GuildId) -> Self {
Self {
fut: None,
Expand All @@ -18,7 +18,7 @@ impl<'a> GetGuildEmbed<'a> {

fn start(&mut self) -> Result<()> {
self.fut.replace(Box::pin(self.http.request(Request::from(
Route::GetGuildEmbed {
Route::GetGuildWidget {
guild_id: self.guild_id.0,
},
))));
Expand All @@ -27,4 +27,4 @@ impl<'a> GetGuildEmbed<'a> {
}
}

poll_req!(GetGuildEmbed<'_>, Option<GuildEmbed>);
poll_req!(GetGuildWidget<'_>, Option<GuildWidget>);
14 changes: 7 additions & 7 deletions http/src/request/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ pub mod role;
mod delete_guild;
mod get_guild;
mod get_guild_channels;
mod get_guild_embed;
mod get_guild_invites;
mod get_guild_preview;
mod get_guild_vanity_url;
mod get_guild_voice_regions;
mod get_guild_webhooks;
mod get_guild_widget;
mod update_current_user_nick;
mod update_guild;
mod update_guild_channel_positions;
mod update_guild_embed;
mod update_guild_widget;

pub use self::{
create_guild::CreateGuild, create_guild_channel::CreateGuildChannel,
create_guild_prune::CreateGuildPrune, delete_guild::DeleteGuild, get_audit_log::GetAuditLog,
get_guild::GetGuild, get_guild_channels::GetGuildChannels, get_guild_embed::GetGuildEmbed,
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::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_widget::GetGuildWidget,
update_current_user_nick::UpdateCurrentUserNick, update_guild::UpdateGuild,
update_guild_channel_positions::UpdateGuildChannelPositions,
update_guild_embed::UpdateGuildEmbed,
update_guild_widget::UpdateGuildWidget,
};
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
use crate::request::prelude::*;
use twilight_model::{
guild::GuildEmbed,
guild::GuildWidget,
id::{ChannelId, GuildId},
};

#[derive(Default, Serialize)]
struct UpdateGuildEmbedFields {
struct UpdateGuildWidgetFields {
channel_id: Option<ChannelId>,
enabled: Option<bool>,
}

pub struct UpdateGuildEmbed<'a> {
fields: UpdateGuildEmbedFields,
fut: Option<Pending<'a, GuildEmbed>>,
pub struct UpdateGuildWidget<'a> {
fields: UpdateGuildWidgetFields,
fut: Option<Pending<'a, GuildWidget>>,
guild_id: GuildId,
http: &'a Client,
}

impl<'a> UpdateGuildEmbed<'a> {
impl<'a> UpdateGuildWidget<'a> {
pub(crate) fn new(http: &'a Client, guild_id: GuildId) -> Self {
Self {
fields: UpdateGuildEmbedFields::default(),
fields: UpdateGuildWidgetFields::default(),
fut: None,
guild_id,
http,
Expand All @@ -42,7 +42,7 @@ impl<'a> UpdateGuildEmbed<'a> {
fn start(&mut self) -> Result<()> {
self.fut.replace(Box::pin(self.http.request(Request::from((
serde_json::to_vec(&self.fields)?,
Route::UpdateGuildEmbed {
Route::UpdateGuildWidget {
guild_id: self.guild_id.0,
},
)))));
Expand All @@ -51,4 +51,4 @@ impl<'a> UpdateGuildEmbed<'a> {
}
}

poll_req!(UpdateGuildEmbed<'_>, GuildEmbed);
poll_req!(UpdateGuildWidget<'_>, GuildWidget);
Loading

0 comments on commit 09b6e7e

Please sign in to comment.