Merge pull request #1 from DylanCa/develop

This commit is contained in:
Dylan 2023-12-29 03:02:34 +01:00 committed by GitHub
commit 6ada7143a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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 log::debug;
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,
payload::OpCode,
commands::Commands};
use crate::models::client::{commands::Commands, payload::OpCode, payload::Payload};
pub struct DiscordClient {
pub id: String,
@ -23,7 +21,9 @@ impl DiscordClient {
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
}

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 models::activity::Activity;
pub use models::activity_data::{activity_flag::ActivityFlag,
activity_type::ActivityType,
asset::Asset,
button::Button,
emoji::Emoji,
party::Party,
secret::Secret,
timestamp::Timestamp};
pub use models::client::{payload::Payload,
event::EventName,
event::EventData};
pub use models::activity_data::{
activity_flag::ActivityFlag, activity_type::ActivityType, asset::Asset, button::Button,
emoji::Emoji, party::Party, secret::Secret, timestamp::Timestamp,
};
pub use models::client::{event::EventData, event::EventName, payload::Payload};

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 crate::models::activity_data::{activity_type::ActivityType,
activity_flag::ActivityFlag,
asset::Asset,
button::Button,
emoji::Emoji,
party::Party,
secret::Secret,
timestamp::Timestamp, };
/// Test Doc
#[derive(Serialize, Debug)]
@ -161,4 +157,4 @@ impl Activity {
self.buttons = buttons;
self
}
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,3 +1,3 @@
pub mod payload;
pub mod commands;
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 serde::Serialize;
pub enum OpCode {
HANDSHAKE,
@ -16,7 +16,7 @@ impl Payload {
pub fn new(event_name: EventName, event_data: EventData) -> Self {
Self {
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_data;
pub mod client;