Compare commits

..

No commits in common. "854c9820ef9938239a10ee776cf90a0b7e44621c" and "2b69035ec7187527e8476dcd26ec29b3d1e408f6" have entirely different histories.

11 changed files with 73 additions and 130 deletions

View File

@ -4,10 +4,7 @@
use std::sync::{Arc, RwLock};
#[allow(unused_imports)]
pub use login::*;
#[allow(unused_imports)]
pub use register::*;
use crate::gateway::Gateway;

View File

@ -2,7 +2,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#![allow(unused_imports)]
pub use channels::*;
pub use messages::*;
pub use permissions::*;

View File

@ -18,25 +18,6 @@ use crate::types::{
use crate::types::{GuildBan, Snowflake};
impl Guild {
/// Fetches a guild by its id.
///
/// # Reference
/// See <https://discord-userdoccers.vercel.app/resources/guild#get-guild>
pub async fn get(guild_id: Snowflake, user: &mut ChorusUser) -> ChorusResult<Guild> {
let chorus_request = ChorusRequest {
request: Client::new()
.get(format!(
"{}/guilds/{}",
user.belongs_to.read().unwrap().urls.api,
guild_id
))
.header("Authorization", user.token()),
limit_type: LimitType::Guild(guild_id),
};
let response = chorus_request.deserialize_response::<Guild>(user).await?;
Ok(response)
}
/// Creates a new guild.
///
/// # Reference
@ -57,35 +38,6 @@ impl Guild {
chorus_request.deserialize_response::<Guild>(user).await
}
/// Modify a guild's settings.
///
/// Requires the [MANAGE_GUILD](crate::types::PermissionFlags::MANAGE_GUILD) permission.
///
/// Returns the updated guild.
///
/// # Reference
/// <https://discord-userdoccers.vercel.app/resources/guild#modify-guild>
pub async fn modify(
guild_id: Snowflake,
schema: GuildModifySchema,
user: &mut ChorusUser,
) -> ChorusResult<Guild> {
let chorus_request = ChorusRequest {
request: Client::new()
.patch(format!(
"{}/guilds/{}",
user.belongs_to.read().unwrap().urls.api,
guild_id,
))
.header("Authorization", user.token())
.header("Content-Type", "application/json")
.body(to_string(&schema).unwrap()),
limit_type: LimitType::Guild(guild_id),
};
let response = chorus_request.deserialize_response::<Guild>(user).await?;
Ok(response)
}
/// Deletes a guild by its id.
///
/// User must be the owner.
@ -175,11 +127,77 @@ impl Guild {
};
}
/// Returns a guild preview object for the given guild ID.
///
/// If the user is not in the guild, the guild must be discoverable.
/// Fetches a guild by its id.
///
/// # Reference
/// See <https://discord-userdoccers.vercel.app/resources/guild#get-guild>
pub async fn get(guild_id: Snowflake, user: &mut ChorusUser) -> ChorusResult<Guild> {
let chorus_request = ChorusRequest {
request: Client::new()
.get(format!(
"{}/guilds/{}",
user.belongs_to.read().unwrap().urls.api,
guild_id
))
.header("Authorization", user.token()),
limit_type: LimitType::Guild(guild_id),
};
let response = chorus_request.deserialize_response::<Guild>(user).await?;
Ok(response)
}
pub async fn create_ban(
guild_id: Snowflake,
user_id: Snowflake,
audit_log_reason: Option<String>,
schema: GuildBanCreateSchema,
user: &mut ChorusUser,
) -> ChorusResult<()> {
// FIXME: Return GuildBan instead of (). Requires <https://github.com/spacebarchat/server/issues/1096> to be resolved.
let request = ChorusRequest::new(
http::Method::PUT,
format!(
"{}/guilds/{}/bans/{}",
user.belongs_to.read().unwrap().urls.api,
guild_id,
user_id
)
.as_str(),
Some(to_string(&schema).unwrap()),
audit_log_reason.as_deref(),
None,
Some(user),
LimitType::Guild(guild_id),
);
request.handle_request_as_result(user).await
}
/// # Reference
/// <https://discord-userdoccers.vercel.app/resources/guild#modify-guild>
pub async fn modify(
guild_id: Snowflake,
schema: GuildModifySchema,
user: &mut ChorusUser,
) -> ChorusResult<Guild> {
let chorus_request = ChorusRequest {
request: Client::new()
.patch(format!(
"{}/guilds/{}",
user.belongs_to.read().unwrap().urls.api,
guild_id,
))
.header("Authorization", user.token())
.header("Content-Type", "application/json")
.body(to_string(&schema).unwrap()),
limit_type: LimitType::Guild(guild_id),
};
let response = chorus_request.deserialize_response::<Guild>(user).await?;
Ok(response)
}
/// Returns a guild preview object for the given guild ID. If the user is not in the guild, the guild must be discoverable.
/// # Reference:
///
/// See <https://discord-userdoccers.vercel.app/resources/guild#get-guild-preview>
pub async fn get_preview(
guild_id: Snowflake,
@ -256,9 +274,7 @@ impl Guild {
request.deserialize_response::<Vec<GuildMember>>(user).await
}
/// Removes a member from a guild.
///
/// Requires the [KICK_MEMBERS](crate::types::PermissionFlags::KICK_MEMBERS) permission.
/// Removes a member from a guild. Requires the KICK_MEMBERS permission. Returns a 204 empty response on success.
///
/// # Reference
/// See <https://discord-userdoccers.vercel.app/resources/guild#remove-guild-member>
@ -371,9 +387,7 @@ impl Guild {
.await
}
/// Returns a list of ban objects for the guild.
///
/// Requires the [BAN_MEMBERS](crate::types::PermissionFlags::BAN_MEMBERS) permission.
/// Returns a list of ban objects for the guild. Requires the `BAN_MEMBERS` permission.
///
/// # Reference:
/// See <https://discord-userdoccers.vercel.app/resources/guild#get-guild-bans>
@ -403,9 +417,7 @@ impl Guild {
request.deserialize_response::<Vec<GuildBan>>(user).await
}
/// Returns a ban object for the given user.
///
/// Requires the [BAN_MEMBERS](crate::types::PermissionFlags::BAN_MEMBERS) permission.
/// Returns a ban object for the given user. Requires the `BAN_MEMBERS` permission.
///
/// # Reference:
/// See <https://discord-userdoccers.vercel.app/resources/guild#get-guild-ban>
@ -433,39 +445,7 @@ impl Guild {
request.deserialize_response::<GuildBan>(user).await
}
/// Creates a ban from the guild.
///
/// Requires the [BAN_MEMBERS](crate::types::PermissionFlags::BAN_MEMBERS) permission.
///
pub async fn create_ban(
guild_id: Snowflake,
user_id: Snowflake,
audit_log_reason: Option<String>,
schema: GuildBanCreateSchema,
user: &mut ChorusUser,
) -> ChorusResult<()> {
// FIXME: Return GuildBan instead of (). Requires <https://github.com/spacebarchat/server/issues/1096> to be resolved.
let request = ChorusRequest::new(
http::Method::PUT,
format!(
"{}/guilds/{}/bans/{}",
user.belongs_to.read().unwrap().urls.api,
guild_id,
user_id
)
.as_str(),
Some(to_string(&schema).unwrap()),
audit_log_reason.as_deref(),
None,
Some(user),
LimitType::Guild(guild_id),
);
request.handle_request_as_result(user).await
}
/// Removes the ban for a user.
///
/// Requires the [BAN_MEMBERS](crate::types::PermissionFlags::BAN_MEMBERS) permission.
/// Removes the ban for a user. Requires the BAN_MEMBERS permissions. Returns a 204 empty response on success.
///
/// # Reference:
/// See <https://discord-userdoccers.vercel.app/resources/guild#delete-guild-ban>

View File

@ -2,7 +2,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#![allow(unused_imports)]
pub use guilds::*;
pub use messages::*;
pub use roles::*;

View File

@ -3,8 +3,6 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//! All of the API's endpoints.
#![allow(unused_imports)]
pub use channels::messages::*;
pub use guilds::*;
pub use invites::*;

View File

@ -2,7 +2,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#![allow(unused_imports)]
pub use instance::*;
pub mod instance;

View File

@ -13,26 +13,6 @@ use crate::{
};
impl ChorusUser {
/// Fetches a list of private channels the user is in.
///
/// # Reference:
/// See <https://docs.discord.sex/resources/channel#get-private-channels>
pub async fn get_private_channels(&mut self) -> ChorusResult<Vec<Channel>> {
let url = format!(
"{}/users/@me/channels",
self.belongs_to.read().unwrap().urls.api
);
ChorusRequest {
request: Client::new()
.get(url)
.header("Authorization", self.token())
.header("Content-Type", "application/json"),
limit_type: LimitType::Global,
}
.deserialize_response::<Vec<Channel>>(self)
.await
}
/// Creates a DM channel or group DM channel.
///
/// One recipient creates or returns an existing DM channel,

View File

@ -2,7 +2,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#![allow(unused_imports)]
pub use channels::*;
pub use guilds::*;
pub use relationships::*;

View File

@ -2,7 +2,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#![allow(unused_imports)]
pub use activity::*;
pub use connected_account::*;
pub use guild_welcome_screen::*;

View File

@ -38,8 +38,6 @@ pub struct GuildBanCreateSchema {
#[derive(Debug, Deserialize, Serialize, Default, Clone, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
/// Represents the schema used to modify a guild.
/// See: <https://docs.discord.sex/resources/guild#modify-guild>
pub struct GuildModifySchema {
pub name: Option<String>,
pub icon: Option<Vec<u8>>,
@ -49,7 +47,6 @@ pub struct GuildModifySchema {
pub discovery_splash: Option<Vec<u8>>,
pub owner_id: Option<Snowflake>,
pub description: Option<String>,
/// Deprecated
pub region: Option<String>,
pub afk_channel_id: Option<Snowflake>,
pub afk_timeout: Option<u16>,
@ -59,9 +56,6 @@ pub struct GuildModifySchema {
pub features: Option<Vec<GuildFeatures>>,
pub system_channel_id: Option<Snowflake>,
pub system_channel_flags: Option<SystemChannelFlags>,
/// If set to Some(1), will create a new #rules channel
///
/// Reference: <https://docs.discord.sex/resources/guild#modify-guild>
pub rules_channel_id: Option<Snowflake>,
pub public_updates_channel_id: Option<Snowflake>,
pub safety_alerts_channel_id: Option<Snowflake>,

View File

@ -2,7 +2,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#![allow(unused_imports)]
pub use regexes::*;
pub use rights::Rights;
pub use snowflake::Snowflake;