More Guild routes (#418)

This commit is contained in:
Flori 2023-08-26 16:56:18 +02:00 committed by GitHub
commit 04c4d24f9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 77 additions and 5 deletions

View File

@ -360,7 +360,7 @@ impl Guild {
/// ///
/// # Reference: /// # Reference:
/// See <https://discord-userdoccers.vercel.app/resources/guild#modify-guild-member-profile> /// 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, guild_id: Snowflake,
schema: ModifyGuildMemberProfileSchema, schema: ModifyGuildMemberProfileSchema,
user: &mut ChorusUser, user: &mut ChorusUser,

View File

@ -160,4 +160,33 @@ impl types::RoleObject {
.deserialize_response::<RoleObject>(user) .deserialize_response::<RoleObject>(user)
.await .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
}
} }

View File

@ -16,6 +16,8 @@ use crate::types::{
}; };
use bitflags::bitflags; use bitflags::bitflags;
use super::PublicUser;
/// See <https://discord.com/developers/docs/resources/guild> /// See <https://discord.com/developers/docs/resources/guild>
#[derive(Serialize, Deserialize, Debug, Default, Clone, Updateable, Composite)] #[derive(Serialize, Deserialize, Debug, Default, Clone, Updateable, Composite)]
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))] #[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
@ -106,8 +108,7 @@ pub struct Guild {
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq)] #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))] #[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
pub struct GuildBan { pub struct GuildBan {
pub user_id: Snowflake, pub user: PublicUser,
pub guild_id: Snowflake,
pub reason: Option<String>, pub reason: Option<String>,
} }

View File

@ -85,3 +85,28 @@ async fn modify_guild() {
assert_eq!(result.name.unwrap(), "Mycoolguild".to_string()); assert_eq!(result.name.unwrap(), "Mycoolguild".to_string());
common::teardown(bundle).await 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
}

View File

@ -1,4 +1,4 @@
use chorus::types::{self, RoleCreateModifySchema}; use chorus::types::{self, RoleCreateModifySchema, RoleObject};
mod common; mod common;
@ -32,7 +32,7 @@ async fn create_and_get_roles() {
} }
#[tokio::test] #[tokio::test]
async fn get_singular_role() { async fn get_and_delete_role() {
let mut bundle = common::setup().await; let mut bundle = common::setup().await;
let guild_id = bundle.guild.read().unwrap().id; let guild_id = bundle.guild.read().unwrap().id;
let role_id = bundle.role.read().unwrap().id; let role_id = bundle.role.read().unwrap().id;
@ -41,5 +41,22 @@ async fn get_singular_role() {
.await .await
.unwrap(); .unwrap();
assert_eq!(role, same_role); 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 common::teardown(bundle).await
} }