71 conflicts due to fmt?!?!?!?!

This commit is contained in:
kozabrada123 2023-05-28 14:52:08 +02:00
commit 51097b3a41
55 changed files with 981 additions and 617 deletions

5
.rusty-hook.toml Normal file
View File

@ -0,0 +1,5 @@
[hooks]
pre-commit = "cargo fmt -p chorus && exit 0"
[logging]
verbose = true

View File

@ -40,3 +40,4 @@ jsonwebtoken = "8.3.0"
[dev-dependencies]
lazy_static = "1.4.0"
rusty-hook = "0.11.2"

View File

@ -70,54 +70,3 @@ pub mod login {
}
}
}
/*#[cfg(test)]
mod test {
use crate::api::schemas::schemas::{
AuthEmail, AuthPassword, AuthUsername, LoginSchema, RegisterSchema,
};
use crate::instance::Instance;
use crate::limit::LimitedRequester;
use crate::URLBundle;
#[tokio::test]
async fn test_login() {
let urls = URLBundle::new(
"http://localhost:3001/api".to_string(),
"http://localhost:3001".to_string(),
"http://localhost:3001".to_string(),
);
let limited_requester = LimitedRequester::new(urls.get_api().to_string()).await;
let mut test_instance = Instance::new(urls.clone(), limited_requester)
.await
.unwrap();
let reg = RegisterSchema::new(
AuthUsername::new("TestAccount".to_string()).unwrap(),
Some(AuthPassword::new("transrights".to_string()).unwrap()),
true,
Some(AuthEmail::new("apiauthlogin1@testlogin.xyz".to_string()).unwrap()),
None,
None,
Some("2000-01-01".to_string()),
None,
None,
None,
)
.unwrap();
test_instance.register_account(&reg).await.unwrap().token;
let login_schema = LoginSchema::new(
AuthUsername::new("apiauthlogin1@testlogin.xyz".to_string()).unwrap(),
"transrights".to_string(),
Some(false),
None,
None,
None,
);
let login_result = test_instance
.login_account(&login_schema.unwrap())
.await
.unwrap();
}
}*/

View File

@ -78,36 +78,3 @@ pub mod register {
}
}
}
#[cfg(test)]
mod test {
use crate::instance::Instance;
use crate::limit::LimitedRequester;
use crate::types::RegisterSchema;
use crate::URLBundle;
#[tokio::test]
async fn test_registration() {
let urls = URLBundle::new(
"http://localhost:3001/api".to_string(),
"http://localhost:3001".to_string(),
"http://localhost:3001".to_string(),
);
let _limited_requester = LimitedRequester::new().await;
let mut test_instance = Instance::new(urls.clone()).await.unwrap();
let reg = RegisterSchema::new(
"Hiiii".to_string(),
None,
true,
None,
None,
None,
Some("2000-01-01".to_string()),
None,
None,
None,
)
.unwrap();
let _ = test_instance.register_account(&reg).await.unwrap().token;
}
}

View File

@ -114,137 +114,3 @@ pub mod messages {
}
}
}
#[cfg(test)]
mod test {
use crate::instance::UserMeta;
use crate::types::{LoginSchema, MessageSendSchema, PartialDiscordFileAttachment};
use crate::{instance::Instance};
use std::io::Read;
use std::{cell::RefCell, fs::File};
use std::{io::BufReader, rc::Rc};
#[tokio::test]
async fn send_message() {
let channel_id = "1106954414356168802".to_string();
let mut message = MessageSendSchema::new(
None,
Some("A Message!".to_string()),
None,
None,
None,
None,
None,
None,
None,
None,
);
let mut instance = Instance::new(crate::URLBundle {
api: "http://localhost:3001/api".to_string(),
wss: "ws://localhost:3001/".to_string(),
cdn: "http://localhost:3001".to_string(),
})
.await
.unwrap();
let login_schema: LoginSchema = LoginSchema::new(
"user@test.xyz".to_string(),
"transrights".to_string(),
None,
None,
None,
None,
)
.unwrap();
let login_result = instance.login_account(&login_schema).await.unwrap();
let token = login_result.token;
println!("TOKEN: {}", token);
let settings = login_result.settings;
let limits = instance.limits.clone();
let mut user = UserMeta::new(
Rc::new(RefCell::new(instance)),
token,
limits,
settings,
None,
);
let _ = user
.send_message(&mut message, channel_id, None)
.await
.unwrap();
}
#[tokio::test]
async fn send_message_attachment() {
let channel_id = "1106954414356168802".to_string();
let f = File::open("./README.md").unwrap();
let mut reader = BufReader::new(f);
let mut buffer = Vec::new();
reader.read_to_end(&mut buffer).unwrap();
let attachment = PartialDiscordFileAttachment {
id: None,
filename: "README.md".to_string(),
description: None,
content_type: None,
size: None,
url: None,
proxy_url: None,
width: None,
height: None,
ephemeral: None,
duration_secs: None,
waveform: None,
content: buffer,
};
let mut message = MessageSendSchema::new(
None,
Some("trans rights now".to_string()),
None,
None,
None,
None,
None,
None,
None,
Some(vec![attachment.clone()]),
);
let mut instance = Instance::new(crate::URLBundle {
api: "http://localhost:3001/api".to_string(),
wss: "ws://localhost:3001/".to_string(),
cdn: "http://localhost:3001".to_string(),
})
.await
.unwrap();
let login_schema: LoginSchema = LoginSchema::new(
"user@test.xyz".to_string(),
"transrights".to_string(),
None,
None,
None,
None,
)
.unwrap();
let login_result = instance.login_account(&login_schema).await.unwrap();
let token = login_result.token;
let settings = login_result.settings;
let limits = instance.limits.clone();
let mut user = UserMeta::new(
Rc::new(RefCell::new(instance)),
token,
limits,
settings,
None,
);
let vec_attach = vec![attachment.clone()];
let _arg = Some(&vec_attach);
let response = user
.send_message(&mut message, channel_id, Some(vec![attachment.clone()]))
.await
.unwrap();
println!("[Response:] {}", response.text().await.unwrap());
}
}

