Merge branch 'refs/heads/feature/reformatting' into develop

This commit is contained in:
DylanCa 2023-12-29 03:00:25 +01:00
commit 5a50d49df8
17 changed files with 62 additions and 88 deletions

View file

@ -1,15 +1,13 @@
use std::os::unix::net::UnixStream;
use std::env::var;
use std::error::Error;
use std::io::{Read, Write};
use std::path::PathBuf;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use log::debug; use log::debug;
use serde_json::{json, Value}; use serde_json::{json, Value};
use std::env::var;
use std::error::Error;
use std::io::{Read, Write};
use std::os::unix::net::UnixStream;
use std::path::PathBuf;
use crate::models::client::{payload::Payload, use crate::models::client::{commands::Commands, payload::OpCode, payload::Payload};
payload::OpCode,
commands::Commands};
pub struct DiscordClient { pub struct DiscordClient {
pub id: String, pub id: String,
@ -23,7 +21,9 @@ impl DiscordClient {
socket: None, socket: None,
}; };
client.connect().expect("Could not connect to client. Is Discord running ?"); client
.connect()
.expect("Could not connect to client. Is Discord running ?");
client client
} }

View file

@ -1 +1 @@
pub mod ipc; pub mod ipc;

View file

@ -3,15 +3,8 @@ pub mod models;
pub use client::ipc::DiscordClient; pub use client::ipc::DiscordClient;
pub use models::activity::Activity; pub use models::activity::Activity;
pub use models::activity_data::{activity_flag::ActivityFlag, pub use models::activity_data::{
activity_type::ActivityType, activity_flag::ActivityFlag, activity_type::ActivityType, asset::Asset, button::Button,
asset::Asset, emoji::Emoji, party::Party, secret::Secret, timestamp::Timestamp,
button::Button, };
emoji::Emoji, pub use models::client::{event::EventData, event::EventName, payload::Payload};
party::Party,
secret::Secret,
timestamp::Timestamp};
pub use models::client::{payload::Payload,
event::EventName,
event::EventData};

View file

@ -1,12 +1,8 @@
use crate::models::activity_data::{
activity_flag::ActivityFlag, activity_type::ActivityType, asset::Asset, button::Button,
emoji::Emoji, party::Party, secret::Secret, timestamp::Timestamp,
};
use serde::Serialize; use serde::Serialize;
use crate::models::activity_data::{activity_type::ActivityType,
activity_flag::ActivityFlag,
asset::Asset,
button::Button,
emoji::Emoji,
party::Party,
secret::Secret,
timestamp::Timestamp, };
/// Test Doc /// Test Doc
#[derive(Serialize, Debug)] #[derive(Serialize, Debug)]
@ -161,4 +157,4 @@ impl Activity {
self.buttons = buttons; self.buttons = buttons;
self self
} }
} }

View file

@ -11,4 +11,4 @@ pub enum ActivityFlag {
PartyPrivacyFriends = 64, PartyPrivacyFriends = 64,
PartyPrivacyVoiceChannel = 128, PartyPrivacyVoiceChannel = 128,
Embedded = 256, Embedded = 256,
} }

View file

@ -16,16 +16,17 @@ pub struct Asset {
} }
impl Asset { impl Asset {
pub fn new(large_image: Option<String>, pub fn new(
large_text: Option<String>, large_image: Option<String>,
small_image: Option<String>, large_text: Option<String>,
small_text: Option<String>, small_image: Option<String>,
small_text: Option<String>,
) -> Asset { ) -> Asset {
Self { Self {
large_image, large_image,
large_text, large_text,
small_image, small_image,
small_text small_text,
} }
} }
} }

View file

