Reformat and cargo fix
This commit is contained in:
commit
dc5e91a784
|
@ -30,7 +30,7 @@
|
|||
|
||||
</div>
|
||||
|
||||
## Roadmap
|
||||
## Progress Tracker/Roadmap:
|
||||
### Core Functionality
|
||||
- [x] Rate Limiter (hint: couldn't be fully tested due to [an Issue with the Spacebar Server](https://github.com/spacebarchat/server/issues/1022))
|
||||
- [x] [Login (the conventional way)](https://github.com/polyphony-chat/chorus/issues/1)
|
||||
|
@ -74,7 +74,7 @@
|
|||
|
||||
### Permissions and Roles
|
||||
- [x] [Role management](https://github.com/polyphony-chat/chorus/issues/46) (creation, deletion, modification)
|
||||
- [ ] [Permission management](https://github.com/polyphony-chat/chorus/issues/46) (assigning and revoking permissions)
|
||||
- [x] [Permission management](https://github.com/polyphony-chat/chorus/issues/46) (assigning and revoking permissions)
|
||||
- [x] [Channel-specific permissions](https://github.com/polyphony-chat/chorus/issues/88)
|
||||
- [x] Role-based access control
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use chorus::{self, gateway::Gateway, types::GatewayIdentifyPayload};
|
||||
use tokio;
|
||||
|
||||
/// This example creates a simple gateway connection and a session with an Identify event
|
||||
#[tokio::main]
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
pub mod login {
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use reqwest::Client;
|
||||
use serde_json::{from_str, json};
|
||||
use reqwest::Client;
|
||||
use serde_json::{from_str, json};
|
||||
|
||||
use crate::api::limits::LimitType;
|
||||
use crate::errors::ChorusLibError;
|
||||
use crate::instance::{Instance, UserMeta};
|
||||
use crate::limit::LimitedRequester;
|
||||
use crate::types::{ErrorResponse, LoginResult, LoginSchema};
|
||||
use crate::api::limits::LimitType;
|
||||
use crate::errors::ChorusLibError;
|
||||
use crate::instance::{Instance, UserMeta};
|
||||
use crate::limit::LimitedRequester;
|
||||
use crate::types::{ErrorResponse, LoginResult, LoginSchema};
|
||||
|
||||
impl Instance {
|
||||
impl Instance {
|
||||
pub async fn login_account(
|
||||
&mut self,
|
||||
login_schema: &LoginSchema,
|
||||
|
@ -68,5 +67,4 @@ pub mod login {
|
|||
|
||||
Ok(user)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
pub mod login;
|
||||
pub mod register;
|
||||
|
||||
pub use login::*;
|
||||
pub use register::*;
|
||||
|
||||
pub mod login;
|
||||
pub mod register;
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
pub mod register {
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
use reqwest::Client;
|
||||
use serde_json::{from_str, json};
|
||||
use reqwest::Client;
|
||||
use serde_json::{from_str, json};
|
||||
|
||||
use crate::{
|
||||
use crate::{
|
||||
api::limits::LimitType,
|
||||
errors::ChorusLibError,
|
||||
instance::{Instance, Token, UserMeta},
|
||||
limit::LimitedRequester,
|
||||
types::{ErrorResponse, RegisterSchema},
|
||||
};
|
||||
};
|
||||
|
||||
impl Instance {
|
||||
impl Instance {
|
||||
/**
|
||||
Registers a new user on the Spacebar server.
|
||||
# Arguments
|
||||
|
@ -75,5 +74,4 @@ pub mod register {
|
|||
);
|
||||
Ok(user)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
pub mod channels;
|
||||
pub mod messages;
|
||||
pub mod permissions;
|
||||
pub mod reactions;
|
||||
|
||||
pub use channels::*;
|
||||
pub use messages::*;
|
||||
pub use permissions::*;
|
||||
pub use reactions::*;
|
||||
|
||||
pub mod channels;
|
||||
pub mod messages;
|
||||
pub mod permissions;
|
||||
pub mod reactions;
|
||||
|
|
|
@ -173,7 +173,7 @@ impl Guild {
|
|||
Err(e) => {
|
||||
return Err(ChorusLibError::InvalidResponseError {
|
||||
error: e.to_string(),
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
let _: Vec<Channel> = match from_str(&stringed_response) {
|
||||
|
@ -181,7 +181,7 @@ impl Guild {
|
|||
Err(e) => {
|
||||
return Err(ChorusLibError::InvalidResponseError {
|
||||
error: e.to_string(),
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ impl types::GuildMember {
|
|||
Err(e) => {
|
||||
return Err(ChorusLibError::InvalidResponseError {
|
||||
error: e.to_string(),
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
let member = from_str::<types::GuildMember>(&response_text);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
pub mod guilds;
|
||||
pub mod member;
|
||||
pub mod roles;
|
||||
|
||||
pub use guilds::*;
|
||||
pub use roles::*;
|
||||
pub use roles::*;
|
||||
|
||||
pub mod guilds;
|
||||
pub mod member;
|
||||
pub mod roles;
|
||||
|
|
|
@ -48,7 +48,7 @@ impl types::RoleObject {
|
|||
Err(e) => {
|
||||
return Err(ChorusLibError::InvalidResponseError {
|
||||
error: e.to_string(),
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -105,7 +105,7 @@ impl types::RoleObject {
|
|||
Err(e) => {
|
||||
return Err(ChorusLibError::InvalidResponseError {
|
||||
error: e.to_string(),
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -139,7 +139,7 @@ impl types::RoleObject {
|
|||
Err(e) => {
|
||||
return Err(ChorusLibError::FormCreationError {
|
||||
error: e.to_string(),
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
let request = Client::new().post(url).bearer_auth(user.token()).body(body);
|
||||
|
@ -161,7 +161,7 @@ impl types::RoleObject {
|
|||
Err(e) => {
|
||||
return Err(ChorusLibError::InvalidResponseError {
|
||||
error: e.to_string(),
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
Ok(role)
|
||||
|
@ -194,7 +194,7 @@ impl types::RoleObject {
|
|||
Err(e) => {
|
||||
return Err(ChorusLibError::FormCreationError {
|
||||
error: e.to_string(),
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
let request = Client::new()
|
||||
|
@ -216,7 +216,7 @@ impl types::RoleObject {
|
|||
Err(e) => {
|
||||
return Err(ChorusLibError::InvalidResponseError {
|
||||
error: e.to_string(),
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
Ok(role)
|
||||
|
@ -256,7 +256,7 @@ impl types::RoleObject {
|
|||
Err(e) => {
|
||||
return Err(ChorusLibError::FormCreationError {
|
||||
error: e.to_string(),
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
let request = Client::new()
|
||||
|
@ -281,7 +281,7 @@ impl types::RoleObject {
|
|||
Err(e) => {
|
||||
return Err(ChorusLibError::InvalidResponseError {
|
||||
error: e.to_string(),
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
Ok(role)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
pub use channels::messages::*;
|
||||
pub use guilds::*;
|
||||
pub use policies::instance::instance::*;
|
||||
pub use policies::instance::limits::*;
|
||||
|
||||
pub mod auth;
|
||||
pub mod channels;
|
||||
pub mod guilds;
|
||||
pub mod policies;
|
||||
pub mod users;
|
||||
|
||||
pub use channels::messages::*;
|
||||
pub use guilds::*;
|
||||
pub use policies::instance::instance::*;
|
||||
pub use policies::instance::limits::*;
|
||||
|
|
|
@ -47,7 +47,6 @@ pub mod limits {
|
|||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[allow(non_snake_case)]
|
||||
|
||||
pub struct Guild {
|
||||
pub maxRoles: u64,
|
||||
pub maxEmojis: u64,
|
||||
|
@ -58,7 +57,6 @@ pub mod limits {
|
|||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[allow(non_snake_case)]
|
||||
|
||||
pub struct Message {
|
||||
pub maxCharacters: u64,
|
||||
pub maxTTSCharacters: u64,
|
||||
|
@ -70,7 +68,6 @@ pub mod limits {
|
|||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[allow(non_snake_case)]
|
||||
|
||||
pub struct Channel {
|
||||
pub maxPins: u64,
|
||||
pub maxTopic: u64,
|
||||
|
@ -102,7 +99,6 @@ pub mod limits {
|
|||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[allow(non_snake_case)]
|
||||
|
||||
pub struct AuthRoutes {
|
||||
pub login: Window,
|
||||
pub register: Window,
|
||||
|
@ -110,7 +106,6 @@ pub mod limits {
|
|||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[allow(non_snake_case)]
|
||||
|
||||
pub struct AbsoluteRate {
|
||||
pub register: AbsoluteWindow,
|
||||
pub sendMessage: AbsoluteWindow,
|
||||
|
@ -125,7 +120,6 @@ pub mod limits {
|
|||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[allow(non_snake_case)]
|
||||
|
||||
pub struct Config {
|
||||
pub user: User,
|
||||
pub guild: Guild,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
pub mod instance;
|
||||
pub mod limits;
|
||||
|
||||
pub use instance::*;
|
||||
pub use limits::*;
|
||||
|
||||
pub mod instance;
|
||||
pub mod limits;
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
pub mod instance;
|
||||
|
||||
pub use instance::limits::*;
|
||||
|
||||
pub mod instance;
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
pub mod users;
|
||||
|
||||
pub use users::*;
|
||||
|
||||
pub mod users;
|
||||
|
|
|
@ -3,12 +3,13 @@ use crate::errors::ObserverError;
|
|||
use crate::gateway::events::Events;
|
||||
use crate::types;
|
||||
use crate::types::WebSocketEvent;
|
||||
use std::sync::Arc;
|
||||
|
||||
use futures_util::stream::SplitSink;
|
||||
use futures_util::stream::SplitStream;
|
||||
use futures_util::SinkExt;
|
||||
use futures_util::StreamExt;
|
||||
use native_tls::TlsConnector;
|
||||
use std::sync::Arc;
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::sync::mpsc::error::TryRecvError;
|
||||
use tokio::sync::mpsc::Sender;
|
||||
|
@ -177,7 +178,7 @@ Represents a handle to a Gateway connection. A Gateway connection will create ob
|
|||
[`GatewayEvents`](GatewayEvent), which you can subscribe to. Gateway events include all currently
|
||||
implemented [Types] with the trait [`WebSocketEvent`]
|
||||
Using this handle you can also send Gateway Events directly.
|
||||
*/
|
||||
*/
|
||||
pub struct GatewayHandle {
|
||||
pub url: String,
|
||||
pub events: Arc<Mutex<Events>>,
|
||||
|
@ -1562,7 +1563,7 @@ impl Gateway {
|
|||
|
||||
/**
|
||||
Handles sending heartbeats to the gateway in another thread
|
||||
*/
|
||||
*/
|
||||
struct HeartbeatHandler {
|
||||
/// The heartbeat interval in milliseconds
|
||||
pub heartbeat_interval: u128,
|
||||
|
@ -1720,8 +1721,7 @@ pub trait Observer<T: types::WebSocketEvent>: std::fmt::Debug {
|
|||
|
||||
/** GatewayEvent is a wrapper around a WebSocketEvent. It is used to notify the observers of a
|
||||
change in the WebSocketEvent. GatewayEvents are observable.
|
||||
*/
|
||||
|
||||
*/
|
||||
#[derive(Default, Debug)]
|
||||
pub struct GatewayEvent<T: types::WebSocketEvent> {
|
||||
observers: Vec<Arc<Mutex<dyn Observer<T> + Sync + Send>>>,
|
||||
|
@ -1799,6 +1799,7 @@ impl<T: types::WebSocketEvent> GatewayEvent<T> {
|
|||
|
||||
mod events {
|
||||
use super::*;
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub struct Events {
|
||||
pub application: Application,
|
||||
|
@ -1963,6 +1964,7 @@ mod example {
|
|||
|
||||
#[derive(Debug)]
|
||||
struct Consumer;
|
||||
|
||||
impl Observer<types::GatewayResume> for Consumer {
|
||||
fn update(&mut self, data: &types::GatewayResume) {
|
||||
println!("{}", data.token)
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
use std::cell::RefCell;
|
||||
use std::fmt;
|
||||
use std::rc::Rc;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::api::limits::Limits;
|
||||
|
@ -5,10 +9,6 @@ use crate::errors::{ChorusLibError, FieldFormatError};
|
|||
use crate::types::{GeneralConfiguration, User, UserSettings};
|
||||
use crate::URLBundle;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::fmt;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
/**
|
||||
The [`Instance`] what you will be using to perform all sorts of actions on the Spacebar server.
|
||||
|
@ -47,7 +47,7 @@ impl Instance {
|
|||
Err(e) => {
|
||||
return Err(ChorusLibError::CantGetInfoError {
|
||||
error: e.to_string(),
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
Ok(instance)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use url::{ParseError, Url};
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
pub mod api;
|
||||
pub mod errors;
|
||||
|
@ -11,9 +13,7 @@ pub mod types;
|
|||
#[cfg(feature = "client")]
|
||||
pub mod voice;
|
||||
|
||||
use url::{ParseError, Url};
|
||||
#[derive(Clone, Default, Debug, PartialEq, Eq)]
|
||||
|
||||
/// A URLBundle is a struct which bundles together the API-, Gateway- and CDN-URLs of a Spacebar
|
||||
/// instance.
|
||||
pub struct URLBundle {
|
||||
|
|
18
src/limit.rs
18
src/limit.rs
|
@ -1,11 +1,12 @@
|
|||
use std::collections::VecDeque;
|
||||
|
||||
use reqwest::{Client, RequestBuilder, Response};
|
||||
|
||||
use crate::{
|
||||
api::limits::{Limit, LimitType, Limits, LimitsMutRef},
|
||||
errors::ChorusLibError,
|
||||
};
|
||||
|
||||
use reqwest::{Client, RequestBuilder, Response};
|
||||
use std::collections::VecDeque;
|
||||
|
||||
// Note: There seem to be some overlapping request limiters. We need to make sure that sending a
|
||||
// request checks for all the request limiters that apply, and blocks if any of the limiters are 0
|
||||
|
||||
|
@ -79,7 +80,7 @@ impl LimitedRequester {
|
|||
return Err(ChorusLibError::RequestErrorError {
|
||||
url: "".to_string(),
|
||||
error: e.to_string(),
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
let result = self.http.execute(built_request).await;
|
||||
|
@ -88,7 +89,7 @@ impl LimitedRequester {
|
|||
Err(e) => {
|
||||
return Err(ChorusLibError::ReceivedErrorCodeError {
|
||||
error_code: e.to_string(),
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
self.update_limits(
|
||||
|
@ -104,7 +105,7 @@ impl LimitedRequester {
|
|||
_ => {
|
||||
return Err(ChorusLibError::ReceivedErrorCodeError {
|
||||
error_code: response.status().as_str().to_string(),
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -281,10 +282,11 @@ impl LimitedRequester {
|
|||
mod rate_limit {
|
||||
use serde_json::from_str;
|
||||
|
||||
use super::*;
|
||||
use crate::{api::limits::Config, URLBundle};
|
||||
#[tokio::test]
|
||||
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn create_limited_requester() {
|
||||
let _urls = URLBundle::new(
|
||||
String::from("http://localhost:3001/api/"),
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
use std::fmt::{Display, Formatter};
|
||||
use std::io::Write;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::str::FromStr;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[cfg(feature = "sqlx")]
|
||||
use sqlx::{
|
||||
|
@ -6,10 +11,6 @@ use sqlx::{
|
|||
error::BoxDynError,
|
||||
Decode, Encode, MySql,
|
||||
};
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::io::Write;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::types::config::types::subconfigs::guild::{
|
||||
autojoin::AutoJoinConfiguration, discovery::DiscoverConfiguration,
|
||||
|
|
|
@ -9,6 +9,7 @@ pub struct RegistrationEmailConfiguration {
|
|||
#[serde(default)]
|
||||
pub domains: Vec<String>,
|
||||
}
|
||||
|
||||
impl Default for RegistrationEmailConfiguration {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
mod date_of_birth;
|
||||
mod email;
|
||||
mod password;
|
||||
|
||||
pub use date_of_birth::DateOfBirthConfiguration;
|
||||
pub use email::RegistrationEmailConfiguration;
|
||||
pub use password::PasswordConfiguration;
|
||||
|
||||
mod date_of_birth;
|
||||
mod email;
|
||||
mod password;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
mod captcha;
|
||||
mod twofactor;
|
||||
|
||||
pub use captcha::{CaptchaConfiguration, CaptchaService};
|
||||
pub use twofactor::TwoFactorConfiguration;
|
||||
|
||||
mod captcha;
|
||||
mod twofactor;
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use crate::types::utils::Snowflake;
|
||||
use crate::types::{Team, User};
|
||||
use bitflags::{bitflags, Flags};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||
|
||||
use crate::types::utils::Snowflake;
|
||||
use crate::types::{Team, User};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
|
||||
pub struct Application {
|
||||
|
|
|
@ -23,7 +23,6 @@ pub struct Attachment {
|
|||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
|
||||
pub struct PartialDiscordFileAttachment {
|
||||
pub id: Option<i16>,
|
||||
pub filename: String,
|
||||
|
|
|
@ -170,7 +170,6 @@ pub struct EmbedAuthor {
|
|||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
|
||||
|
||||
pub struct EmbedField {
|
||||
name: String,
|
||||
value: String,
|
||||
|
|
|
@ -1,26 +1,3 @@
|
|||
mod application;
|
||||
mod attachment;
|
||||
mod audit_log;
|
||||
mod auto_moderation;
|
||||
mod channel;
|
||||
mod config;
|
||||
mod emoji;
|
||||
mod guild;
|
||||
mod guild_member;
|
||||
mod integration;
|
||||
mod message;
|
||||
mod relationship;
|
||||
mod role;
|
||||
mod security_key;
|
||||
mod stage_instance;
|
||||
mod sticker;
|
||||
mod team;
|
||||
mod template;
|
||||
mod user;
|
||||
mod user_settings;
|
||||
mod voice_state;
|
||||
mod webhook;
|
||||
|
||||
pub use application::*;
|
||||
pub use attachment::*;
|
||||
pub use audit_log::*;
|
||||
|
@ -43,3 +20,26 @@ pub use user::*;
|
|||
pub use user_settings::*;
|
||||
pub use voice_state::*;
|
||||
pub use webhook::*;
|
||||
|
||||
mod application;
|
||||
mod attachment;
|
||||
mod audit_log;
|
||||
mod auto_moderation;
|
||||
mod channel;
|
||||
mod config;
|
||||
mod emoji;
|
||||
mod guild;
|
||||
mod guild_member;
|
||||
mod integration;
|
||||
mod message;
|
||||
mod relationship;
|
||||
mod role;
|
||||
mod security_key;
|
||||
mod stage_instance;
|
||||
mod sticker;
|
||||
mod team;
|
||||
mod template;
|
||||
mod user;
|
||||
mod user_settings;
|
||||
mod voice_state;
|
||||
mod webhook;
|
||||
|
|
|
@ -21,7 +21,8 @@ pub struct GuildTemplate {
|
|||
pub updated_at: DateTime<Utc>,
|
||||
pub source_guild_id: String,
|
||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||
pub source_guild: Vec<Guild>, // Unsure how a {recursive: Guild} looks like, might be a Vec?
|
||||
pub source_guild: Vec<Guild>,
|
||||
// Unsure how a {recursive: Guild} looks like, might be a Vec?
|
||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||
pub serialized_source_guild: Vec<Guild>,
|
||||
}
|
||||
|
|
|
@ -11,12 +11,14 @@ pub struct CallCreate {
|
|||
pub voice_states: Vec<VoiceState>,
|
||||
/// Seems like a vec of channel ids
|
||||
pub ringing: Vec<String>,
|
||||
pub region: String, // milan
|
||||
pub region: String,
|
||||
// milan
|
||||
pub message_id: String,
|
||||
/// What is this?
|
||||
pub embedded_activities: Vec<serde_json::Value>,
|
||||
pub channel_id: String,
|
||||
}
|
||||
|
||||
impl WebSocketEvent for CallCreate {}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
|
||||
|
@ -27,11 +29,13 @@ impl WebSocketEvent for CallCreate {}
|
|||
pub struct CallUpdate {
|
||||
/// Seems like a vec of channel ids
|
||||
pub ringing: Vec<String>,
|
||||
pub region: String, // milan
|
||||
pub region: String,
|
||||
// milan
|
||||
pub message_id: String,
|
||||
pub guild_id: Option<String>,
|
||||
pub channel_id: String,
|
||||
}
|
||||
|
||||
impl WebSocketEvent for CallUpdate {}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
|
||||
|
@ -41,6 +45,7 @@ impl WebSocketEvent for CallUpdate {}
|
|||
pub struct CallDelete {
|
||||
pub channel_id: String,
|
||||
}
|
||||
|
||||
impl WebSocketEvent for CallDelete {}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
|
||||
|
@ -51,4 +56,5 @@ impl WebSocketEvent for CallDelete {}
|
|||
pub struct CallSync {
|
||||
pub channel_id: String,
|
||||
}
|
||||
|
||||
impl WebSocketEvent for CallSync {}
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::types::events::WebSocketEvent;
|
|||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
/// See https://discord.com/developers/docs/topics/gateway-events#channel-pins-update
|
||||
pub struct ChannelPinsUpdate {
|
||||
pub guild_id: Option<String>,
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::entities::{Guild, PublicUser, UnavailableGuild};
|
||||
use crate::types::events::WebSocketEvent;
|
||||
use crate::types::{AuditLogEntry, Emoji, GuildMember, GuildScheduledEvent, RoleObject, Sticker};
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::PresenceUpdate;
|
||||
|
||||
|
@ -27,6 +28,7 @@ impl Default for GuildCreateDataOption {
|
|||
GuildCreateDataOption::UnavailableGuild(UnavailableGuild::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl WebSocketEvent for GuildCreate {}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::types::events::WebSocketEvent;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct GatewayHeartbeat {
|
||||
pub op: u8,
|
||||
pub d: Option<u64>,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::types::events::WebSocketEvent;
|
||||
use crate::types::WebSocketEvent;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
|
||||
/// Received on gateway init, tells the client how often to send heartbeats;
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct GatewayHello {
|
||||
pub op: i32,
|
||||
pub d: HelloData,
|
||||
|
|
|
@ -2,14 +2,15 @@ use crate::types::events::{PresenceUpdate, WebSocketEvent};
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::serde_as;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct GatewayIdentifyPayload {
|
||||
pub token: String,
|
||||
pub properties: GatewayIdentifyConnectionProps,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub compress: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub large_threshold: Option<i16>, //default: 50
|
||||
pub large_threshold: Option<i16>,
|
||||
//default: 50
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub shard: Option<Vec<(i32, i32)>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
|
|
@ -24,4 +24,5 @@ pub struct LazyRequest {
|
|||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub channels: Option<HashMap<String, Vec<Vec<u64>>>>,
|
||||
}
|
||||
|
||||
impl WebSocketEvent for LazyRequest {}
|
||||
|
|
|
@ -126,4 +126,5 @@ pub struct MessageACK {
|
|||
pub flags: Option<serde_json::Value>,
|
||||
pub channel_id: String,
|
||||
}
|
||||
|
||||
impl WebSocketEvent for MessageACK {}
|
||||
|
|
|
@ -1,31 +1,5 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
mod application;
|
||||
mod auto_moderation;
|
||||
mod call;
|
||||
mod channel;
|
||||
mod guild;
|
||||
mod heartbeat;
|
||||
mod hello;
|
||||
mod identify;
|
||||
mod integration;
|
||||
mod interaction;
|
||||
mod invite;
|
||||
mod lazy_request;
|
||||
mod message;
|
||||
mod passive_update;
|
||||
mod presence;
|
||||
mod ready;
|
||||
mod relationship;
|
||||
mod request_members;
|
||||
mod resume;
|
||||
mod session;
|
||||
mod stage_instance;
|
||||
mod thread;
|
||||
mod user;
|
||||
mod voice;
|
||||
mod webhooks;
|
||||
|
||||
pub use application::*;
|
||||
pub use auto_moderation::*;
|
||||
pub use call::*;
|
||||
|
@ -52,6 +26,32 @@ pub use user::*;
|
|||
pub use voice::*;
|
||||
pub use webhooks::*;
|
||||
|
||||
mod application;
|
||||
mod auto_moderation;
|
||||
mod call;
|
||||
mod channel;
|
||||
mod guild;
|
||||
mod heartbeat;
|
||||
mod hello;
|
||||
mod identify;
|
||||
mod integration;
|
||||
mod interaction;
|
||||
mod invite;
|
||||
mod lazy_request;
|
||||
mod message;
|
||||
mod passive_update;
|
||||
mod presence;
|
||||
mod ready;
|
||||
mod relationship;
|
||||
mod request_members;
|
||||
mod resume;
|
||||
mod session;
|
||||
mod stage_instance;
|
||||
mod thread;
|
||||
mod user;
|
||||
mod voice;
|
||||
mod webhooks;
|
||||
|
||||
pub trait WebSocketEvent {}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Clone)]
|
||||
|
@ -79,7 +79,6 @@ impl WebSocketEvent for GatewaySendPayload {}
|
|||
///
|
||||
/// Similar to [GatewaySendPayload], except we send a [Value] for d whilst we receive a [serde_json::value::RawValue]
|
||||
/// Also, we never need to sent the event name
|
||||
|
||||
pub struct GatewayReceivePayload<'a> {
|
||||
#[serde(rename = "op")]
|
||||
pub op_code: u8,
|
||||
|
|
|
@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
|
|||
use super::{ChannelUnreadUpdateObject, WebSocketEvent};
|
||||
use crate::types::{GuildMember, VoiceState};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
|
||||
#[derive(Debug, Deserialize, Serialize, Default)]
|
||||
/// Officially Undocumented
|
||||
///
|
||||
/// Seems to be passively set to update the client on guild details (though, why not just send the update events?)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use crate::types::interfaces::Activity;
|
||||
use crate::types::{events::WebSocketEvent, UserStatus};
|
||||
use crate::types::{PublicUser, Snowflake};
|
||||
use crate::types::{Activity, PublicUser, Snowflake};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::entities::{Guild, User};
|
||||
use crate::types::events::{Session, WebSocketEvent};
|
||||
use crate::types::interfaces::ClientStatusObject;
|
||||
use crate::types::{Activity, GuildMember, PresenceUpdate, VoiceState};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
|
||||
/// 1/2 half documented;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::types::{events::WebSocketEvent, Relationship, RelationshipType, Snowflake};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
|
||||
#[derive(Debug, Deserialize, Serialize, Default)]
|
||||
/// See https://github.com/spacebarchat/server/issues/204
|
||||
pub struct RelationshipAdd {
|
||||
#[serde(flatten)]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::types::events::WebSocketEvent;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
|
||||
#[derive(Debug, Deserialize, Serialize, Default)]
|
||||
/// See https://discord.com/developers/docs/topics/gateway-events#request-guild-members-request-guild-members-structure
|
||||
pub struct GatewayRequestGuildMembers {
|
||||
pub guild_id: String,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::types::events::WebSocketEvent;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
|
||||
#[derive(Debug, Deserialize, Serialize, Default)]
|
||||
pub struct GatewayResume {
|
||||
pub token: String,
|
||||
pub session_id: String,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::entities::{Channel, ThreadMember};
|
||||
use crate::types::events::WebSocketEvent;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
|
||||
/// See https://discord.com/developers/docs/topics/gateway-events#thread-create
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::entities::PublicUser;
|
||||
use crate::types::events::WebSocketEvent;
|
||||
use crate::types::utils::Snowflake;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
|
||||
/// See https://discord.com/developers/docs/topics/gateway-events#user-update;
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use crate::types::{events::WebSocketEvent, VoiceState};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
|
||||
/// See https://discord.com/developers/docs/topics/gateway-events#update-voice-state;
|
||||
#[derive(Debug, Deserialize, Serialize, Default)]
|
||||
///
|
||||
/// Sent to the server to indicate an update of the voice state (leave voice channel, join voice channel, mute, deafen);
|
||||
///
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::types::entities::Emoji;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::entities::Emoji;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
pub struct Activity {
|
||||
name: String,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::types::utils::Snowflake;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::utils::Snowflake;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)]
|
||||
pub struct WelcomeScreenObject {
|
||||
pub enabled: bool,
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use crate::types::entities::{AllowedMention, Embed};
|
||||
use crate::types::utils::Snowflake;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::types::entities::{AllowedMention, Embed};
|
||||
use crate::types::utils::Snowflake;
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Interaction {
|
||||
pub id: Snowflake,
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
mod activity;
|
||||
mod connected_account;
|
||||
mod guild_welcome_screen;
|
||||
mod interaction;
|
||||
mod status;
|
||||
|
||||
pub use activity::*;
|
||||
pub use connected_account::*;
|
||||
pub use guild_welcome_screen::*;
|
||||
pub use interaction::*;
|
||||
pub use status::*;
|
||||
|
||||
mod activity;
|
||||
mod connected_account;
|
||||
mod guild_welcome_screen;
|
||||
mod interaction;
|
||||
mod status;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use crate::errors::FieldFormatError;
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::errors::FieldFormatError;
|
||||
|
||||
/**
|
||||
A struct that represents a well-formed email address.
|
||||
*/
|
||||
|
@ -100,7 +101,6 @@ You will receive a [`FieldFormatError`], if:
|
|||
- The username is not between 2 and 32 characters.
|
||||
- The password is not between 1 and 72 characters.
|
||||
*/
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct RegisterSchema {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::types::entities::Channel;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::entities::Channel;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
/// Represents the schema which needs to be sent to create a Guild.
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::entities::{
|
||||
AllowedMention, Component, Embed, MessageReference, PartialDiscordFileAttachment,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
|
|
|
@ -1,11 +1,3 @@
|
|||
mod apierror;
|
||||
mod auth;
|
||||
mod channel;
|
||||
mod guild;
|
||||
mod message;
|
||||
mod role;
|
||||
mod user;
|
||||
|
||||
pub use apierror::*;
|
||||
pub use auth::*;
|
||||
pub use channel::*;
|
||||
|
@ -14,11 +6,20 @@ pub use message::*;
|
|||
pub use role::*;
|
||||
pub use user::*;
|
||||
|
||||
mod apierror;
|
||||
mod auth;
|
||||
mod channel;
|
||||
mod guild;
|
||||
mod message;
|
||||
mod role;
|
||||
mod user;
|
||||
|
||||
#[cfg(test)]
|
||||
mod schemas_tests {
|
||||
use super::*;
|
||||
use crate::errors::FieldFormatError;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn password_too_short() {
|
||||
assert_eq!(
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use crate::types::Snowflake;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
pub use regexes::*;
|
||||
pub use rights::Rights;
|
||||
pub use snowflake::{DeconstructedSnowflake, Snowflake};
|
||||
|
||||
pub mod jwt;
|
||||
mod regexes;
|
||||
mod rights;
|
||||
mod snowflake;
|
||||
|
||||
pub use regexes::*;
|
||||
pub use rights::Rights;
|
||||
pub use snowflake::{DeconstructedSnowflake, Snowflake};
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
mod common;
|
||||
use chorus::types;
|
||||
|
||||
mod common;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_registration() {
|
||||
let mut bundle = common::setup().await;
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
mod common;
|
||||
use chorus::types::{self, Channel, PermissionFlags, PermissionOverwrite};
|
||||
|
||||
mod common;
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_channel() {
|
||||
let mut bundle = common::setup().await;
|
||||
let bundle_channel = bundle.channel.clone();
|
||||
let mut bundle_user = &mut bundle.user;
|
||||
let bundle_user = &mut bundle.user;
|
||||
|
||||
assert_eq!(
|
||||
bundle_channel,
|
||||
Channel::get(&mut bundle_user, &bundle_channel.id.to_string(),)
|
||||
Channel::get(bundle_user, &bundle_channel.id.to_string())
|
||||
.await
|
||||
.unwrap()
|
||||
);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
mod common;
|
||||
use chorus::types::{Guild, GuildCreateSchema};
|
||||
|
||||
mod common;
|
||||
|
||||
#[tokio::test]
|
||||
async fn guild_creation_deletion() {
|
||||
let mut bundle = common::setup().await;
|
||||
|
|
|
@ -7,7 +7,7 @@ async fn add_remove_role() {
|
|||
let role_id = &bundle.role.id.to_string();
|
||||
let user_id = &bundle.user.object.id.to_string();
|
||||
chorus::types::GuildMember::add_role(&mut bundle.user, guild_id, user_id, role_id).await;
|
||||
let member = chorus::types::GuildMember::get(&mut bundle.user, &guild_id, &user_id)
|
||||
let member = chorus::types::GuildMember::get(&mut bundle.user, guild_id, user_id)
|
||||
.await
|
||||
.unwrap();
|
||||
let mut role_found = false;
|
||||
|
@ -21,7 +21,7 @@ async fn add_remove_role() {
|
|||
assert!(false)
|
||||
}
|
||||
chorus::types::GuildMember::remove_role(&mut bundle.user, guild_id, user_id, role_id).await;
|
||||
let member = chorus::types::GuildMember::get(&mut bundle.user, &guild_id, &user_id)
|
||||
let member = chorus::types::GuildMember::get(&mut bundle.user, guild_id, user_id)
|
||||
.await
|
||||
.unwrap();
|
||||
for role in member.roles.iter() {
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
mod common;
|
||||
|
||||
use chorus::types;
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader, Read};
|
||||
|
||||
use chorus::types;
|
||||
|
||||
mod common;
|
||||
|
||||
#[tokio::test]
|
||||
async fn send_message() {
|
||||
let mut bundle = common::setup().await;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
mod common;
|
||||
|
||||
use chorus::types::{self, RoleCreateModifySchema};
|
||||
|
||||
mod common;
|
||||
|
||||
#[tokio::test]
|
||||
async fn create_and_get_roles() {
|
||||
let mut bundle = common::setup().await;
|
||||
|
|
Loading…
Reference in New Issue