diff --git a/Cargo.lock b/Cargo.lock index 59abf2a..079d0f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -108,9 +108,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" dependencies = [ "iana-time-zone", + "js-sys", "num-integer", "num-traits", "serde", + "time 0.1.45", + "wasm-bindgen", "winapi", ] @@ -276,6 +279,8 @@ dependencies = [ name = "echbot" version = "0.1.0" dependencies = [ + "chrono", + "md5", "poise", "rand", "tokio", @@ -398,7 +403,7 @@ checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", ] [[package]] @@ -611,6 +616,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "md5" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" + [[package]] name = "memchr" version = "2.5.0" @@ -650,7 +661,7 @@ checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" dependencies = [ "libc", "log", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys", ] @@ -1037,7 +1048,7 @@ dependencies = [ "serde", "serde-value", "serde_json", - "time", + "time 0.3.17", "tokio", "tracing", "typemap_rev", @@ -1132,6 +1143,17 @@ dependencies = [ "syn", ] +[[package]] +name = "time" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", +] + [[package]] name = "time" version = "0.3.17" @@ -1382,6 +1404,12 @@ dependencies = [ "try-lock", ] +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index a2dcf56..fdd3ea4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,5 @@ edition = "2021" poise = "0.5.2" tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] } rand = "0.8.5" +chrono = "0.4.23" +md5 = "0.7.0" diff --git a/README.md b/README.md index fb15fbd..bf6c315 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ You must set the following for the bot to run. environment: - DISCORD_TOKEN=your_token_here - GUILD_ID=your_guild_id_here + - DEV_ID=your_hi-rez_dev_id + - AUTH_KEY=your_hi-rez_auth_key ``` ## Quotes diff --git a/src/api.rs b/src/api.rs new file mode 100644 index 0000000..cc27990 --- /dev/null +++ b/src/api.rs @@ -0,0 +1,23 @@ +use chrono; +use crate::Error; + +fn get_utc_timestamp() -> String { + return chrono::Utc::now().format("%Y%m%d%H%M%S").to_string(); +} + +fn generate_signature(timestamp: String) -> String { + let dev_id = std::env::var("DEV_ID") + .expect("Missing DEV_ID"); + let auth_key = std::env::var("AUTH_KEY") + .expect("Missing AUTH_KEY"); + let signature = md5::compute(format!("{}createsession{}{}", dev_id, auth_key, timestamp)); + + return format!("{:?}", signature); +} + +pub(crate) async fn create_session() -> Result<(), Error> { + let timestamp = get_utc_timestamp(); + let signature: String = generate_signature(timestamp); + println!("{}", signature); + Ok(()) +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 439df73..a32f99d 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,4 +1,4 @@ // Group all commands for registration pub(crate) mod slur; pub(crate) mod team; -pub(crate) mod random; \ No newline at end of file +pub(crate) mod random; diff --git a/src/commands/team.rs b/src/commands/team.rs index 7cdafb7..d61f1a0 100644 --- a/src/commands/team.rs +++ b/src/commands/team.rs @@ -12,17 +12,15 @@ pub(crate) async fn team( ) -> Result<(), Error> { let mut v = ctx.guild().unwrap().voice_states; // Get hashmap of users' voice states within the guild v.retain(|_, s| s.channel_id == Some(channel.id())); // Drop users not active in requested voice channel from hashmap - let res = format!("Channel {} has {} active users.", channel.id(), v.keys().len()); ctx.send(|f| f - .content(res) .embed(|f| f .title(format!("Custom {}v{} Teams", size, size)) .description("I'm not done with this yet.") .field("Order", "Some names", true) .field("Chaos", "Other names", true) .field("Spectators", "You guessed it, names.", false) - .color(serenity::Colour(16711680)) // Red + .color(serenity::Colour::DARK_GREEN) )).await?; Ok(()) } diff --git a/src/main.rs b/src/main.rs index 5e784af..3c0a841 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ mod commands; +mod api; use poise::serenity_prelude as serenity;