diff --git a/.idea/csv-plugin.xml b/.idea/csv-plugin.xml index 0fba93a..36b3458 100644 --- a/.idea/csv-plugin.xml +++ b/.idea/csv-plugin.xml @@ -10,6 +10,20 @@ + + + + + + + + + + + + diff --git a/Cargo.lock b/Cargo.lock index b664d26..20b934d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,12 +6,30 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aead" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fc95d1bdb8e6666b2b217308eeeb09f2d6728d104be3e31916cc74d15420331" +dependencies = [ + "generic-array", +] + [[package]] name = "ahash" version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e" +[[package]] +name = "aho-corasick" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" +dependencies = [ + "memchr", +] + [[package]] name = "anyhow" version = "1.0.40" @@ -37,14 +55,49 @@ checksum = "f7cc5408453d37e2b1c6f01d8078af1da58b6cfa6a80fa2ede3bd2b9a6ada9c4" dependencies = [ "futures-io", "futures-util", - "log", + "log 0.4.14", "pin-project", "tokio", "tokio-rustls", - "tungstenite", + "tungstenite 0.11.1", "webpki-roots 0.20.0", ] +[[package]] +name = "async-tungstenite" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07b30ef0ea5c20caaa54baea49514a206308989c68be7ecd86c7f956e4da6378" +dependencies = [ + "futures-io", + "futures-util", + "log 0.4.14", + "pin-project-lite", + "tokio", + "tokio-rustls", + "tungstenite 0.13.0", + "webpki-roots 0.21.1", +] + +[[package]] +name = "audiopus" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3743519567e9135cf6f9f1a509851cb0c8e4cb9d66feb286668afb1923bec458" +dependencies = [ + "audiopus_sys", +] + +[[package]] +name = "audiopus_sys" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "927791de46f70facea982dbfaf19719a41ce6064443403be631a85de6a58fff9" +dependencies = [ + "log 0.4.14", + "pkg-config", +] + [[package]] name = "autocfg" version = "1.0.1" @@ -63,6 +116,12 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +[[package]] +name = "bitflags" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f67931368edf3a9a51d29886d245f1c3db2f1ef0dcc9e35ff70341b78c10d23" + [[package]] name = "bitflags" version = "1.2.1" @@ -108,6 +167,12 @@ version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + [[package]] name = "cfg-if" version = "1.0.0" @@ -122,10 +187,19 @@ checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" dependencies = [ "libc", "num-integer", - "num-traits", + "num-traits 0.2.14", "serde", "time", - "winapi", + "winapi 0.3.9", +] + +[[package]] +name = "cipher" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" +dependencies = [ + "generic-array", ] [[package]] @@ -145,13 +219,39 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" +[[package]] +name = "cpuid-bool" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb25d077389e53838a8158c8e99174c5a9d902dee4904320db714f3c653ffba" + [[package]] name = "crc32fast" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", +] + +[[package]] +name = "crossbeam-utils" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +dependencies = [ + "autocfg", + "cfg-if 0.1.10", +] + +[[package]] +name = "dashmap" +version = "4.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c" +dependencies = [ + "cfg-if 1.0.0", + "num_cpus", ] [[package]] @@ -163,6 +263,18 @@ dependencies = [ "generic-array", ] +[[package]] +name = "discortp" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c0d482488c336a2164529765da3f645f26215df9c2033137ddedac333c8e2e8" +dependencies = [ + "glob", + "pnet_macros", + "pnet_macros_support", + "syntex", +] + [[package]] name = "dotenv" version = "0.15.0" @@ -181,7 +293,16 @@ version = "0.8.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", +] + +[[package]] +name = "enum_primitive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4551092f4d519593039259a9ed8daedf0da12e5109c5280338073eaeb81180" +dependencies = [ + "num-traits 0.1.43", ] [[package]] @@ -202,12 +323,25 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd3aec53de10fe96d7d8c565eb17f2c687bb5518a2ec453b5b1252964526abe0" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "crc32fast", "libc", "miniz_oxide", ] +[[package]] +name = "flume" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "531a685ab99b8f60a271b44d5dd1a76e55124a8c9fa0407b7a8e9cd172d5b588" +dependencies = [ + "futures-core", + "futures-sink", + "nanorand", + "pin-project", + "spinning_top", +] + [[package]] name = "fnv" version = "1.0.7" @@ -232,6 +366,7 @@ checksum = "7f55667319111d593ba876406af7c409c0ebb44dc4be6132a783ccf163ea14c1" dependencies = [ "futures-channel", "futures-core", + "futures-executor", "futures-io", "futures-sink", "futures-task", @@ -254,6 +389,17 @@ version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15496a72fabf0e62bdc3df11a59a3787429221dd0710ba8ef163d6f7a9112c94" +[[package]] +name = "futures-executor" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891a4b7b96d84d5940084b2a37632dd65deeae662c114ceaa2c879629c9c0ad1" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + [[package]] name = "futures-io" version = "0.3.13" @@ -304,6 +450,19 @@ dependencies = [ "slab", ] +[[package]] +name = "generator" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "061d3be1afec479d56fa3bd182bf966c7999ec175fcfdb87ac14d417241366c6" +dependencies = [ + "cc", + "libc", + "log 0.4.14", + "rustversion", + "winapi 0.3.9", +] + [[package]] name = "generic-array" version = "0.14.4" @@ -320,11 +479,24 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "wasi 0.9.0+wasi-snapshot-preview1", ] +[[package]] +name = "getrandom" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "wasm-bindgen", +] + [[package]] name = "glob" version = "0.3.0" @@ -443,7 +615,7 @@ checksum = "5f9f7a97316d44c0af9b0301e65010573a853a9fc97046d7331d7f6bc0fd5a64" dependencies = [ "futures-util", "hyper", - "log", + "log 0.4.14", "rustls", "tokio", "tokio-rustls", @@ -504,13 +676,22 @@ dependencies = [ "bytes 0.5.6", ] +[[package]] +name = "input_buffer" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f97967975f448f1a7ddb12b0bc41069d09ed6a1c161a92687e057325db35d413" +dependencies = [ + "bytes 1.0.1", +] + [[package]] name = "instant" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -543,6 +724,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -574,13 +765,35 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "log" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" +dependencies = [ + "log 0.4.14", +] + [[package]] name = "log" version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", +] + +[[package]] +name = "loom" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0e8460f2f2121162705187214720353c517b97bdfb3494c0b1e33d83ebe4bed" +dependencies = [ + "cfg-if 0.1.10", + "generator", + "scoped-tls", + "serde", + "serde_json", ] [[package]] @@ -643,10 +856,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956" dependencies = [ "libc", - "log", + "log 0.4.14", "miow", "ntapi", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -655,7 +868,16 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" dependencies = [ - "winapi", + "winapi 0.3.9", +] + +[[package]] +name = "nanorand" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac1378b66f7c93a1c0f8464a19bf47df8795083842e5090f4b7305973d5a22d0" +dependencies = [ + "getrandom 0.2.2", ] [[package]] @@ -664,7 +886,7 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -674,7 +896,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" dependencies = [ "autocfg", - "num-traits", + "num-traits 0.2.14", +] + +[[package]] +name = "num-traits" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" +dependencies = [ + "num-traits 0.2.14", ] [[package]] @@ -725,12 +956,12 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "instant", "libc", "redox_syscall", "smallvec", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -777,6 +1008,42 @@ version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" +[[package]] +name = "pnet_base" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7cd5f7e15220afa66b0a9a62841ea10089f39dcaa1c29752c0b22dfc03111b5" + +[[package]] +name = "pnet_macros" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbbd5c52c6e04aa720400f9c71cd0e8bcb38cd13421d5caabd9035e9efa47de9" +dependencies = [ + "regex", + "syntex", + "syntex_syntax", +] + +[[package]] +name = "pnet_macros_support" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf9c5c0c36766d0a4da9ab268c0700771b8ec367b9463fd678109fa28463c5b" +dependencies = [ + "pnet_base", +] + +[[package]] +name = "poly1305" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b7456bc1ad2d4cf82b3a016be4c2ac48daf11bf990c1603ebd447fe6f30fca8" +dependencies = [ + "cpuid-bool 0.2.0", + "universal-hash", +] + [[package]] name = "ppv-lite86" version = "0.2.10" @@ -801,7 +1068,7 @@ version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" dependencies = [ - "unicode-xid", + "unicode-xid 0.2.1", ] [[package]] @@ -819,11 +1086,23 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom", + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc 0.2.0", +] + +[[package]] +name = "rand" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +dependencies = [ "libc", - "rand_chacha", - "rand_core", - "rand_hc", + "rand_chacha 0.3.0", + "rand_core 0.6.2", + "rand_hc 0.3.0", ] [[package]] @@ -833,7 +1112,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.2", ] [[package]] @@ -842,7 +1131,16 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom", + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +dependencies = [ + "getrandom 0.2.2", ] [[package]] @@ -851,7 +1149,16 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_hc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +dependencies = [ + "rand_core 0.6.2", ] [[package]] @@ -860,9 +1167,26 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" dependencies = [ - "bitflags", + "bitflags 1.2.1", +] + +[[package]] +name = "regex" +version = "1.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", ] +[[package]] +name = "regex-syntax" +version = "0.6.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" + [[package]] name = "reqwest" version = "0.11.2" @@ -881,7 +1205,7 @@ dependencies = [ "ipnet", "js-sys", "lazy_static", - "log", + "log 0.4.14", "mime", "mime_guess", "percent-encoding", @@ -912,7 +1236,7 @@ dependencies = [ "spin", "untrusted", "web-sys", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -921,7 +1245,7 @@ version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5f38ee71cbab2c827ec0ac24e76f82eca723cee92c509a65f67dee393c25112" dependencies = [ - "bitflags", + "bitflags 1.2.1", "fallible-iterator", "fallible-streaming-iterator", "hashlink", @@ -930,6 +1254,12 @@ dependencies = [ "smallvec", ] +[[package]] +name = "rustc-serialize" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" + [[package]] name = "rustls" version = "0.19.0" @@ -937,18 +1267,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "064fd21ff87c6e87ed4506e68beb42459caa4a0e2eb144932e6776768556980b" dependencies = [ "base64 0.13.0", - "log", + "log 0.4.14", "ring", "sct", "webpki", ] +[[package]] +name = "rustversion" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb5d2a036dc6d2d8fd16fde3498b04306e29bd193bf306a57427019b823d5acd" + [[package]] name = "ryu" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +[[package]] +name = "salsa20" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "399f290ffc409596022fce5ea5d4138184be4784f2b28c62c59f0d8389059a15" +dependencies = [ + "cipher", + "zeroize", +] + +[[package]] +name = "scoped-tls" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" + [[package]] name = "scopeguard" version = "1.1.0" @@ -996,6 +1348,17 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_repr" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dc6b7951b17b051f3210b063f12cc17320e2fe30ae05b0fe2a3abb068551c76" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "serde_rusqlite" version = "0.26.0" @@ -1025,9 +1388,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "deead3f7ecbbbe4c249e07af17686937ccb9d7fa24ca3accd1d223e369a75272" dependencies = [ "async-trait", - "async-tungstenite", + "async-tungstenite 0.11.0", "base64 0.13.0", - "bitflags", + "bitflags 1.2.1", "bytes 1.0.1", "chrono", "command_attr", @@ -1045,6 +1408,19 @@ dependencies = [ "uwl", ] +[[package]] +name = "serenity-voice-model" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "158aeb823791f79bbb92110212970797757fee7102784453dcb9b172a8af272b" +dependencies = [ + "bitflags 1.2.1", + "enum_primitive", + "serde", + "serde_json", + "serde_repr", +] + [[package]] name = "sha-1" version = "0.9.4" @@ -1052,12 +1428,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfebf75d25bd900fd1e7d11501efab59bc846dbc76196839663e6637bba9f25f" dependencies = [ "block-buffer", - "cfg-if", - "cpuid-bool", + "cfg-if 1.0.0", + "cpuid-bool 0.1.2", "digest", "opaque-debug", ] +[[package]] +name = "signal-hook-registry" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" +dependencies = [ + "libc", +] + [[package]] name = "slab" version = "0.4.2" @@ -1077,7 +1462,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" dependencies = [ "libc", - "winapi", + "winapi 0.3.9", +] + +[[package]] +name = "songbird" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7f905ef041c2222d57d3e77868d5cdc616f42b7c506d21a87b14fc62784209e" +dependencies = [ + "async-trait", + "async-tungstenite 0.13.1", + "audiopus", + "byteorder", + "dashmap", + "discortp", + "flume", + "futures", + "parking_lot", + "rand 0.8.3", + "serde", + "serde_json", + "serenity", + "serenity-voice-model", + "spin_sleep", + "streamcatcher", + "tokio", + "tracing", + "tracing-futures", + "typemap_rev", + "url", + "uuid", + "xsalsa20poly1305", ] [[package]] @@ -1086,12 +1502,48 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "spin_sleep" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a98101bdc3833e192713c2af0b0dd2614f50d1cf1f7a97c5221b7aac052acc7" +dependencies = [ + "once_cell", + "winapi 0.3.9", +] + +[[package]] +name = "spinning_top" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bd0ab6b8c375d2d963503b90d3770010d95bc3b5f98036f948dee24bf4e8879" +dependencies = [ + "lock_api", +] + [[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "streamcatcher" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa50ae63198c9af3ffb3a1fa8877d54bb1a569a2a61cb519097c7989f1a151ff" +dependencies = [ + "crossbeam-utils", + "futures-util", + "loom", +] + +[[package]] +name = "subtle" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" + [[package]] name = "syn" version = "1.0.68" @@ -1100,7 +1552,66 @@ checksum = "3ce15dd3ed8aa2f8eeac4716d6ef5ab58b6b9256db41d7e1a0224c2788e8fd87" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-xid 0.2.1", +] + +[[package]] +name = "syntex" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a30b08a6b383a22e5f6edc127d169670d48f905bb00ca79a00ea3e442ebe317" +dependencies = [ + "syntex_errors", + "syntex_syntax", +] + +[[package]] +name = "syntex_errors" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04c48f32867b6114449155b2a82114b86d4b09e1bddb21c47ff104ab9172b646" +dependencies = [ + "libc", + "log 0.3.9", + "rustc-serialize", + "syntex_pos", + "term", + "unicode-xid 0.0.3", +] + +[[package]] +name = "syntex_pos" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fd49988e52451813c61fecbe9abb5cfd4e1b7bb6cdbb980a6fbcbab859171a6" +dependencies = [ + "rustc-serialize", +] + +[[package]] +name = "syntex_syntax" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7628a0506e8f9666fdabb5f265d0059b059edac9a3f810bda077abb5d826bd8d" +dependencies = [ + "bitflags 0.5.0", + "libc", + "log 0.3.9", + "rustc-serialize", + "syntex_errors", + "syntex_pos", + "term", + "unicode-xid 0.0.3", +] + +[[package]] +name = "term" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa63644f74ce96fbeb9b794f66aff2a52d601cbd5e80f4b97123e3899f4570f1" +dependencies = [ + "kernel32-sys", + "winapi 0.2.8", ] [[package]] @@ -1131,7 +1642,7 @@ checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ "libc", "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1156,11 +1667,14 @@ dependencies = [ "dotenv", "minecraft-data-rs", "parking_lot", + "rand 0.8.3", "rusqlite", "serde", "serde_derive", + "serde_json", "serde_rusqlite", "serenity", + "songbird", "thiserror", "tokio", ] @@ -1177,8 +1691,11 @@ dependencies = [ "memchr", "mio", "num_cpus", + "once_cell", "pin-project-lite", + "signal-hook-registry", "tokio-macros", + "winapi 0.3.9", ] [[package]] @@ -1212,7 +1729,7 @@ dependencies = [ "bytes 1.0.1", "futures-core", "futures-sink", - "log", + "log 0.4.14", "pin-project-lite", "tokio", ] @@ -1229,8 +1746,8 @@ version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" dependencies = [ - "cfg-if", - "log", + "cfg-if 1.0.0", + "log 0.4.14", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -1256,6 +1773,16 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + [[package]] name = "try-lock" version = "0.2.3" @@ -1273,14 +1800,37 @@ dependencies = [ "bytes 0.5.6", "http", "httparse", - "input_buffer", - "log", - "rand", + "input_buffer 0.3.1", + "log 0.4.14", + "rand 0.7.3", "sha-1", "url", "utf-8", ] +[[package]] +name = "tungstenite" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fe8dada8c1a3aeca77d6b51a4f1314e0f4b8e438b7b1b71e3ddaca8080e4093" +dependencies = [ + "base64 0.13.0", + "byteorder", + "bytes 1.0.1", + "http", + "httparse", + "input_buffer 0.4.0", + "log 0.4.14", + "rand 0.8.3", + "rustls", + "sha-1", + "thiserror", + "url", + "utf-8", + "webpki", + "webpki-roots 0.21.1", +] + [[package]] name = "typemap_rev" version = "0.1.4" @@ -1320,12 +1870,28 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-xid" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36dff09cafb4ec7c8cf0023eb0b686cb6ce65499116a12201c9e11840ca01beb" + [[package]] name = "unicode-xid" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +[[package]] +name = "universal-hash" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402" +dependencies = [ + "generic-array", + "subtle", +] + [[package]] name = "untrusted" version = "0.7.1" @@ -1350,6 +1916,15 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7" +[[package]] +name = "uuid" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +dependencies = [ + "getrandom 0.2.2", +] + [[package]] name = "uwl" version = "0.6.0" @@ -1374,7 +1949,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" dependencies = [ - "log", + "log 0.4.14", "try-lock", ] @@ -1396,7 +1971,7 @@ version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83240549659d187488f91f33c0f8547cbfef0b2088bc470c116d1d260ef623d9" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "serde", "serde_json", "wasm-bindgen-macro", @@ -1410,7 +1985,7 @@ checksum = "ae70622411ca953215ca6d06d3ebeb1e915f0f6613e3b495122878d7ebec7dae" dependencies = [ "bumpalo", "lazy_static", - "log", + "log 0.4.14", "proc-macro2", "quote", "syn", @@ -1423,7 +1998,7 @@ version = "0.4.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81b8b767af23de6ac18bf2168b690bed2902743ddf0fb39252e36f9e2bfc63ea" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "js-sys", "wasm-bindgen", "web-sys", @@ -1496,6 +2071,12 @@ dependencies = [ "webpki", ] +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + [[package]] name = "winapi" version = "0.3.9" @@ -1506,6 +2087,12 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -1524,5 +2111,25 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" dependencies = [ - "winapi", + "winapi 0.3.9", ] + +[[package]] +name = "xsalsa20poly1305" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0304c336e98d753428f7b3d8899d60b8a87a961ef50bdfc44af0c1bea2651ce5" +dependencies = [ + "aead", + "poly1305", + "rand_core 0.5.1", + "salsa20", + "subtle", + "zeroize", +] + +[[package]] +name = "zeroize" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81a974bcdd357f0dca4d41677db03436324d45a4c9ed2d0b873a5a360ce41c36" diff --git a/Cargo.toml b/Cargo.toml index f0077b3..4d28677 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,4 +16,7 @@ serde_derive = "1.0.125" serde = "1.0.125" thiserror = "1.0.24" parking_lot = "0.11.1" -minecraft-data-rs = "0.2.0" \ No newline at end of file +minecraft-data-rs = "0.2.0" +songbird = {version = "0.1.5", features=["builtin-queue"]} +serde_json = "1.0.64" +rand = "0.8.3" \ No newline at end of file diff --git a/src/client.rs b/src/client.rs index 0f06613..aec2966 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,4 +1,4 @@ -use crate::commands::minecraft::Minecraft; +use crate::commands::*; use crate::database::{get_database, Database}; use crate::utils::error::{BotError, BotResult}; use crate::utils::store::{Store, StoreData}; @@ -9,6 +9,7 @@ use serenity::framework::standard::CommandResult; use serenity::framework::StandardFramework; use serenity::model::channel::Message; use serenity::Client; +use songbird::SerenityInit; struct Handler; @@ -19,7 +20,10 @@ pub async fn get_client() -> BotResult { let token = dotenv::var("BOT_TOKEN").map_err(|_| BotError::MissingToken)?; let database = get_database()?; - let client = Client::builder(token).framework(get_framework()).await?; + let client = Client::builder(token) + .framework(get_framework()) + .register_songbird() + .await?; { let mut data = client.data.write().await; data.insert::(StoreData::new(database)) @@ -39,9 +43,11 @@ pub fn get_framework() -> StandardFramework { .allow_dm(true) .ignore_bots(true) }) - .group(&crate::commands::minecraft::MINECRAFT_GROUP) - .group(&crate::GENERAL_GROUP) + .group(&MINECRAFT_GROUP) + .group(&MISC_GROUP) + .group(&MUSIC_GROUP) .after(after_hook) + .before(before_hook) } #[hook] @@ -52,3 +58,9 @@ async fn after_hook(ctx: &Context, msg: &Message, cmd_name: &str, error: Command println!("Error in {}: {:?}", cmd_name, why); } } + +#[hook] +async fn before_hook(ctx: &Context, msg: &Message, _: &str) -> bool { + let _ = msg.channel_id.broadcast_typing(ctx).await; + true +} diff --git a/src/commands/misc/mod.rs b/src/commands/misc/mod.rs index e69de29..c8812a4 100644 --- a/src/commands/misc/mod.rs +++ b/src/commands/misc/mod.rs @@ -0,0 +1,8 @@ +pub(crate) mod ping; + +use ping::PING_COMMAND; +use serenity::framework::standard::macros::group; + +#[group] +#[commands(ping)] +pub struct Misc; diff --git a/src/commands/misc/ping.rs b/src/commands/misc/ping.rs new file mode 100644 index 0000000..1198939 --- /dev/null +++ b/src/commands/misc/ping.rs @@ -0,0 +1,14 @@ +use serenity::client::Context; +use serenity::framework::standard::macros::command; +use serenity::framework::standard::CommandResult; +use serenity::model::channel::Message; + +#[command] +#[description("Simple ping test command")] +#[usage("ping")] +#[example("ping")] +async fn ping(ctx: &Context, msg: &Message) -> CommandResult { + msg.reply(ctx, "Pong!").await?; + + Ok(()) +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 94caf87..37d1c9f 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1 +1,7 @@ pub(crate) mod minecraft; +pub(crate) mod misc; +pub(crate) mod music; + +pub use minecraft::MINECRAFT_GROUP; +pub use misc::MISC_GROUP; +pub use music::MUSIC_GROUP; diff --git a/src/commands/music/current.rs b/src/commands/music/current.rs new file mode 100644 index 0000000..856ae7e --- /dev/null +++ b/src/commands/music/current.rs @@ -0,0 +1,47 @@ +use serenity::client::Context; +use serenity::framework::standard::macros::command; +use serenity::framework::standard::{CommandError, CommandResult}; +use serenity::model::channel::Message; + +#[command] +#[only_in(guilds)] +#[description("Displays the currently playing song")] +#[usage("current")] +#[aliases("nowplaying", "np")] +async fn current(ctx: &Context, msg: &Message) -> CommandResult { + let guild = msg.guild(&ctx.cache).await.unwrap(); + + let manager = songbird::get(ctx) + .await + .expect("Songbird Voice client placed in at initialisation.") + .clone(); + + let handler_lock = manager + .get(guild.id) + .ok_or(CommandError::from("Not in a voice channel"))?; + let handler = handler_lock.lock().await; + + if let Some(current) = handler.queue().current() { + let metadata = current.metadata().clone(); + msg.channel_id + .send_message(ctx, |m| { + m.embed(|mut e| { + e = e.description(format!( + "Now Playing [{}]({}) by {}", + metadata.title.unwrap(), + metadata.source_url.unwrap(), + metadata.artist.unwrap() + )); + + if let Some(thumb) = metadata.thumbnail { + e = e.thumbnail(thumb); + } + + e + }) + }) + .await?; + } + + Ok(()) +} diff --git a/src/commands/music/join.rs b/src/commands/music/join.rs new file mode 100644 index 0000000..eae1067 --- /dev/null +++ b/src/commands/music/join.rs @@ -0,0 +1,17 @@ +use crate::commands::music::utils::{get_channel_for_author, join_channel}; +use serenity::client::Context; +use serenity::framework::standard::macros::command; +use serenity::framework::standard::{CommandError, CommandResult}; +use serenity::model::channel::Message; + +#[command] +#[only_in(guilds)] +#[description("Joins a voice channel")] +#[usage("join")] +async fn join(ctx: &Context, msg: &Message) -> CommandResult { + let guild = msg.guild(&ctx.cache).await.unwrap(); + let channel_id = get_channel_for_author(&msg.author.id, &guild)?; + join_channel(ctx, channel_id, guild.id).await; + + Ok(()) +} diff --git a/src/commands/music/leave.rs b/src/commands/music/leave.rs new file mode 100644 index 0000000..c78550c --- /dev/null +++ b/src/commands/music/leave.rs @@ -0,0 +1,28 @@ +use serenity::client::Context; +use serenity::framework::standard::macros::command; +use serenity::framework::standard::CommandResult; +use serenity::model::channel::Message; + +#[command] +#[only_in(guilds)] +#[description("Leaves a voice channel")] +#[usage("leave")] +#[aliases("stop")] +async fn leave(ctx: &Context, msg: &Message) -> CommandResult { + let guild = msg.guild(&ctx.cache).await.unwrap(); + let guild_id = guild.id; + + let manager = songbird::get(ctx) + .await + .expect("Songbird Voice client placed in at initialisation.") + .clone(); + + if manager.get(guild_id).is_some() { + manager.remove(guild_id).await?; + msg.channel_id.say(ctx, "Left the voice channel").await?; + } else { + msg.channel_id.say(ctx, "Not in a voice channel").await?; + } + + Ok(()) +} diff --git a/src/commands/music/mod.rs b/src/commands/music/mod.rs new file mode 100644 index 0000000..50df9ce --- /dev/null +++ b/src/commands/music/mod.rs @@ -0,0 +1,23 @@ +mod current; +mod join; +mod leave; +mod play; +mod queue; +mod shuffle; +mod skip; +mod utils; + +use serenity::framework::standard::macros::group; + +use current::CURRENT_COMMAND; +use join::JOIN_COMMAND; +use leave::LEAVE_COMMAND; +use play::PLAY_COMMAND; +use queue::QUEUE_COMMAND; +use shuffle::SHUFFLE_COMMAND; +use skip::SKIP_COMMAND; + +#[group] +#[commands(join, leave, play, queue, skip, shuffle, current)] +#[prefix("m")] +pub struct Music; diff --git a/src/commands/music/play.rs b/src/commands/music/play.rs new file mode 100644 index 0000000..d10155f --- /dev/null +++ b/src/commands/music/play.rs @@ -0,0 +1,91 @@ +use crate::commands::music::utils::{get_channel_for_author, join_channel}; +use crate::providers::ytdl::get_videos_for_url; +use serenity::client::Context; +use serenity::framework::standard::macros::command; +use serenity::framework::standard::{Args, CommandError, CommandResult}; +use serenity::model::channel::Message; + +#[command] +#[only_in(guilds)] +#[description("Plays a song in a voice channel")] +#[usage("play ")] +#[min_args(1)] +#[max_args(1)] +#[aliases("p")] +async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { + let url = args.message(); + + if !url.starts_with("http") { + return Err(CommandError::from("The provided url is not valid")); + } + + let guild = msg.guild(&ctx.cache).await.unwrap(); + + let manager = songbird::get(ctx) + .await + .expect("Songbird Voice client placed in at initialisation.") + .clone(); + + let mut handler = manager.get(guild.id); + + if handler.is_none() { + msg.guild(&ctx.cache).await.unwrap(); + let channel_id = get_channel_for_author(&msg.author.id, &guild)?; + handler = Some(join_channel(ctx, channel_id, guild.id).await); + } + + let handler_lock = handler.ok_or(CommandError::from("Not in a voice channel"))?; + let mut handler = handler_lock.lock().await; + let mut videos: Vec = get_videos_for_url(url)? + .into_iter() + .map(|v| format!("https://www.youtube.com/watch?v={}", v.url)) + .collect(); + if videos.len() == 0 { + videos.push(url.to_string()); + } + + let mut metadata = None; + + for video in &videos { + let source = match songbird::ytdl(video).await { + Ok(s) => s, + Err(e) => { + msg.channel_id + .say(ctx, format!("Failed to enqueue {}: {:?}", video, e)) + .await?; + continue; + } + }; + + metadata = Some(source.metadata.clone()); + + handler.enqueue_source(source); + } + if videos.len() == 1 { + let metadata = metadata.unwrap(); + msg.channel_id + .send_message(&ctx.http, |m| { + m.embed(|mut e| { + e = e.description(format!( + "Added [{}]({}) to the queue", + metadata.title.unwrap(), + url + )); + if let Some(thumb) = metadata.thumbnail { + e = e.thumbnail(thumb); + } + + e + }) + }) + .await?; + } else { + msg.channel_id + .send_message(&ctx.http, |m| { + m.embed(|e| e.description(format!("Added {} songs to the queue", videos.len()))) + }) + .await?; + } + + Ok(()) +} diff --git a/src/commands/music/queue.rs b/src/commands/music/queue.rs new file mode 100644 index 0000000..bdb7be5 --- /dev/null +++ b/src/commands/music/queue.rs @@ -0,0 +1,62 @@ +use serenity::client::Context; +use serenity::framework::standard::macros::command; +use serenity::framework::standard::{CommandError, CommandResult}; +use serenity::model::channel::Message; +use std::cmp::min; + +#[command] +#[only_in(guilds)] +#[description("Shows the song queue")] +#[usage("queue")] +#[aliases("q")] +async fn queue(ctx: &Context, msg: &Message) -> CommandResult { + let guild = msg.guild(&ctx.cache).await.unwrap(); + + let manager = songbird::get(ctx) + .await + .expect("Songbird Voice client placed in at initialisation.") + .clone(); + + let handler_lock = manager + .get(guild.id) + .ok_or(CommandError::from("Not in a voice channel"))?; + let handler = handler_lock.lock().await; + let songs: Vec<(usize, String)> = handler + .queue() + .current_queue() + .into_iter() + .map(|t| t.metadata().title.clone().unwrap()) + .enumerate() + .collect(); + + if songs.len() == 0 { + msg.channel_id + .send_message(ctx, |m| { + m.embed(|e| e.title("Queue").description("*The queue is empty*")) + }) + .await?; + + return Ok(()); + } + + let mut song_list = Vec::new(); + + for i in 0..min(10, songs.len() - 1) { + song_list.push(format!("{:0>3} - {}", songs[i].0, songs[i].1)) + } + if songs.len() > 10 { + song_list.push("...".to_string()); + let last = songs.last().unwrap(); + song_list.push(format!("{:0>3} - {}", last.0, last.1)) + } + msg.channel_id + .send_message(ctx, |m| { + m.embed(|e| { + e.title("Queue") + .description(format!("```\n{}\n```", song_list.join("\n"))) + }) + }) + .await?; + + Ok(()) +} diff --git a/src/commands/music/shuffle.rs b/src/commands/music/shuffle.rs new file mode 100644 index 0000000..07221c3 --- /dev/null +++ b/src/commands/music/shuffle.rs @@ -0,0 +1,41 @@ +use rand::Rng; +use serenity::client::Context; +use serenity::framework::standard::macros::command; +use serenity::framework::standard::{CommandError, CommandResult}; +use serenity::model::channel::Message; +use std::collections::VecDeque; + +#[command] +#[only_in(guilds)] +#[description("Shuffles the queue")] +#[usage("shuffle")] +#[aliases("sh")] +async fn shuffle(ctx: &Context, msg: &Message) -> CommandResult { + let guild = msg.guild(&ctx.cache).await.unwrap(); + + let manager = songbird::get(ctx) + .await + .expect("Songbird Voice client placed in at initialisation.") + .clone(); + + let handler_lock = manager + .get(guild.id) + .ok_or(CommandError::from("Not in a voice channel"))?; + let handler = handler_lock.lock().await; + handler.queue().modify_queue(shuffle_vec_deque); + msg.channel_id + .say(ctx, "The queue has been shuffled") + .await?; + + Ok(()) +} + +/// Fisher-Yates shuffle for VecDeque +fn shuffle_vec_deque(deque: &mut VecDeque) { + let mut rng = rand::thread_rng(); + let mut i = deque.len(); + while i >= 2 { + i -= 1; + deque.swap(i, rng.gen_range(0..i + 1)) + } +} diff --git a/src/commands/music/skip.rs b/src/commands/music/skip.rs new file mode 100644 index 0000000..38b8cff --- /dev/null +++ b/src/commands/music/skip.rs @@ -0,0 +1,31 @@ +use serenity::client::Context; +use serenity::framework::standard::macros::command; +use serenity::framework::standard::{CommandError, CommandResult}; +use serenity::model::channel::Message; + +#[command] +#[only_in(guilds)] +#[description("Skips to the next song")] +#[usage("skip")] +#[aliases("next")] +async fn skip(ctx: &Context, msg: &Message) -> CommandResult { + let guild = msg.guild(&ctx.cache).await.unwrap(); + + let manager = songbird::get(ctx) + .await + .expect("Songbird Voice client placed in at initialisation.") + .clone(); + + let handler_lock = manager + .get(guild.id) + .ok_or(CommandError::from("Not in a voice channel"))?; + let handler = handler_lock.lock().await; + + if let Some(current) = handler.queue().current() { + current.stop()?; + } + handler.queue().skip()?; + msg.channel_id.say(ctx, "Skipped to the next song").await?; + + Ok(()) +} diff --git a/src/commands/music/utils.rs b/src/commands/music/utils.rs new file mode 100644 index 0000000..50dc64c --- /dev/null +++ b/src/commands/music/utils.rs @@ -0,0 +1,31 @@ +use crate::utils::error::{BotError, BotResult}; +use serenity::client::Context; +use serenity::model::guild::Guild; +use serenity::model::id::{ChannelId, GuildId, UserId}; +use songbird::Call; +use std::sync::Arc; +use tokio::sync::Mutex; + +/// Joins a voice channel +pub(crate) async fn join_channel( + ctx: &Context, + channel_id: ChannelId, + guild_id: GuildId, +) -> Arc> { + let manager = songbird::get(ctx) + .await + .expect("Songbird Voice client placed in at initialisation.") + .clone(); + + let (handler, _) = manager.join(guild_id, channel_id).await; + handler +} + +/// Returns the voice channel the author is in +pub(crate) fn get_channel_for_author(author_id: &UserId, guild: &Guild) -> BotResult { + guild + .voice_states + .get(author_id) + .and_then(|voice_state| voice_state.channel_id) + .ok_or(BotError::from("Not in a voice channel.")) +} diff --git a/src/main.rs b/src/main.rs index 2c2cc6f..da7ab3e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,10 +12,6 @@ pub(crate) mod database; mod providers; pub(crate) mod utils; -#[group] -#[commands(ping)] -struct General; - struct Handler; #[tokio::main] @@ -27,10 +23,3 @@ async fn main() { println!("An error occurred while running the client: {:?}", why); } } - -#[command] -async fn ping(ctx: &Context, msg: &Message) -> CommandResult { - msg.reply(ctx, "Pong!").await?; - - Ok(()) -} diff --git a/src/providers/mod.rs b/src/providers/mod.rs index e69de29..107aef4 100644 --- a/src/providers/mod.rs +++ b/src/providers/mod.rs @@ -0,0 +1 @@ +pub(crate) mod ytdl; diff --git a/src/providers/ytdl/mod.rs b/src/providers/ytdl/mod.rs new file mode 100644 index 0000000..1d9d231 --- /dev/null +++ b/src/providers/ytdl/mod.rs @@ -0,0 +1,31 @@ +use crate::providers::ytdl::playlist_entry::PlaylistEntry; +use crate::utils::error::{BotError, BotResult}; +use std::io::Read; +use std::process::{Command, Stdio}; + +mod playlist_entry; + +/// Returns a list of youtube videos for a given url +pub(crate) fn get_videos_for_url(url: &str) -> BotResult> { + let ytdl = Command::new("youtube-dl") + .args(&[ + "-f", + "--no-warnings", + "--flat-playlist", + "--dump-json", + "-i", + url, + ]) + .stdout(Stdio::piped()) + .spawn()?; + + let mut output = String::new(); + ytdl.stdout.unwrap().read_to_string(&mut output)?; + + let videos = output + .lines() + .map(|l| serde_json::from_str::(l).unwrap()) + .collect(); + + Ok(videos) +} diff --git a/src/providers/ytdl/playlist_entry.rs b/src/providers/ytdl/playlist_entry.rs new file mode 100644 index 0000000..edd2402 --- /dev/null +++ b/src/providers/ytdl/playlist_entry.rs @@ -0,0 +1,9 @@ +use serde_derive::Deserialize; + +#[derive(Deserialize, Clone, Debug)] +pub(crate) struct PlaylistEntry { + ie_key: String, + id: String, + pub url: String, + pub title: String, +} diff --git a/src/utils/error.rs b/src/utils/error.rs index 66c2289..bb98357 100644 --- a/src/utils/error.rs +++ b/src/utils/error.rs @@ -16,4 +16,16 @@ pub enum BotError { #[error("Minecraft Data Error: {0}")] MinecraftDataError(#[from] minecraft_data_rs::DataError), + + #[error("IO Error: {0}")] + IOError(#[from] std::io::Error), + + #[error("{0}")] + Msg(String), +} + +impl From<&str> for BotError { + fn from(s: &str) -> Self { + Self::Msg(s.to_string()) + } }