aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Perry <np@nathanperry.dev>2020-06-20 16:17:05 -0400
committerNathan Perry <np@nathanperry.dev>2020-06-20 16:17:05 -0400
commit16e660f5cd3787e587a5d082f57ab9d900aee0ca (patch)
treeb6d67d820f2342f42f2dae00318f416d8a6142f9
parent7cd17b04f7422dcce1410ec26922cba161cd6e0d (diff)
move configuration into envconfig
-rw-r--r--Cargo.lock164
-rw-r--r--Cargo.toml3
-rw-r--r--src/audio/play_queue.rs7
-rw-r--r--src/audio/timeutil.rs1
-rw-r--r--src/commands/meme/history.rs35
-rw-r--r--src/commands/playback.rs6
-rw-r--r--src/commands/sound_levels.rs6
-rw-r--r--src/config.rs80
-rw-r--r--src/game.rs25
-rw-r--r--src/main.rs32
-rw-r--r--src/util.rs19
11 files changed, 160 insertions, 218 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 1aefb49..d4df2c7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -15,14 +15,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "aho-corasick"
-version = "0.5.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "aho-corasick"
version = "0.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
@@ -387,14 +379,6 @@ dependencies = [
[[package]]
name = "dotenv"
-version = "0.8.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "dotenv"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
@@ -404,27 +388,6 @@ dependencies = [
]
[[package]]
-name = "dotenv_codegen"
-version = "0.11.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "dotenv 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "dotenv_codegen_impl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "proc-macro-hack 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "dotenv_codegen_impl"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "dotenv 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "proc-macro-hack 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
- "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "dtoa"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -443,6 +406,24 @@ dependencies = [
]
[[package]]
+name = "envconfig"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "thiserror 1.0.20 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "envconfig_derive"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "error-chain"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -872,14 +853,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "memchr"
-version = "0.1.11"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "memchr"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
@@ -1251,19 +1224,6 @@ dependencies = [
]
[[package]]
-name = "proc-macro-hack"
-version = "0.4.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "proc-macro-hack-impl 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "proc-macro-hack-impl"
-version = "0.4.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
name = "proc-macro2"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1285,11 +1245,6 @@ dependencies = [
[[package]]
name = "quote"
-version = "0.3.15"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
-name = "quote"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
@@ -1497,18 +1452,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "regex"
-version = "0.1.80"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
- "regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
- "thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
- "utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "regex"
version = "1.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
@@ -1521,11 +1464,6 @@ dependencies = [
[[package]]
name = "regex-syntax"
-version = "0.3.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
-name = "regex-syntax"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1865,16 +1803,6 @@ dependencies = [
[[package]]
name = "syn"
-version = "0.11.11"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
- "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "syn"
version = "1.0.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
@@ -1884,14 +1812,6 @@ dependencies = [
]
[[package]]
-name = "synom"
-version = "0.11.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "synstructure"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1950,23 +1870,6 @@ dependencies = [
]
[[package]]
-name = "thread-id"
-version = "2.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "thread_local"
-version = "0.2.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "thread_local"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1991,8 +1894,9 @@ dependencies = [
"ctrlc 3.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"diesel 1.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"dotenv 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "dotenv_codegen 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "envconfig 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "envconfig_derive 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fern 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2256,11 +2160,6 @@ dependencies = [
[[package]]
name = "unicode-xid"
-version = "0.0.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
-name = "unicode-xid"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2304,11 +2203,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "utf8-ranges"
-version = "0.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
-name = "utf8-ranges"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2487,7 +2381,6 @@ dependencies = [
[metadata]
"checksum addr2line 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a49806b9dadc843c61e7c97e72490ad7f7220ae249012fbda9ad0609457c0543"
"checksum adler32 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "567b077b825e468cc974f0020d4082ee6e03132512f207ef1a02fd5d00d1f32d"
-"checksum aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66"
"checksum aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada"
"checksum anyhow 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb70cc08ec97ca5450e6eba421deeea5f172c0fc61f78b5357b2a8e8be195f"
"checksum arrayref 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544"
@@ -2533,12 +2426,11 @@ dependencies = [
"checksum digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90"
"checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5"
"checksum dotenv 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0d0a1279c96732bc6800ce6337b6a614697b0e74ae058dc03c62ebeb78b4d86"
-"checksum dotenv 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eea1395d2df3b5344dc577809296d9578303296e8d105c408aa80ed67d598ef1"
-"checksum dotenv_codegen 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "106db107983c2d0c10a9601cdd0c88514df87515e18d24df87e7ae0e2a50c3fa"
-"checksum dotenv_codegen_impl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a600a6c3ca6ff4d85b97125eaaba6f67fd50c0efff2ff91b2e04e64d4432944a"
"checksum dtoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b"
"checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
"checksum encoding_rs 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)" = "e8ac63f94732332f44fe654443c46f6375d1939684c17b0afb6cb56b0456e171"
+"checksum envconfig 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca475bc6bdc0c0e3c74dfcc08cf4b39a5d43f1d597afa4d36d069f17b2108f5d"
+"checksum envconfig_derive 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0bb6cec7a023cdb44f38c5b99c26f520d279eec7265d9c957970d8b073bb2f17"
"checksum error-chain 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d371106cc88ffdfb1eabd7111e432da544f16f3e2d7bf1dfe8bf575f1df045cd"
"checksum failure 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86"
"checksum failure_derive 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4"
@@ -2589,7 +2481,6 @@ dependencies = [
"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
"checksum maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
"checksum md5 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "79c56d6a0b07f9e19282511c83fc5b086364cbae4ba8c7d5f190c3d9b0425a48"
-"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20"
"checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a"
"checksum memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
"checksum memoffset 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b4fc2c02a7e374099d4ee95a193111f72d2110197fe200272371758f6c3643d8"
@@ -2630,11 +2521,8 @@ dependencies = [
"checksum postgres-shared 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ffac35b3e0029b404c24a3b82149b4e904f293e8ca4a327eefa24d3ca50df36f"
"checksum ppv-lite86 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea"
"checksum pq-sys 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6ac25eee5a0582f45a67e837e350d784e7003bd29a5f460796772061ca49ffda"
-"checksum proc-macro-hack 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "463bf29e7f11344e58c9e01f171470ab15c925c6822ad75028cc1c0e1d1eb63b"
-"checksum proc-macro-hack-impl 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "38c47dcb1594802de8c02f3b899e2018c78291168a22c281be21ea0fb4796842"
"checksum proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa"
"checksum publicsuffix 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9bf259a81de2b2eb9850ec990ec78e6a25319715584fd7652b9b26f96fcb1510"
-"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
"checksum r2d2 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1497e40855348e4a8a40767d8e55174bce1e445a3ac9254ad44ad468ee0485af"
"checksum r2d2_postgres 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "78c7fe9c0c3d2c298cf262bc3ce4b89cdf0eab620fd9fe759f65b34a1a00fb93"
@@ -2657,9 +2545,7 @@ dependencies = [
"checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"
"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
-"checksum regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)" = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f"
"checksum regex 1.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "d9d8297cc20bbb6184f8b45ff61c8ee6a9ac56c156cec8e38c3e5084773c44ad"
-"checksum regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957"
"checksum regex-syntax 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)" = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8"
"checksum remove_dir_all 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
"checksum reqwest 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)" = "f88643aea3c1343c804950d7bf983bd2067f5ab59db6d613a08e05572f2714ab"
@@ -2696,17 +2582,13 @@ dependencies = [
"checksum statrs 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "10102ac8d55e35db2b3fafc26f81ba8647da2e15879ab686a67e6d19af2685e8"
"checksum string 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d24114bfcceb867ca7f71a0d3fe45d45619ec47a6fbfa98cb14e14250bfa5d6d"
"checksum stringprep 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8ee348cb74b87454fff4b551cbf727025810a004f88aeacae7f85b87f4e9a1c1"
-"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
"checksum syn 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "b5304cfdf27365b7585c25d4af91b35016ed21ef88f17ced89c7093b43dba8b6"
-"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
"checksum synstructure 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701"
"checksum take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60"
"checksum tar 0.4.29 (registry+https://github.com/rust-lang/crates.io-index)" = "c8a4c1d0bee3230179544336c15eefb563cf0302955d962e456542323e8c2e8a"
"checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
"checksum thiserror 1.0.20 (registry+https://github.com/rust-lang/crates.io-index)" = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08"
"checksum thiserror-impl 1.0.20 (registry+https://github.com/rust-lang/crates.io-index)" = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793"
-"checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03"
-"checksum thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5"
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum threadpool 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa"
"checksum time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
@@ -2733,14 +2615,12 @@ dependencies = [
"checksum unicase 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
"checksum unicode-normalization 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6fb19cf769fa8c6a80a162df694621ebeb4dafb606470b2b2fce0be40a98a977"
-"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
"checksum unsafe-any 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f30360d7979f5e9c6e6cea48af192ea8fab4afb3cf72597154b8f08935bc9c7f"
"checksum untrusted 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
"checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a"
"checksum url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb"
"checksum utf-8 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)" = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7"
-"checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f"
"checksum utf8-ranges 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b4ae116fef2b7fea257ed6440d3cfcff7f190865f170cdad00bb6465bf18ecba"
"checksum uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "90dbc611eb48397705a6b0f6e917da23ae517e4d127123d2cf7674206627d32a"
"checksum uwl 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dfabe4f248cd69106fdbea55ddd1a1d7aa7abd1a2b167ad62245b7a9306fb1f1"
diff --git a/Cargo.toml b/Cargo.toml
index 169025e..5033f2a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,7 +17,6 @@ log = "^0.4"
typemap = "^0.3"
url = "~1.7"
dotenv = "^0.13"
-dotenv_codegen = "^0.11"
chrono = "^0.4"
time = "^0.1"
fern = { version = "^0.5", features = ["colored"] }
@@ -38,6 +37,8 @@ pest = "~2.1"
pest_derive = "~2.1"
postgres = { version = "^0.15", optional = true, features = ["with-chrono"] }
r2d2_postgres = { version = "^0.14", optional = true }
+envconfig = "^0.8"
+envconfig_derive = "^0.8"
[dependencies.serenity]
default-features = false
diff --git a/src/audio/play_queue.rs b/src/audio/play_queue.rs
index 6026587..e2d4468 100644
--- a/src/audio/play_queue.rs
+++ b/src/audio/play_queue.rs
@@ -30,9 +30,8 @@ use crate::{
commands::{
sound_levels::DEFAULT_VOLUME,
},
- must_env_lookup,
Result,
- TARGET_GUILD_ID,
+ CONFIG,
};
const SECONDS_LEAD_TIME: f32 = 0.75;
@@ -115,7 +114,7 @@ impl PlayQueue {
queue.playing = None;
let mut manager = voice_manager.lock();
- manager.leave(*TARGET_GUILD_ID);
+ manager.leave(CONFIG.discord.guild());
debug!("disconnected because playback finished");
}
@@ -228,7 +227,7 @@ impl PlayQueue {
};
let mut manager = voice_manager.lock();
- let handler = manager.join(*TARGET_GUILD_ID, must_env_lookup::<u64>("VOICE_CHANNEL"));
+ let handler = manager.join(CONFIG.discord.guild(), CONFIG.discord.voice_channel());
match handler {
Some(handler) => {
diff --git a/src/audio/timeutil.rs b/src/audio/timeutil.rs
index c9b38dd..238897f 100644
--- a/src/audio/timeutil.rs
+++ b/src/audio/timeutil.rs
@@ -50,6 +50,7 @@ pub fn parse_times<A: AsRef<str>>(s: A) -> (Option<Duration>, Option<Duration>)
#[cfg(test)]
mod test {
use time::Duration;
+ use itertools::iproduct;
use super::*;
diff --git a/src/commands/meme/history.rs b/src/commands/meme/history.rs
index 7579524..8186f57 100644
--- a/src/commands/meme/history.rs
+++ b/src/commands/meme/history.rs
@@ -31,7 +31,7 @@ use crate::{
Meme,
Metadata,
},
- must_env_lookup,
+ CONFIG,
Result,
util::CtxExt,
};
@@ -71,7 +71,7 @@ pub fn wat(ctx: &mut Context, msg: &Message, _: Args) -> Result<()> {
match meme {
Ok(ref meme) => {
let metadata = Metadata::find(&conn, meme.metadata_id)?;
- let author = crate::TARGET_GUILD_ID.member(&ctx, metadata.created_by as u64)?;
+ let author = CONFIG.discord.guild().member(&ctx, metadata.created_by as u64)?;
ctx.send(msg.channel_id,
&format!("that was \"{}\" by {} ({})",
@@ -95,21 +95,16 @@ pub fn wat(ctx: &mut Context, msg: &Message, _: Args) -> Result<()> {
pub fn history(ctx: &mut Context, msg: &Message, mut args: Args) -> Result<()> {
use itertools::Itertools;
- lazy_static! {
- static ref MAX_HIST: usize = must_env_lookup("MAX_HIST");
- static ref DEFAULT_HIST: usize = must_env_lookup("DEFAULT_HIST");
- }
-
let conn = connection()?;
- let n = args.single_quoted::<usize>().unwrap_or(*DEFAULT_HIST);
+ let n = args.single_quoted::<usize>().unwrap_or(CONFIG.default_hist);
- if n > *MAX_HIST {
- debug!("user requested more than MAX_HIST ({}) items from history", *MAX_HIST);
+ if n > CONFIG.max_hist {
+ debug!("user requested more than MAX_HIST ({}) items from history", CONFIG.max_hist);
ctx.send(msg.channel_id, "YER PUSHIN ME OVER THE FUCKIN LINE", true)?;
}
- let n = n.min(*MAX_HIST);
+ let n = n.min(CONFIG.max_hist);
let records = InvocationRecord::last_n(&conn, n)?;
@@ -133,8 +128,8 @@ pub fn history(ctx: &mut Context, msg: &Message, mut args: Args) -> Result<()> {
Metadata::find(&conn, meme.metadata_id).map(|metadata| (metadata, meme))
})
.map(|(metadata, meme)| {
- let author_name = crate::TARGET_GUILD_ID.member(&ctx, metadata.created_by as u64).map(|m| m.display_name().into_owned()).unwrap_or("???".to_owned());
- let invoker_name = crate::TARGET_GUILD_ID.member(&ctx, rec.user_id as u64).map(|m| m.display_name().into_owned()).unwrap_or("???".to_owned());
+ let author_name = CONFIG.discord.guild().member(&ctx, metadata.created_by as u64).map(|m| m.display_name().into_owned()).unwrap_or("???".to_owned());
+ let invoker_name = CONFIG.discord.guild().member(&ctx, rec.user_id as u64).map(|m| m.display_name().into_owned()).unwrap_or("???".to_owned());
format!("{}. [{}{}] \"{}\" by {} ({}). invoked by {}.", i + 1, rand, ago, meme.title, author_name, metadata.created.date().format(CLEAN_DATE_FORMAT), invoker_name)
})
.unwrap_or_else(|e| {
@@ -144,7 +139,7 @@ pub fn history(ctx: &mut Context, msg: &Message, mut args: Args) -> Result<()> {
}
}
- let invoker_name = crate::TARGET_GUILD_ID.member(&ctx, rec.user_id as u64).map(|m| m.display_name().into_owned()).unwrap_or("???".to_owned());
+ let invoker_name = CONFIG.discord.guild().member(&ctx, rec.user_id as u64).map(|m| m.display_name().into_owned()).unwrap_or("???".to_owned());
format!("{}. [{}{}] not found. invoked by {}.", i + 1, rand, ago, invoker_name)
})
})
@@ -161,7 +156,6 @@ pub fn stats(ctx: &mut Context, msg: &Message, _: Args) -> Result<()> {
id::UserId,
user::User,
};
- use crate::TARGET_GUILD_ID;
let conn = connection()?;
let stats = db::stats(&conn)?;
@@ -171,8 +165,8 @@ pub fn stats(ctx: &mut Context, msg: &Message, _: Args) -> Result<()> {
let rand_user: User = UserId(stats.most_random_meme_user).to_user(&ctx)?;
let direct_user: User = UserId(stats.most_directly_named_meme_user).to_user(&ctx)?;
- let rand_user = rand_user.nick_in(&ctx, *TARGET_GUILD_ID).unwrap_or(rand_user.name);
- let direct_user = direct_user.nick_in(&ctx, *TARGET_GUILD_ID).unwrap_or(direct_user.name);
+ let rand_user = rand_user.nick_in(&ctx, CONFIG.discord.guild()).unwrap_or(rand_user.name);
+ let direct_user = direct_user.nick_in(&ctx, CONFIG.discord.guild()).unwrap_or(direct_user.name);
let s = format!(
r#"
@@ -224,13 +218,12 @@ pub fn memers(ctx: &mut Context, msg: &Message, _args: Args) -> Result<()> {
use serenity::model::{
id::UserId,
};
- use crate::TARGET_GUILD_ID;
let s = db::memers()?
.into_iter()
.map(|info| {
let user = UserId(info.user_id).to_user(&ctx)?;
- let username = user.nick_in(&ctx, *TARGET_GUILD_ID).unwrap_or(user.name);
+ let username = user.nick_in(&ctx, CONFIG.discord.guild()).unwrap_or(user.name);
let res = format!(
"**{}**: {} total, {} random, {} specific. favorite meme: *{}* ({})",
@@ -262,7 +255,7 @@ pub fn query(ctx: &mut Context, msg: &Message, mut args: Args) -> Result<()> {
use crate::{
game::get_user_id,
db,
- TARGET_GUILD_ID,
+ CONFIG,
};
lazy_static! {
@@ -310,7 +303,7 @@ pub fn query(ctx: &mut Context, msg: &Message, mut args: Args) -> Result<()> {
.into_iter()
.map(|(meme, metadata)| {
let user = UserId(metadata.created_by as u64).to_user(&ctx)?;
- let username = user.nick_in(&ctx, *TARGET_GUILD_ID).unwrap_or(user.name);
+ let username = user.nick_in(&ctx, CONFIG.discord.guild()).unwrap_or(user.name);
Ok(format!("*{}* by **{}** ({}). text length: **{}**, image: **{}**, audio: **{}**",
meme.title,
diff --git a/src/commands/playback.rs b/src/commands/playback.rs
index c11eac8..f80ec17 100644
--- a/src/commands/playback.rs
+++ b/src/commands/playback.rs
@@ -22,7 +22,7 @@ use crate::{
VoiceManager,
},
Result,
- TARGET_GUILD_ID,
+ CONFIG,
util::CtxExt,
commands::sound_levels::*,
};
@@ -196,7 +196,7 @@ pub fn skip(ctx: &mut Context, _msg: &Message, _args: Args) -> Result<()> {
let queue_lock = data.get::<PlayQueue>().cloned().unwrap();
- if let Some(handler) = manager.get_mut(*TARGET_GUILD_ID) {
+ if let Some(handler) = manager.get_mut(CONFIG.discord.guild()) {
handler.stop();
let mut play_queue = queue_lock.write().unwrap();
play_queue.playing = None;
@@ -226,7 +226,7 @@ pub fn die(ctx: &mut Context, msg: &Message, _: Args) -> Result<()> {
play_queue.meme_queue.clear();
}
- if let Some(handler) = manager.get_mut(*TARGET_GUILD_ID) {
+ if let Some(handler) = manager.get_mut(CONFIG.discord.guild()) {
info!("killing playback");
handler.stop();
handler.leave();
diff --git a/src/commands/sound_levels.rs b/src/commands/sound_levels.rs
index 648e54b..ab98806 100644
--- a/src/commands/sound_levels.rs
+++ b/src/commands/sound_levels.rs
@@ -15,8 +15,8 @@ use serenity::{
use crate::{
Result,
+ CONFIG,
audio::{PlayQueue, VoiceManager},
- TARGET_GUILD_ID,
util::CtxExt,
};
@@ -27,7 +27,7 @@ pub fn mute(ctx: &mut Context, _: &Message, _: Args) -> Result<()> {
let mgr_lock = ctx.data.write().get::<VoiceManager>().cloned().unwrap();
let mut manager = mgr_lock.lock();
- manager.get_mut(*TARGET_GUILD_ID)
+ manager.get_mut(CONFIG.discord.guild())
.map(|handler| {
if handler.self_mute {
trace!("Already muted.")
@@ -45,7 +45,7 @@ pub fn unmute(ctx: &mut Context, msg: &Message, _: Args) -> Result<()> {
let mgr_lock = ctx.data.write().get::<VoiceManager>().cloned().unwrap();
let mut manager = mgr_lock.lock();
- manager.get_mut(*TARGET_GUILD_ID)
+ manager.get_mut(CONFIG.discord.guild())
.map(|handler| {
if !handler.self_mute {
trace!("Already unmuted.")
diff --git a/src/config.rs b/src/config.rs
new file mode 100644
index 0000000..13d015e
--- /dev/null
+++ b/src/config.rs
@@ -0,0 +1,80 @@
+use serenity::{
+ model::id::{
+ GuildId,
+ UserId,
+ ChannelId,
+ },
+};
+
+use envconfig::Envconfig;
+
+#[derive(Envconfig)]
+pub struct Config {
+ #[envconfig(from = "DATABASE_URL")]
+ pub db_string: String,
+
+ #[envconfig(from = "MAX_HIST")]
+ pub max_hist: usize,
+
+ #[envconfig(from = "DEFAULT_HIST")]
+ pub default_hist: usize,
+
+ #[envconfig(from = "STEAM_API_KEY")]
+ pub steam_api_key: String,
+
+ pub discord: DiscordConfig,
+
+ pub sheets: SheetsConfig,
+}
+
+#[derive(Envconfig)]
+pub struct DiscordConfig {
+ pub auth: DiscordAuth,
+
+ #[envconfig(from = "TARGET_GUILD")]
+ guild: u64,
+
+ #[envconfig(from = "OWNER_ID")]
+ owner: u64,
+
+ #[envconfig(from = "VOICE_CHANNEL")]
+ voice_channel: u64,
+}
+
+impl DiscordConfig {
+ #[inline]
+ pub fn guild(&self) -> GuildId {
+ self.guild.into()
+ }
+
+ #[inline]
+ pub fn owner(&self) -> UserId {
+ self.owner.into()
+ }
+
+ #[inline]
+ pub fn voice_channel(&self) -> ChannelId {
+ self.voice_channel.into()
+ }
+}
+
+#[derive(Envconfig)]
+pub struct DiscordAuth {
+ #[envconfig(from = "THULANI_CLIENT_ID")]
+ pub client_id: u64,
+
+ #[envconfig(from = "THULANI_TOKEN")]
+ pub token: String,
+}
+
+#[derive(Envconfig)]
+pub struct SheetsConfig {
+ #[envconfig(from = "SHEETS_API_KEY")]
+ pub api_key: String,
+
+ #[envconfig(from = "SPREADSHEET_ID")]
+ pub spreadsheet: String,
+
+ #[envconfig(from = "MAX_SHEET_COLUMN")]
+ pub max_column: String,
+} \ No newline at end of file
diff --git a/src/game.rs b/src/game.rs
index 02f3f45..626c7ff 100644
--- a/src/game.rs
+++ b/src/game.rs
@@ -43,10 +43,9 @@ use anyhow::{
use lazy_static::lazy_static;
use crate::{
- must_env_lookup,
Result,
util::CtxExt,
- VOICE_CHANNEL_ID,
+ CONFIG,
};
pub use self::GAME_GROUP as GROUP;
@@ -65,15 +64,10 @@ group!({
});
lazy_static! {
- static ref SHEETS_API_KEY: String = must_env_lookup("SHEETS_API_KEY");
- static ref STEAM_API_KEY: String = must_env_lookup("STEAM_API_KEY");
- static ref SPREADSHEET_ID: String = must_env_lookup("SPREADSHEET_ID");
- static ref MAX_SHEET_COLUMN: String = must_env_lookup("MAX_SHEET_COLUMN");
-
static ref SPREADSHEET_URL: Url = Url::parse(&format!(
"https://sheets.googleapis.com/v4/spreadsheets/{}/values:batchGet",
- *SPREADSHEET_ID,
- )).expect("prasing spreadsheet url");
+ &CONFIG.sheets.spreadsheet,
+ )).expect("parsing spreadsheet url");
}
#[derive(Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
@@ -285,12 +279,15 @@ fn _game(ctx: &mut Context, msg: &Message, mut args: Args, min_status: GameStatu
})
.collect::<FnvHashMap<_, _>>();
- let channel = pairs.get(&msg.author.id).unwrap_or(&*VOICE_CHANNEL_ID);
+ let channel = pairs
+ .get(&msg.author.id)
+ .cloned()
+ .unwrap_or(CONFIG.discord.voice_channel());
users = pairs
.iter()
.filter_map(|(uid, cid)| {
- if cid == channel {
+ if *cid == channel {
DISCORD_MAP.get(uid).map(|s| s.to_lowercase())
} else { None }
})
@@ -384,10 +381,10 @@ fn load_spreadsheet() -> Result<Vec<Vec<String>>> {
let mut u = SPREADSHEET_URL.clone();
u.query_pairs_mut()
- .append_pair("ranges", &format!("a1:{}", &*MAX_SHEET_COLUMN))
+ .append_pair("ranges", &format!("a1:{}", &CONFIG.sheets.max_column))
.append_pair("valueRenderOption", "FORMATTED_VALUE")
.append_pair("majorDimension", "COLUMNS")
- .append_pair("key", &*SHEETS_API_KEY);
+ .append_pair("key", &CONFIG.sheets.api_key);
let req = reqwest::Request::new(reqwest::Method::GET, u);
let client = reqwest::Client::new();
@@ -482,7 +479,7 @@ pub fn updategaem(ctx: &mut Context, msg: &Message, mut args: Args) -> Result<()
let mut u = Url::parse("https://api.steampowered.com/IPlayerService/GetOwnedGames/v1")?;
u.query_pairs_mut()
- .append_pair("key", &*STEAM_API_KEY)
+ .append_pair("key", &CONFIG.steam_api_key)
.append_pair("include_played_free_games", "1")
.append_pair("steamid", &steam_id.to_string());
diff --git a/src/main.rs b/src/main.rs
index f3c7bac..55205ba 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,8 +7,8 @@
// trash dependencies that can't be fucked to upgrade to ed. 2018
#[macro_use] extern crate diesel;
-#[macro_use] extern crate dotenv_codegen;
#[macro_use] extern crate pest_derive;
+#[macro_use] extern crate envconfig_derive;
use std::{
default::Default,
@@ -33,17 +33,19 @@ use serenity::{
framework::StandardFramework,
model::{
gateway::Ready,
- id::{ChannelId, GuildId, MessageId, UserId},
+ id::{ChannelId, MessageId},
},
prelude::*,
};
-use anyhow::anyhow;
-use dotenv::{dotenv, var as dvar};
+use dotenv::dotenv;
use lazy_static::lazy_static;
+use envconfig::Envconfig;
use self::commands::register_commands;
+
pub use self::util::*;
+pub use self::config::*;
#[cfg(feature = "diesel")]
mod db;
@@ -64,22 +66,25 @@ mod game {
mod commands;
mod util;
mod audio;
+mod config;
pub type Error = anyhow::Error;
pub type Result<T> = anyhow::Result<T>;
lazy_static! {
- static ref TARGET_GUILD: u64 = dotenv!("TARGET_GUILD").parse().expect("unable to parse TARGET_GUILD as u64");
- static ref TARGET_GUILD_ID: GuildId = GuildId(*TARGET_GUILD);
- static ref VOICE_CHANNEL_ID: ChannelId = ChannelId(must_env_lookup::<u64>("VOICE_CHANNEL"));
+ pub static ref CONFIG: Config = {
+ dotenv().ok();
+
+ Config::init().unwrap()
+ };
}
struct Handler;
impl EventHandler for Handler {
fn ready(&self, ctx: Context, r: Ready) {
let guild = r.guilds.iter()
- .find(|g| g.id().0 == *TARGET_GUILD);
+ .find(|g| g.id() == CONFIG.discord.guild());
if guild.is_none() {
info!("bot isn't in configured guild. join here: {:?}", OAUTH_URL.as_str());
@@ -114,7 +119,7 @@ lazy_static! {
fn run() -> Result<()> {
- let token = &dvar("THULANI_TOKEN").map_err(|_| anyhow!("missing token"))?;
+ let token = &CONFIG.discord.auth.token;
let mut client = Client::new(token, Handler)?;
audio::VoiceManager::register(&mut client);
@@ -140,7 +145,6 @@ fn run() -> Result<()> {
.into_iter()
.collect::<FnvHashSet<_>>();
- let owner_id = must_env_lookup::<u64>("OWNER_ID");
let mut framework = StandardFramework::new()
.configure(|c| c
.allow_dm(false)
@@ -148,17 +152,17 @@ fn run() -> Result<()> {
.prefixes(all_prefixes)
.ignore_bots(true)
.on_mention(None)
- .owners(vec![UserId(owner_id)].into_iter().collect())
+ .owners(vec![CONFIG.discord.owner()].into_iter().collect())
.case_insensitivity(true)
)
.before(move |ctx, message, cmd| {
debug!("got command '{}' from user '{}' ({})", cmd, message.author.name, message.author.id);
- if !message.guild_id.map_or(false, |x| x.0 == *TARGET_GUILD) {
+ if !message.guild_id.map_or(false, |x| x == CONFIG.discord.guild()) {
info!("rejecting command '{}' from user '{}': wrong guild", cmd, message.author.name);
return false;
}
- if message.author.id.0 == owner_id {
+ if message.author.id == CONFIG.discord.owner() {
return true;
}
@@ -239,8 +243,6 @@ fn main() {
info!("starting");
- dotenv().ok();
-
use fern::colors::{Color, ColoredLevelConfig};
let colors = ColoredLevelConfig::new()
.info(Color::Green)
diff --git a/src/util.rs b/src/util.rs
index eb38d9c..ca50157 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -1,9 +1,3 @@
-use std::{
- env,
- str::FromStr,
-};
-
-use dotenv;
use serenity::{
client::Context,
model::{
@@ -19,6 +13,7 @@ use url::Url;
use lazy_static::lazy_static;
use crate::{
+ CONFIG,
audio::PlayQueue,
Result,
};
@@ -38,13 +33,12 @@ impl CtxExt for Context {
}
fn users_listening(&self) -> Result<bool> {
- let channel_id = ChannelId(must_env_lookup::<u64>("VOICE_CHANNEL"));
- let channel = channel_id.to_channel(self)?;
+ let channel = CONFIG.discord.voice_channel().to_channel(self)?;
let res = channel.guild()
.and_then(|ch| ch.read().guild(self))
.map(|g| (&g.read().voice_states)
.into_iter()
- .any(|(_, state)| state.channel_id == Some(channel_id)))
+ .any(|(_, state)| state.channel_id == Some(CONFIG.discord.voice_channel())))
.unwrap_or(false);
Ok(res)
@@ -81,12 +75,7 @@ lazy_static! {
pub static ref OAUTH_URL: Url = Url::parse(
&format!(
"https://discordapp.com/api/oauth2/authorize?scope=bot&permissions={}&client_id={}",
- REQUIRED_PERMS.bits(), dotenv!("THULANI_CLIENT_ID"),
+ REQUIRED_PERMS.bits(), CONFIG.discord.auth.client_id,
)
).unwrap();
}
-
-pub fn must_env_lookup<T: FromStr>(s: &str) -> T {
- env::var(s).expect(&format!("missing env var {}", s))
- .parse::<T>().unwrap_or_else(|_| panic!(format!("bad format for {}", s)))
-}