View File

@ -1,3 +1 @@
pub mod guilds;
use guilds::*;

View File

@ -37,21 +37,3 @@ impl Instance {
Ok(instance_policies_schema)
}
}
#[cfg(test)]
mod instance_policies_schema_test {
use crate::{instance::Instance, limit::LimitedRequester, URLBundle};
#[tokio::test]
async fn generate_instance_policies_schema() {
let urls = URLBundle::new(
"http://localhost:3001/api".to_string(),
"http://localhost:3001".to_string(),
"http://localhost:3001".to_string(),
);
let _limited_requester = LimitedRequester::new().await;
let test_instance = Instance::new(urls.clone()).await.unwrap();
let _schema = test_instance.general_configuration_schema().await.unwrap();
}
}

View File

@ -178,10 +178,3 @@ impl Instance {
.await
}
}
#[cfg(test)]
mod test {
#[tokio::test]
async fn get_user() {}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,5 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct LatLong {
pub latitude: f64,

View File

@ -1,4 +1,3 @@
use crate::types::Message;
use serde::{Deserialize, Serialize};
use crate::types::utils::Snowflake;

View File

@ -13,7 +13,7 @@ pub struct AuditLogEntry {
pub action_type: u8,
// to:do add better options type
pub options: Option<serde_json::Value>,
pub reason: Option<String>
pub reason: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
@ -21,5 +21,5 @@ pub struct AuditLogEntry {
pub struct AuditLogChange {
pub new_value: Option<serde_json::Value>,
pub old_value: Option<serde_json::Value>,
pub key: String
pub key: String,
}

View File

@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use serde_repr::{Serialize_repr, Deserialize_repr};
use serde_repr::{Deserialize_repr, Serialize_repr};
use crate::types::utils::Snowflake;
@ -21,23 +21,23 @@ pub struct AutoModerationRule {
#[derive(Serialize_repr, Deserialize_repr, Debug, Clone, Default)]
#[repr(u8)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// See https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types
pub enum AutoModerationRuleEventType {
#[default]
MessageSend = 1
MessageSend = 1,
}
#[derive(Serialize_repr, Deserialize_repr, Debug, Clone, Default)]
#[repr(u8)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// See https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types
pub enum AutoModerationRuleTriggerType {
#[default]
Keyword = 1,
Spam = 3,
KeywordPreset = 4,
MentionSpam = 5
MentionSpam = 5,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
@ -48,7 +48,7 @@ pub enum AutoModerationRuleTriggerMetadata {
ForKeywordPreset(AutoModerationRuleTriggerMetadataForKeywordPreset),
ForMentionSpam(AutoModerationRuleTriggerMetadataForMentionSpam),
#[default]
None
None,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
@ -71,37 +71,37 @@ pub struct AutoModerationRuleTriggerMetadataForKeywordPreset {
pub struct AutoModerationRuleTriggerMetadataForMentionSpam {
/// Max 50
pub mention_total_limit: u8,
pub mention_raid_protection_enabled: bool
pub mention_raid_protection_enabled: bool,
}
#[derive(Serialize_repr, Deserialize_repr, Debug, Clone, Default)]
#[repr(u8)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// See https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-preset-types
pub enum AutoModerationRuleKeywordPresetType {
#[default]
Profanity = 1,
SexualContent = 2,
Slurs = 3
Slurs = 3,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
/// See https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object
pub struct AutoModerationAction {
#[serde(rename = "type")]
#[serde(rename = "type")]
pub action_type: AutoModerationActionType,
pub metadata: Option<AutoModerationActionMetadata>
pub metadata: Option<AutoModerationActionMetadata>,
}
#[derive(Serialize_repr, Deserialize_repr, Debug, Clone, Default)]
#[repr(u8)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// See https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-types
pub enum AutoModerationActionType {
#[default]
BlockMessage = 1,
SendAlertMessage = 2,
Timeout = 3
Timeout = 3,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
@ -112,19 +112,19 @@ pub enum AutoModerationActionMetadata {
ForSendAlertMessage(AutoModerationActionMetadataForSendAlertMessage),
ForTimeout(AutoModerationActionMetadataForTimeout),
#[default]
None
None,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
/// See https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-metadata
pub struct AutoModerationActionMetadataForBlockMessage {
pub custom_message: Option<String>
pub custom_message: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
/// See https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-metadata
pub struct AutoModerationActionMetadataForSendAlertMessage {
pub channel_id: Snowflake
pub channel_id: Snowflake,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
@ -132,4 +132,4 @@ pub struct AutoModerationActionMetadataForSendAlertMessage {
pub struct AutoModerationActionMetadataForTimeout {
/// Max 2419200
pub duration_seconds: u32,
}
}

View File

@ -1,6 +1,9 @@
use chrono::Utc;
use serde::{Deserialize, Serialize};
use serde_aux::prelude::{deserialize_number_from_string, deserialize_option_number_from_string, deserialize_string_from_number};
use serde_aux::prelude::{
deserialize_number_from_string, deserialize_option_number_from_string,
deserialize_string_from_number,
};
use serde_repr::{Deserialize_repr, Serialize_repr};
use crate::types::{

View File

@ -1,8 +1,7 @@
use serde::{Deserialize, Serialize};
use serde_aux::prelude::deserialize_option_number_from_string;
use crate::types::entities::User;
use crate::types::{Guild, Snowflake};
use crate::types::Snowflake;
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize, Default)]
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]

View File

@ -1,9 +1,9 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_repr::{Serialize_repr, Deserialize_repr};
use serde_repr::{Deserialize_repr, Serialize_repr};
use crate::types::{
entities::{Channel, Emoji, GuildTemplate, RoleObject, Sticker, User, VoiceState, Webhook},
entities::{Channel, Emoji, RoleObject, Sticker, User, VoiceState, Webhook},
interfaces::WelcomeScreenObject,
utils::Snowflake,
};
@ -140,7 +140,7 @@ pub struct GuildScheduledEvent {
pub entity_metadata: Option<GuildScheduledEventEntityMetadata>,
pub creator: Option<User>,
pub user_count: Option<u64>,
pub image: Option<String>
pub image: Option<String>,
}
#[derive(Serialize_repr, Deserialize_repr, Debug, Default, Clone)]
@ -159,7 +159,7 @@ pub enum GuildScheduledEventStatus {
Scheduled = 1,
Active = 2,
Completed = 3,
Canceled = 4
Canceled = 4,
}
#[derive(Serialize_repr, Deserialize_repr, Debug, Default, Clone)]
@ -175,5 +175,5 @@ pub enum GuildScheduledEventEntityType {
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
/// See https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-entity-metadata
pub struct GuildScheduledEventEntityMetadata {
pub location: Option<String>
}
pub location: Option<String>,
}

View File

@ -1,5 +1,7 @@
mod application;
mod attachment;
mod audit_log;
mod auto_moderation;
mod channel;
mod config;
mod emoji;
@ -7,8 +9,10 @@ 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;
@ -16,13 +20,11 @@ mod user;
mod user_settings;
mod voice_state;
mod webhook;
mod audit_log;
mod relationship;
mod auto_moderation;
mod stage_instance;
pub use application::*;
pub use attachment::*;
pub use audit_log::*;
pub use auto_moderation::*;
pub use channel::*;
pub use config::*;
pub use emoji::*;
@ -30,8 +32,10 @@ pub use guild::*;
pub use guild_member::*;
pub use integration::*;
pub use message::*;
pub use relationship::*;
pub use role::*;
pub use security_key::*;
pub use stage_instance::*;
pub use sticker::*;
pub use team::*;
pub use template::*;
@ -39,7 +43,3 @@ pub use user::*;
pub use user_settings::*;
pub use voice_state::*;
pub use webhook::*;
pub use audit_log::*;
pub use relationship::*;
pub use auto_moderation::*;
pub use stage_instance::*;

View File

@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use serde_repr::{Serialize_repr, Deserialize_repr};
use serde_repr::{Deserialize_repr, Serialize_repr};
use crate::types::Snowflake;
@ -9,10 +9,10 @@ use super::PublicUser;
/// See https://docs.spacebar.chat/routes/#get-/users/@me/relationships/
pub struct Relationship {
pub id: Snowflake,
#[serde(rename = "type")]
#[serde(rename = "type")]
pub relationship_type: RelationshipType,
pub nickname: Option<String>,
pub user: PublicUser
pub user: PublicUser,
}
#[derive(Serialize_repr, Deserialize_repr, Debug, Clone, Default)]
@ -24,4 +24,4 @@ pub enum RelationshipType {
Blocked = 2,
#[default]
Friends = 1,
}
}

View File

@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use serde_aux::prelude::{deserialize_string_from_number, deserialize_option_number_from_string};
use serde_aux::prelude::{deserialize_option_number_from_string, deserialize_string_from_number};
use crate::types::utils::Snowflake;
@ -19,7 +19,7 @@ pub struct RoleObject {
pub permissions: String,
pub managed: bool,
pub mentionable: bool,
pub tags: Option<RoleTags>
pub tags: Option<RoleTags>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]

View File

@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use serde_repr::{Serialize_repr, Deserialize_repr};
use serde_repr::{Deserialize_repr, Serialize_repr};
use crate::types::Snowflake;
@ -19,11 +19,11 @@ pub struct StageInstance {
#[derive(Serialize_repr, Deserialize_repr, Debug, Clone, Default)]
#[repr(u8)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// See https://discord.com/developers/docs/resources/stage-instance#stage-instance-object-privacy-level
pub enum StageInstancePrivacyLevel {
/// deprecated, apparently
Public = 1,
#[default]
GuildOnly = 2
}
GuildOnly = 2,
}

View File

@ -1,5 +1,4 @@
use serde::{Deserialize, Serialize};
use serde_aux::prelude::{deserialize_option_number_from_string};
use crate::types::{entities::User, utils::Snowflake};

View File

@ -1,12 +1,8 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_aux::prelude::deserialize_option_number_from_string;
use serde_json::{Map, Value};
use crate::types::{
errors::Error,
utils::Snowflake, //util::{email::adjust_email, entities::user_setting::UserSettings},
};
use crate::types::utils::Snowflake;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]

View File

@ -1,8 +1,6 @@
use chrono::{serde::ts_milliseconds_option, Utc};
use serde::{Deserialize, Serialize};
use crate::types::utils::Snowflake;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
#[serde(rename_all = "lowercase")]

View File

@ -2,7 +2,7 @@ use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::types::{
entities::{Channel, Guild, GuildMember, User},
entities::{Guild, GuildMember},
utils::Snowflake,
};

View File

@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use crate::types::{
entities::{Application, Channel, Guild, User},
entities::{Guild, User},
utils::Snowflake,
};

View File

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use crate::types::{WebSocketEvent, GuildApplicationCommandPermissions};
use crate::types::{GuildApplicationCommandPermissions, WebSocketEvent};
#[derive(Debug, Deserialize, Serialize, Default)]
/// See https://discord.com/developers/docs/topics/gateway-events#application-command-permissions-update
@ -9,4 +9,4 @@ pub struct ApplicationCommandPermissionsUpdate {
pub permissions: GuildApplicationCommandPermissions,
}
impl WebSocketEvent for ApplicationCommandPermissionsUpdate {}
impl WebSocketEvent for ApplicationCommandPermissionsUpdate {}

View File

@ -1,6 +1,9 @@
use serde::{Deserialize, Serialize};
use crate::types::{WebSocketEvent, AutoModerationRule, Snowflake, AutoModerationAction, AutoModerationRuleTriggerType};
use crate::types::{
AutoModerationAction, AutoModerationRule, AutoModerationRuleTriggerType, Snowflake,
WebSocketEvent,
};
#[derive(Debug, Deserialize, Serialize, Default)]
/// See https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-create
@ -9,7 +12,7 @@ pub struct AutoModerationRuleCreate {
pub rule: AutoModerationRule,
}
impl WebSocketEvent for AutoModerationRuleCreate {}
impl WebSocketEvent for AutoModerationRuleCreate {}
#[derive(Debug, Deserialize, Serialize, Default)]
/// See https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-update
@ -18,7 +21,7 @@ pub struct AutoModerationRuleUpdate {
pub rule: AutoModerationRule,
}
impl WebSocketEvent for AutoModerationRuleUpdate {}
impl WebSocketEvent for AutoModerationRuleUpdate {}
#[derive(Debug, Deserialize, Serialize, Default)]
/// See https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-delete
@ -27,7 +30,7 @@ pub struct AutoModerationRuleDelete {
pub rule: AutoModerationRule,
}
impl WebSocketEvent for AutoModerationRuleDelete {}
impl WebSocketEvent for AutoModerationRuleDelete {}
#[derive(Debug, Deserialize, Serialize, Default)]
/// See https://discord.com/developers/docs/topics/gateway-events#auto-moderation-action-execution
@ -42,7 +45,7 @@ pub struct AutoModerationActionExecution {
pub alert_system_message_id: Option<Snowflake>,
pub content: Option<String>,
pub matched_keyword: Option<String>,
pub matched_content: Option<String>
pub matched_content: Option<String>,
}
impl WebSocketEvent for AutoModerationActionExecution {}
impl WebSocketEvent for AutoModerationActionExecution {}

View File

@ -48,4 +48,4 @@ impl WebSocketEvent for CallDelete {}
pub struct CallSync {
pub channel_id: String,
}
impl WebSocketEvent for CallSync {}
impl WebSocketEvent for CallSync {}

View File

@ -46,7 +46,7 @@ pub struct ChannelUnreadUpdate {
pub struct ChannelUnreadUpdateObject {
pub id: String,
pub last_message_id: String,
pub last_pin_timestamp: Option<String>
pub last_pin_timestamp: Option<String>,
}
impl WebSocketEvent for ChannelUnreadUpdate {}

View File

@ -30,4 +30,4 @@ pub struct IntegrationDelete {
pub application_id: Option<String>,
}
impl WebSocketEvent for IntegrationDelete {}
impl WebSocketEvent for IntegrationDelete {}

View File

@ -9,4 +9,4 @@ pub struct InteractionCreate {
pub interaction: Interaction,
}
impl WebSocketEvent for InteractionCreate {}
impl WebSocketEvent for InteractionCreate {}

View File

@ -6,7 +6,7 @@ use crate::types::{GuildInvite, WebSocketEvent};
/// See https://discord.com/developers/docs/topics/gateway-events#invite-create
pub struct InviteCreate {
#[serde(flatten)]
pub invite: GuildInvite
pub invite: GuildInvite,
}
impl WebSocketEvent for InviteCreate {}
@ -19,4 +19,4 @@ pub struct InviteDelete {
pub code: String,
}
impl WebSocketEvent for InviteDelete {}
impl WebSocketEvent for InviteDelete {}

View File

@ -6,13 +6,13 @@ use super::WebSocketEvent;
#[derive(Debug, Deserialize, Serialize, Default)]
/// Officially Undocumented
///
///
/// Sent to the server to signify lazy loading of a guild;
/// Sent by the official client when switching to a guild or channel;
/// After this, you should recieve message updates
///
///
/// See https://luna.gitlab.io/discord-unofficial-docs/lazy_guilds.html#op-14-lazy-request
///
///
/// {"op":14,"d":{"guild_id":"848582562217590824","typing":true,"activities":true,"threads":true}}
pub struct LazyRequest {
pub guild_id: String,
@ -22,6 +22,6 @@ pub struct LazyRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub members: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub channels: Option<HashMap<String, Vec<Vec<u64>>>>
pub channels: Option<HashMap<String, Vec<Vec<u64>>>>,
}
impl WebSocketEvent for LazyRequest {}
impl WebSocketEvent for LazyRequest {}

View File

@ -1,10 +1,7 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::types::{
entities::{Emoji, GuildMember, Message, User},
utils::Snowflake, PublicUser,
};
use crate::types::entities::{Emoji, GuildMember, Message, PublicUser};
use super::WebSocketEvent;
@ -34,7 +31,7 @@ pub struct MessageCreate {
pub struct MessageCreateUser {
#[serde(flatten)]
user: PublicUser,
member: Option<GuildMember>
member: Option<GuildMember>,
}
impl WebSocketEvent for MessageCreate {}
@ -112,12 +109,12 @@ impl WebSocketEvent for MessageReactionRemoveEmoji {}
#[derive(Debug, Deserialize, Serialize, Default)]
/// Officially Undocumented
///
///
/// Not documented anywhere unofficially
///
///
/// Apparently "Message ACK refers to marking a message as read for Discord's API." (https://github.com/Rapptz/discord.py/issues/1851)
/// I suspect this is sent and recieved from the gateway to let clients on other devices know the user has read a message
///
///
/// {"t":"MESSAGE_ACK","s":3,"op":0,"d":{"version":52,"message_id":"1107236673638633472","last_viewed":null,"flags":null,"channel_id":"967363950217936897"}}
pub struct MessageACK {
/// ?
@ -130,4 +127,4 @@ pub struct MessageACK {
pub flags: Option<serde_json::Value>,
pub channel_id: String,
}
impl WebSocketEvent for MessageACK {}
impl WebSocketEvent for MessageACK {}

View File

@ -1,62 +1,62 @@
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 session;
mod webhooks;
mod passive_update;
mod integration;
mod invite;
mod call;
mod lazy_request;
mod relationship;
mod auto_moderation;
mod stage_instance;
mod interaction;
mod application;
pub use application::*;
pub use auto_moderation::*;
pub use call::*;
pub use channel::*;
pub use guild::*;
pub use heartbeat::*;
pub use hello::*;
pub use identify::*;
pub use integration::*;
pub use interaction::*;
pub use invite::*;
pub use lazy_request::*;
pub use message::*;
pub use passive_update::*;
pub use presence::*;
pub use ready::*;
pub use relationship::*;
pub use request_members::*;
pub use resume::*;
pub use session::*;
pub use stage_instance::*;
pub use thread::*;
pub use user::*;
pub use voice::*;
pub use session::*;
pub use webhooks::*;
pub use passive_update::*;
pub use integration::*;
pub use invite::*;
pub use call::*;
pub use lazy_request::*;
pub use relationship::*;
pub use auto_moderation::*;
pub use stage_instance::*;
pub use interaction::*;
pub use application::*;
pub trait WebSocketEvent {}
#[derive(Debug, Default, Serialize, Clone)]
/// The payload used for sending events to the gateway
///
///
/// Similar to [GatewayReceivePayload], except we send a [Value] for d whilst we receive a [serde_json::value::RawValue]
/// Also, we never need to send the event name
pub struct GatewaySendPayload {
@ -76,7 +76,7 @@ impl WebSocketEvent for GatewaySendPayload {}
#[derive(Debug, Default, Deserialize, Clone)]
/// The payload used for receiving events from the gateway
///
///
/// 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

View File

@ -1,11 +1,11 @@
use serde::{Deserialize, Serialize};
use crate::types::{VoiceState, GuildMember};
use super::{ChannelUnreadUpdateObject, WebSocketEvent};
use crate::types::{GuildMember, VoiceState};
#[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?)
pub struct PassiveUpdateV1 {
pub voice_states: Vec<VoiceState>,
@ -14,4 +14,4 @@ pub struct PassiveUpdateV1 {
pub channels: Vec<ChannelUnreadUpdateObject>,
}
impl WebSocketEvent for PassiveUpdateV1 {}
impl WebSocketEvent for PassiveUpdateV1 {}

View File

@ -1,6 +1,6 @@
use crate::types::PublicUser;
use crate::types::events::WebSocketEvent;
use crate::types::interfaces::Activity;
use crate::types::PublicUser;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Default, Clone)]

View File

@ -1,7 +1,7 @@
use crate::types::entities::{UnavailableGuild, User, Guild};
use crate::types::events::{WebSocketEvent, Session};
use crate::types::entities::{Guild, User};
use crate::types::events::{Session, WebSocketEvent};
use crate::types::interfaces::ClientStatusObject;
use crate::types::{PresenceUpdate, GuildMember, Activity, VoiceState};
use crate::types::{Activity, GuildMember, PresenceUpdate, VoiceState};
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Default)]
@ -46,7 +46,7 @@ impl WebSocketEvent for GatewayReadySupplemental {}
#[derive(Debug, Deserialize, Serialize, Default)]
pub struct MergedPresences {
pub guilds: Vec<Vec<MergedPresenceGuild>>,
pub friends: Vec<MergedPresenceFriend>
pub friends: Vec<MergedPresenceFriend>,
}
#[derive(Debug, Deserialize, Serialize, Default)]
@ -56,7 +56,7 @@ pub struct MergedPresenceFriend {
/// Looks like ms??
pub last_modified: u128,
pub client_status: ClientStatusObject,
pub activities: Vec<Activity>
pub activities: Vec<Activity>,
}
#[derive(Debug, Deserialize, Serialize, Default)]
@ -66,12 +66,12 @@ pub struct MergedPresenceGuild {
// ?
pub game: Option<serde_json::Value>,
pub client_status: ClientStatusObject,
pub activities: Vec<Activity>
pub activities: Vec<Activity>,
}
#[derive(Debug, Deserialize, Serialize, Default)]
pub struct SupplimentalGuild {
pub voice_states: Option<Vec<VoiceState>>,
pub id: String,
pub embedded_activities: Vec<serde_json::Value>
pub embedded_activities: Vec<serde_json::Value>,
}

View File

@ -1,4 +1,4 @@
use crate::types::{events::WebSocketEvent, Relationship, Snowflake, RelationshipType};
use crate::types::{events::WebSocketEvent, Relationship, RelationshipType, Snowflake};
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Default)]
@ -15,8 +15,8 @@ impl WebSocketEvent for RelationshipAdd {}
/// See https://github.com/spacebarchat/server/issues/203
pub struct RelationshipRemove {
pub id: Snowflake,
#[serde(rename = "type")]
#[serde(rename = "type")]
pub relationship_type: RelationshipType,
}
impl WebSocketEvent for RelationshipRemove {}
impl WebSocketEvent for RelationshipRemove {}

View File

@ -7,7 +7,7 @@ use crate::types::{Activity, WebSocketEvent};
/// Seems like it sends active session info to users on connect
/// [{"activities":[],"client_info":{"client":"web","os":"other","version":0},"session_id":"ab5941b50d818b1f8d93b4b1b581b192","status":"online"}]
pub struct SessionsReplace {
pub sessions: Vec<Session>
pub sessions: Vec<Session>,
}
#[derive(Debug, Deserialize, Serialize, Default)]
@ -22,11 +22,11 @@ pub struct Session {
#[derive(Debug, Deserialize, Serialize, Default)]
/// Another Client info object
/// {"client":"web","os":"other","version":0}
// Note: I don't think this one exists yet? Though I might've made a mistake and this might be a duplicate
// Note: I don't think this one exists yet? Though I might've made a mistake and this might be a duplicate
pub struct ClientInfo {
pub client: String,
pub os: String,
pub version: u8
pub version: u8,
}
impl WebSocketEvent for SessionsReplace {}

View File

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use crate::types::{WebSocketEvent, StageInstance};
use crate::types::{StageInstance, WebSocketEvent};
#[derive(Debug, Deserialize, Serialize, Default)]
/// See https://discord.com/developers/docs/topics/gateway-events#stage-instance-create
@ -9,7 +9,7 @@ pub struct StageInstanceCreate {
pub stage_instance: StageInstance,
}
impl WebSocketEvent for StageInstanceCreate {}
impl WebSocketEvent for StageInstanceCreate {}
#[derive(Debug, Deserialize, Serialize, Default)]
/// See https://discord.com/developers/docs/topics/gateway-events#stage-instance-update
@ -18,7 +18,7 @@ pub struct StageInstanceUpdate {
pub stage_instance: StageInstance,
}
impl WebSocketEvent for StageInstanceUpdate {}
impl WebSocketEvent for StageInstanceUpdate {}
#[derive(Debug, Deserialize, Serialize, Default)]
/// See https://discord.com/developers/docs/topics/gateway-events#stage-instance-delete
@ -27,4 +27,4 @@ pub struct StageInstanceDelete {
pub stage_instance: StageInstance,
}
impl WebSocketEvent for StageInstanceDelete {}
impl WebSocketEvent for StageInstanceDelete {}

View File

@ -1,4 +1,4 @@
use crate::types::entities::{Channel, GuildMember, ThreadMember};
use crate::types::entities::{Channel, ThreadMember};
use crate::types::events::WebSocketEvent;
use serde::{Deserialize, Serialize};

View File

@ -3,9 +3,9 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Default)]
/// See https://discord.com/developers/docs/topics/gateway-events#update-voice-state
///
///
/// Sent to the server
///
///
/// Not to be confused with [VoiceStateUpdate]
pub struct UpdateVoiceState {
pub guild_id: Option<String>,
@ -18,13 +18,13 @@ impl WebSocketEvent for UpdateVoiceState {}
#[derive(Debug, Deserialize, Serialize, Default)]
/// See https://discord.com/developers/docs/topics/gateway-events#voice-state-update
///
///
/// Received from the server
///
///
/// Not to be confused with [UpdateVoiceState]
pub struct VoiceStateUpdate {
#[serde(flatten)]
pub state: VoiceState
pub state: VoiceState,
}
impl WebSocketEvent for VoiceStateUpdate {}
@ -34,7 +34,7 @@ impl WebSocketEvent for VoiceStateUpdate {}
pub struct VoiceServerUpdate {
pub token: String,
pub guild_id: String,
pub endpoint: Option<String>
pub endpoint: Option<String>,
}
impl WebSocketEvent for VoiceServerUpdate {}
impl WebSocketEvent for VoiceServerUpdate {}

View File

@ -9,4 +9,4 @@ pub struct WebhooksUpdate {
pub channel_id: String,
}
impl WebSocketEvent for WebhooksUpdate {}
impl WebSocketEvent for WebhooksUpdate {}

View File

@ -0,0 +1 @@

View File

@ -8,4 +8,4 @@ pub use activity::*;
pub use connected_account::*;
pub use guild_welcome_screen::*;
pub use interaction::*;
pub use status::*;
pub use status::*;

View File

@ -6,4 +6,4 @@ pub struct ClientStatusObject {
pub desktop: Option<String>,
pub mobile: Option<String>,
pub web: Option<String>,
}
}

View File

@ -187,7 +187,7 @@ You will receive a [`FieldFormatError`], if:
#[serde(rename_all = "snake_case")]
pub struct LoginSchema {
pub login: String,
pub password: String,
pub password: Option<String>,
pub undelete: Option<bool>,
pub captcha_key: Option<String>,
pub login_source: Option<String>,
@ -210,15 +210,12 @@ impl LoginSchema {
*/
pub fn new(
login: String,
password: String,
password: Option<String>,
undelete: Option<bool>,
captcha_key: Option<String>,
login_source: Option<String>,
gift_code_sku_id: Option<String>,
) -> Result<LoginSchema, FieldFormatError> {
let login = AuthUsername::new(login)?.username;
let password = AuthPassword::new(password)?.password;
Ok(LoginSchema {
login,
password,

View File

@ -13,4 +13,4 @@ pub struct UserModifySchema {
pub code: Option<String>,
pub email: Option<String>,
pub discriminator: Option<i16>,
}
}

22
tests/auth.rs Normal file
View File

@ -0,0 +1,22 @@
mod common;
use chorus::types;
#[tokio::test]
async fn test_registration() {
let mut bundle = common::setup().await;
let reg = types::RegisterSchema::new(
"Hiiii".to_string(),
None,
true,
None,
None,
None,
Some("2000-01-01".to_string()),
None,
None,
None,
)
.unwrap();
bundle.instance.register_account(&reg).await.unwrap();
common::teardown(bundle).await;
}

23
tests/channel.rs Normal file
View File

@ -0,0 +1,23 @@
mod common;
use chorus::types::Channel;
#[tokio::test]
async fn get_channel() {
let mut bundle = common::setup().await;
let bundle_channel = bundle.channel.clone();
let bundle_user = &mut bundle.user;
assert_eq!(
bundle_channel,
Channel::get(
bundle_user.token.as_str(),
bundle.instance.urls.get_api(),
&bundle_channel.id.to_string(),
&mut bundle_user.limits,
&mut bundle.instance.limits
)
.await
.unwrap()
);
common::teardown(bundle).await
}

View File

@ -5,16 +5,16 @@ use chorus::{
};
#[derive(Debug)]
struct TestBundle {
urls: URLBundle,
user: UserMeta,
instance: Instance,
guild_id: String,
channel: Channel,
pub struct TestBundle {
pub urls: URLBundle,
pub user: UserMeta,
pub instance: Instance,
pub guild_id: String,
pub channel: Channel,
}
// Set up a test by creating an Instance and a User. Reduces Test boilerplate.
async fn setup() -> TestBundle {
pub async fn setup() -> TestBundle {
let urls = URLBundle::new(
"http://localhost:3001/api".to_string(),
"ws://localhost:3001".to_string(),
@ -89,7 +89,7 @@ async fn setup() -> TestBundle {
}
// Teardown method to clean up after a test.
async fn teardown(mut bundle: TestBundle) {
pub async fn teardown(mut bundle: TestBundle) {
Guild::delete(
&mut bundle.user,
bundle.instance.urls.get_api(),
@ -98,55 +98,3 @@ async fn teardown(mut bundle: TestBundle) {
.await;
bundle.user.delete().await;
}
mod guild {
use chorus::types::{Channel, Guild, GuildCreateSchema};
#[tokio::test]
async fn guild_creation_deletion() {
let mut bundle = crate::setup().await;
let guild_create_schema = GuildCreateSchema {
name: Some("test".to_string()),
region: None,
icon: None,
channels: None,
guild_template_code: None,
system_channel_id: None,
rules_channel_id: None,
};
let guild = Guild::create(&mut bundle.user, bundle.urls.get_api(), guild_create_schema)
.await
.unwrap();
println!("{}", guild);
match Guild::delete(&mut bundle.user, bundle.urls.get_api(), guild).await {
None => assert!(true),
Some(_) => assert!(false),
}
crate::teardown(bundle).await
}
#[tokio::test]
async fn get_channel() {
let mut bundle = crate::setup().await;
let bundle_channel = bundle.channel.clone();
let bundle_user = &mut bundle.user;
assert_eq!(
bundle_channel,
Channel::get(
bundle_user.token.as_str(),
bundle.instance.urls.get_api(),
&bundle_channel.id.to_string(),
&mut bundle_user.limits,
&mut bundle.instance.limits
)
.await
.unwrap()
);
crate::teardown(bundle).await
}
}

29
tests/guild.rs Normal file
View File

@ -0,0 +1,29 @@
mod common;
use chorus::types::{Guild, GuildCreateSchema};
#[tokio::test]
async fn guild_creation_deletion() {
let mut bundle = common::setup().await;
let guild_create_schema = GuildCreateSchema {
name: Some("test".to_string()),
region: None,
icon: None,
channels: None,
guild_template_code: None,
system_channel_id: None,
rules_channel_id: None,
};
let guild = Guild::create(&mut bundle.user, bundle.urls.get_api(), guild_create_schema)
.await
.unwrap();
println!("{}", guild);
match Guild::delete(&mut bundle.user, bundle.urls.get_api(), guild).await {
None => assert!(true),
Some(_) => assert!(false),
}
common::teardown(bundle).await
}

12
tests/instance.rs Normal file
View File

@ -0,0 +1,12 @@
mod common;
#[tokio::test]
async fn generate_general_configuration_schema() {
let bundle = common::setup().await;
bundle
.instance
.general_configuration_schema()
.await
.unwrap();
common::teardown(bundle).await;
}

80
tests/message.rs Normal file
View File

@ -0,0 +1,80 @@
mod common;
use chorus::types;
use std::fs::File;
use std::io::{BufReader, Read};
#[tokio::test]
async fn send_message() {
let mut bundle = common::setup().await;
let mut message = types::MessageSendSchema::new(
None,
Some("A Message!".to_string()),
None,
None,
None,
None,
None,
None,
None,
None,
);
let _ = bundle
.user
.send_message(&mut message, bundle.channel.id.to_string(), None)
.await
.unwrap();
common::teardown(bundle).await
}
#[tokio::test]
async fn send_message_attachment() {
let f = File::open("./README.md").unwrap();
let mut reader = BufReader::new(f);
let mut buffer = Vec::new();
let mut bundle = common::setup().await;
reader.read_to_end(&mut buffer).unwrap();
let attachment = types::PartialDiscordFileAttachment {
id: None,
filename: "README.md".to_string(),
description: None,
content_type: None,
size: None,
url: None,
proxy_url: None,
width: None,
height: None,
ephemeral: None,
duration_secs: None,
waveform: None,
content: buffer,
};
let mut message = types::MessageSendSchema::new(
None,
Some("trans rights now".to_string()),
None,
None,
None,
None,
None,
None,
None,
Some(vec![attachment.clone()]),
);
let vec_attach = vec![attachment.clone()];
let _arg = Some(&vec_attach);
bundle
.user
.send_message(
&mut message,
bundle.channel.id.to_string(),
Some(vec![attachment.clone()]),
)
.await
.unwrap();
common::teardown(bundle).await
}