Documemtaiom
This commit is contained in:
parent
d50e969a07
commit
b72ebf36ed
|
@ -13,6 +13,7 @@ use crate::types::{GatewayIdentifyPayload, LoginResult, LoginSchema};
|
|||
|
||||
impl Instance {
|
||||
/// Logs into an existing account on the spacebar server.
|
||||
// TODO: Couldn't find reference
|
||||
pub async fn login_account(&mut self, login_schema: &LoginSchema) -> ChorusResult<UserMeta> {
|
||||
let endpoint_url = self.urls.api.clone() + "/auth/login";
|
||||
let chorus_request = ChorusRequest {
|
||||
|
|
|
@ -15,6 +15,7 @@ use crate::{
|
|||
|
||||
impl Instance {
|
||||
/// Registers a new user on the server.
|
||||
// TODO: Couldn't find reference
|
||||
pub async fn register_account(
|
||||
&mut self,
|
||||
register_schema: &RegisterSchema,
|
||||
|
|
|
@ -12,6 +12,9 @@ use crate::{
|
|||
|
||||
impl Channel {
|
||||
/// Retrieves a channel from the server.
|
||||
///
|
||||
/// # Reference
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/channel#get-channel>
|
||||
pub async fn get(user: &mut UserMeta, channel_id: Snowflake) -> ChorusResult<Channel> {
|
||||
let url = user.belongs_to.borrow().urls.api.clone();
|
||||
let chorus_request = ChorusRequest {
|
||||
|
@ -24,6 +27,9 @@ impl Channel {
|
|||
}
|
||||
|
||||
/// Deletes self.
|
||||
///
|
||||
/// # Reference
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/channel#delete-channel>
|
||||
pub async fn delete(self, user: &mut UserMeta) -> ChorusResult<()> {
|
||||
let chorus_request = ChorusRequest {
|
||||
request: Client::new()
|
||||
|
@ -40,6 +46,9 @@ impl Channel {
|
|||
|
||||
/// Modifies a channel with the provided data.
|
||||
/// Returns the new Channel.
|
||||
///
|
||||
/// # Reference
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/channel#modify-channel>
|
||||
pub async fn modify(
|
||||
&self,
|
||||
modify_data: ChannelModifySchema,
|
||||
|
@ -61,6 +70,9 @@ impl Channel {
|
|||
}
|
||||
|
||||
/// Fetches recent messages from a channel.
|
||||
///
|
||||
/// # Reference
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/message#get-messages>
|
||||
pub async fn messages(
|
||||
range: GetChannelMessagesSchema,
|
||||
channel_id: Snowflake,
|
||||
|
@ -83,8 +95,10 @@ impl Channel {
|
|||
.await
|
||||
}
|
||||
|
||||
/// Adds a recipient to a group DM.
|
||||
///
|
||||
/// # Reference:
|
||||
/// Read: <https://discord-userdoccers.vercel.app/resources/channel#add-channel-recipient>
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/channel#add-channel-recipient>
|
||||
pub async fn add_channel_recipient(
|
||||
&self,
|
||||
recipient_id: Snowflake,
|
||||
|
@ -110,8 +124,10 @@ impl Channel {
|
|||
.await
|
||||
}
|
||||
|
||||
/// Removes a recipient from a group DM.
|
||||
///
|
||||
/// # Reference:
|
||||
/// Read: <https://discord-userdoccers.vercel.app/resources/channel#remove-channel-recipient>
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/channel#remove-channel-recipient>
|
||||
pub async fn remove_channel_recipient(
|
||||
&self,
|
||||
recipient_id: Snowflake,
|
||||
|
|
|
@ -12,6 +12,9 @@ use crate::types::{Message, MessageSendSchema, Snowflake};
|
|||
impl Message {
|
||||
/// Sends a message in the channel with the provided channel_id.
|
||||
/// Returns the sent message.
|
||||
///
|
||||
/// # Reference
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/message#create-message>
|
||||
pub async fn send(
|
||||
user: &mut UserMeta,
|
||||
channel_id: Snowflake,
|
||||
|
@ -71,8 +74,12 @@ impl Message {
|
|||
impl UserMeta {
|
||||
/// Sends a message in the channel with the provided channel_id.
|
||||
/// Returns the sent message.
|
||||
///
|
||||
/// # Notes
|
||||
/// Shorthand call for Message::send()
|
||||
/// Shorthand call for [`Message::send`]
|
||||
///
|
||||
/// # Reference
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/message#create-message>
|
||||
pub async fn send_message(
|
||||
&mut self,
|
||||
message: MessageSendSchema,
|
||||
|
|
|
@ -11,6 +11,9 @@ use crate::{
|
|||
|
||||
impl types::Channel {
|
||||
/// Edits the permission overwrites for a channel.
|
||||
///
|
||||
/// # Reference
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/channel#modify-channel-permissions>
|
||||
pub async fn edit_permissions(
|
||||
user: &mut UserMeta,
|
||||
channel_id: Snowflake,
|
||||
|
@ -38,6 +41,9 @@ impl types::Channel {
|
|||
}
|
||||
|
||||
/// Deletes a permission overwrite for a channel.
|
||||
///
|
||||
/// # Reference
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/channel#delete-channel-permission>
|
||||
pub async fn delete_permission(
|
||||
user: &mut UserMeta,
|
||||
channel_id: Snowflake,
|
||||
|
|
|
@ -16,6 +16,10 @@ impl UserMeta {
|
|||
///
|
||||
/// # Notes
|
||||
/// This function is a wrapper around [`User::get`].
|
||||
///
|
||||
/// # Reference
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/user#get-user> and
|
||||
/// <https://discord-userdoccers.vercel.app/resources/user#get-current-user>
|
||||
pub async fn get(user: &mut UserMeta, id: Option<&String>) -> ChorusResult<User> {
|
||||
User::get(user, id).await
|
||||
}
|
||||
|
@ -33,6 +37,9 @@ impl UserMeta {
|
|||
}
|
||||
|
||||
/// Modifies the current user's representation. (See [`User`])
|
||||
///
|
||||
/// # Reference
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/user#modify-current-user>
|
||||
pub async fn modify(&mut self, modify_schema: UserModifySchema) -> ChorusResult<User> {
|
||||
if modify_schema.new_password.is_some()
|
||||
|| modify_schema.email.is_some()
|
||||
|
@ -57,6 +64,9 @@ impl UserMeta {
|
|||
}
|
||||
|
||||
/// Deletes the user from the Instance.
|
||||
///
|
||||
/// # Reference
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/user#disable-user>
|
||||
pub async fn delete(mut self) -> ChorusResult<()> {
|
||||
let request = Client::new()
|
||||
.post(format!(
|
||||
|
@ -74,6 +84,10 @@ impl UserMeta {
|
|||
|
||||
impl User {
|
||||
/// Gets a user by id, or if the id is None, gets the current user.
|
||||
///
|
||||
/// # Reference
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/user#get-user> and
|
||||
/// <https://discord-userdoccers.vercel.app/resources/user#get-current-user>
|
||||
pub async fn get(user: &mut UserMeta, id: Option<&String>) -> ChorusResult<User> {
|
||||
let url_api = user.belongs_to.borrow().urls.api.clone();
|
||||
let url = if id.is_none() {
|
||||
|
@ -96,6 +110,7 @@ impl User {
|
|||
}
|
||||
|
||||
/// Gets the user's settings.
|
||||
// TODO: Couldn't find reference
|
||||
pub async fn get_settings(
|
||||
token: &String,
|
||||
url_api: &String,
|
||||
|
@ -127,6 +142,10 @@ impl Instance {
|
|||
///
|
||||
/// # Notes
|
||||
/// This function is a wrapper around [`User::get`].
|
||||
///
|
||||
/// # Reference
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/user#get-user> and
|
||||
/// <https://discord-userdoccers.vercel.app/resources/user#get-current-user>
|
||||
pub async fn get_user(&mut self, token: String, id: Option<&String>) -> ChorusResult<User> {
|
||||
let mut user = UserMeta::shell(Rc::new(RefCell::new(self.clone())), token).await;
|
||||
let result = User::get(&mut user, id).await;
|
||||
|
|
|
@ -12,6 +12,10 @@ use crate::types::{
|
|||
|
||||
#[derive(Default, Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Updateable)]
|
||||
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
|
||||
/// Represents a guild of private channel
|
||||
///
|
||||
/// # Reference
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/channel#channels-resource>
|
||||
pub struct Channel {
|
||||
pub application_id: Option<Snowflake>,
|
||||
#[cfg(feature = "sqlx")]
|
||||
|
@ -120,27 +124,55 @@ pub struct DefaultReaction {
|
|||
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
|
||||
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||
#[repr(i32)]
|
||||
/// # Reference
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/channel#channel-type>
|
||||
pub enum ChannelType {
|
||||
#[default]
|
||||
/// A text channel within a guild
|
||||
GuildText = 0,
|
||||
/// A private channel between two users
|
||||
Dm = 1,
|
||||
/// A voice channel within a guild
|
||||
GuildVoice = 2,
|
||||
/// A private channel between multiple users
|
||||
GroupDm = 3,
|
||||
/// An organizational category that contains up to 50 channels
|
||||
GuildCategory = 4,
|
||||
/// Similar to [GuildText], a channel that users can follow and crosspost into their own guild
|
||||
GuildNews = 5,
|
||||
/// A channel in which game developers can sell their game on Discord
|
||||
///
|
||||
/// # Note
|
||||
/// Deprecated.
|
||||
GuildStore = 6,
|
||||
// FIXME userdoccers says 7 is GuildLfg, is this a spacebar specific thing?
|
||||
Encrypted = 7,
|
||||
// FIXME userdoccers says 8 is LfgGuildDm, is this a spacebar specific thing?
|
||||
EncryptedThreads = 8,
|
||||
// FIXME userdoccers says 9 is ThreadAlpha, was this changed?
|
||||
Transactional = 9,
|
||||
/// A thread within a [GuildNews] channel
|
||||
GuildNewsThread = 10,
|
||||
/// A thread within a [GuildText], [GuildForum], or [GuildMedia] channel
|
||||
GuildPublicThread = 11,
|
||||
/// A thread within a [GuildText] channel, that is only viewable by those invited and those with the [ManageThreads] permission
|
||||
GuildPrivateThread = 12,
|
||||
/// A voice channel for hosting events with an audience in a guild
|
||||
GuildStageVoice = 13,
|
||||
/// The main channel in a hub containing the listed guilds
|
||||
Directory = 14,
|
||||
/// A channel that can only contain threads
|
||||
GuildForum = 15,
|
||||
/// A channel that can only contain threads in a gallery view
|
||||
GuildMedia = 16,
|
||||
// TODO: Couldn't find reference
|
||||
TicketTracker = 33,
|
||||
// TODO: Couldn't find reference
|
||||
Kanban = 34,
|
||||
// TODO: Couldn't find reference
|
||||
VoicelessWhiteboard = 35,
|
||||
// TODO: Couldn't find reference
|
||||
CustomStart = 64,
|
||||
// TODO: Couldn't find reference
|
||||
Unhandled = 255,
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@ use sqlx::Type;
|
|||
const EPOCH: i64 = 1420070400000;
|
||||
|
||||
/// Unique identifier including a timestamp.
|
||||
///
|
||||
/// # Reference
|
||||
/// See <https://discord.com/developers/docs/reference#snowflakes>
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
#[cfg_attr(feature = "sqlx", derive(Type))]
|
||||
|
|
Loading…
Reference in New Issue