Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,28 @@ homepage = "https://github.com/Leastrio/Shaco"
repository = "https://github.com/Leastrio/Shaco"

[dependencies]
sysinfo = "0.29.11"
base64 = "0.21.0"
native-tls = "0.2.11"
futures-util = "0.3.25"
# async
tokio = "1.24.2"
tokio-tungstenite = { version = "0.20.1", features = ["native-tls"] }
reqwest = { version = "0.11.14", features = ["json"] }
futures-util = "0.3.25"
# async websockets
tokio-tungstenite = { version = "0.23.1", features = ["__rustls-tls"] }
# async http
reqwest = { version = "0.12.2", default-features = false, features = [
"json",
"rustls-tls",
] }
# riot auth
riot_local_auth = { git = "https://github.com/FFFFFFFXXXXXXX/riot_local_auth" }
rustls = { version = "0.23.12", default-features = false, features = [
"ring",
"logging",
"std",
"tls12",
] }
rustls-pemfile = "2.0.0"
# serde
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0.91", features = ["raw_value"] }
serde-single-key-map = "0.1.0"
serde_json = "1.0.91"
derive_more = { version = "0.99.17", features = ["display"] }

[dev-dependencies]
Expand Down
15 changes: 7 additions & 8 deletions examples/change_status.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = shaco::rest::RESTClient::new()?;
let client = shaco::rest::LcuRestClient::new()?;

client.put("/lol-chat/v1/me",
serde_json::json!({
"statusMessage": "Please DO NOT buy the BTS meal if you don't stan them. You're preventing the actual BTS fans who have waited for months from having the BTS meal experience. Eating the sauces without understanding their significance is literally cultural appropriation and it's not okay"
})
).await?;

println!("Status Changed!");
println!(
"{:#?}",
client
.get("/lol-gameflow/v1/gameflow-metadata/player-status")
.await?
);

Ok(())
}
2 changes: 1 addition & 1 deletion examples/game_data.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = shaco::ingame::IngameClient::new()?;
let client = shaco::ingame::IngameClient::new();

let data = client.all_game_data(None).await?;

Expand Down
29 changes: 14 additions & 15 deletions examples/ingame_events.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use futures_util::StreamExt;

use shaco::{ingame::EventStream, ingame::IngameClient};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let ingame_client = IngameClient::new()?;
let mut event_stream = EventStream::from_ingame_client(ingame_client, None);

while let Some(event) = event_stream.next().await {
println!("{:?}", event)
}

Ok(())
}
use futures_util::StreamExt;

use shaco::ingame::EventStream;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut event_stream = EventStream::new();

while let Some(event) = event_stream.next().await {
println!("{:?}", event)
}

Ok(())
}
47 changes: 47 additions & 0 deletions examples/ingame_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use shaco::ingame::IngameClient;

#[tokio::main]
async fn main() {
let client = IngameClient::new();

let mut loading_screen = false;
let mut ingame = false;
let mut spectator = false;
loop {
let mut print = false;

let new_loading_screen = client.active_game_loadingscreen().await;
if new_loading_screen != loading_screen {
loading_screen = new_loading_screen;
print = true;
}

let new_ingame = client.active_game().await;
if new_ingame != ingame {
ingame = new_ingame;
print = true;

if ingame {
let time = client
.all_game_data(None)
.await
.unwrap()
.game_data
.game_time;
println!("time: {time}");
}
}

let new_spectator = client.is_spectator_mode().await.is_ok_and(|b| b);
if new_spectator != spectator {
spectator = new_spectator;
print = true;
}

if print {
println!("loading screen: {loading_screen}");
println!("ingame: {ingame}");
println!("spectator: {spectator}");
}
}
}
4 changes: 2 additions & 2 deletions examples/websocket_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = ws::LcuWebsocketClient::connect().await?;
client
.subscribe(LcuSubscriptionType::JsonApiEvent(
"/lol-gameflow/v1/gameflow-phase".to_string(),
"/lol-gameflow/v1/session".to_string(),
))
.await
.unwrap();

while let Some(event) = client.next().await {
println!("Event: {:?}", event);
println!("Event: {:#?}", event);
}

Ok(())
Expand Down
File renamed without changes.
38 changes: 2 additions & 36 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,45 +1,11 @@
use std::{error::Error, fmt, fmt::Display};

/// Errors that can occur when trying to get the Riot process information
#[derive(Debug, Clone)]
pub(crate) enum ProcessInfoError {
/// League client has not been started
ProcessNotAvailable,
/// There has been an error getting the API port
PortNotFound,
/// There has been an error getting the API auth token
AuthTokenNotFound,
}

impl Error for ProcessInfoError {}

impl Display for ProcessInfoError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ProcessNotAvailable => write!(
f,
"{:?}: Riot/League client process could not be found",
self
),
Self::PortNotFound => write!(
f,
"{:?}: API port could not be parsed from process arguments",
self
),
Self::AuthTokenNotFound => write!(
f,
"{:?}: API auth token could not be parsed from process arguments",
self
),
}
}
}

/// Errors for the Ingame API
#[derive(Debug, Clone)]
pub enum IngameClientError {
/// An API might not be available yet during the loading screen
/// Some API calls only return valid results after the game has started even if other API calls already work
ApiNotAvailableInSpectatorMode,
/// An API might not be available yet during the loading screen
ApiNotAvailableDuringLoadingScreen,
/// An error occurred on the client side probably because of a malformed request \
/// Corresponds to HTTP status responses 400 – 499, excluding 400 and 404 which are [IngameClientError::ApiNotAvailableInSpectatorMode] and [IngameClientError::ApiNotAvailableDuringLoadingScreen]
Expand Down
Loading
Loading