Compare commits
No commits in common. "854c9820ef9938239a10ee776cf90a0b7e44621c" and "2b69035ec7187527e8476dcd26ec29b3d1e408f6" have entirely different histories.
854c9820ef
...
2b69035ec7
|
@ -4,10 +4,7 @@
|
||||||
|
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use login::*;
|
pub use login::*;
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use register::*;
|
pub use register::*;
|
||||||
|
|
||||||
use crate::gateway::Gateway;
|
use crate::gateway::Gateway;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// 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/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
#![allow(unused_imports)]
|
|
||||||
pub use channels::*;
|
pub use channels::*;
|
||||||
pub use messages::*;
|
pub use messages::*;
|
||||||
pub use permissions::*;
|
pub use permissions::*;
|
||||||
|
|
|
@ -18,25 +18,6 @@ use crate::types::{
|
||||||
use crate::types::{GuildBan, Snowflake};
|
use crate::types::{GuildBan, Snowflake};
|
||||||
|
|
||||||
impl Guild {
|
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.
|
/// Creates a new guild.
|
||||||
///
|
///
|
||||||
/// # Reference
|
/// # Reference
|
||||||
|
@ -57,35 +38,6 @@ impl Guild {
|
||||||
chorus_request.deserialize_response::<Guild>(user).await
|
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.
|
/// Deletes a guild by its id.
|
||||||
///
|
///
|
||||||
/// User must be the owner.
|
/// User must be the owner.
|
||||||
|
@ -175,11 +127,77 @@ impl Guild {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a guild preview object for the given guild ID.
|
/// Fetches a guild by its 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>
|
||||||
|
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:
|
/// # Reference:
|
||||||
|
///
|
||||||
/// See <https://discord-userdoccers.vercel.app/resources/guild#get-guild-preview>
|
/// See <https://discord-userdoccers.vercel.app/resources/guild#get-guild-preview>
|
||||||
pub async fn get_preview(
|
pub async fn get_preview(
|
||||||
guild_id: Snowflake,
|
guild_id: Snowflake,
|
||||||
|
@ -256,9 +274,7 @@ impl Guild {
|
||||||
request.deserialize_response::<Vec<GuildMember>>(user).await
|
request.deserialize_response::<Vec<GuildMember>>(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes a member from a guild.
|
/// Removes a member from a guild. Requires the KICK_MEMBERS permission. Returns a 204 empty response on success.
|
||||||
///
|
|
||||||
/// Requires the [KICK_MEMBERS](crate::types::PermissionFlags::KICK_MEMBERS) permission.
|
|
||||||
///
|
///
|
||||||
/// # Reference
|
/// # Reference
|
||||||
/// See <https://discord-userdoccers.vercel.app/resources/guild#remove-guild-member>
|
/// See <https://discord-userdoccers.vercel.app/resources/guild#remove-guild-member>
|
||||||
|
@ -371,9 +387,7 @@ impl Guild {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a list of ban objects for the guild.
|
/// Returns a list of ban objects for the guild. Requires the `BAN_MEMBERS` permission.
|
||||||
///
|
|
||||||
/// Requires the [BAN_MEMBERS](crate::types::PermissionFlags::BAN_MEMBERS) permission.
|
|
||||||
///
|
///
|
||||||
/// # Reference:
|
/// # Reference:
|
||||||
/// See <https://discord-userdoccers.vercel.app/resources/guild#get-guild-bans>
|
/// See <https://discord-userdoccers.vercel.app/resources/guild#get-guild-bans>
|
||||||
|
@ -403,9 +417,7 @@ impl Guild {
|
||||||
request.deserialize_response::<Vec<GuildBan>>(user).await
|
request.deserialize_response::<Vec<GuildBan>>(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a ban object for the given user.
|
/// Returns a ban object for the given user. Requires the `BAN_MEMBERS` permission.
|
||||||
///
|
|
||||||
/// Requires the [BAN_MEMBERS](crate::types::PermissionFlags::BAN_MEMBERS) permission.
|
|
||||||
///
|
///
|
||||||
/// # Reference:
|
/// # Reference:
|
||||||
/// See <https://discord-userdoccers.vercel.app/resources/guild#get-guild-ban>
|
/// See <https://discord-userdoccers.vercel.app/resources/guild#get-guild-ban>
|
||||||
|
@ -433,39 +445,7 @@ impl Guild {
|
||||||
request.deserialize_response::<GuildBan>(user).await
|
request.deserialize_response::<GuildBan>(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a ban from the guild.
|
/// Removes the ban for a user. Requires the BAN_MEMBERS permissions. Returns a 204 empty response on success.
|
||||||
///
|
|
||||||
/// 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.
|
|
||||||
///
|
///
|
||||||
/// # Reference:
|
/// # Reference:
|
||||||
/// See <https://discord-userdoccers.vercel.app/resources/guild#delete-guild-ban>
|
/// See <https://discord-userdoccers.vercel.app/resources/guild#delete-guild-ban>
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// 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/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
#![allow(unused_imports)]
|
|
||||||
pub use guilds::*;
|
pub use guilds::*;
|
||||||
pub use messages::*;
|
pub use messages::*;
|
||||||
pub use roles::*;
|
pub use roles::*;
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
//! All of the API's endpoints.
|
//! All of the API's endpoints.
|
||||||
|
|
||||||
#![allow(unused_imports)]
|
|
||||||
pub use channels::messages::*;
|
pub use channels::messages::*;
|
||||||
pub use guilds::*;
|
pub use guilds::*;
|
||||||
pub use invites::*;
|
pub use invites::*;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// 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/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
#![allow(unused_imports)]
|
|
||||||
pub use instance::*;
|
pub use instance::*;
|
||||||
|
|
||||||
pub mod instance;
|
pub mod instance;
|
||||||
|
|
|
@ -13,26 +13,6 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
impl ChorusUser {
|
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.
|
/// Creates a DM channel or group DM channel.
|
||||||
///
|
///
|
||||||
/// One recipient creates or returns an existing DM channel,
|
/// One recipient creates or returns an existing DM channel,
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// 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/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
#![allow(unused_imports)]
|
|
||||||
pub use channels::*;
|
pub use channels::*;
|
||||||
pub use guilds::*;
|
pub use guilds::*;
|
||||||
pub use relationships::*;
|
pub use relationships::*;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// 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/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
#![allow(unused_imports)]
|
|
||||||
pub use activity::*;
|
pub use activity::*;
|
||||||
pub use connected_account::*;
|
pub use connected_account::*;
|
||||||
pub use guild_welcome_screen::*;
|
pub use guild_welcome_screen::*;
|
||||||
|
|
|
@ -38,8 +38,6 @@ pub struct GuildBanCreateSchema {
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Default, Clone, Eq, PartialEq)]
|
#[derive(Debug, Deserialize, Serialize, Default, Clone, Eq, PartialEq)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[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 struct GuildModifySchema {
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
pub icon: Option<Vec<u8>>,
|
pub icon: Option<Vec<u8>>,
|
||||||
|
@ -49,7 +47,6 @@ pub struct GuildModifySchema {
|
||||||
pub discovery_splash: Option<Vec<u8>>,
|
pub discovery_splash: Option<Vec<u8>>,
|
||||||
pub owner_id: Option<Snowflake>,
|
pub owner_id: Option<Snowflake>,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
/// Deprecated
|
|
||||||
pub region: Option<String>,
|
pub region: Option<String>,
|
||||||
pub afk_channel_id: Option<Snowflake>,
|
pub afk_channel_id: Option<Snowflake>,
|
||||||
pub afk_timeout: Option<u16>,
|
pub afk_timeout: Option<u16>,
|
||||||
|
@ -59,9 +56,6 @@ pub struct GuildModifySchema {
|
||||||
pub features: Option<Vec<GuildFeatures>>,
|
pub features: Option<Vec<GuildFeatures>>,
|
||||||
pub system_channel_id: Option<Snowflake>,
|
pub system_channel_id: Option<Snowflake>,
|
||||||
pub system_channel_flags: Option<SystemChannelFlags>,
|
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 rules_channel_id: Option<Snowflake>,
|
||||||
pub public_updates_channel_id: Option<Snowflake>,
|
pub public_updates_channel_id: Option<Snowflake>,
|
||||||
pub safety_alerts_channel_id: Option<Snowflake>,
|
pub safety_alerts_channel_id: Option<Snowflake>,
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// 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/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
#![allow(unused_imports)]
|
|
||||||
pub use regexes::*;
|
pub use regexes::*;
|
||||||
pub use rights::Rights;
|
pub use rights::Rights;
|
||||||
pub use snowflake::Snowflake;
|
pub use snowflake::Snowflake;
|
||||||
|
|
Loading…
Reference in New Issue