Minor doc changes

This commit is contained in:
kozabrada123 2023-07-29 11:26:00 +02:00
parent 1e81a2682f
commit ede965411e
5 changed files with 12 additions and 3 deletions

View File

@ -34,6 +34,7 @@ pub struct UrlBundle {
} }
impl UrlBundle { impl UrlBundle {
/// Creates a new UrlBundle from the relevant urls.
pub fn new(api: String, wss: String, cdn: String) -> Self { pub fn new(api: String, wss: String, cdn: String) -> Self {
Self { Self {
api: UrlBundle::parse_url(api), api: UrlBundle::parse_url(api),

View File

@ -6,6 +6,7 @@ use crate::types::Snowflake;
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
/// A schema used to modify a user.
pub struct UserModifySchema { pub struct UserModifySchema {
pub username: Option<String>, pub username: Option<String>,
pub avatar: Option<String>, pub avatar: Option<String>,
@ -19,6 +20,8 @@ pub struct UserModifySchema {
pub discriminator: Option<i16>, pub discriminator: Option<i16>,
} }
/// A schema used to create a private channel.
///
/// # Attributes: /// # Attributes:
/// - recipients: The users to include in the private channel /// - recipients: The users to include in the private channel
/// - access_tokens: The access tokens of users that have granted your app the `gdm.join` scope. Only usable for OAuth2 requests (which can only create group DMs). /// - access_tokens: The access tokens of users that have granted your app the `gdm.join` scope. Only usable for OAuth2 requests (which can only create group DMs).

View File

@ -1,8 +1,8 @@
#[allow(missing_docs)]
use crate::types::utils::Snowflake;
use jsonwebtoken::{encode, EncodingKey, Header}; use jsonwebtoken::{encode, EncodingKey, Header};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::types::utils::Snowflake;
pub fn generate_token(id: &Snowflake, email: String, jwt_key: &str) -> String { pub fn generate_token(id: &Snowflake, email: String, jwt_key: &str) -> String {
let claims = Claims::new(&email, id); let claims = Claims::new(&email, id);
@ -11,7 +11,9 @@ pub fn generate_token(id: &Snowflake, email: String, jwt_key: &str) -> String {
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Claims { pub struct Claims {
/// When the token expires, unix epoch
pub exp: i64, pub exp: i64,
/// When the token was issued
pub iat: i64, pub iat: i64,
pub email: String, pub email: String,
pub id: String, pub id: String,

View File

@ -18,6 +18,7 @@ const EPOCH: i64 = 1420070400000;
pub struct Snowflake(u64); pub struct Snowflake(u64);
impl Snowflake { impl Snowflake {
/// Generates a snowflake for the current epoch.
pub fn generate() -> Self { pub fn generate() -> Self {
const WORKER_ID: u64 = 0; const WORKER_ID: u64 = 0;
const PROCESS_ID: u64 = 1; const PROCESS_ID: u64 = 1;
@ -31,6 +32,7 @@ impl Snowflake {
Self(time as u64 | worker | process | increment) Self(time as u64 | worker | process | increment)
} }
/// Returns the snowflake's timestamp
pub fn timestamp(self) -> DateTime<Utc> { pub fn timestamp(self) -> DateTime<Utc> {
Utc.timestamp_millis_opt((self.0 >> 22) as i64 + EPOCH) Utc.timestamp_millis_opt((self.0 >> 22) as i64 + EPOCH)
.unwrap() .unwrap()

View File

@ -1 +1,2 @@
//! Where the voice chat implementation will be, once it's finished.
//! For development on voice, see the feature/voice branch.