From 779bd00d5fb84f1d270175599f9e426ed43fc116 Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Mon, 2 Mar 2020 11:49:51 -0800 Subject: [PATCH 01/20] Adds in call to Heroku to list all apps associated with a Heroku account Signed-off-by: Nell Shamrell wip Signed-off-by: Nell Shamrell wip Signed-off-by: Nell Shamrell wip Signed-off-by: Nell Shamrell wip - make each app an instance of the HerokuApp struct Signed-off-by: Nell Shamrell working command to get list of Heroku apps associated with a Heroku token Signed-off-by: Nell Shamrell refactors heroku get apps command Signed-off-by: Nell Shamrell corrects formatting Signed-off-by: Nell Shamrell refactors finding environmental variable values into a config struct Signed-off-by: Nell Shamrell implements and references default config Signed-off-by: Nell Shamrell correct formatting Signed-off-by: Nell Shamrell further refactoring Signed-off-by: Nell Shamrell --- .env.sample | 3 +- Cargo.lock | 734 ++++++++++++++++++++++++++++++------ Cargo.toml | 11 +- src/authorizations/users.rs | 17 +- src/commands/heroku.rs | 66 ++++ src/commands/mod.rs | 1 + src/config.rs | 27 ++ src/lib.rs | 13 +- src/main.rs | 5 +- 9 files changed, 747 insertions(+), 130 deletions(-) create mode 100644 src/commands/heroku.rs create mode 100644 src/config.rs diff --git a/.env.sample b/.env.sample index d13cd67..8f70872 100644 --- a/.env.sample +++ b/.env.sample @@ -1 +1,2 @@ -DISCORD_TOKEN="abc123" \ No newline at end of file +DISCORD_TOKEN="abc123" +HEROKU_API_KEY="1234" \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 5a4228c..3a30db8 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", ] @@ -168,6 +191,8 @@ name = "crates-io-ops-bot" version = "0.1.0" dependencies = [ "dotenv", + "heroku_rs", + "serde_json", "serenity", ] @@ -180,11 +205,58 @@ 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" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d3686f5fa27dbc1d76c751300376e167c5a43387f44bb451fd1c24776e49113" +checksum = "1b4660f8b07a560a88c02d76286edb9f0d5d64e495d2b0f233186155aa51be1f" dependencies = [ "sct", ] @@ -210,6 +282,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 +297,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 +331,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 +362,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" @@ -275,22 +384,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f25592f769825e89b92358db00d26f965761e094951ac44d3663ef25b7ac464a" [[package]] -name = "futures-io" -version = "0.3.4" +name = "futures-cpupool" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a638959aa96152c7a4cddf50fcb1e3fede0583b27157c26e67d6f99904090dc6" +checksum = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" +dependencies = [ + "futures", + "num_cpus", +] [[package]] -name = "futures-macro" +name = "futures-io" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a5081aa3de1f7542a794a397cde100ed903b0630152d0973479018fd85423a7" -dependencies = [ - "proc-macro-hack", - "proc-macro2", - "quote", - "syn", -] +checksum = "a638959aa96152c7a4cddf50fcb1e3fede0583b27157c26e67d6f99904090dc6" [[package]] name = "futures-sink" @@ -312,12 +419,9 @@ checksum = "22766cf25d64306bedf0384da004d05c9974ab104fcc4528f1236181c18004c5" dependencies = [ "futures-core", "futures-io", - "futures-macro", "futures-task", "memchr", "pin-utils", - "proc-macro-hack", - "proc-macro-nested", "slab", ] @@ -341,6 +445,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 +478,7 @@ dependencies = [ "indexmap", "log", "slab", - "tokio", + "tokio 0.2.13", "tokio-util", ] @@ -371,13 +493,28 @@ 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-rustls", + "serde", + "serde_json", + "tokio-core", +] + [[package]] name = "http" version = "0.1.21" @@ -400,6 +537,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 +565,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,35 +605,48 @@ 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.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ea6215c7314d450ee45970ab8b3851ab447a0e6bafdd19e31b20a42dbb7faf" +checksum = "15b66d1bd4864ef036adf2363409caa3acd63ebb4725957b66e621c8a36631a3" dependencies = [ - "bytes 0.5.4", + "bytes 0.4.12", "ct-logs", - "futures-util", - "hyper", + "futures", + "hyper 0.12.35", "rustls", - "rustls-native-certs", - "tokio", + "tokio-io", "tokio-rustls", "webpki", + "webpki-roots", +] + +[[package]] +name = "hyper-tls" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3adcd308402b9553630734e9c36b77a7e48b3821251ca2493e8cd596763aafaa" +dependencies = [ + "bytes 0.5.4", + "hyper 0.13.2", + "native-tls", + "tokio 0.2.13", + "tokio-tls", ] [[package]] @@ -528,9 +720,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 +756,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 = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" + +[[package]] +name = "memoffset" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53445de381a1f436797497c61d851644d0e8e88e6140f22872ad33a704933978" +checksum = "75189eb85871ea5c2e2c15abbdd541185f63b408415e5051f5cac122d8c774b9" +dependencies = [ + "rustc_version", +] [[package]] name = "mime" @@ -576,9 +777,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 +813,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 +836,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", + "security-framework-sys", + "tempfile", +] + [[package]] name = "net2" version = "0.2.33" @@ -680,12 +910,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" @@ -751,33 +1008,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5894c618ce612a3fa23881b152b608bafb8c56cfc22f434a3ba3120b40f7b587" [[package]] -name = "ppv-lite86" -version = "0.2.6" +name = "pkg-config" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" +checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" [[package]] -name = "proc-macro-hack" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecd45702f76d6d3c75a80564378ae228a85f0b59d2f3ed43c91b4a69eb2ebfc5" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "proc-macro-nested" -version = "0.1.3" +name = "ppv-lite86" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "369a6ed065f249a159e06c45752c780bda2fb53c995718f9e484d08daa9eb42e" +checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" [[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 +1084,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,46 +1105,50 @@ dependencies = [ "futures-core", "futures-util", "http 0.2.0", - "http-body", - "hyper", - "hyper-rustls", + "http-body 0.3.1", + "hyper 0.13.2", + "hyper-tls", "js-sys", "lazy_static", "log", "mime", "mime_guess", + "native-tls", "percent-encoding", "pin-project-lite", - "rustls", "serde", "serde_json", "serde_urlencoded", "time", - "tokio", - "tokio-rustls", + "tokio 0.2.13", + "tokio-tls", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots 0.17.0", "winreg", ] [[package]] name = "ring" -version = "0.16.11" +version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "741ba1704ae21999c00942f9f5944f801e977f54302af346b596287599ad1862" +checksum = "426bc186e3e95cac1e4a4be125a4aca7e84c2d616ffc02244eef36e2a60a093c" dependencies = [ "cc", "lazy_static", "libc", "spin", "untrusted", - "web-sys", "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" @@ -901,29 +1160,18 @@ dependencies = [ [[package]] name = "rustls" -version = "0.16.0" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b25a18b1bf7387f0145e7f8324e700805aade3842dd3db2e74e4cdeb4677c09e" +checksum = "f271e3552cd835fa28c541c34a7e8fdd8cdff09d77fe4eb8f6c42e87a11b096e" dependencies = [ "base64 0.10.1", "log", "ring", "sct", + "untrusted", "webpki", ] -[[package]] -name = "rustls-native-certs" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51ffebdbb48c14f84eba0b715197d673aff1dd22cc1007ca647e28483bbcc307" -dependencies = [ - "openssl-probe", - "rustls", - "schannel", - "security-framework", -] - [[package]] name = "ryu" version = "1.0.2" @@ -940,17 +1188,23 @@ 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" -version = "0.6.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3042af939fca8c3453b7af0f1c66e533a15a86169e39de2657310ade8f98d3c" +checksum = "2f5adf8fbd58e1b1b52699dc8bed2630faecb6d8c7bee77d009d6bbe4af569b9" dependencies = [ "ring", "untrusted", @@ -1014,9 +1268,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 +1303,6 @@ dependencies = [ "log", "parking_lot", "reqwest", - "rustls", "serde", "serde_json", "static_assertions", @@ -1058,8 +1311,6 @@ dependencies = [ "typemap", "url", "uwl", - "webpki", - "webpki-roots 0.18.0", ] [[package]] @@ -1113,17 +1364,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 +1420,33 @@ dependencies = [ [[package]] name = "tokio" -version = "0.2.11" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +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 = "8fdd17989496f49cdc57978c96f0c9fe5e4a58a8bddc6813c449a4624f6a030b" +checksum = "0fa5e81d6bc4e67fe889d5783bd2a128ab2e0cfa487e0be16b6a8d177b101616" dependencies = [ "bytes 0.5.4", "fnv", @@ -1161,18 +1459,216 @@ 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.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "141afec0978abae6573065a48882c6bae44c5cc61db9b511ac4abf6a09bfd9cc" +checksum = "95a199832a67452c60bed18ed951d28d5755ff57b02b3d2d535d9f13a81ea6c9" dependencies = [ - "futures-core", + "futures", "rustls", - "tokio", + "tokio-io", "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-tls" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bde02a3a5291395f59b06ec6945a3077602fac2b07eeeaf0dee2122f3619828" +dependencies = [ + "native-tls", + "tokio 0.2.13", +] + +[[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 +1680,7 @@ dependencies = [ "futures-sink", "log", "pin-project-lite", - "tokio", + "tokio 0.2.13", ] [[package]] @@ -1218,6 +1714,7 @@ dependencies = [ "httparse", "input_buffer", "log", + "native-tls", "rand", "sha-1", "url", @@ -1289,9 +1786,9 @@ dependencies = [ [[package]] name = "untrusted" -version = "0.7.0" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60369ef7a31de49bcb3f6ca728d4ba7300d9a1658f94c727d4cab8c8d9f4aece" +checksum = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f" [[package]] name = "url" @@ -1316,6 +1813,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 +1831,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" @@ -1443,9 +1957,9 @@ dependencies = [ [[package]] name = "webpki" -version = "0.21.2" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1f50e1972865d6b1adb54167d1c8ed48606004c2c9d0ea5f1eeb34d95e863ef" +checksum = "4f7e1cd7900a3a6b65a3e8780c51a3e6b59c0e2c55c6dc69578c288d69f7d082" dependencies = [ "ring", "untrusted", @@ -1453,19 +1967,11 @@ dependencies = [ [[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" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91cd5736df7f12a964a5067a12c62fa38e1bd8080aff1f80bc29be7c80d19ab4" +checksum = "c10fa4212003ba19a564f25cd8ab572c6791f99a03cc219c13ed35ccab00de0e" dependencies = [ + "untrusted", "webpki", ] diff --git a/Cargo.toml b/Cargo.toml index cd9b118..9fe11fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,13 @@ license = "MIT OR Apache-2.0" [dependencies] dotenv = "0.15" -serenity = "0.8" \ No newline at end of file +serde_json = "1.0" +heroku_rs = "0.2" + +# Uses native_tls_backend feature rather than the default rustls_backend +# As serenity and heroku_rs depend on different versions of rustls_backend +# This makes them compatible +[dependencies.serenity] +default-features = false +features = ["builder", "cache", "client", "framework", "gateway", "http", "model", "standard_framework", "utils", "native_tls_backend"] +version = "0.8" diff --git a/src/authorizations/users.rs b/src/authorizations/users.rs index 1af2abf..2447a6a 100644 --- a/src/authorizations/users.rs +++ b/src/authorizations/users.rs @@ -1,19 +1,22 @@ +use crate::config::Config; + fn authorized_users() -> Vec { - dotenv::var("AUTHORIZED_USERS") - .unwrap() - .split(',') - .map(String::from) - .collect() + let bot_config = Config::default(); + + let split_string = bot_config.authorized_users.split(','); + let auth_users: Vec = split_string.map(String::from).collect(); + + auth_users } pub fn is_authorized(id: &str) -> bool { - authorized_users().iter().any(|i| i == id) + authorized_users().iter().any(|i| i == id) } #[cfg(test)] mod tests { - use std::env; use super::*; + use std::env; fn set_authorized_users() { env::set_var("AUTHORIZED_USERS", "123,456"); diff --git a/src/commands/heroku.rs b/src/commands/heroku.rs new file mode 100644 index 0000000..515eb38 --- /dev/null +++ b/src/commands/heroku.rs @@ -0,0 +1,66 @@ +use heroku_rs::client::{Executor, Heroku}; + +use serde_json::Value; + +use serenity::framework::standard::{macros::command, Args, CommandResult}; +use serenity::model::prelude::*; +use serenity::prelude::*; + +use crate::config::Config; + +#[derive(Debug)] +struct HerokuApp { + id: String, + name: String, +} + +#[command] +pub fn get_apps(ctx: &mut Context, msg: &Message, _args: Args) -> CommandResult { + let response = heroku_client().get().apps().execute::(); + let mut processed_app_list: Vec = Vec::new(); + + match response { + Ok((_headers, _status, json)) => { + if let Some(json) = json { + let array = json.as_array().unwrap(); + processed_app_list.append(&mut app_list(array)) + } + } + + Err(e) => println!("Err {}", e), + } + + msg.reply(ctx, app_response(processed_app_list))?; + + Ok(()) +} + +fn heroku_client() -> heroku_rs::client::Heroku { + let heroku_api_key = Config::default().heroku_api_key; + Heroku::new(heroku_api_key).unwrap() +} + +fn app_list(app_array: &std::vec::Vec) -> Vec { + let mut app_list: Vec = Vec::new(); + + for item in app_array.iter() { + let app: HerokuApp = HerokuApp { + id: item["id"].to_string(), + name: item["name"].to_string(), + }; + app_list.push(app); + } + + app_list +} + +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/config.rs b/src/config.rs new file mode 100644 index 0000000..575a8b2 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,27 @@ +pub struct Config { + pub discord_token: String, + pub authorized_users: String, + pub heroku_api_key: String, +} + +impl Default for Config { + fn default() -> Self { + Config { + discord_token: discord_token(), + authorized_users: authorized_users(), + heroku_api_key: heroku_api_key(), + } + } +} + +fn discord_token() -> String { + dotenv::var("DISCORD_TOKEN").expect("DISCORD_TOKEN must be set") +} + +fn authorized_users() -> String { + dotenv::var("AUTHORIZED_USERS").expect("AUTHORIZED_USERS must be set") +} + +fn heroku_api_key() -> String { + dotenv::var("HEROKU_API_KEY").expect("HEROKU_API_KEY must be set") +} diff --git a/src/lib.rs b/src/lib.rs index 85798a4..1eaadd3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,12 +5,16 @@ use serenity::prelude::{Context, EventHandler}; mod commands; -use commands::{math::*, myid::*, ping::*}; +use commands::{heroku::*, math::*, myid::*, ping::*}; mod authorizations; +mod config; + +use crate::config::Config; + #[group] -#[commands(ping, multiply, myid)] +#[commands(ping, multiply, myid, get_apps)] struct General; struct Handler; @@ -21,8 +25,9 @@ impl EventHandler for Handler { } } -pub fn run(token: String) { - let mut client = Client::new(&token, Handler).expect("Err creating client"); +pub fn run() { + let mut client = + Client::new(Config::default().discord_token, Handler).expect("Err creating client"); client.with_framework( StandardFramework::new() diff --git a/src/main.rs b/src/main.rs index a0360b3..8089ac8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,7 @@ extern crate crates_io_ops_bot; extern crate dotenv; fn main() { - // Load Discord Token - let token = dotenv::var("DISCORD_TOKEN").expect("DISCORD_TOKEN must be set"); + // let config = crates_io_ops_bot::Config::new().unwrap(); - crates_io_ops_bot::run(token) + crates_io_ops_bot::run() } From 1a12f21ee93224adcf4a2ad57f898677d6e0f727 Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Tue, 3 Mar 2020 14:58:24 -0800 Subject: [PATCH 02/20] Update README with new command Signed-off-by: Nell Shamrell --- README.md | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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) From 7d8efd413fd99753ef869aeb79dfa3241f727ab2 Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Tue, 3 Mar 2020 15:43:10 -0800 Subject: [PATCH 03/20] add setting of enviromental variables in test Signed-off-by: Nell Shamrell --- .env.sample | 1 + src/authorizations/users.rs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/.env.sample b/.env.sample index 8f70872..b9d7524 100644 --- a/.env.sample +++ b/.env.sample @@ -1,2 +1,3 @@ DISCORD_TOKEN="abc123" +AUTHORIZED_USER="pikachu,omynite" HEROKU_API_KEY="1234" \ No newline at end of file diff --git a/src/authorizations/users.rs b/src/authorizations/users.rs index 2447a6a..0315e9a 100644 --- a/src/authorizations/users.rs +++ b/src/authorizations/users.rs @@ -18,12 +18,22 @@ mod tests { use super::*; use std::env; + fn set_discord_token() { + env::set_var("DISCORD_TOKEN", "abc123"); + } + + fn set_heroku_api_key() { + env::set_var("HEROKU_API", "abc123"); + } + fn set_authorized_users() { env::set_var("AUTHORIZED_USERS", "123,456"); } #[test] fn list_authorized_users() { + set_discord_token(); + set_heroku_api_key(); set_authorized_users(); let result = authorized_users(); From 4175fdd1ead35d540dd1d2439a7e9188a9a1cf58 Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Thu, 5 Mar 2020 11:54:56 -0800 Subject: [PATCH 04/20] refactor to use serde deserialize macro, rather than custom deserialization code Signed-off-by: Nell Shamrell --- Cargo.lock | 1 + Cargo.toml | 1 + src/commands/heroku.rs | 25 +++++-------------------- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3a30db8..a38b7cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -192,6 +192,7 @@ version = "0.1.0" dependencies = [ "dotenv", "heroku_rs", + "serde", "serde_json", "serenity", ] diff --git a/Cargo.toml b/Cargo.toml index 9fe11fa..4179eb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ license = "MIT OR Apache-2.0" [dependencies] dotenv = "0.15" +serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" heroku_rs = "0.2" diff --git a/src/commands/heroku.rs b/src/commands/heroku.rs index 515eb38..c99df35 100644 --- a/src/commands/heroku.rs +++ b/src/commands/heroku.rs @@ -1,6 +1,6 @@ use heroku_rs::client::{Executor, Heroku}; -use serde_json::Value; +use serde::{Deserialize}; use serenity::framework::standard::{macros::command, Args, CommandResult}; use serenity::model::prelude::*; @@ -8,7 +8,7 @@ use serenity::prelude::*; use crate::config::Config; -#[derive(Debug)] +#[derive(Debug, Deserialize)] struct HerokuApp { id: String, name: String, @@ -16,14 +16,13 @@ struct HerokuApp { #[command] pub fn get_apps(ctx: &mut Context, msg: &Message, _args: Args) -> CommandResult { - let response = heroku_client().get().apps().execute::(); + let response = heroku_client().get().apps().execute::>(); let mut processed_app_list: Vec = Vec::new(); match response { Ok((_headers, _status, json)) => { - if let Some(json) = json { - let array = json.as_array().unwrap(); - processed_app_list.append(&mut app_list(array)) + if let Some(mut json) = json { + processed_app_list.append(&mut json); } } @@ -40,20 +39,6 @@ fn heroku_client() -> heroku_rs::client::Heroku { Heroku::new(heroku_api_key).unwrap() } -fn app_list(app_array: &std::vec::Vec) -> Vec { - let mut app_list: Vec = Vec::new(); - - for item in app_array.iter() { - let app: HerokuApp = HerokuApp { - id: item["id"].to_string(), - name: item["name"].to_string(), - }; - app_list.push(app); - } - - app_list -} - fn app_response(processed_app_list: Vec) -> String { let mut list = String::from("Here are your Heroku apps\n"); From 8a59c485101505e4f9db6d70d89fc36491cde29c Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Thu, 5 Mar 2020 13:59:09 -0800 Subject: [PATCH 05/20] refactors heroku command to read api key from passed in config Signed-off-by: Nell Shamrell --- src/commands/heroku.rs | 12 ++++++++---- src/config.rs | 7 +++++++ src/lib.rs | 10 +++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/commands/heroku.rs b/src/commands/heroku.rs index c99df35..6db7d73 100644 --- a/src/commands/heroku.rs +++ b/src/commands/heroku.rs @@ -16,7 +16,11 @@ struct HerokuApp { #[command] pub fn get_apps(ctx: &mut Context, msg: &Message, _args: Args) -> CommandResult { - let response = heroku_client().get().apps().execute::>(); + let ctx_clone = ctx.clone(); + let data = ctx_clone.data.read(); + let config = data.get::().expect("Expected config"); + + let response = heroku_client(&config.heroku_api_key).get().apps().execute::>(); let mut processed_app_list: Vec = Vec::new(); match response { @@ -34,11 +38,11 @@ pub fn get_apps(ctx: &mut Context, msg: &Message, _args: Args) -> CommandResult Ok(()) } -fn heroku_client() -> heroku_rs::client::Heroku { - let heroku_api_key = Config::default().heroku_api_key; - Heroku::new(heroku_api_key).unwrap() +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"); diff --git a/src/config.rs b/src/config.rs index 575a8b2..061f2fc 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,3 +1,6 @@ +use serenity::prelude::TypeMapKey; + +#[derive(Debug)] pub struct Config { pub discord_token: String, pub authorized_users: String, @@ -14,6 +17,10 @@ impl Default for Config { } } +impl TypeMapKey for Config { + type Value = Config; +} + fn discord_token() -> String { dotenv::var("DISCORD_TOKEN").expect("DISCORD_TOKEN must be set") } diff --git a/src/lib.rs b/src/lib.rs index 1eaadd3..b2b5a12 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,6 +29,14 @@ pub fn run() { let mut client = Client::new(Config::default().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::(Config::default()); + } + client.with_framework( StandardFramework::new() .configure(|c| c.prefix("~")) // set the bot's prefix to "~" @@ -38,4 +46,4 @@ pub fn run() { if let Err(why) = client.start() { println!("Client error: {:?}", why); } -} +} \ No newline at end of file From 95f14d8680576581218149034f2a5a8cf2c89a72 Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Thu, 5 Mar 2020 14:24:57 -0800 Subject: [PATCH 06/20] refactor to pass Config struct to ping command and use in users authorization functions Signed-off-by: Nell Shamrell --- src/authorizations/users.rs | 10 ++++------ src/commands/ping.rs | 7 ++++++- src/config.rs | 2 +- src/lib.rs | 6 ++++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/authorizations/users.rs b/src/authorizations/users.rs index 0315e9a..a13be03 100644 --- a/src/authorizations/users.rs +++ b/src/authorizations/users.rs @@ -1,16 +1,14 @@ use crate::config::Config; -fn authorized_users() -> Vec { - let bot_config = Config::default(); - - let split_string = bot_config.authorized_users.split(','); +fn authorized_users(config: &Config) -> Vec { + let split_string = config.authorized_users.split(','); let auth_users: Vec = split_string.map(String::from).collect(); auth_users } -pub fn is_authorized(id: &str) -> bool { - authorized_users().iter().any(|i| i == id) +pub fn is_authorized(id: &str, config: &Config) -> bool { + authorized_users(config).iter().any(|i| i == id) } #[cfg(test)] diff --git a/src/commands/ping.rs b/src/commands/ping.rs index 6d7183b..6240673 100644 --- a/src/commands/ping.rs +++ b/src/commands/ping.rs @@ -3,12 +3,17 @@ 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"); - if is_authorized(&msg.author.id.to_string()) { + let ctx_clone = ctx.clone(); + let data = ctx_clone.data.read(); + let config = data.get::().expect("Expected config"); + + 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 index 061f2fc..bf9d17b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -31,4 +31,4 @@ fn authorized_users() -> String { fn heroku_api_key() -> String { dotenv::var("HEROKU_API_KEY").expect("HEROKU_API_KEY must be set") -} +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index b2b5a12..2e9a212 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,15 +26,17 @@ impl EventHandler for Handler { } pub fn run() { + let config = Config::default(); + let mut client = - Client::new(Config::default().discord_token, Handler).expect("Err creating 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::(Config::default()); + data.insert::(config); } client.with_framework( From 0d2c0134de2e60355e93129ce79e4bf931b0ff94 Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Thu, 5 Mar 2020 14:46:30 -0800 Subject: [PATCH 07/20] remove unnecessary commented out code Signed-off-by: Nell Shamrell --- src/main.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8089ac8..09e8d67 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,5 @@ extern crate crates_io_ops_bot; extern crate dotenv; fn main() { - // let config = crates_io_ops_bot::Config::new().unwrap(); - crates_io_ops_bot::run() } From 919fe55b2eccfc06965e35a730faa2b48ccbc197 Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Thu, 5 Mar 2020 14:47:11 -0800 Subject: [PATCH 08/20] correct formatting Signed-off-by: Nell Shamrell --- src/authorizations/users.rs | 2 +- src/commands/heroku.rs | 8 +++++--- src/config.rs | 2 +- src/lib.rs | 6 ++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/authorizations/users.rs b/src/authorizations/users.rs index a13be03..683fc82 100644 --- a/src/authorizations/users.rs +++ b/src/authorizations/users.rs @@ -19,7 +19,7 @@ mod tests { fn set_discord_token() { env::set_var("DISCORD_TOKEN", "abc123"); } - + fn set_heroku_api_key() { env::set_var("HEROKU_API", "abc123"); } diff --git a/src/commands/heroku.rs b/src/commands/heroku.rs index 6db7d73..2df5bb1 100644 --- a/src/commands/heroku.rs +++ b/src/commands/heroku.rs @@ -1,6 +1,6 @@ use heroku_rs::client::{Executor, Heroku}; -use serde::{Deserialize}; +use serde::Deserialize; use serenity::framework::standard::{macros::command, Args, CommandResult}; use serenity::model::prelude::*; @@ -20,7 +20,10 @@ pub fn get_apps(ctx: &mut Context, msg: &Message, _args: Args) -> CommandResult let data = ctx_clone.data.read(); let config = data.get::().expect("Expected config"); - let response = heroku_client(&config.heroku_api_key).get().apps().execute::>(); + let response = heroku_client(&config.heroku_api_key) + .get() + .apps() + .execute::>(); let mut processed_app_list: Vec = Vec::new(); match response { @@ -42,7 +45,6 @@ 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"); diff --git a/src/config.rs b/src/config.rs index bf9d17b..061f2fc 100644 --- a/src/config.rs +++ b/src/config.rs @@ -31,4 +31,4 @@ fn authorized_users() -> String { fn heroku_api_key() -> String { dotenv::var("HEROKU_API_KEY").expect("HEROKU_API_KEY must be set") -} \ No newline at end of file +} diff --git a/src/lib.rs b/src/lib.rs index 2e9a212..dee0f56 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,9 +28,7 @@ impl EventHandler for Handler { pub fn run() { let config = Config::default(); - let mut client = - Client::new(&config.discord_token, Handler).expect("Err creating client"); - + 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 @@ -48,4 +46,4 @@ pub fn run() { if let Err(why) = client.start() { println!("Client error: {:?}", why); } -} \ No newline at end of file +} From 1c0cacc3b92d789d9f02a53bb3b903934b9f0c0d Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Thu, 5 Mar 2020 15:24:12 -0800 Subject: [PATCH 09/20] repair broken tests Signed-off-by: Nell Shamrell --- src/authorizations/users.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/authorizations/users.rs b/src/authorizations/users.rs index 683fc82..3e3ea51 100644 --- a/src/authorizations/users.rs +++ b/src/authorizations/users.rs @@ -34,7 +34,7 @@ mod tests { set_heroku_api_key(); set_authorized_users(); - let result = authorized_users(); + let result = authorized_users(&Config::default()); assert!( result.contains(&String::from("123")), "Result does not contain the expected name. Result was {:?}", @@ -50,10 +50,11 @@ mod tests { #[test] fn check_whether_user_is_authorized() { + let config = Config::default(); set_authorized_users(); - 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)); } } From 99fd8d4459dc2a06a751bfdb00f9d71549999ed7 Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Thu, 5 Mar 2020 15:28:42 -0800 Subject: [PATCH 10/20] further repair tests Signed-off-by: Nell Shamrell --- src/authorizations/users.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/authorizations/users.rs b/src/authorizations/users.rs index 3e3ea51..9df9fb8 100644 --- a/src/authorizations/users.rs +++ b/src/authorizations/users.rs @@ -50,8 +50,11 @@ mod tests { #[test] fn check_whether_user_is_authorized() { - let config = Config::default(); + set_discord_token(); + set_heroku_api_key(); set_authorized_users(); + + let config = Config::default(); assert!(is_authorized("123", &config)); assert!(is_authorized("456", &config)); From 17a66ab2a3726c2af4e556d013e8d0885dd29302 Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Thu, 5 Mar 2020 15:37:11 -0800 Subject: [PATCH 11/20] create and pass config from main function Signed-off-by: Nell Shamrell --- src/authorizations/users.rs | 4 +-- src/commands/heroku.rs | 2 +- src/commands/ping.rs | 2 +- src/config.rs | 52 +++++++++++++++++++------------------ src/lib.rs | 8 +++--- src/main.rs | 4 ++- 6 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/authorizations/users.rs b/src/authorizations/users.rs index 9df9fb8..c53e242 100644 --- a/src/authorizations/users.rs +++ b/src/authorizations/users.rs @@ -1,4 +1,4 @@ -use crate::config::Config; +use crate::config::config::Config; fn authorized_users(config: &Config) -> Vec { let split_string = config.authorized_users.split(','); @@ -53,7 +53,7 @@ mod tests { set_discord_token(); set_heroku_api_key(); set_authorized_users(); - + let config = Config::default(); assert!(is_authorized("123", &config)); diff --git a/src/commands/heroku.rs b/src/commands/heroku.rs index 2df5bb1..1b4a308 100644 --- a/src/commands/heroku.rs +++ b/src/commands/heroku.rs @@ -6,7 +6,7 @@ use serenity::framework::standard::{macros::command, Args, CommandResult}; use serenity::model::prelude::*; use serenity::prelude::*; -use crate::config::Config; +use crate::config::config::Config; #[derive(Debug, Deserialize)] struct HerokuApp { diff --git a/src/commands/ping.rs b/src/commands/ping.rs index 6240673..0a29f46 100644 --- a/src/commands/ping.rs +++ b/src/commands/ping.rs @@ -3,7 +3,7 @@ use serenity::model::prelude::*; use serenity::prelude::*; use crate::authorizations::users::*; -use crate::config::Config; +use crate::config::config::Config; #[command] fn ping(ctx: &mut Context, msg: &Message) -> CommandResult { diff --git a/src/config.rs b/src/config.rs index 061f2fc..75439bb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,34 +1,36 @@ -use serenity::prelude::TypeMapKey; +pub mod config { + use serenity::prelude::TypeMapKey; -#[derive(Debug)] -pub struct Config { - pub discord_token: String, - pub authorized_users: String, - pub heroku_api_key: String, -} + #[derive(Debug)] + pub struct Config { + pub discord_token: String, + pub authorized_users: String, + pub heroku_api_key: String, + } -impl Default for Config { - fn default() -> Self { - Config { - discord_token: discord_token(), - authorized_users: authorized_users(), - heroku_api_key: heroku_api_key(), + impl Default for Config { + fn default() -> Self { + Config { + discord_token: discord_token(), + authorized_users: authorized_users(), + heroku_api_key: heroku_api_key(), + } } } -} -impl TypeMapKey for Config { - type Value = Config; -} + impl TypeMapKey for Config { + type Value = Config; + } -fn discord_token() -> String { - dotenv::var("DISCORD_TOKEN").expect("DISCORD_TOKEN must be set") -} + fn discord_token() -> String { + dotenv::var("DISCORD_TOKEN").expect("DISCORD_TOKEN must be set") + } -fn authorized_users() -> String { - dotenv::var("AUTHORIZED_USERS").expect("AUTHORIZED_USERS must be set") -} + fn authorized_users() -> String { + dotenv::var("AUTHORIZED_USERS").expect("AUTHORIZED_USERS must be set") + } -fn heroku_api_key() -> String { - dotenv::var("HEROKU_API_KEY").expect("HEROKU_API_KEY must be set") + fn heroku_api_key() -> String { + dotenv::var("HEROKU_API_KEY").expect("HEROKU_API_KEY must be set") + } } diff --git a/src/lib.rs b/src/lib.rs index dee0f56..4fec2bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,9 +9,9 @@ use commands::{heroku::*, math::*, myid::*, ping::*}; mod authorizations; -mod config; +pub mod config; -use crate::config::Config; +use crate::config::config::Config; #[group] #[commands(ping, multiply, myid, get_apps)] @@ -25,9 +25,7 @@ impl EventHandler for Handler { } } -pub fn run() { - let config = Config::default(); - +pub fn run(config: Config) { let mut client = Client::new(&config.discord_token, Handler).expect("Err creating client"); // Insert default config into data diff --git a/src/main.rs b/src/main.rs index 09e8d67..e643701 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,9 @@ extern crate crates_io_ops_bot; extern crate dotenv; +use crates_io_ops_bot::config::config::Config; fn main() { - crates_io_ops_bot::run() + let config = Config::default(); + crates_io_ops_bot::run(config) } From 931c63b1b013868dd2da27be27acf2f4bc5885ee Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Thu, 5 Mar 2020 15:54:51 -0800 Subject: [PATCH 12/20] further refactors config Signed-off-by: Nell Shamrell --- src/authorizations/users.rs | 29 +++++++++-------------------- src/config.rs | 31 +++++++++++-------------------- src/main.rs | 7 ++++++- 3 files changed, 26 insertions(+), 41 deletions(-) diff --git a/src/authorizations/users.rs b/src/authorizations/users.rs index c53e242..ef13fa9 100644 --- a/src/authorizations/users.rs +++ b/src/authorizations/users.rs @@ -16,25 +16,18 @@ mod tests { use super::*; use std::env; - fn set_discord_token() { - env::set_var("DISCORD_TOKEN", "abc123"); - } - - fn set_heroku_api_key() { - env::set_var("HEROKU_API", "abc123"); - } - - fn set_authorized_users() { - env::set_var("AUTHORIZED_USERS", "123,456"); + fn test_config() -> Config { + Config::new( + String::from("123"), + String::from("123,456"), + String::from("456") + ) } #[test] fn list_authorized_users() { - set_discord_token(); - set_heroku_api_key(); - set_authorized_users(); - - let result = authorized_users(&Config::default()); + let config = test_config(); + let result = authorized_users(&config); assert!( result.contains(&String::from("123")), "Result does not contain the expected name. Result was {:?}", @@ -50,11 +43,7 @@ mod tests { #[test] fn check_whether_user_is_authorized() { - set_discord_token(); - set_heroku_api_key(); - set_authorized_users(); - - let config = Config::default(); + let config = test_config(); assert!(is_authorized("123", &config)); assert!(is_authorized("456", &config)); diff --git a/src/config.rs b/src/config.rs index 75439bb..de99465 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,29 +8,20 @@ pub mod config { pub heroku_api_key: String, } - impl Default for Config { - fn default() -> Self { - Config { - discord_token: discord_token(), - authorized_users: authorized_users(), - heroku_api_key: heroku_api_key(), - } - } + impl Config { + pub fn new(discord_token: String, + authorized_users: String, + heroku_api_key: String + ) -> Config { + Config { + discord_token: discord_token, + authorized_users: authorized_users, + heroku_api_key: heroku_api_key + } + } } impl TypeMapKey for Config { type Value = Config; } - - fn discord_token() -> String { - dotenv::var("DISCORD_TOKEN").expect("DISCORD_TOKEN must be set") - } - - fn authorized_users() -> String { - dotenv::var("AUTHORIZED_USERS").expect("AUTHORIZED_USERS must be set") - } - - fn heroku_api_key() -> String { - dotenv::var("HEROKU_API_KEY").expect("HEROKU_API_KEY must be set") - } } diff --git a/src/main.rs b/src/main.rs index e643701..aca5085 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,11 @@ extern crate dotenv; use crates_io_ops_bot::config::config::Config; fn main() { - let config = Config::default(); + 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(config) } From 3900c3cdaf5f4035ce6e8552810dc40280622516 Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Thu, 5 Mar 2020 16:13:16 -0800 Subject: [PATCH 13/20] further refactoring Signed-off-by: Nell Shamrell --- src/authorizations/users.rs | 2 +- src/config.rs | 21 +++++++++++---------- src/main.rs | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/authorizations/users.rs b/src/authorizations/users.rs index ef13fa9..9108d25 100644 --- a/src/authorizations/users.rs +++ b/src/authorizations/users.rs @@ -20,7 +20,7 @@ mod tests { Config::new( String::from("123"), String::from("123,456"), - String::from("456") + String::from("456"), ) } diff --git a/src/config.rs b/src/config.rs index de99465..c78cd2f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,16 +9,17 @@ pub mod config { } impl Config { - pub fn new(discord_token: String, - authorized_users: String, - heroku_api_key: String - ) -> Config { - Config { - discord_token: discord_token, - authorized_users: authorized_users, - heroku_api_key: heroku_api_key - } - } + pub fn new( + discord_token: String, + authorized_users: String, + heroku_api_key: String, + ) -> Config { + Config { + discord_token, + authorized_users, + heroku_api_key, + } + } } impl TypeMapKey for Config { diff --git a/src/main.rs b/src/main.rs index aca5085..2784fb0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ fn main() { 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") + dotenv::var("HEROKU_API_KEY").expect("HEROKU_API_KEY must be set"), ); crates_io_ops_bot::run(config) From ad0c92d1672af3c015f49ac4e82776ebd8407ba5 Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Fri, 6 Mar 2020 10:16:24 -0800 Subject: [PATCH 14/20] refactor processed_app list assignment Signed-off-by: Nell Shamrell --- src/commands/heroku.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/commands/heroku.rs b/src/commands/heroku.rs index 1b4a308..aa22f22 100644 --- a/src/commands/heroku.rs +++ b/src/commands/heroku.rs @@ -24,12 +24,13 @@ pub fn get_apps(ctx: &mut Context, msg: &Message, _args: Args) -> CommandResult .get() .apps() .execute::>(); + let mut processed_app_list: Vec = Vec::new(); match response { Ok((_headers, _status, json)) => { - if let Some(mut json) = json { - processed_app_list.append(&mut json); + if let Some(json) = json { + processed_app_list = json; } } From e6b2947c286f02943fa30b2e3797c94a9c4fafb0 Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Fri, 6 Mar 2020 10:48:13 -0800 Subject: [PATCH 15/20] refactor parsing users string to the config module so we only have to do it once for the config Signed-off-by: Nell Shamrell --- src/authorizations/users.rs | 27 +-------------------------- src/config.rs | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/authorizations/users.rs b/src/authorizations/users.rs index 9108d25..9146930 100644 --- a/src/authorizations/users.rs +++ b/src/authorizations/users.rs @@ -1,20 +1,12 @@ use crate::config::config::Config; -fn authorized_users(config: &Config) -> Vec { - let split_string = config.authorized_users.split(','); - let auth_users: Vec = split_string.map(String::from).collect(); - - auth_users -} - pub fn is_authorized(id: &str, config: &Config) -> bool { - authorized_users(config).iter().any(|i| i == id) + config.authorized_users.iter().any(|i| i == id) } #[cfg(test)] mod tests { use super::*; - use std::env; fn test_config() -> Config { Config::new( @@ -24,23 +16,6 @@ mod tests { ) } - #[test] - fn list_authorized_users() { - let config = test_config(); - let result = authorized_users(&config); - 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 - ); - } - #[test] fn check_whether_user_is_authorized() { let config = test_config(); diff --git a/src/config.rs b/src/config.rs index c78cd2f..cb286e9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,10 +1,11 @@ pub mod config { use serenity::prelude::TypeMapKey; + use std::collections::HashSet; #[derive(Debug)] pub struct Config { pub discord_token: String, - pub authorized_users: String, + pub authorized_users: HashSet, pub heroku_api_key: String, } @@ -16,7 +17,7 @@ pub mod config { ) -> Config { Config { discord_token, - authorized_users, + authorized_users: authorized_users_set(authorized_users), heroku_api_key, } } @@ -25,4 +26,31 @@ pub mod config { impl TypeMapKey for Config { type Value = Config; } + + 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")); + } + } } From b4df4ab1fe2b66a7d82621cedf60d2f11b0149f3 Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Fri, 6 Mar 2020 10:54:22 -0800 Subject: [PATCH 16/20] remove redundant config mod Signed-off-by: Nell Shamrell --- src/authorizations/users.rs | 2 +- src/commands/heroku.rs | 2 +- src/commands/ping.rs | 2 +- src/config.rs | 81 +++++++++++++++++-------------------- src/lib.rs | 2 +- src/main.rs | 2 +- 6 files changed, 43 insertions(+), 48 deletions(-) diff --git a/src/authorizations/users.rs b/src/authorizations/users.rs index 9146930..0d28a7f 100644 --- a/src/authorizations/users.rs +++ b/src/authorizations/users.rs @@ -1,4 +1,4 @@ -use crate::config::config::Config; +use crate::config::Config; pub fn is_authorized(id: &str, config: &Config) -> bool { config.authorized_users.iter().any(|i| i == id) diff --git a/src/commands/heroku.rs b/src/commands/heroku.rs index aa22f22..5a6f468 100644 --- a/src/commands/heroku.rs +++ b/src/commands/heroku.rs @@ -6,7 +6,7 @@ use serenity::framework::standard::{macros::command, Args, CommandResult}; use serenity::model::prelude::*; use serenity::prelude::*; -use crate::config::config::Config; +use crate::config::Config; #[derive(Debug, Deserialize)] struct HerokuApp { diff --git a/src/commands/ping.rs b/src/commands/ping.rs index 0a29f46..6240673 100644 --- a/src/commands/ping.rs +++ b/src/commands/ping.rs @@ -3,7 +3,7 @@ use serenity::model::prelude::*; use serenity::prelude::*; use crate::authorizations::users::*; -use crate::config::config::Config; +use crate::config::Config; #[command] fn ping(ctx: &mut Context, msg: &Message) -> CommandResult { diff --git a/src/config.rs b/src/config.rs index cb286e9..2848eef 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,56 +1,51 @@ -pub mod config { - use serenity::prelude::TypeMapKey; - use std::collections::HashSet; - - #[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, - } - } - } +use serenity::prelude::TypeMapKey; +use std::collections::HashSet; - impl TypeMapKey for Config { - type Value = Config; +#[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, + } } +} - fn authorized_users_set(users: String) -> HashSet { - let mut users_set = HashSet::new(); +impl TypeMapKey for Config { + type Value = Config; +} - let split_string = users.split(','); +fn authorized_users_set(users: String) -> HashSet { + let mut users_set = HashSet::new(); - for string in split_string { - users_set.insert(String::from(string)); - } + let split_string = users.split(','); - users_set + for string in split_string { + users_set.insert(String::from(string)); } - #[cfg(test)] - mod tests { - use super::*; + users_set +} - #[test] - fn create_authorized_users_hashset() { - let test_string = String::from("123,456,789"); - let users_set = authorized_users_set(test_string); +#[cfg(test)] +mod tests { + use super::*; - assert!(users_set.contains("123")); - assert!(users_set.contains("456")); - assert!(users_set.contains("789")); - } + #[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 4fec2bd..ab5c1d2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,7 @@ mod authorizations; pub mod config; -use crate::config::config::Config; +use crate::config::Config; #[group] #[commands(ping, multiply, myid, get_apps)] diff --git a/src/main.rs b/src/main.rs index 2784fb0..0debfff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ extern crate crates_io_ops_bot; extern crate dotenv; -use crates_io_ops_bot::config::config::Config; +use crates_io_ops_bot::config::Config; fn main() { let config = Config::new( From 6b7a29508ace3f516ca5ed0f3139fec82338318f Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Fri, 6 Mar 2020 11:00:56 -0800 Subject: [PATCH 17/20] refactor config to be passed in an Arc Signed-off-by: Nell Shamrell --- src/commands/heroku.rs | 4 +--- src/commands/ping.rs | 8 ++------ src/config.rs | 4 ++-- src/lib.rs | 3 ++- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/commands/heroku.rs b/src/commands/heroku.rs index 5a6f468..dc305ca 100644 --- a/src/commands/heroku.rs +++ b/src/commands/heroku.rs @@ -16,9 +16,7 @@ struct HerokuApp { #[command] pub fn get_apps(ctx: &mut Context, msg: &Message, _args: Args) -> CommandResult { - let ctx_clone = ctx.clone(); - let data = ctx_clone.data.read(); - let config = data.get::().expect("Expected config"); + let config = ctx.data.read().get::().expect("Expected config").clone(); let response = heroku_client(&config.heroku_api_key) .get() diff --git a/src/commands/ping.rs b/src/commands/ping.rs index 6240673..25b4b81 100644 --- a/src/commands/ping.rs +++ b/src/commands/ping.rs @@ -7,13 +7,9 @@ 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(); - let ctx_clone = ctx.clone(); - let data = ctx_clone.data.read(); - let config = data.get::().expect("Expected config"); - - if is_authorized(&msg.author.id.to_string(), config) { + 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 index 2848eef..d665302 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,6 @@ - use serenity::prelude::TypeMapKey; use std::collections::HashSet; +use std::sync::Arc; #[derive(Debug)] pub struct Config { @@ -20,7 +20,7 @@ impl Config { } impl TypeMapKey for Config { - type Value = Config; + type Value = Arc; } fn authorized_users_set(users: String) -> HashSet { diff --git a/src/lib.rs b/src/lib.rs index ab5c1d2..cd9d148 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ 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; @@ -32,7 +33,7 @@ pub fn run(config: Config) { // that is passed to each of the commands { let mut data = client.data.write(); - data.insert::(config); + data.insert::(Arc::new(config)); } client.with_framework( From 588235fbf671cd858ae3d34918e5af808b6ec16e Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Fri, 6 Mar 2020 11:33:49 -0800 Subject: [PATCH 18/20] simplify Cargo.toml Signed-off-by: Nell Shamrell --- Cargo.lock | 203 ++++++++++++++++++++++++++++++++++++++--------------- Cargo.toml | 11 ++- 2 files changed, 150 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a38b7cd..a8dc16a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -176,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", ] @@ -186,6 +196,12 @@ 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" @@ -255,9 +271,9 @@ dependencies = [ [[package]] name = "ct-logs" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b4660f8b07a560a88c02d76286edb9f0d5d64e495d2b0f233186155aa51be1f" +checksum = "4d3686f5fa27dbc1d76c751300376e167c5a43387f44bb451fd1c24776e49113" dependencies = [ "sct", ] @@ -400,6 +416,18 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a638959aa96152c7a4cddf50fcb1e3fede0583b27157c26e67d6f99904090dc6" +[[package]] +name = "futures-macro" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a5081aa3de1f7542a794a397cde100ed903b0630152d0973479018fd85423a7" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "futures-sink" version = "0.3.4" @@ -420,9 +448,12 @@ checksum = "22766cf25d64306bedf0384da004d05c9974ab104fcc4528f1236181c18004c5" dependencies = [ "futures-core", "futures-io", + "futures-macro", "futures-task", "memchr", "pin-utils", + "proc-macro-hack", + "proc-macro-nested", "slab", ] @@ -510,7 +541,8 @@ dependencies = [ "error-chain", "futures", "hyper 0.12.35", - "hyper-rustls", + "hyper-tls", + "native-tls", "serde", "serde_json", "tokio-core", @@ -622,32 +654,33 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.16.1" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15b66d1bd4864ef036adf2363409caa3acd63ebb4725957b66e621c8a36631a3" +checksum = "ac965ea399ec3a25ac7d13b8affd4b8f39325cca00858ddf5eb29b79e6b14b08" dependencies = [ - "bytes 0.4.12", + "bytes 0.5.4", "ct-logs", - "futures", - "hyper 0.12.35", - "rustls", - "tokio-io", + "futures-util", + "hyper 0.13.2", + "log", + "rustls 0.17.0", + "rustls-native-certs", + "tokio 0.2.13", "tokio-rustls", "webpki", - "webpki-roots", ] [[package]] name = "hyper-tls" -version = "0.4.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3adcd308402b9553630734e9c36b77a7e48b3821251ca2493e8cd596763aafaa" +checksum = "3a800d6aa50af4b5850b2b0f659625ce9504df908e9733b635720483be26174f" dependencies = [ - "bytes 0.5.4", - "hyper 0.13.2", + "bytes 0.4.12", + "futures", + "hyper 0.12.35", "native-tls", - "tokio 0.2.13", - "tokio-tls", + "tokio-io", ] [[package]] @@ -850,8 +883,8 @@ dependencies = [ "openssl-probe", "openssl-sys", "schannel", - "security-framework", - "security-framework-sys", + "security-framework 0.3.4", + "security-framework-sys 0.3.3", "tempfile", ] @@ -1020,6 +1053,23 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" +[[package]] +name = "proc-macro-hack" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecd45702f76d6d3c75a80564378ae228a85f0b59d2f3ed43c91b4a69eb2ebfc5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "proc-macro-nested" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "369a6ed065f249a159e06c45752c780bda2fb53c995718f9e484d08daa9eb42e" + [[package]] name = "proc-macro2" version = "1.0.9" @@ -1108,39 +1158,41 @@ dependencies = [ "http 0.2.0", "http-body 0.3.1", "hyper 0.13.2", - "hyper-tls", + "hyper-rustls", "js-sys", "lazy_static", "log", "mime", "mime_guess", - "native-tls", "percent-encoding", "pin-project-lite", + "rustls 0.17.0", "serde", "serde_json", "serde_urlencoded", "time", "tokio 0.2.13", - "tokio-tls", + "tokio-rustls", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "winreg", ] [[package]] name = "ring" -version = "0.14.6" +version = "0.16.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "426bc186e3e95cac1e4a4be125a4aca7e84c2d616ffc02244eef36e2a60a093c" +checksum = "741ba1704ae21999c00942f9f5944f801e977f54302af346b596287599ad1862" dependencies = [ "cc", "lazy_static", "libc", "spin", "untrusted", + "web-sys", "winapi 0.3.8", ] @@ -1161,18 +1213,42 @@ dependencies = [ [[package]] name = "rustls" -version = "0.15.2" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f271e3552cd835fa28c541c34a7e8fdd8cdff09d77fe4eb8f6c42e87a11b096e" +checksum = "b25a18b1bf7387f0145e7f8324e700805aade3842dd3db2e74e4cdeb4677c09e" dependencies = [ "base64 0.10.1", "log", "ring", "sct", - "untrusted", "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.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75ffeb84a6bd9d014713119542ce415db3a3e4748f0bfce1e1416cd224a23a5" +dependencies = [ + "openssl-probe", + "rustls 0.17.0", + "schannel", + "security-framework 0.4.1", +] + [[package]] name = "ryu" version = "1.0.2" @@ -1203,9 +1279,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "sct" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f5adf8fbd58e1b1b52699dc8bed2630faecb6d8c7bee77d009d6bbe4af569b9" +checksum = "e3042af939fca8c3453b7af0f1c66e533a15a86169e39de2657310ade8f98d3c" dependencies = [ "ring", "untrusted", @@ -1217,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]] @@ -1229,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]] @@ -1304,6 +1402,7 @@ dependencies = [ "log", "parking_lot", "reqwest", + "rustls 0.16.0", "serde", "serde_json", "static_assertions", @@ -1312,6 +1411,8 @@ dependencies = [ "typemap", "url", "uwl", + "webpki", + "webpki-roots", ] [[package]] @@ -1564,13 +1665,13 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.9.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a199832a67452c60bed18ed951d28d5755ff57b02b3d2d535d9f13a81ea6c9" +checksum = "4adb8b3e5f86b707f1b54e7c15b6de52617a823608ccda98a15d3a24222f265a" dependencies = [ - "futures", - "rustls", - "tokio-io", + "futures-core", + "rustls 0.17.0", + "tokio 0.2.13", "webpki", ] @@ -1627,16 +1728,6 @@ dependencies = [ "tokio-executor", ] -[[package]] -name = "tokio-tls" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bde02a3a5291395f59b06ec6945a3077602fac2b07eeeaf0dee2122f3619828" -dependencies = [ - "native-tls", - "tokio 0.2.13", -] - [[package]] name = "tokio-udp" version = "0.1.6" @@ -1715,7 +1806,6 @@ dependencies = [ "httparse", "input_buffer", "log", - "native-tls", "rand", "sha-1", "url", @@ -1787,9 +1877,9 @@ dependencies = [ [[package]] name = "untrusted" -version = "0.6.2" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f" +checksum = "60369ef7a31de49bcb3f6ca728d4ba7300d9a1658f94c727d4cab8c8d9f4aece" [[package]] name = "url" @@ -1958,9 +2048,9 @@ dependencies = [ [[package]] name = "webpki" -version = "0.19.1" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f7e1cd7900a3a6b65a3e8780c51a3e6b59c0e2c55c6dc69578c288d69f7d082" +checksum = "f1f50e1972865d6b1adb54167d1c8ed48606004c2c9d0ea5f1eeb34d95e863ef" dependencies = [ "ring", "untrusted", @@ -1968,11 +2058,10 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.16.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c10fa4212003ba19a564f25cd8ab572c6791f99a03cc219c13ed35ccab00de0e" +checksum = "91cd5736df7f12a964a5067a12c62fa38e1bd8080aff1f80bc29be7c80d19ab4" dependencies = [ - "untrusted", "webpki", ] diff --git a/Cargo.toml b/Cargo.toml index 4179eb6..15447fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,12 +11,9 @@ license = "MIT OR Apache-2.0" dotenv = "0.15" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -heroku_rs = "0.2" +serenity = "0.8" -# Uses native_tls_backend feature rather than the default rustls_backend -# As serenity and heroku_rs depend on different versions of rustls_backend -# This makes them compatible -[dependencies.serenity] +[dependencies.heroku_rs] +version = "0.2" default-features = false -features = ["builder", "cache", "client", "framework", "gateway", "http", "model", "standard_framework", "utils", "native_tls_backend"] -version = "0.8" +features = ["rust-native-tls"] \ No newline at end of file From 3b49d9816fd8a0fc22ea2d116d2c7cf8b459080c Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Fri, 6 Mar 2020 12:40:17 -0800 Subject: [PATCH 19/20] refactoring Signed-off-by: Nell Shamrell --- src/authorizations/users.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/authorizations/users.rs b/src/authorizations/users.rs index 0d28a7f..8f4a188 100644 --- a/src/authorizations/users.rs +++ b/src/authorizations/users.rs @@ -1,7 +1,7 @@ use crate::config::Config; pub fn is_authorized(id: &str, config: &Config) -> bool { - config.authorized_users.iter().any(|i| i == id) + config.authorized_users.contains(id) } #[cfg(test)] From 6b1c02a40dc86514f62f9ee9d67c75587e3fa0d4 Mon Sep 17 00:00:00 2001 From: Nell Shamrell Date: Fri, 6 Mar 2020 14:06:45 -0800 Subject: [PATCH 20/20] further refactoring Signed-off-by: Nell Shamrell --- src/commands/heroku.rs | 19 +++++++------------ src/commands/ping.rs | 7 ++++++- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/commands/heroku.rs b/src/commands/heroku.rs index dc305ca..851bfb0 100644 --- a/src/commands/heroku.rs +++ b/src/commands/heroku.rs @@ -23,19 +23,14 @@ pub fn get_apps(ctx: &mut Context, msg: &Message, _args: Args) -> CommandResult .apps() .execute::>(); - let mut processed_app_list: Vec = Vec::new(); - - match response { - Ok((_headers, _status, json)) => { - if let Some(json) = json { - processed_app_list = json; - } + 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() } - - Err(e) => println!("Err {}", e), - } - - msg.reply(ctx, app_response(processed_app_list))?; + })?; Ok(()) } diff --git a/src/commands/ping.rs b/src/commands/ping.rs index 25b4b81..2fc2d1b 100644 --- a/src/commands/ping.rs +++ b/src/commands/ping.rs @@ -7,7 +7,12 @@ use crate::config::Config; #[command] fn ping(ctx: &mut Context, msg: &Message) -> CommandResult { - let config = ctx.data.read().get::().expect("Expected config").clone(); + let config = ctx + .data + .read() + .get::() + .expect("Expected config") + .clone(); if is_authorized(&msg.author.id.to_string(), &*config) { msg.reply(ctx, "Pong!")?;