More Guild routes (#418)
This commit is contained in:
commit
b7b8023f11
|
@ -360,7 +360,7 @@ impl Guild {
|
|||
///
|
||||
/// # Reference:
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/guild#modify-guild-member-profile>
|
||||
pub async fn modify_member_profile(
|
||||
pub async fn modify_current_member_profile(
|
||||
guild_id: Snowflake,
|
||||
schema: ModifyGuildMemberProfileSchema,
|
||||
user: &mut ChorusUser,
|
||||
|
|
|
@ -160,4 +160,33 @@ impl types::RoleObject {
|
|||
.deserialize_response::<RoleObject>(user)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Deletes a guild role. Requires the `MANAGE_ROLES` permission. Returns a 204 empty response on success.
|
||||
///
|
||||
/// # Reference:
|
||||
/// See <https://discord.com/developers/docs/resources/guild#delete-guild-role>
|
||||
pub async fn delete_role(
|
||||
user: &mut ChorusUser,
|
||||
guild_id: Snowflake,
|
||||
role_id: Snowflake,
|
||||
audit_log_reason: Option<String>,
|
||||
) -> ChorusResult<()> {
|
||||
let url = format!(
|
||||
"{}/guilds/{}/roles/{}",
|
||||
user.belongs_to.borrow_mut().urls.api,
|
||||
guild_id,
|
||||
role_id
|
||||
);
|
||||
|
||||
let request = ChorusRequest::new(
|
||||
http::Method::DELETE,
|
||||
&url,
|
||||
None,
|
||||
audit_log_reason.as_deref(),
|
||||
None,
|
||||
Some(user),
|
||||
LimitType::Guild(guild_id),
|
||||
);
|
||||
request.handle_request_as_result(user).await
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ use crate::types::{
|
|||
};
|
||||
use bitflags::bitflags;
|
||||
|
||||
use super::PublicUser;
|
||||
|
||||
/// See <https://discord.com/developers/docs/resources/guild>
|
||||
#[derive(Serialize, Deserialize, Debug, Default, Clone, Updateable, Composite)]
|
||||
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
|
||||
|
@ -106,8 +108,7 @@ pub struct Guild {
|
|||
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
|
||||
pub struct GuildBan {
|
||||
pub user_id: Snowflake,
|
||||
pub guild_id: Snowflake,
|
||||
pub user: PublicUser,
|
||||
pub reason: Option<String>,
|
||||
}
|
||||
|
||||
|
|
|
@ -85,3 +85,28 @@ async fn modify_guild() {
|
|||
assert_eq!(result.name.unwrap(), "Mycoolguild".to_string());
|
||||
common::teardown(bundle).await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn guild_remove_member() {
|
||||
let mut bundle = common::setup().await;
|
||||
let channel = bundle.channel.read().unwrap().clone();
|
||||
let mut other_user = bundle.create_user("testuser1312").await;
|
||||
let user = &mut bundle.user;
|
||||
let create_channel_invite_schema = CreateChannelInviteSchema::default();
|
||||
let guild = bundle.guild.read().unwrap().clone();
|
||||
let invite = user
|
||||
.create_channel_invite(create_channel_invite_schema, channel.id)
|
||||
.await
|
||||
.unwrap();
|
||||
other_user.accept_invite(&invite.code, None).await.unwrap();
|
||||
let other_user_id = other_user.object.read().unwrap().id;
|
||||
Guild::remove_member(guild.id, other_user_id, None, &mut bundle.user)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(
|
||||
Guild::remove_member(guild.id, other_user_id, None, &mut bundle.user,)
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
common::teardown(bundle).await
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use chorus::types::{self, RoleCreateModifySchema};
|
||||
use chorus::types::{self, RoleCreateModifySchema, RoleObject};
|
||||
|
||||
mod common;
|
||||
|
||||
|
@ -32,7 +32,7 @@ async fn create_and_get_roles() {
|
|||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_singular_role() {
|
||||
async fn get_and_delete_role() {
|
||||
let mut bundle = common::setup().await;
|
||||
let guild_id = bundle.guild.read().unwrap().id;
|
||||
let role_id = bundle.role.read().unwrap().id;
|
||||
|
@ -41,5 +41,22 @@ async fn get_singular_role() {
|
|||
.await
|
||||
.unwrap();
|
||||
assert_eq!(role, same_role);
|
||||
assert_eq!(
|
||||
chorus::types::RoleObject::get_all(&mut bundle.user, guild_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.len(),
|
||||
2
|
||||
);
|
||||
RoleObject::delete_role(&mut bundle.user, guild_id, role_id, None)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
chorus::types::RoleObject::get_all(&mut bundle.user, guild_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.len(),
|
||||
1
|
||||
);
|
||||
common::teardown(bundle).await
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue