EnvVars for life

master
Julius 2019-12-04 10:11:49 +01:00
parent 777e941469
commit ecf36d442e
5 changed files with 24 additions and 5 deletions

3
.env.example Normal file
View File

@ -0,0 +1,3 @@
WH_TOKEN=Webhook token
WH_ID=Webhook server id
WH_SESSION=aoc session cookie

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
/target
**/*.rs.bk
.idea/
.idea/
.env

7
Cargo.lock generated
View File

@ -14,6 +14,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "aoclog"
version = "0.1.0"
dependencies = [
"dotenv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)",
@ -257,6 +258,11 @@ dependencies = [
"generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dotenv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "dtoa"
version = "0.4.4"
@ -1744,6 +1750,7 @@ dependencies = [
"checksum crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4"
"checksum ct-logs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4d3686f5fa27dbc1d76c751300376e167c5a43387f44bb451fd1c24776e49113"
"checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5"
"checksum dotenv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
"checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e"
"checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
"checksum encoding_rs 0.8.20 (registry+https://github.com/rust-lang/crates.io-index)" = "87240518927716f79692c2ed85bfe6e98196d18c6401ec75355760233a7e12e9"

View File

@ -10,6 +10,7 @@ edition = "2018"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
reqwest = "0.9"
dotenv = "0.15"
[dependencies.serenity]
default-features = false

View File

@ -2,6 +2,7 @@ extern crate reqwest;
extern crate serde;
extern crate serde_json;
use dotenv;
use std::collections::HashMap;
use std::str::FromStr;
@ -9,6 +10,7 @@ use serde::{Deserialize, Deserializer};
use serde::de::{self};
use serde::export::fmt::Display;
use serde_json::Value;
use std::env;
#[derive(Deserialize, PartialEq, Debug)]
struct AOCRequest {
@ -46,14 +48,19 @@ fn from_str<'de, T, D>(deserializer: D) -> Result<T, D::Error>
fn main() {
dotenv::dotenv().ok();
let token = env::var_os("WH_TOKEN").expect("Token not set!");
let id = env::var_os("WH_ID").expect("ID not set!");
let sess = env::var_os("WH_SESSION").expect("Session not set!");
let client = reqwest::Client::new();
let json: AOCRequest = client.get("https://adventofcode.com/2019/leaderboard/private/view/356604.json")
.header("Cookie",
"session=lol")
format!("session={}", sess.as_os_str().to_str().expect("oof")))
.send().expect("Failed to send request").json().expect("Error parsing response");
//"https://discordapp.com/api/webhooks/651520885349548044/EY0yz2fvWiViMr_mr1AhgTQ2xikC32U_ncEnpAy4sy7zlsq8hDFufYuynUjw22vbLHlQ"
let id = 651_520_885_349_548_044;
let token = "EY0yz2fvWiViMr_mr1AhgTQ2xikC32U_ncEnpAy4sy7zlsq8hDFufYuynUjw22vbLHlQ";
let id = id.as_os_str().to_str().expect("ID is not an int").parse().expect("ID is not an int");
let token = token.to_str().expect("Token is not valid");
let http = serenity::http::Http::default();
let mut wh = http.as_ref().get_webhook_with_token(id, token).expect("Cannot create webhook");