Merge remote-tracking branch 'origin/main' into improvement/update-rate-limiter-implementation

This commit is contained in:
bitfl0wer 2023-04-24 19:50:36 +02:00
commit c9d5bb8b6e
No known key found for this signature in database
GPG Key ID: 84BBB60DF895ABF2
2 changed files with 74 additions and 4 deletions

View File

@ -3,7 +3,7 @@ pub mod schemas {
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, fmt};
use crate::errors::FieldFormatError;
use crate::{errors::FieldFormatError, URLBundle};
/**
A struct that represents a well-formed email address.
@ -380,6 +380,76 @@ pub mod schemas {
pub message: String,
pub code: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct UserObject {
id: String,
username: String,
discriminator: String,
avatar: Option<String>,
bot: Option<bool>,
system: Option<bool>,
mfa_enabled: Option<bool>,
banner: Option<bool>,
accent_color: Option<String>,
locale: String,
verified: Option<bool>,
email: Option<String>,
flags: i8,
premium_type: Option<i8>,
public_flags: Option<i8>,
}
#[derive(Debug)]
pub struct User {
logged_in: bool,
belongs_to: URLBundle,
token: String,
pub settings: UserSettings,
pub object: UserObject,
}
impl User {
pub fn is_logged_in(&self) -> bool {
if self.logged_in == true {
true
} else {
false
}
}
pub fn belongs_to(&self) -> URLBundle {
return self.belongs_to.clone();
}
pub fn token(&self) -> String {
return self.token.clone();
}
pub fn set_logged_in(&mut self, bool: bool) {
self.logged_in = bool;
}
pub fn set_token(&mut self, token: String) {
self.token = token;
}
pub fn new(
logged_in: bool,
belongs_to: URLBundle,
token: String,
settings: UserSettings,
object: UserObject,
) -> User {
User {
logged_in,
belongs_to,
token,
settings,
object,
}
}
}
}
// I know that some of these tests are... really really basic and unneccessary, but sometimes, I

View File

@ -1,5 +1,5 @@
use crate::api::limits::{Limit, LimitType, Limits};
use crate::api::schemas::schemas::InstancePoliciesSchema;
use crate::api::schemas::schemas::{InstancePoliciesSchema, User};
use crate::errors::{FieldFormatError, InstanceServerError};
use crate::limit::LimitedRequester;
use crate::URLBundle;
@ -17,7 +17,7 @@ pub struct Instance {
pub requester: LimitedRequester,
pub limits: Limits,
//pub gateway: Gateway,
pub users: HashMap<Token, Username>,
pub users: HashMap<Token, User>,
}
impl Instance {
@ -31,7 +31,7 @@ impl Instance {
urls: URLBundle,
requester: LimitedRequester,
) -> Result<Instance, InstanceServerError> {
let users: HashMap<Token, Username> = HashMap::new();
let users: HashMap<Token, User> = HashMap::new();
let mut instance = Instance {
urls: urls.clone(),
instance_info: InstancePoliciesSchema::new(