@ -8,9 +8,6 @@ pub struct Button {
impl Button { impl Button {
pub fn new(label: String, url: String) -> Button { pub fn new(label: String, url: String) -> Button {
Self { Self { label, url }
label,
url
}
} }
} }

View file

@ -8,17 +8,11 @@ pub struct Emoji {
id: Option<i64>, id: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
animated: Option<bool> animated: Option<bool>,
} }
impl Emoji { impl Emoji {
pub fn new(name: String, pub fn new(name: String, id: Option<i64>, animated: Option<bool>) -> Emoji {
id: Option<i64>, Self { name, id, animated }
animated: Option<bool>) -> Emoji {
Self {
name,
id,
animated
}
} }
} }

View file

@ -1,8 +1,8 @@
pub mod activity_flag;
pub mod activity_type; pub mod activity_type;
pub mod timestamp; pub mod asset;
pub mod button;
pub mod emoji; pub mod emoji;
pub mod party; pub mod party;
pub mod asset;
pub mod secret; pub mod secret;
pub mod activity_flag; pub mod timestamp;
pub mod button;

View file

@ -6,14 +6,11 @@ pub struct Party {
id: Option<String>, id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
size: Option<(i8, i8)> size: Option<(i8, i8)>,
} }
impl Party { impl Party {
pub fn new(id: Option<String>, size: Option<(i8, i8)>) -> Party { pub fn new(id: Option<String>, size: Option<(i8, i8)>) -> Party {
Self { Self { id, size }
id,
size
}
} }
} }

View file

@ -9,18 +9,19 @@ pub struct Secret {
spectate: Option<String>, spectate: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
instanced_match: Option<String> instanced_match: Option<String>,
} }
impl Secret { impl Secret {
pub fn new(join: Option<String>, pub fn new(
spectate: Option<String>, join: Option<String>,
instanced_match: Option<String>) -> Secret { spectate: Option<String>,
instanced_match: Option<String>,
) -> Secret {
Self { Self {
join, join,
spectate, spectate,
instanced_match instanced_match,
} }
} }
}
}

View file

@ -10,11 +10,7 @@ pub struct Timestamp {
} }
impl Timestamp { impl Timestamp {
pub fn new(start: Option<u128>, pub fn new(start: Option<u128>, end: Option<u128>) -> Timestamp {
end: Option<u128>) -> Timestamp { Self { start, end }
Self {
start,
end,
}
} }
} }

View file

@ -1,5 +1,5 @@
pub enum Commands { pub enum Commands {
SetActivity SetActivity,
} }
impl Commands { impl Commands {

View file

@ -5,18 +5,17 @@ use crate::models::activity::Activity;
#[derive(Serialize, Debug)] #[derive(Serialize, Debug)]
#[serde(untagged)] #[serde(untagged)]
pub enum EventData { pub enum EventData {
Activity(Activity) Activity(Activity),
} }
pub enum EventName { pub enum EventName {
Activity Activity,
} }
impl EventName { impl EventName {
pub fn as_string(&self) -> String { pub fn as_string(&self) -> String {
match self { match self {
EventName::Activity => "activity".into(), EventName::Activity => "activity".into(),
} }
} }
} }

View file

@ -1,3 +1,3 @@
pub mod payload; pub mod commands;
pub mod event; pub mod event;
pub mod commands; pub mod payload;

View file

@ -1,5 +1,5 @@
use serde::Serialize;
use crate::models::client::event::{EventData, EventName}; use crate::models::client::event::{EventData, EventName};
use serde::Serialize;
pub enum OpCode { pub enum OpCode {
HANDSHAKE, HANDSHAKE,
@ -16,7 +16,7 @@ impl Payload {
pub fn new(event_name: EventName, event_data: EventData) -> Self { pub fn new(event_name: EventName, event_data: EventData) -> Self {
Self { Self {
event_name: event_name.as_string(), event_name: event_name.as_string(),
event_data event_data,
} }
} }
} }

View file

@ -1,3 +1,3 @@
pub mod activity_data;
pub mod activity; pub mod activity;
pub mod activity_data;
pub mod client; pub mod client;