diff --git a/.env.sample b/.env.sample index d13cd67..b9d7524 100644 --- a/.env.sample +++ b/.env.sample @@ -1 +1,3 @@ -DISCORD_TOKEN="abc123" \ No newline at end of file +DISCORD_TOKEN="abc123" +AUTHORIZED_USER="pikachu,omynite" +HEROKU_API_KEY="1234" \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 5a4228c..a8dc16a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,6 +18,28 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" +[[package]] +name = "backtrace" +version = "0.3.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4036b9bf40f3cf16aba72a3d65e8a520fc4bafcdc7079aea8f848c58c5b5536" +dependencies = [ + "backtrace-sys", + "cfg-if", + "libc", + "rustc-demangle", +] + +[[package]] +name = "backtrace-sys" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "base64" version = "0.10.1" @@ -85,6 +107,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" dependencies = [ "byteorder", + "either", "iovec", ] @@ -153,7 +176,17 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25b9e03f145fd4f2bf705e07b900cd41fc636598fe5dc452fd0db1441c3f496d" dependencies = [ - "core-foundation-sys", + "core-foundation-sys 0.6.2", + "libc", +] + +[[package]] +name = "core-foundation" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" +dependencies = [ + "core-foundation-sys 0.7.0", "libc", ] @@ -163,11 +196,20 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7ca8a5221364ef15ce201e8ed2f609fc312682a8f4e0e3d4aa5879764e0fa3b" +[[package]] +name = "core-foundation-sys" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" + [[package]] name = "crates-io-ops-bot" version = "0.1.0" dependencies = [ "dotenv", + "heroku_rs", + "serde", + "serde_json", "serenity", ] @@ -180,6 +222,53 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam-deque" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", + "maybe-uninit", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "lazy_static", + "maybe-uninit", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-queue" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c695eeca1e7173472a32221542ae469b3e9aac3a4fc81f7696bcad82029493db" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +dependencies = [ + "autocfg", + "cfg-if", + "lazy_static", +] + [[package]] name = "ct-logs" version = "0.6.0" @@ -210,6 +299,12 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4358a9e11b9a09cf52383b451b49a169e8d797b68aa02301ff586d70d9661ea3" +[[package]] +name = "either" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" + [[package]] name = "encoding_rs" version = "0.8.22" @@ -219,6 +314,16 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "error-chain" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d371106cc88ffdfb1eabd7111e432da544f16f3e2d7bf1dfe8bf575f1df045cd" +dependencies = [ + "backtrace", + "version_check 0.9.1", +] + [[package]] name = "fake-simd" version = "0.1.2" @@ -243,6 +348,21 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -259,6 +379,12 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" +[[package]] +name = "futures" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef" + [[package]] name = "futures-channel" version = "0.3.4" @@ -274,6 +400,16 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f25592f769825e89b92358db00d26f965761e094951ac44d3663ef25b7ac464a" +[[package]] +name = "futures-cpupool" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" +dependencies = [ + "futures", + "num_cpus", +] + [[package]] name = "futures-io" version = "0.3.4" @@ -341,6 +477,24 @@ dependencies = [ "wasi", ] +[[package]] +name = "h2" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462" +dependencies = [ + "byteorder", + "bytes 0.4.12", + "fnv", + "futures", + "http 0.1.21", + "indexmap", + "log", + "slab", + "string", + "tokio-io", +] + [[package]] name = "h2" version = "0.2.1" @@ -356,7 +510,7 @@ dependencies = [ "indexmap", "log", "slab", - "tokio", + "tokio 0.2.13", "tokio-util", ] @@ -371,13 +525,29 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.6" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eff2656d88f158ce120947499e971d743c05dbcbed62e5bd2f38f1698bbc3772" +checksum = "1010591b26bbfe835e9faeabeb11866061cc7dcebffd56ad7d0942d0e61aefd8" dependencies = [ "libc", ] +[[package]] +name = "heroku_rs" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c974b4b46ec593fa2b59df56de52512897645a18de43843d2486e1f8b108cdad" +dependencies = [ + "error-chain", + "futures", + "hyper 0.12.35", + "hyper-tls", + "native-tls", + "serde", + "serde_json", + "tokio-core", +] + [[package]] name = "http" version = "0.1.21" @@ -400,6 +570,18 @@ dependencies = [ "itoa", ] +[[package]] +name = "http-body" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6741c859c1b2463a423a1dbce98d418e6c3c3fc720fb0d45528657320920292d" +dependencies = [ + "bytes 0.4.12", + "futures", + "http 0.1.21", + "tokio-buf", +] + [[package]] name = "http-body" version = "0.3.1" @@ -416,6 +598,36 @@ version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" +[[package]] +name = "hyper" +version = "0.12.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dbe6ed1438e1f8ad955a4701e9a944938e9519f6888d12d8558b645e247d5f6" +dependencies = [ + "bytes 0.4.12", + "futures", + "futures-cpupool", + "h2 0.1.26", + "http 0.1.21", + "http-body 0.1.0", + "httparse", + "iovec", + "itoa", + "log", + "net2", + "rustc_version", + "time", + "tokio 0.1.22", + "tokio-buf", + "tokio-executor", + "tokio-io", + "tokio-reactor", + "tokio-tcp", + "tokio-threadpool", + "tokio-timer", + "want 0.2.0", +] + [[package]] name = "hyper" version = "0.13.2" @@ -426,37 +638,51 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2", + "h2 0.2.1", "http 0.2.0", - "http-body", + "http-body 0.3.1", "httparse", "itoa", "log", "net2", "pin-project", "time", - "tokio", + "tokio 0.2.13", "tower-service", - "want", + "want 0.3.0", ] [[package]] name = "hyper-rustls" -version = "0.19.1" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ea6215c7314d450ee45970ab8b3851ab447a0e6bafdd19e31b20a42dbb7faf" +checksum = "ac965ea399ec3a25ac7d13b8affd4b8f39325cca00858ddf5eb29b79e6b14b08" dependencies = [ "bytes 0.5.4", "ct-logs", "futures-util", - "hyper", - "rustls", + "hyper 0.13.2", + "log", + "rustls 0.17.0", "rustls-native-certs", - "tokio", + "tokio 0.2.13", "tokio-rustls", "webpki", ] +[[package]] +name = "hyper-tls" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a800d6aa50af4b5850b2b0f659625ce9504df908e9733b635720483be26174f" +dependencies = [ + "bytes 0.4.12", + "futures", + "hyper 0.12.35", + "native-tls", + "tokio-io", +] + [[package]] name = "idna" version = "0.2.0" @@ -528,9 +754,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.66" +version = "0.2.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" +checksum = "eb147597cdf94ed43ab7a9038716637d2d1bf2bc571da995d0028dec06bd3018" [[package]] name = "lock_api" @@ -564,9 +790,18 @@ checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" [[package]] name = "memchr" -version = "2.3.2" +version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53445de381a1f436797497c61d851644d0e8e88e6140f22872ad33a704933978" +checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" + +[[package]] +name = "memoffset" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75189eb85871ea5c2e2c15abbdd541185f63b408415e5051f5cac122d8c774b9" +dependencies = [ + "rustc_version", +] [[package]] name = "mime" @@ -576,9 +811,9 @@ checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" [[package]] name = "mime_guess" -version = "2.0.1" +version = "2.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a0ed03949aef72dbdf3116a383d7b38b4768e6f960528cd6a6044aa9ed68599" +checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" dependencies = [ "mime", "unicase", @@ -612,6 +847,17 @@ dependencies = [ "winapi 0.2.8", ] +[[package]] +name = "mio-uds" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125" +dependencies = [ + "iovec", + "libc", + "mio", +] + [[package]] name = "miow" version = "0.2.1" @@ -624,6 +870,24 @@ dependencies = [ "ws2_32-sys", ] +[[package]] +name = "native-tls" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b2df1a4c22fd44a62147fd8f13dd0f95c9d8ca7b2610299b2a2f9cf8964274e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework 0.3.4", + "security-framework-sys 0.3.3", + "tempfile", +] + [[package]] name = "net2" version = "0.2.33" @@ -680,12 +944,39 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" +[[package]] +name = "openssl" +version = "0.10.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "973293749822d7dd6370d6da1e523b0d1db19f06c459134c658b2a4261378b52" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "lazy_static", + "libc", + "openssl-sys", +] + [[package]] name = "openssl-probe" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" +[[package]] +name = "openssl-sys" +version = "0.9.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1024c0a59774200a555087a6da3f253a9095a5f344e353b212ac4c8b8e450986" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "parking_lot" version = "0.9.0" @@ -750,6 +1041,12 @@ version = "0.1.0-alpha.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5894c618ce612a3fa23881b152b608bafb8c56cfc22f434a3ba3120b40f7b587" +[[package]] +name = "pkg-config" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" + [[package]] name = "ppv-lite86" version = "0.2.6" @@ -775,9 +1072,9 @@ checksum = "369a6ed065f249a159e06c45752c780bda2fb53c995718f9e484d08daa9eb42e" [[package]] name = "proc-macro2" -version = "1.0.8" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548" +checksum = "6c09721c6781493a2a492a96b5a5bf19b65917fe6728884e7c44dd0c60ca3435" dependencies = [ "unicode-xid", ] @@ -838,11 +1135,20 @@ version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +[[package]] +name = "remove_dir_all" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" +dependencies = [ + "winapi 0.3.8", +] + [[package]] name = "reqwest" -version = "0.10.1" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0e798e19e258bf6c30a304622e3e9ac820e483b06a1857a026e1f109b113fe4" +checksum = "a9f62f24514117d09a8fc74b803d3d65faa27cea1c7378fb12b0d002913f3831" dependencies = [ "base64 0.11.0", "bytes 0.5.4", @@ -850,8 +1156,8 @@ dependencies = [ "futures-core", "futures-util", "http 0.2.0", - "http-body", - "hyper", + "http-body 0.3.1", + "hyper 0.13.2", "hyper-rustls", "js-sys", "lazy_static", @@ -860,18 +1166,18 @@ dependencies = [ "mime_guess", "percent-encoding", "pin-project-lite", - "rustls", + "rustls 0.17.0", "serde", "serde_json", "serde_urlencoded", "time", - "tokio", + "tokio 0.2.13", "tokio-rustls", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots 0.17.0", + "webpki-roots", "winreg", ] @@ -890,6 +1196,12 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "rustc-demangle" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" + [[package]] name = "rustc_version" version = "0.2.3" @@ -912,16 +1224,29 @@ dependencies = [ "webpki", ] +[[package]] +name = "rustls" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0d4a31f5d68413404705d6982529b0e11a9aacd4839d1d6222ee3b8cb4015e1" +dependencies = [ + "base64 0.11.0", + "log", + "ring", + "sct", + "webpki", +] + [[package]] name = "rustls-native-certs" -version = "0.1.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51ffebdbb48c14f84eba0b715197d673aff1dd22cc1007ca647e28483bbcc307" +checksum = "a75ffeb84a6bd9d014713119542ce415db3a3e4748f0bfce1e1416cd224a23a5" dependencies = [ "openssl-probe", - "rustls", + "rustls 0.17.0", "schannel", - "security-framework", + "security-framework 0.4.1", ] [[package]] @@ -940,11 +1265,17 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "scoped-tls" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "332ffa32bf586782a3efaeb58f127980944bbc8c4d6913a86107ac2a5ab24b28" + [[package]] name = "scopeguard" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "sct" @@ -962,10 +1293,22 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ef2429d7cefe5fd28bd1d2ed41c944547d4ff84776f5935b456da44593a16df" dependencies = [ - "core-foundation", - "core-foundation-sys", + "core-foundation 0.6.4", + "core-foundation-sys 0.6.2", "libc", - "security-framework-sys", + "security-framework-sys 0.3.3", +] + +[[package]] +name = "security-framework" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97bbedbe81904398b6ebb054b3e912f99d55807125790f3198ac990d98def5b0" +dependencies = [ + "bitflags", + "core-foundation 0.7.0", + "core-foundation-sys 0.7.0", + "security-framework-sys 0.4.1", ] [[package]] @@ -974,7 +1317,17 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e31493fc37615debb8c5090a7aeb4a9730bc61e77ab10b9af59f1a202284f895" dependencies = [ - "core-foundation-sys", + "core-foundation-sys 0.6.2", +] + +[[package]] +name = "security-framework-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06fd2f23e31ef68dd2328cc383bd493142e46107a3a0e24f7d734e3f3b80fe4c" +dependencies = [ + "core-foundation-sys 0.7.0", + "libc", ] [[package]] @@ -1014,9 +1367,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.47" +version = "1.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15913895b61e0be854afd32fd4163fcd2a3df34142cf2cb961b310ce694cbf90" +checksum = "9371ade75d4c2d6cb154141b9752cf3781ec9c05e0e5cf35060e1e70ee7b9c25" dependencies = [ "itoa", "ryu", @@ -1049,7 +1402,7 @@ dependencies = [ "log", "parking_lot", "reqwest", - "rustls", + "rustls 0.16.0", "serde", "serde_json", "static_assertions", @@ -1059,7 +1412,7 @@ dependencies = [ "url", "uwl", "webpki", - "webpki-roots 0.18.0", + "webpki-roots", ] [[package]] @@ -1113,17 +1466,40 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "string" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24114bfcceb867ca7f71a0d3fe45d45619ec47a6fbfa98cb14e14250bfa5d6d" +dependencies = [ + "bytes 0.4.12", +] + [[package]] name = "syn" -version = "1.0.14" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5" +checksum = "123bd9499cfb380418d509322d7a6d52e5315f064fe4b3ad18a53d6b92c07859" dependencies = [ "proc-macro2", "quote", "unicode-xid", ] +[[package]] +name = "tempfile" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +dependencies = [ + "cfg-if", + "libc", + "rand", + "redox_syscall", + "remove_dir_all", + "winapi 0.3.8", +] + [[package]] name = "threadpool" version = "1.7.1" @@ -1146,9 +1522,33 @@ dependencies = [ [[package]] name = "tokio" -version = "0.2.11" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fdd17989496f49cdc57978c96f0c9fe5e4a58a8bddc6813c449a4624f6a030b" +checksum = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6" +dependencies = [ + "bytes 0.4.12", + "futures", + "mio", + "num_cpus", + "tokio-codec", + "tokio-current-thread", + "tokio-executor", + "tokio-fs", + "tokio-io", + "tokio-reactor", + "tokio-sync", + "tokio-tcp", + "tokio-threadpool", + "tokio-timer", + "tokio-udp", + "tokio-uds", +] + +[[package]] +name = "tokio" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa5e81d6bc4e67fe889d5783bd2a128ab2e0cfa487e0be16b6a8d177b101616" dependencies = [ "bytes 0.5.4", "fnv", @@ -1161,18 +1561,206 @@ dependencies = [ "slab", ] +[[package]] +name = "tokio-buf" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fb220f46c53859a4b7ec083e41dec9778ff0b1851c0942b211edb89e0ccdc46" +dependencies = [ + "bytes 0.4.12", + "either", + "futures", +] + +[[package]] +name = "tokio-codec" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25b2998660ba0e70d18684de5d06b70b70a3a747469af9dea7618cc59e75976b" +dependencies = [ + "bytes 0.4.12", + "futures", + "tokio-io", +] + +[[package]] +name = "tokio-core" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeeffbbb94209023feaef3c196a41cbcdafa06b4a6f893f68779bb5e53796f71" +dependencies = [ + "bytes 0.4.12", + "futures", + "iovec", + "log", + "mio", + "scoped-tls", + "tokio 0.1.22", + "tokio-executor", + "tokio-io", + "tokio-reactor", + "tokio-timer", +] + +[[package]] +name = "tokio-current-thread" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1de0e32a83f131e002238d7ccde18211c0a5397f60cbfffcb112868c2e0e20e" +dependencies = [ + "futures", + "tokio-executor", +] + +[[package]] +name = "tokio-executor" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb2d1b8f4548dbf5e1f7818512e9c406860678f29c300cdf0ebac72d1a3a1671" +dependencies = [ + "crossbeam-utils", + "futures", +] + +[[package]] +name = "tokio-fs" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "297a1206e0ca6302a0eed35b700d292b275256f596e2f3fea7729d5e629b6ff4" +dependencies = [ + "futures", + "tokio-io", + "tokio-threadpool", +] + +[[package]] +name = "tokio-io" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57fc868aae093479e3131e3d165c93b1c7474109d13c90ec0dda2a1bbfff0674" +dependencies = [ + "bytes 0.4.12", + "futures", + "log", +] + +[[package]] +name = "tokio-reactor" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09bc590ec4ba8ba87652da2068d150dcada2cfa2e07faae270a5e0409aa51351" +dependencies = [ + "crossbeam-utils", + "futures", + "lazy_static", + "log", + "mio", + "num_cpus", + "parking_lot", + "slab", + "tokio-executor", + "tokio-io", + "tokio-sync", +] + [[package]] name = "tokio-rustls" -version = "0.12.2" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "141afec0978abae6573065a48882c6bae44c5cc61db9b511ac4abf6a09bfd9cc" +checksum = "4adb8b3e5f86b707f1b54e7c15b6de52617a823608ccda98a15d3a24222f265a" dependencies = [ "futures-core", - "rustls", - "tokio", + "rustls 0.17.0", + "tokio 0.2.13", "webpki", ] +[[package]] +name = "tokio-sync" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edfe50152bc8164fcc456dab7891fa9bf8beaf01c5ee7e1dd43a397c3cf87dee" +dependencies = [ + "fnv", + "futures", +] + +[[package]] +name = "tokio-tcp" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98df18ed66e3b72e742f185882a9e201892407957e45fbff8da17ae7a7c51f72" +dependencies = [ + "bytes 0.4.12", + "futures", + "iovec", + "mio", + "tokio-io", + "tokio-reactor", +] + +[[package]] +name = "tokio-threadpool" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df720b6581784c118f0eb4310796b12b1d242a7eb95f716a8367855325c25f89" +dependencies = [ + "crossbeam-deque", + "crossbeam-queue", + "crossbeam-utils", + "futures", + "lazy_static", + "log", + "num_cpus", + "slab", + "tokio-executor", +] + +[[package]] +name = "tokio-timer" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93044f2d313c95ff1cb7809ce9a7a05735b012288a888b62d4434fd58c94f296" +dependencies = [ + "crossbeam-utils", + "futures", + "slab", + "tokio-executor", +] + +[[package]] +name = "tokio-udp" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2a0b10e610b39c38b031a2fcab08e4b82f16ece36504988dcbd81dbba650d82" +dependencies = [ + "bytes 0.4.12", + "futures", + "log", + "mio", + "tokio-codec", + "tokio-io", + "tokio-reactor", +] + +[[package]] +name = "tokio-uds" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5076db410d6fdc6523df7595447629099a1fdc47b3d9f896220780fa48faf798" +dependencies = [ + "bytes 0.4.12", + "futures", + "iovec", + "libc", + "log", + "mio", + "mio-uds", + "tokio-codec", + "tokio-io", + "tokio-reactor", +] + [[package]] name = "tokio-util" version = "0.2.0" @@ -1184,7 +1772,7 @@ dependencies = [ "futures-sink", "log", "pin-project-lite", - "tokio", + "tokio 0.2.13", ] [[package]] @@ -1316,6 +1904,12 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a7ab913a1e7531084274437e24137ef81065a4b7c05a76d4a6311d48bf4ae4d" +[[package]] +name = "vcpkg" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168" + [[package]] name = "version_check" version = "0.1.5" @@ -1328,6 +1922,17 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" +[[package]] +name = "want" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6395efa4784b027708f7451087e647ec73cc74f5d9bc2e418404248d679a230" +dependencies = [ + "futures", + "log", + "try-lock", +] + [[package]] name = "want" version = "0.3.0" @@ -1451,15 +2056,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "webpki-roots" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a262ae37dd9d60f60dd473d1158f9fbebf110ba7b6a5051c8160460f6043718b" -dependencies = [ - "webpki", -] - [[package]] name = "webpki-roots" version = "0.18.0" diff --git a/Cargo.toml b/Cargo.toml index cd9b118..15447fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,11 @@ license = "MIT OR Apache-2.0" [dependencies] dotenv = "0.15" -serenity = "0.8" \ No newline at end of file +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +serenity = "0.8" + +[dependencies.heroku_rs] +version = "0.2" +default-features = false +features = ["rust-native-tls"] \ No newline at end of file diff --git a/README.md b/README.md index a7414c7..a907152 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,22 @@ you: ~myid crates-io-bot: @you: Here is your user id 1234567 ``` -These are obviously contrived commands, there will be commands specific to managing the crates.io infrastructure very soon. +If you run the ~get_apps command (and you have a Heroku token set in your environmental variables), +this bot will respond with a list of apps associated with that Heroku account +``` +you: ~get_apps +crates-io-bot: @you: Here are your Heroku apps +App ID: "123abc" +App Name: "My app 1" + +App ID: "456def" +App Name: "My app 2" + +App ID: "789ghi" +App Name: "My app 3" +``` + +There will be more commands specific to managing the crates.io infrastructure very soon. ## Setup @@ -124,6 +139,20 @@ AUTHORIZED_USERS="123,456" To use the authorized user list in a CI/CD or production environment, make sure to set it wherever you define your environmental variables for that environment. +### Setting up the Heroku API key + +In order to use commands that call out to Heroku, you must set the HEROKU_API_KEY environmental variable. + +To use the Heroku API key in development at test environments, set this variable in your .env file + +**.env** +``` +HEROKU_API_KEY="123abc" +``` + +To use the Heroku API key in a CI/CD or production environment, make sure to set it wherever you define your environmental variables +for that environment. + ### Running locally You can run this bot in your local environment with this command (make sure you are in your copy of this repo) diff --git a/src/authorizations/users.rs b/src/authorizations/users.rs index 1af2abf..8f4a188 100644 --- a/src/authorizations/users.rs +++ b/src/authorizations/users.rs @@ -1,48 +1,27 @@ -fn authorized_users() -> Vec { - dotenv::var("AUTHORIZED_USERS") - .unwrap() - .split(',') - .map(String::from) - .collect() -} +use crate::config::Config; -pub fn is_authorized(id: &str) -> bool { - authorized_users().iter().any(|i| i == id) +pub fn is_authorized(id: &str, config: &Config) -> bool { + config.authorized_users.contains(id) } #[cfg(test)] mod tests { - use std::env; use super::*; - fn set_authorized_users() { - env::set_var("AUTHORIZED_USERS", "123,456"); - } - - #[test] - fn list_authorized_users() { - set_authorized_users(); - - let result = authorized_users(); - assert!( - result.contains(&String::from("123")), - "Result does not contain the expected name. Result was {:?}", - result - ); - - assert!( - result.contains(&String::from("456")), - "Result does not contain the expected name. Result was {:?}", - result - ); + fn test_config() -> Config { + Config::new( + String::from("123"), + String::from("123,456"), + String::from("456"), + ) } #[test] fn check_whether_user_is_authorized() { - set_authorized_users(); + let config = test_config(); - assert!(is_authorized("123")); - assert!(is_authorized("456")); - assert!(!is_authorized("789")); + assert!(is_authorized("123", &config)); + assert!(is_authorized("456", &config)); + assert!(!is_authorized("789", &config)); } } diff --git a/src/commands/heroku.rs b/src/commands/heroku.rs new file mode 100644 index 0000000..851bfb0 --- /dev/null +++ b/src/commands/heroku.rs @@ -0,0 +1,51 @@ +use heroku_rs::client::{Executor, Heroku}; + +use serde::Deserialize; + +use serenity::framework::standard::{macros::command, Args, CommandResult}; +use serenity::model::prelude::*; +use serenity::prelude::*; + +use crate::config::Config; + +#[derive(Debug, Deserialize)] +struct HerokuApp { + id: String, + name: String, +} + +#[command] +pub fn get_apps(ctx: &mut Context, msg: &Message, _args: Args) -> CommandResult { + let config = ctx.data.read().get::().expect("Expected config").clone(); + + let response = heroku_client(&config.heroku_api_key) + .get() + .apps() + .execute::>(); + + msg.reply(ctx, match response { + Ok((_, _, Some(apps))) => app_response(apps), + Ok((_, _, None)) => "You have no Heroku apps".into(), + Err(err) => { + println!("Err {}", err); + "An error occured while fetching your Heroku apps".into() + } + })?; + + Ok(()) +} + +fn heroku_client(api_key: &str) -> heroku_rs::client::Heroku { + Heroku::new(api_key).unwrap() +} + +fn app_response(processed_app_list: Vec) -> String { + let mut list = String::from("Here are your Heroku apps\n"); + + for app in processed_app_list { + let app_info = format!("App ID: {}\n App Name: {}\n\n", app.id, app.name); + list.push_str(&app_info); + } + + list +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 15d64f3..5574342 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,3 +1,4 @@ +pub mod heroku; pub mod math; pub mod myid; pub mod ping; diff --git a/src/commands/ping.rs b/src/commands/ping.rs index 6d7183b..2fc2d1b 100644 --- a/src/commands/ping.rs +++ b/src/commands/ping.rs @@ -3,12 +3,18 @@ use serenity::model::prelude::*; use serenity::prelude::*; use crate::authorizations::users::*; +use crate::config::Config; #[command] fn ping(ctx: &mut Context, msg: &Message) -> CommandResult { - println!("running pong command"); + let config = ctx + .data + .read() + .get::() + .expect("Expected config") + .clone(); - if is_authorized(&msg.author.id.to_string()) { + if is_authorized(&msg.author.id.to_string(), &*config) { msg.reply(ctx, "Pong!")?; } else { msg.reply( diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..d665302 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,51 @@ +use serenity::prelude::TypeMapKey; +use std::collections::HashSet; +use std::sync::Arc; + +#[derive(Debug)] +pub struct Config { + pub discord_token: String, + pub authorized_users: HashSet, + pub heroku_api_key: String, +} + +impl Config { + pub fn new(discord_token: String, authorized_users: String, heroku_api_key: String) -> Config { + Config { + discord_token, + authorized_users: authorized_users_set(authorized_users), + heroku_api_key, + } + } +} + +impl TypeMapKey for Config { + type Value = Arc; +} + +fn authorized_users_set(users: String) -> HashSet { + let mut users_set = HashSet::new(); + + let split_string = users.split(','); + + for string in split_string { + users_set.insert(String::from(string)); + } + + users_set +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn create_authorized_users_hashset() { + let test_string = String::from("123,456,789"); + let users_set = authorized_users_set(test_string); + + assert!(users_set.contains("123")); + assert!(users_set.contains("456")); + assert!(users_set.contains("789")); + } +} diff --git a/src/lib.rs b/src/lib.rs index 85798a4..cd9d148 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,15 +2,20 @@ use serenity::client::Client; use serenity::framework::standard::{macros::group, StandardFramework}; use serenity::model::gateway::Ready; use serenity::prelude::{Context, EventHandler}; +use std::sync::Arc; mod commands; -use commands::{math::*, myid::*, ping::*}; +use commands::{heroku::*, math::*, myid::*, ping::*}; mod authorizations; +pub mod config; + +use crate::config::Config; + #[group] -#[commands(ping, multiply, myid)] +#[commands(ping, multiply, myid, get_apps)] struct General; struct Handler; @@ -21,8 +26,15 @@ impl EventHandler for Handler { } } -pub fn run(token: String) { - let mut client = Client::new(&token, Handler).expect("Err creating client"); +pub fn run(config: Config) { + let mut client = Client::new(&config.discord_token, Handler).expect("Err creating client"); + + // Insert default config into data + // that is passed to each of the commands + { + let mut data = client.data.write(); + data.insert::(Arc::new(config)); + } client.with_framework( StandardFramework::new() diff --git a/src/main.rs b/src/main.rs index a0360b3..0debfff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,10 +3,14 @@ extern crate crates_io_ops_bot; extern crate dotenv; +use crates_io_ops_bot::config::Config; fn main() { - // Load Discord Token - let token = dotenv::var("DISCORD_TOKEN").expect("DISCORD_TOKEN must be set"); + let config = Config::new( + dotenv::var("DISCORD_TOKEN").expect("DISCORD_TOKEN must be set"), + dotenv::var("AUTHORIZED_USERS").expect("AUTHORIZED_USERS must be set"), + dotenv::var("HEROKU_API_KEY").expect("HEROKU_API_KEY must be set"), + ); - crates_io_ops_bot::run(token) + crates_io_ops_bot::run(config) }