From f0590328b05535cae8804f025f212f7343cc3a57 Mon Sep 17 00:00:00 2001 From: jellywx Date: Thu, 24 Jun 2021 15:52:45 +0100 Subject: [PATCH 1/9] start of soundboard and help rework --- Cargo.lock | 596 ++++++++++++++++++++++++++++++++--------------- Cargo.toml | 4 +- src/framework.rs | 10 +- src/main.rs | 232 +++++++++--------- 4 files changed, 530 insertions(+), 312 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 807fd05..83c048a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,9 +8,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aead" -version = "0.4.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "922b33332f54fc0ad13fa3e514601e8d30fb54e1f3eadc36643f6526db645621" +checksum = "7fc95d1bdb8e6666b2b217308eeeb09f2d6728d104be3e31916cc74d15420331" dependencies = [ "generic-array", ] @@ -21,7 +21,7 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98" dependencies = [ - "getrandom", + "getrandom 0.2.3", "once_cell", "version_check", ] @@ -35,15 +35,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "arrayvec" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9" -dependencies = [ - "nodrop", -] - [[package]] name = "arrayvec" version = "0.5.2" @@ -61,6 +52,22 @@ dependencies = [ "syn", ] +[[package]] +name = "async-tungstenite" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7cc5408453d37e2b1c6f01d8078af1da58b6cfa6a80fa2ede3bd2b9a6ada9c4" +dependencies = [ + "futures-io", + "futures-util", + "log 0.4.14", + "pin-project", + "tokio", + "tokio-rustls", + "tungstenite 0.11.1", + "webpki-roots 0.20.0", +] + [[package]] name = "async-tungstenite" version = "0.13.1" @@ -69,12 +76,12 @@ checksum = "07b30ef0ea5c20caaa54baea49514a206308989c68be7ecd86c7f956e4da6378" dependencies = [ "futures-io", "futures-util", - "log", + "log 0.4.14", "pin-project-lite", "tokio", "tokio-rustls", - "tungstenite", - "webpki-roots", + "tungstenite 0.13.0", + "webpki-roots 0.21.1", ] [[package]] @@ -94,7 +101,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -112,7 +119,7 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "927791de46f70facea982dbfaf19719a41ce6064443403be631a85de6a58fff9" dependencies = [ - "log", + "log 0.4.14", "pkg-config", ] @@ -128,6 +135,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +[[package]] +name = "base64" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" + [[package]] name = "base64" version = "0.13.0" @@ -145,6 +158,12 @@ dependencies = [ "num-traits 0.2.14", ] +[[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" @@ -184,6 +203,12 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "bytes" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" + [[package]] name = "bytes" version = "1.0.1" @@ -219,22 +244,21 @@ dependencies = [ "num-traits 0.2.14", "serde", "time", - "winapi", + "winapi 0.3.9", ] [[package]] name = "cipher" -version = "0.3.0" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" +checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" dependencies = [ "generic-array", ] [[package]] name = "command_attr" -version = "0.3.6" -source = "git+https://github.com/serenity-rs/serenity?branch=next#a24132fc66bea5fe7772d9f694ab3517d24d286b" +version = "0.3.7" dependencies = [ "proc-macro2", "quote", @@ -259,13 +283,19 @@ checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" [[package]] name = "cpufeatures" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed00c67cb5d0a7d64a44f6ad2668db7e7530311dd53ea79bcd4fb022c64911c8" +checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef" dependencies = [ "libc", ] +[[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" @@ -336,12 +366,14 @@ dependencies = [ [[package]] name = "discortp" -version = "0.4.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb66017646a48220b5ea30d63ac18bb5952f647f1a41ed755880895125d26972" +checksum = "9c0d482488c336a2164529765da3f645f26215df9c2033137ddedac333c8e2e8" dependencies = [ + "glob", "pnet_macros", "pnet_macros_support", + "syntex", ] [[package]] @@ -376,13 +408,13 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17392a012ea30ef05a610aa97dfb49496e71c9f676b27879922ea5bdf60d9d3f" +checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" dependencies = [ "atty", "humantime", - "log", + "log 0.4.14", "regex", "termcolor", ] @@ -401,9 +433,9 @@ dependencies = [ [[package]] name = "flume" -version = "0.10.5" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa9d66b91e902db43baefd8e40c8678ce29db2cf1d88ebd715174368d5fe70a9" +checksum = "ddad16e8529759736a9ce4cdf078ed702e45d3c5b0474a1c65f5149e9fa7f1eb" dependencies = [ "futures-core", "futures-sink", @@ -551,9 +583,9 @@ checksum = "061d3be1afec479d56fa3bd182bf966c7999ec175fcfdb87ac14d417241366c6" dependencies = [ "cc", "libc", - "log", + "log 0.4.14", "rustversion", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -566,6 +598,17 @@ dependencies = [ "version_check", ] +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + [[package]] name = "getrandom" version = "0.2.3" @@ -575,17 +618,23 @@ dependencies = [ "cfg-if 1.0.0", "js-sys", "libc", - "wasi", + "wasi 0.10.2+wasi-snapshot-preview1", "wasm-bindgen", ] +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + [[package]] name = "h2" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "825343c4eef0b63f541f8903f395dc5beb362a979b5799a84062527ef1e37726" dependencies = [ - "bytes", + "bytes 1.0.1", "fnv", "futures-core", "futures-sink", @@ -652,7 +701,7 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" dependencies = [ - "bytes", + "bytes 1.0.1", "fnv", "itoa", ] @@ -663,7 +712,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9" dependencies = [ - "bytes", + "bytes 1.0.1", "http", "pin-project-lite", ] @@ -688,11 +737,11 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.8" +version = "0.14.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3f71a7eea53a3f8257a7b4795373ff886397178cd634430ea94e12d7fe4fe34" +checksum = "07d6baa1b441335f3ce5098ac421fb6547c46dda735ca1bc6d0153c838f9dd83" dependencies = [ - "bytes", + "bytes 1.0.1", "futures-channel", "futures-core", "futures-util", @@ -702,7 +751,7 @@ dependencies = [ "httparse", "httpdate", "itoa", - "pin-project", + "pin-project-lite", "socket2", "tokio", "tower-service", @@ -718,7 +767,7 @@ checksum = "5f9f7a97316d44c0af9b0301e65010573a853a9fc97046d7331d7f6bc0fd5a64" dependencies = [ "futures-util", "hyper", - "log", + "log 0.4.14", "rustls", "tokio", "tokio-rustls", @@ -731,7 +780,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ - "bytes", + "bytes 1.0.1", "hyper", "native-tls", "tokio", @@ -759,13 +808,22 @@ dependencies = [ "hashbrown 0.9.1", ] +[[package]] +name = "input_buffer" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19a8a95243d5a0398cae618ec29477c6e3cb631152be5c19481f80bc71559754" +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", + "bytes 1.0.1", ] [[package]] @@ -779,9 +837,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" +checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9" [[package]] name = "itoa" @@ -798,6 +856,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" @@ -813,8 +881,8 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe" dependencies = [ - "arrayvec 0.5.2", - "bitflags", + "arrayvec", + "bitflags 1.2.1", "cfg-if 1.0.0", "ryu", "static_assertions", @@ -822,9 +890,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.95" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" +checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" [[package]] name = "libm" @@ -841,6 +909,15 @@ 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" @@ -909,15 +986,15 @@ dependencies = [ [[package]] name = "mio" -version = "0.7.11" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956" +checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" dependencies = [ "libc", - "log", + "log 0.4.14", "miow", "ntapi", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -926,7 +1003,7 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -935,7 +1012,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac1378b66f7c93a1c0f8464a19bf47df8795083842e5090f4b7305973d5a22d0" dependencies = [ - "getrandom", + "getrandom 0.2.3", ] [[package]] @@ -946,7 +1023,7 @@ checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" dependencies = [ "lazy_static", "libc", - "log", + "log 0.4.14", "openssl", "openssl-probe", "openssl-sys", @@ -956,12 +1033,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "nodrop" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" - [[package]] name = "nom" version = "6.1.2" @@ -981,7 +1052,7 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1019,7 +1090,7 @@ dependencies = [ "num-integer", "num-iter", "num-traits 0.2.14", - "rand", + "rand 0.8.4", "smallvec", "zeroize", ] @@ -1076,9 +1147,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] name = "opaque-debug" @@ -1088,11 +1159,11 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.34" +version = "0.10.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d7830286ad6a3973c0f1d9b73738f69c76b739301d0229c4b96501695cbe4c8" +checksum = "549430950c79ae24e6d02e0b7404534ecf311d94cc9f861e9e4020187d13d885" dependencies = [ - "bitflags", + "bitflags 1.2.1", "cfg-if 1.0.0", "foreign-types", "libc", @@ -1108,9 +1179,9 @@ checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" [[package]] name = "openssl-sys" -version = "0.9.63" +version = "0.9.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6b0d6fb7d80f877617dfcb014e605e2b5ab2fb0afdf27935219bb6bd984cb98" +checksum = "7a7907e3bfa08bb85105209cdfcb6c63d109f8f6c1ed6ca318fff5c1853fbc1d" dependencies = [ "autocfg 1.0.1", "cc", @@ -1141,7 +1212,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1150,7 +1221,7 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd56cbd21fea48d0c440b41cd69c589faacade08c992d9a54e471b79d0fd13eb" dependencies = [ - "base64", + "base64 0.13.0", "once_cell", "regex", ] @@ -1201,39 +1272,37 @@ checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" [[package]] name = "pnet_base" -version = "0.28.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25488cd551a753dcaaa6fffc9f69a7610a412dd8954425bf7ffad5f7d1156fb8" +checksum = "b7cd5f7e15220afa66b0a9a62841ea10089f39dcaa1c29752c0b22dfc03111b5" [[package]] name = "pnet_macros" -version = "0.28.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30490e0852e58402b8fae0d39897b08a24f493023a4d6cf56b2e30f31ed57548" +checksum = "bbbd5c52c6e04aa720400f9c71cd0e8bcb38cd13421d5caabd9035e9efa47de9" dependencies = [ - "proc-macro2", - "quote", "regex", - "syn", + "syntex", + "syntex_syntax", ] [[package]] name = "pnet_macros_support" -version = "0.28.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4714e10f30cab023005adce048f2d30dd4ac4f093662abf2220855655ef8f90" +checksum = "daf9c5c0c36766d0a4da9ab268c0700771b8ec367b9463fd678109fa28463c5b" dependencies = [ "pnet_base", ] [[package]] name = "poly1305" -version = "0.7.0" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fe800695325da85083cd23b56826fccb2e2dc29b218e7811a6f33bc93f414be" +checksum = "4b7456bc1ad2d4cf82b3a016be4c2ac48daf11bf990c1603ebd447fe6f30fca8" dependencies = [ - "cpufeatures", - "opaque-debug", + "cpuid-bool", "universal-hash", ] @@ -1261,7 +1330,7 @@ version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" dependencies = [ - "unicode-xid", + "unicode-xid 0.2.2", ] [[package]] @@ -1281,51 +1350,92 @@ checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8" [[package]] name = "rand" -version = "0.8.3" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "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.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" dependencies = [ "libc", - "rand_chacha", - "rand_core", - "rand_hc", + "rand_chacha 0.3.1", + "rand_core 0.6.3", + "rand_hc 0.3.1", ] [[package]] name = "rand_chacha" -version = "0.3.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.3", ] [[package]] name = "rand_core" -version = "0.6.2" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom", + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom 0.2.3", ] [[package]] name = "rand_hc" -version = "0.3.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_hc" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" +dependencies = [ + "rand_core 0.6.3", ] [[package]] name = "redox_syscall" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "742739e41cd49414de871ea5e549afb7e2a3ac77b589bcbebe8c82fab37147fc" +checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" dependencies = [ - "bitflags", + "bitflags 1.2.1", ] [[package]] @@ -1360,17 +1470,17 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] name = "reqwest" -version = "0.11.3" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2296f2fac53979e8ccbc4a1136b25dcefd37be9ed7e4a1f6b05a6029c84ff124" +checksum = "246e9f61b9bb77df069a947682be06e31ac43ea37862e244a69f177694ea6d22" dependencies = [ - "base64", - "bytes", + "base64 0.13.0", + "bytes 1.0.1", "encoding_rs", "futures-core", "futures-util", @@ -1382,7 +1492,7 @@ dependencies = [ "ipnet", "js-sys", "lazy_static", - "log", + "log 0.4.14", "mime", "mime_guess", "native-tls", @@ -1399,7 +1509,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots", + "webpki-roots 0.21.1", "winreg", ] @@ -1415,7 +1525,7 @@ dependencies = [ "spin", "untrusted", "web-sys", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1432,20 +1542,26 @@ dependencies = [ "num-iter", "num-traits 0.2.14", "pem", - "rand", + "rand 0.8.4", "simple_asn1", "subtle", "zeroize", ] +[[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.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" dependencies = [ - "base64", - "log", + "base64 0.13.0", + "log 0.4.14", "ring", "sct", "webpki", @@ -1465,9 +1581,9 @@ checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] name = "salsa20" -version = "0.8.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c7c5f10864beba947e1a1b43f3ef46c8cc58d1c2ae549fa471713e8ff60787a" +checksum = "399f290ffc409596022fce5ea5d4138184be4784f2b28c62c59f0d8389059a15" dependencies = [ "cipher", "zeroize", @@ -1480,7 +1596,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" dependencies = [ "lazy_static", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1507,11 +1623,11 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.2.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3670b1d2fdf6084d192bc71ead7aabe6c06aa2ea3fbd9cc3ac111fa5c2b1bd84" +checksum = "23a2ac85147a3a11d77ecf1bc7166ec0b92febfa4461c37944e180f319ece467" dependencies = [ - "bitflags", + "bitflags 1.2.1", "core-foundation", "core-foundation-sys", "libc", @@ -1520,9 +1636,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3676258fd3cfe2c9a0ec99ce3038798d847ce3e4bb17746373eb9f0f1ac16339" +checksum = "7e4effb91b4b8b6fb7732e670b6cee160278ff8e6bf485c7805d9e319d76e284" dependencies = [ "core-foundation-sys", "libc", @@ -1584,14 +1700,13 @@ dependencies = [ [[package]] name = "serenity" -version = "0.10.7" -source = "git+https://github.com/serenity-rs/serenity?branch=next#a24132fc66bea5fe7772d9f694ab3517d24d286b" +version = "0.10.8" dependencies = [ "async-trait", - "async-tungstenite", - "base64", - "bitflags", - "bytes", + "async-tungstenite 0.11.0", + "base64 0.13.0", + "bitflags 1.2.1", + "bytes 1.0.1", "chrono", "command_attr", "flate2", @@ -1611,9 +1726,10 @@ dependencies = [ [[package]] name = "serenity-voice-model" version = "0.1.0" -source = "git+https://github.com/serenity-rs/serenity?branch=next#a24132fc66bea5fe7772d9f694ab3517d24d286b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "158aeb823791f79bbb92110212970797757fee7102784453dcb9b172a8af272b" dependencies = [ - "bitflags", + "bitflags 1.2.1", "enum_primitive", "serde", "serde_json", @@ -1686,16 +1802,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" dependencies = [ "libc", - "winapi", + "winapi 0.3.9", ] [[package]] name = "songbird" -version = "0.2.0-beta.3" -source = "git+https://github.com/serenity-rs/songbird?branch=next#e0ea2f5fe2fe14cb2de0774227f27cb1175d8295" +version = "0.1.7" dependencies = [ "async-trait", - "async-tungstenite", + "async-tungstenite 0.13.1", "audiopus", "byteorder", "dashmap", @@ -1703,15 +1818,14 @@ dependencies = [ "flume", "futures", "parking_lot", - "pin-project", - "rand", + "rand 0.8.4", "serde", "serde_json", "serenity", "serenity-voice-model", "spin_sleep", + "spinning_top", "streamcatcher", - "symphonia-core", "tokio", "tracing", "tracing-futures", @@ -1729,7 +1843,7 @@ dependencies = [ "dotenv", "env_logger", "lazy_static", - "log", + "log 0.4.14", "regex", "regex_command_attr", "reqwest", @@ -1753,14 +1867,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a98101bdc3833e192713c2af0b0dd2614f50d1cf1f7a97c5221b7aac052acc7" dependencies = [ "once_cell", - "winapi", + "winapi 0.3.9", ] [[package]] name = "spinning_top" -version = "0.2.4" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75adad84ee84b521fb2cca2d4fd0f1dab1d8d026bda3c5bea4ca63b5f9f9293c" +checksum = "7e529d73e80d64b5f2631f9035113347c578a1c9c7774b83a2b880788459ab36" dependencies = [ "lock_api", ] @@ -1796,11 +1910,11 @@ checksum = "7f23af36748ec8ea8d49ef8499839907be41b0b1178a4e82b8cb45d29f531dc9" dependencies = [ "ahash", "atoi", - "base64", + "base64 0.13.0", "bigdecimal", - "bitflags", + "bitflags 1.2.1", "byteorder", - "bytes", + "bytes 1.0.1", "crossbeam-channel", "crossbeam-queue", "crossbeam-utils 0.8.5", @@ -1814,13 +1928,13 @@ dependencies = [ "hex", "itoa", "libc", - "log", + "log 0.4.14", "memchr", "num-bigint 0.3.2", "once_cell", "parking_lot", "percent-encoding", - "rand", + "rand 0.8.4", "rsa", "rustls", "sha-1", @@ -1833,7 +1947,7 @@ dependencies = [ "tokio-stream", "url", "webpki", - "webpki-roots", + "webpki-roots 0.21.1", "whoami", ] @@ -1900,28 +2014,15 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" -[[package]] -name = "symphonia-core" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e32b956473d98c601dac257fab8a7700d42e49fdd7a33432dd5dc7fdd2448dd" -dependencies = [ - "arrayvec 0.4.12", - "bitflags", - "byteorder", - "lazy_static", - "log", -] - [[package]] name = "syn" -version = "1.0.72" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" +checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-xid 0.2.2", ] [[package]] @@ -1933,7 +2034,56 @@ dependencies = [ "proc-macro2", "quote", "syn", - "unicode-xid", + "unicode-xid 0.2.2", +] + +[[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]] @@ -1950,10 +2100,20 @@ checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ "cfg-if 1.0.0", "libc", - "rand", + "rand 0.8.4", "redox_syscall", "remove_dir_all", - "winapi", + "winapi 0.3.9", +] + +[[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]] @@ -1992,7 +2152,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -2012,12 +2172,12 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.6.1" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a38d31d7831c6ed7aad00aa4c12d9375fd225a6dd77da1d25b707346319a975" +checksum = "5fb2ed024293bb19f7a5dc54fe83bf86532a44c12a2bb8ba40d64a4509395ca2" dependencies = [ "autocfg 1.0.1", - "bytes", + "bytes 1.0.1", "libc", "memchr", "mio", @@ -2026,7 +2186,7 @@ dependencies = [ "pin-project-lite", "signal-hook-registry", "tokio-macros", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -2078,10 +2238,10 @@ version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1caa0b0c8d94a049db56b5acf8cba99dc0623aab1b26d5b5f5e2d945846b3592" dependencies = [ - "bytes", + "bytes 1.0.1", "futures-core", "futures-sink", - "log", + "log 0.4.14", "pin-project-lite", "tokio", ] @@ -2099,7 +2259,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" dependencies = [ "cfg-if 1.0.0", - "log", + "log 0.4.14", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -2141,27 +2301,46 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" +[[package]] +name = "tungstenite" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0308d80d86700c5878b9ef6321f020f29b1bb9d5ff3cab25e75e23f3a492a23" +dependencies = [ + "base64 0.12.3", + "byteorder", + "bytes 0.5.6", + "http", + "httparse", + "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", + "base64 0.13.0", "byteorder", - "bytes", + "bytes 1.0.1", "http", "httparse", - "input_buffer", - "log", - "rand", + "input_buffer 0.4.0", + "log 0.4.14", + "rand 0.8.4", "rustls", "sha-1", "thiserror", "url", "utf-8", "webpki", - "webpki-roots", + "webpki-roots 0.21.1", ] [[package]] @@ -2209,6 +2388,12 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" +[[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.2" @@ -2261,7 +2446,7 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" dependencies = [ - "getrandom", + "getrandom 0.2.3", ] [[package]] @@ -2272,9 +2457,9 @@ checksum = "f4bf03e0ca70d626ecc4ba6b0763b934b6f2976e8c744088bb3c1d646fbb1ad0" [[package]] name = "vcpkg" -version = "0.2.13" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "025ce40a007e1907e58d5bc1a594def78e5573bb0b1160bc389634e8f12e4faa" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "version_check" @@ -2288,10 +2473,16 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" dependencies = [ - "log", + "log 0.4.14", "try-lock", ] +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" @@ -2318,7 +2509,7 @@ checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900" dependencies = [ "bumpalo", "lazy_static", - "log", + "log 0.4.14", "proc-macro2", "quote", "syn", @@ -2386,6 +2577,15 @@ dependencies = [ "untrusted", ] +[[package]] +name = "webpki-roots" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f20dea7535251981a9670857150d571846545088359b28e4951d350bdaf179f" +dependencies = [ + "webpki", +] + [[package]] name = "webpki-roots" version = "0.21.1" @@ -2405,6 +2605,12 @@ dependencies = [ "web-sys", ] +[[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" @@ -2415,6 +2621,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" @@ -2427,7 +2639,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -2442,7 +2654,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -2453,13 +2665,13 @@ checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" [[package]] name = "xsalsa20poly1305" -version = "0.7.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a214b4d445e6534a858c970b44eb526c398dbfaa2961e3efb637307af634284d" +checksum = "0304c336e98d753428f7b3d8899d60b8a87a961ef50bdfc44af0c1bea2651ce5" dependencies = [ "aead", "poly1305", - "rand_core", + "rand_core 0.5.1", "salsa20", "subtle", "zeroize", diff --git a/Cargo.toml b/Cargo.toml index 4310403..6660e5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,8 +5,8 @@ authors = ["jellywx "] edition = "2018" [dependencies] -songbird = { git = "https://github.com/serenity-rs/songbird", branch = "next" } -serenity = { git = "https://github.com/serenity-rs/serenity", branch = "next", features = ["voice", "collector", "unstable_discord_api"] } +songbird = { path = "/home/jude/songbird" } +serenity = { path = "/home/jude/serenity", features = ["voice", "collector", "unstable_discord_api"] } sqlx = { version = "0.5", default-features = false, features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal"] } dotenv = "0.15" tokio = { version = "1", features = ["fs", "process", "io-util"] } diff --git a/src/framework.rs b/src/framework.rs index 45d402d..11388a2 100644 --- a/src/framework.rs +++ b/src/framework.rs @@ -10,7 +10,7 @@ use serenity::{ channel::{Channel, GuildChannel, Message}, guild::{Guild, Member}, id::{ChannelId, GuildId, UserId}, - interactions::{ApplicationCommand, Interaction, InteractionType}, + interactions::{ApplicationCommand, Interaction, InteractionData, InteractionType}, prelude::{ApplicationCommandOptionType, InteractionResponseType}, }, prelude::TypeMapKey, @@ -249,7 +249,7 @@ impl CommandInvoke for Interaction { d.content(generic_response.content); if let Some(embed) = generic_response.embed { - d.set_embed(embed.clone()); + d.add_embed(embed.clone()); } d @@ -268,7 +268,7 @@ impl CommandInvoke for Interaction { d.content(generic_response.content); if let Some(embed) = generic_response.embed { - d.set_embed(embed.clone()); + d.add_embed(embed.clone()); } d @@ -408,7 +408,7 @@ impl fmt::Debug for Command { } pub struct RegexFramework { - commands: HashMap, + pub commands: HashMap, commands_: HashSet<&'static Command>, command_matcher: Regex, default_prefix: String, @@ -615,7 +615,7 @@ impl RegexFramework { pub async fn execute(&self, ctx: Context, interaction: Interaction) { if interaction.kind == InteractionType::ApplicationCommand && interaction.guild_id.is_some() { - if let Some(data) = interaction.data.clone() { + if let Some(InteractionData::ApplicationCommand(data)) = interaction.data.clone() { let command = { let name = data.name; diff --git a/src/main.rs b/src/main.rs index 3833949..d56e2d8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,12 +19,14 @@ use log::info; use regex_command_attr::command; use serenity::{ + builder::CreateActionRow, client::{bridge::gateway::GatewayIntents, Client, Context}, framework::standard::CommandResult, http::Http, model::{ guild::Guild, id::{ChannelId, GuildId, RoleId, UserId}, + interactions::ButtonStyle, }, prelude::*, }; @@ -46,6 +48,7 @@ use dashmap::DashMap; use std::{collections::HashMap, convert::TryFrom, env, sync::Arc, time::Duration}; +use serenity::model::prelude::InteractionResponseType; use tokio::sync::{MutexGuard, RwLock}; struct MySQL; @@ -193,6 +196,7 @@ async fn main() -> Result<(), Box> { .add_command(&PLAY_COMMAND) .add_command(&STOP_PLAYING_COMMAND) .add_command(&DISCONNECT_COMMAND) + .add_command(&SOUNDBOARD_COMMAND) // sound management commands .add_command(&UPLOAD_NEW_SOUND_COMMAND) .add_command(&DELETE_SOUND_COMMAND) @@ -298,8 +302,8 @@ async fn main() -> Result<(), Box> { #[command] #[description("Get information on the commands of the bot")] #[arg( - name = "category", - description = "Get help for a specific category", + name = "command", + description = "Get help for a specific command", kind = "String", required = false )] @@ -308,123 +312,80 @@ async fn help( invoke: &(dyn CommandInvoke + Sync + Send), args: Args, ) -> CommandResult { - if let Some(category) = args.named("category") { - let body = match category.to_lowercase().as_str() { - "info" => { - "__Info Commands__ -`help` - view all commands -`help [category]` - view help for the commands in a category + if let Some(command_name) = args.named("command") { + let framework = ctx + .data + .read() + .await + .get::() + .cloned() + .unwrap(); -`info` - view information about the bot + if let Some(command) = framework.commands.get(command_name) { + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().embed(|e| { + e.title(format!("{} Help", command_name)) + .color(THEME_COLOR) + .description(format!( + "**Aliases** +{} -`invite` - get an invite link for the bot +**Overview** + • {} -`donate` - view information about the Patreon - " - } - "play" => { - "__Play Commands__ -`play [sound]` - play a sound matching the name \"sound\" -`play [id]` - play the sound with numerical ID `id` - -`p` - an alias for `play` - -`stop` - stop the bot from playing -`dc` - disconnect the bot from the current channel - -`loop [sound]` - play a sound matching the name \"sound\" on loop -`loop [id]` - play a sound matching the numerical ID `id` on loop - " - } - "manage" => { - "__Manage Commands__ -`upload [name]` - upload a new sound effect to the name \"name\" - -`delete [name]` - delete a sound you have uploaded under the name \"name\" - -`list` - list sounds uploaded on the server you are on -`list me` - list sounds you have uploaded to any server - -`public [name]` - make a sound you have uploaded public or private - " - } - "settings" => { - "__Settings Commands__ -`prefix [new prefix]` - change the prefix of the bot - -`roles [role list]` - set which roles can use the bot -`roles off` - allow all users to use the bot - -`volume [new volume]` - change the volume of the bot - -`allow_greet` - toggle whether users in your server can use greet sounds - " - } - "search" => { - "__Search Commands__ -`search [term]` - search for sounds matching \"term\" - -`random` - find some random sounds on the bot - -`popular` - find the most played sounds on the bot - " - } - "other" => { - "__Other Commands__ -`greet [name]` - set your greet sound (join sound) to the sound called \"name\" -`greet [id]` - set your greet sound (join sound) to the sound with numerical ID `id` - -`ambience` - view a list of ambience sounds -`ambience [name]` - set an ambience sound playing - " - } - _ => { - "__Unrecognised Category__ -Please select a category from the following: - -`info` -`play` -`manage` -`settings` -`search` -`other` - " - } - }; +**Arguments** +{} +**Examples** +{}", + command + .names + .iter() + .map(|n| format!("`{}`", n)) + .collect::>() + .join(" "), + command.desc, + command + .args + .iter() + .map(|a| format!( + " • `{}` {} - {}", + a.name, + if a.required { "" } else { "[optional]" }, + a.description + )) + .collect::>() + .join("\n"), + command + .examples + .iter() + .map(|e| format!(" • {}", e)) + .collect::>() + .join("\n") + )) + }), + ) + .await?; + } else { + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().embed(|e| { + e.title("Invalid Command") + .color(THEME_COLOR) + .description("") + }), + ) + .await?; + } + } else { invoke .respond( ctx.http.clone(), CreateGenericResponse::new() - .embed(|e| e.title("Help").color(THEME_COLOR).description(body)), - ) - .await?; - } else { - let description = { - let guild_data = ctx.guild_data(invoke.guild_id().unwrap()).await.unwrap(); - - let read_lock = guild_data.read().await; - - format!( - "Type `{}help category` to view help for a command category below:", - read_lock.prefix - ) - }; - - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().embed(|e| { - e.title("Help") - .color(THEME_COLOR) - .description(description) - .field("Info", "`help` `info` `invite` `donate`", false) - .field("Play", "`play` `p` `stop` `dc` `loop`", false) - .field("Manage", "`upload` `delete` `list` `public`", false) - .field("Settings", "`prefix` `roles` `volume` `allow_greet`", false) - .field("Search", "`search` `random` `popular`", false) - .field("Other", "`greet` `ambience`", false) - }), + .embed(|e| e.title("Help").color(THEME_COLOR).description("")), ) .await?; } @@ -499,8 +460,6 @@ async fn play_cmd(ctx: &Context, guild: Guild, user_id: UserId, args: Args, loop Some(user_channel) => { let search_term = args.named("query").unwrap(); - println!("{}", search_term); - let pool = ctx .data .read() @@ -1177,6 +1136,53 @@ async fn list_sounds( Ok(()) } +#[command("soundboard")] +#[aliases("board")] +#[description("Get a menu of sounds in this server with buttons to play them")] +async fn soundboard( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + _args: Args, +) -> CommandResult { + let pool = ctx + .data + .read() + .await + .get::() + .cloned() + .expect("Could not get SQLPool from data"); + + let sounds = Sound::get_guild_sounds(invoke.guild_id().unwrap(), pool).await?; + + if let Some(interaction) = invoke.interaction() { + interaction + .create_interaction_response(&ctx, |r| r.kind(InteractionResponseType::Pong)) + .await?; + } + + invoke + .channel_id() + .send_message(&ctx, |m| { + m.components(|c| { + for row in sounds.as_slice().chunks(5) { + let mut action_row: CreateActionRow = Default::default(); + for sound in row { + action_row.create_button(|b| { + b.style(ButtonStyle::Primary) + .label(&sound.name) + .custom_id(sound.id) + }); + } + } + + c + }) + }) + .await?; + + Ok(()) +} + #[command("public")] #[description("Change a sound between public and private")] #[arg( From b4b8d16bcc3c208bda1c69255993e724d18ff2e5 Mon Sep 17 00:00:00 2001 From: jellywx Date: Fri, 25 Jun 2021 14:51:52 +0100 Subject: [PATCH 2/9] soundboard cmd --- src/event_handlers.rs | 56 +++++++++++++--- src/framework.rs | 147 +++++++++++++++++++++++++----------------- src/main.rs | 43 ++++++------ 3 files changed, 154 insertions(+), 92 deletions(-) diff --git a/src/event_handlers.rs b/src/event_handlers.rs index e0f39cf..6b3be41 100644 --- a/src/event_handlers.rs +++ b/src/event_handlers.rs @@ -1,7 +1,7 @@ use crate::{ framework::RegexFramework, guild_data::CtxGuildData, - join_channel, play_audio, + join_channel, play_audio, play_cmd, sound::{JoinSoundCtx, Sound}, MySQL, ReqwestClient, }; @@ -22,6 +22,9 @@ use serenity::{ use songbird::{Event, EventContext, EventHandler as SongbirdEventHandler}; +use crate::framework::{Args, CommandInvoke}; +use serenity::model::interactions::{InteractionData, InteractionType}; +use serenity::model::prelude::InteractionResponseType; use std::{collections::HashMap, env}; pub struct RestartTrack; @@ -180,14 +183,49 @@ SELECT name, id, plays, public, server_id, uploader_id } async fn interaction_create(&self, ctx: Context, interaction: Interaction) { - let framework = ctx - .data - .read() - .await - .get::() - .cloned() - .expect("RegexFramework not found in context"); + if interaction.guild_id.is_none() { + return; + } - framework.execute(ctx, interaction).await; + match interaction.kind { + InteractionType::ApplicationCommand => { + let framework = ctx + .data + .read() + .await + .get::() + .cloned() + .expect("RegexFramework not found in context"); + + framework.execute(ctx, interaction).await; + } + InteractionType::MessageComponent => { + if let (Some(InteractionData::MessageComponent(data)), Some(member)) = + (interaction.clone().data, interaction.clone().member) + { + let mut args = Args { + args: Default::default(), + }; + args.args.insert("query".to_string(), data.custom_id); + + play_cmd( + &ctx, + interaction.guild(ctx.cache.clone()).await.unwrap(), + member.user.id, + args, + false, + ) + .await; + + interaction + .create_interaction_response(ctx, |r| { + r.kind(InteractionResponseType::DeferredUpdateMessage) + }) + .await + .unwrap(); + } + } + _ => {} + } } } diff --git a/src/framework.rs b/src/framework.rs index 11388a2..a177b7c 100644 --- a/src/framework.rs +++ b/src/framework.rs @@ -10,14 +10,14 @@ use serenity::{ channel::{Channel, GuildChannel, Message}, guild::{Guild, Member}, id::{ChannelId, GuildId, UserId}, - interactions::{ApplicationCommand, Interaction, InteractionData, InteractionType}, + interactions::{ApplicationCommand, Interaction, InteractionData}, prelude::{ApplicationCommandOptionType, InteractionResponseType}, }, prelude::TypeMapKey, Result as SerenityResult, }; -use log::{error, info, warn}; +use log::{debug, error, info, warn}; use regex::{Match, Regex, RegexBuilder}; @@ -30,6 +30,7 @@ use std::{ use crate::{guild_data::CtxGuildData, MySQL}; use serde_json::Value; +use serenity::builder::CreateComponents; type CommandFn = for<'fut> fn( &'fut Context, @@ -38,7 +39,7 @@ type CommandFn = for<'fut> fn( ) -> BoxFuture<'fut, CommandResult>; pub struct Args { - args: HashMap, + pub args: HashMap, } impl Args { @@ -87,6 +88,7 @@ impl Args { pub struct CreateGenericResponse { content: String, embed: Option, + components: Option, } impl CreateGenericResponse { @@ -94,6 +96,7 @@ impl CreateGenericResponse { Self { content: "".to_string(), embed: None, + components: None, } } @@ -112,6 +115,19 @@ impl CreateGenericResponse { self } + + pub fn components &mut CreateComponents>( + mut self, + f: F, + ) -> Self { + let mut components = CreateComponents::default(); + + f(&mut components); + + self.components = Some(components); + + self + } } #[async_trait] @@ -178,6 +194,10 @@ impl CommandInvoke for Message { m.set_embed(embed.clone()); } + if let Some(components) = generic_response.components { + m.set_components(components.clone()); + } + m }) .await @@ -197,6 +217,10 @@ impl CommandInvoke for Message { m.set_embed(embed.clone()); } + if let Some(components) = generic_response.components { + m.set_components(components.clone()); + } + m }) .await @@ -252,6 +276,10 @@ impl CommandInvoke for Interaction { d.add_embed(embed.clone()); } + if let Some(components) = generic_response.components { + d.set_components(components.clone()); + } + d }) }) @@ -271,6 +299,10 @@ impl CommandInvoke for Interaction { d.add_embed(embed.clone()); } + if let Some(components) = generic_response.components { + d.set_components(components.clone()); + } + d }) .await @@ -453,8 +485,6 @@ impl RegexFramework { } pub fn add_command(mut self, command: &'static Command) -> Self { - info!("{:?}", command); - self.commands_.insert(command); for name in command.names { @@ -475,7 +505,7 @@ impl RegexFramework { command_names = command_names_vec.join("|"); } - info!("Command names: {}", command_names); + debug!("Command names: {}", command_names); { let match_string = r#"^(?:(?:<@ID>\s*)|(?:<@!ID>\s*)|(?P\S{1,5}?))(?PCOMMANDS)(?:$|\s+(?P.*))$"# @@ -534,7 +564,7 @@ impl RegexFramework { .await .expect("Failed to fetch existing commands"); - info!("Existing commands: {:?}", current_commands); + debug!("Existing commands: {:?}", current_commands); // delete commands not in use for command in ¤t_commands { @@ -613,64 +643,61 @@ impl RegexFramework { } pub async fn execute(&self, ctx: Context, interaction: Interaction) { - if interaction.kind == InteractionType::ApplicationCommand && interaction.guild_id.is_some() - { - if let Some(InteractionData::ApplicationCommand(data)) = interaction.data.clone() { - let command = { - let name = data.name; + if let Some(InteractionData::ApplicationCommand(data)) = interaction.data.clone() { + let command = { + let name = data.name; - self.commands - .get(&name) - .expect(&format!("Received invalid command: {}", name)) - }; + self.commands + .get(&name) + .expect(&format!("Received invalid command: {}", name)) + }; - if command - .check_permissions( - &ctx, - &interaction.guild(ctx.cache.clone()).await.unwrap(), - &interaction.member(&ctx).await.unwrap(), - ) - .await - { - let mut args = HashMap::new(); + if command + .check_permissions( + &ctx, + &interaction.guild(ctx.cache.clone()).await.unwrap(), + &interaction.member(&ctx).await.unwrap(), + ) + .await + { + let mut args = HashMap::new(); - for arg in data.options.iter().filter(|o| o.value.is_some()) { - args.insert( - arg.name.clone(), - match arg.value.clone().unwrap() { - Value::Bool(b) => { - if b { - arg.name.clone() - } else { - String::new() - } + for arg in data.options.iter().filter(|o| o.value.is_some()) { + args.insert( + arg.name.clone(), + match arg.value.clone().unwrap() { + Value::Bool(b) => { + if b { + arg.name.clone() + } else { + String::new() } - Value::Number(n) => n.to_string(), - Value::String(s) => s, - _ => String::new(), - }, - ); - } - - (command.fun)(&ctx, &interaction, Args { args }) - .await - .unwrap(); - } else if command.required_permissions == PermissionLevel::Managed { - let _ = interaction - .respond( - ctx.http.clone(), - CreateGenericResponse::new().content("You must either be an Admin or have a role specified in `?roles` to do this command") - ) - .await; - } else if command.required_permissions == PermissionLevel::Restricted { - let _ = interaction - .respond( - ctx.http.clone(), - CreateGenericResponse::new() - .content("You must be an Admin to do this command"), - ) - .await; + } + Value::Number(n) => n.to_string(), + Value::String(s) => s, + _ => String::new(), + }, + ); } + + (command.fun)(&ctx, &interaction, Args { args }) + .await + .unwrap(); + } else if command.required_permissions == PermissionLevel::Managed { + let _ = interaction + .respond( + ctx.http.clone(), + CreateGenericResponse::new().content("You must either be an Admin or have a role specified in `?roles` to do this command") + ) + .await; + } else if command.required_permissions == PermissionLevel::Restricted { + let _ = interaction + .respond( + ctx.http.clone(), + CreateGenericResponse::new() + .content("You must be an Admin to do this command"), + ) + .await; } } } diff --git a/src/main.rs b/src/main.rs index d56e2d8..0929b2e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,7 +48,6 @@ use dashmap::DashMap; use std::{collections::HashMap, convert::TryFrom, env, sync::Arc, time::Duration}; -use serenity::model::prelude::InteractionResponseType; use tokio::sync::{MutexGuard, RwLock}; struct MySQL; @@ -1154,30 +1153,28 @@ async fn soundboard( let sounds = Sound::get_guild_sounds(invoke.guild_id().unwrap(), pool).await?; - if let Some(interaction) = invoke.interaction() { - interaction - .create_interaction_response(&ctx, |r| r.kind(InteractionResponseType::Pong)) - .await?; - } - invoke - .channel_id() - .send_message(&ctx, |m| { - m.components(|c| { - for row in sounds.as_slice().chunks(5) { - let mut action_row: CreateActionRow = Default::default(); - for sound in row { - action_row.create_button(|b| { - b.style(ButtonStyle::Primary) - .label(&sound.name) - .custom_id(sound.id) - }); - } - } + .respond( + ctx.http.clone(), + CreateGenericResponse::new() + .content("Select a sound from below:") + .components(|c| { + for row in sounds.as_slice().chunks(5) { + let mut action_row: CreateActionRow = Default::default(); + for sound in row { + action_row.create_button(|b| { + b.style(ButtonStyle::Primary) + .label(&sound.name) + .custom_id(sound.id) + }); + } - c - }) - }) + c.add_action_row(action_row); + } + + c + }), + ) .await?; Ok(()) From 87301e421264a3afe8d46b10304c67313b0577fd Mon Sep 17 00:00:00 2001 From: jellywx Date: Fri, 25 Jun 2021 18:45:59 +0100 Subject: [PATCH 3/9] soundboard working pretty nicely --- regex_command_attr/src/lib.rs | 11 +- regex_command_attr/src/structures.rs | 2 +- src/framework.rs | 11 +- src/main.rs | 184 ++++++++++++++++++++++++++- src/sound.rs | 1 + 5 files changed, 193 insertions(+), 16 deletions(-) diff --git a/regex_command_attr/src/lib.rs b/regex_command_attr/src/lib.rs index f02df84..be33c48 100644 --- a/regex_command_attr/src/lib.rs +++ b/regex_command_attr/src/lib.rs @@ -68,7 +68,7 @@ pub fn command(attr: TokenStream, input: TokenStream) -> TokenStream { _ => { match_options!(name, values, options, span => [ aliases; - usage; + group; required_permissions; allow_slash ]); @@ -79,7 +79,7 @@ pub fn command(attr: TokenStream, input: TokenStream) -> TokenStream { let Options { aliases, description, - usage, + group, examples, required_permissions, allow_slash, @@ -108,7 +108,10 @@ pub fn command(attr: TokenStream, input: TokenStream) -> TokenStream { let arg_idents = cmd_args .iter() - .map(|arg| n.with_suffix(arg.name.as_str()).with_suffix(ARG)) + .map(|arg| { + n.with_suffix(arg.name.replace(" ", "_").replace("-", "_").as_str()) + .with_suffix(ARG) + }) .collect::>(); let mut tokens = cmd_args @@ -146,7 +149,7 @@ pub fn command(attr: TokenStream, input: TokenStream) -> TokenStream { fun: #name, names: &[#_name, #(#aliases),*], desc: #description, - usage: #usage, + group: #group, examples: &[#(#examples),*], required_permissions: #required_permissions, allow_slash: #allow_slash, diff --git a/regex_command_attr/src/structures.rs b/regex_command_attr/src/structures.rs index f552e2b..9ca087f 100644 --- a/regex_command_attr/src/structures.rs +++ b/regex_command_attr/src/structures.rs @@ -290,7 +290,7 @@ impl Default for Arg { pub(crate) struct Options { pub aliases: Vec, pub description: String, - pub usage: AsOption, + pub group: AsOption, pub examples: Vec, pub required_permissions: PermissionLevel, pub allow_slash: bool, diff --git a/src/framework.rs b/src/framework.rs index a177b7c..a4035ee 100644 --- a/src/framework.rs +++ b/src/framework.rs @@ -108,11 +108,9 @@ impl CreateGenericResponse { pub fn embed &mut CreateEmbed>(mut self, f: F) -> Self { let mut embed = CreateEmbed::default(); - f(&mut embed); self.embed = Some(embed); - self } @@ -121,11 +119,9 @@ impl CreateGenericResponse { f: F, ) -> Self { let mut components = CreateComponents::default(); - f(&mut components); self.components = Some(components); - self } } @@ -344,12 +340,15 @@ impl Arg { pub struct Command { pub fun: CommandFn, + pub names: &'static [&'static str], + pub desc: &'static str, - pub usage: Option<&'static str>, pub examples: &'static [&'static str], - pub required_permissions: PermissionLevel, + pub group: Option<&'static str>, + pub allow_slash: bool, + pub required_permissions: PermissionLevel, pub args: &'static [&'static Arg], } diff --git a/src/main.rs b/src/main.rs index 0929b2e..74e6c27 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,6 +48,7 @@ use dashmap::DashMap; use std::{collections::HashMap, convert::TryFrom, env, sync::Arc, time::Duration}; +use serenity::model::prelude::InteractionResponseType; use tokio::sync::{MutexGuard, RwLock}; struct MySQL; @@ -1137,12 +1138,170 @@ async fn list_sounds( #[command("soundboard")] #[aliases("board")] -#[description("Get a menu of sounds in this server with buttons to play them")] +#[description("Get a menu of sounds with buttons to play them")] +#[arg( + name = "1", + description = "Query for sound button 1", + kind = "String", + required = false +)] +#[arg( + name = "2", + description = "Query for sound button 2", + kind = "String", + required = false +)] +#[arg( + name = "3", + description = "Query for sound button 3", + kind = "String", + required = false +)] +#[arg( + name = "4", + description = "Query for sound button 4", + kind = "String", + required = false +)] +#[arg( + name = "5", + description = "Query for sound button 5", + kind = "String", + required = false +)] +#[arg( + name = "6", + description = "Query for sound button 6", + kind = "String", + required = false +)] +#[arg( + name = "7", + description = "Query for sound button 7", + kind = "String", + required = false +)] +#[arg( + name = "8", + description = "Query for sound button 8", + kind = "String", + required = false +)] +#[arg( + name = "9", + description = "Query for sound button 9", + kind = "String", + required = false +)] +#[arg( + name = "10", + description = "Query for sound button 10", + kind = "String", + required = false +)] +#[arg( + name = "11", + description = "Query for sound button 11", + kind = "String", + required = false +)] +#[arg( + name = "12", + description = "Query for sound button 12", + kind = "String", + required = false +)] +#[arg( + name = "13", + description = "Query for sound button 13", + kind = "String", + required = false +)] +#[arg( + name = "14", + description = "Query for sound button 14", + kind = "String", + required = false +)] +#[arg( + name = "15", + description = "Query for sound button 15", + kind = "String", + required = false +)] +#[arg( + name = "16", + description = "Query for sound button 16", + kind = "String", + required = false +)] +#[arg( + name = "17", + description = "Query for sound button 17", + kind = "String", + required = false +)] +#[arg( + name = "18", + description = "Query for sound button 18", + kind = "String", + required = false +)] +#[arg( + name = "19", + description = "Query for sound button 19", + kind = "String", + required = false +)] +#[arg( + name = "20", + description = "Query for sound button 20", + kind = "String", + required = false +)] +#[arg( + name = "21", + description = "Query for sound button 21", + kind = "String", + required = false +)] +#[arg( + name = "22", + description = "Query for sound button 22", + kind = "String", + required = false +)] +#[arg( + name = "23", + description = "Query for sound button 23", + kind = "String", + required = false +)] +#[arg( + name = "24", + description = "Query for sound button 24", + kind = "String", + required = false +)] +#[arg( + name = "25", + description = "Query for sound button 25", + kind = "String", + required = false +)] async fn soundboard( ctx: &Context, invoke: &(dyn CommandInvoke + Sync + Send), - _args: Args, + args: Args, ) -> CommandResult { + if let Some(interaction) = invoke.interaction() { + let _ = interaction + .create_interaction_response(&ctx, |r| { + r.kind(InteractionResponseType::DeferredChannelMessageWithSource) + }) + .await; + } + let pool = ctx .data .read() @@ -1151,13 +1310,28 @@ async fn soundboard( .cloned() .expect("Could not get SQLPool from data"); - let sounds = Sound::get_guild_sounds(invoke.guild_id().unwrap(), pool).await?; + let mut sounds = vec![]; + + for n in 1..25 { + let search = Sound::search_for_sound( + args.named(&n.to_string()).unwrap_or(&"".to_string()), + invoke.guild_id().unwrap(), + invoke.author_id(), + pool.clone(), + true, + ) + .await?; + + if let Some(sound) = search.first() { + sounds.push(sound.clone()); + } + } invoke - .respond( + .followup( ctx.http.clone(), CreateGenericResponse::new() - .content("Select a sound from below:") + .content("**Play a sound:**") .components(|c| { for row in sounds.as_slice().chunks(5) { let mut action_row: CreateActionRow = Default::default(); diff --git a/src/sound.rs b/src/sound.rs index d85a857..6e86c11 100644 --- a/src/sound.rs +++ b/src/sound.rs @@ -111,6 +111,7 @@ WHERE } } +#[derive(Clone)] pub struct Sound { pub name: String, pub id: u32, From 14ef6385a04c9e56c8cf1d67cde29a0100794a8d Mon Sep 17 00:00:00 2001 From: jellywx Date: Fri, 25 Jun 2021 22:20:44 +0100 Subject: [PATCH 4/9] moved code around. made help menu work nice --- regex_command_attr/src/structures.rs | 5 +- src/cmds/info.rs | 198 ++++ src/cmds/manage.rs | 343 ++++++ src/cmds/mod.rs | 6 + src/cmds/play.rs | 405 +++++++ src/cmds/search.rs | 214 ++++ src/cmds/settings.rs | 351 ++++++ src/cmds/stop.rs | 56 + src/framework.rs | 8 +- src/main.rs | 1597 ++------------------------ 10 files changed, 1665 insertions(+), 1518 deletions(-) create mode 100644 src/cmds/info.rs create mode 100644 src/cmds/manage.rs create mode 100644 src/cmds/mod.rs create mode 100644 src/cmds/play.rs create mode 100644 src/cmds/search.rs create mode 100644 src/cmds/settings.rs create mode 100644 src/cmds/stop.rs diff --git a/regex_command_attr/src/structures.rs b/regex_command_attr/src/structures.rs index 9ca087f..36e9331 100644 --- a/regex_command_attr/src/structures.rs +++ b/regex_command_attr/src/structures.rs @@ -7,7 +7,7 @@ use syn::{ Attribute, Block, FnArg, Ident, Pat, ReturnType, Stmt, Token, Type, Visibility, }; -use crate::util::{self, Argument, AsOption, Parenthesised}; +use crate::util::{self, Argument, Parenthesised}; fn parse_argument(arg: FnArg) -> Result { match arg { @@ -290,7 +290,7 @@ impl Default for Arg { pub(crate) struct Options { pub aliases: Vec, pub description: String, - pub group: AsOption, + pub group: String, pub examples: Vec, pub required_permissions: PermissionLevel, pub allow_slash: bool, @@ -302,6 +302,7 @@ impl Options { pub fn new() -> Self { Self { allow_slash: true, + group: "Other".to_string(), ..Default::default() } } diff --git a/src/cmds/info.rs b/src/cmds/info.rs new file mode 100644 index 0000000..7b82717 --- /dev/null +++ b/src/cmds/info.rs @@ -0,0 +1,198 @@ +use regex_command_attr::command; + +use serenity::{client::Context, framework::standard::CommandResult}; + +use crate::{ + framework::{Args, CommandInvoke, CreateGenericResponse, RegexFramework}, + THEME_COLOR, +}; + +use std::{collections::HashMap, sync::Arc}; + +#[command] +#[group("Information")] +#[description("Get information on the commands of the bot")] +#[arg( + name = "command", + description = "Get help for a specific command", + kind = "String", + required = false +)] +#[example("`/help` - see all commands")] +#[example("`/help play` - get help about the `play` command")] +pub async fn help( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + args: Args, +) -> CommandResult { + fn get_groups(framework: Arc) -> HashMap<&'static str, Vec<&'static str>> { + let mut groups = HashMap::new(); + + for command in &framework.commands_ { + let entry = groups.entry(command.group).or_insert(vec![]); + + entry.push(command.names[0]); + } + + groups + } + + let framework = ctx + .data + .read() + .await + .get::() + .cloned() + .unwrap(); + + if let Some(command_name) = args.named("command") { + if let Some(command) = framework.commands.get(command_name) { + let examples = if command.examples.is_empty() { + "".to_string() + } else { + format!( + "**Examples** +{}", + command + .examples + .iter() + .map(|e| format!(" • {}", e)) + .collect::>() + .join("\n") + ) + }; + + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().embed(|e| { + e.title(format!("{} Help", command_name)) + .color(THEME_COLOR) + .description(format!( + "**Aliases** +{} + +**Overview** + • {} +**Arguments** +{} + +{}", + command + .names + .iter() + .map(|n| format!("`{}`", n)) + .collect::>() + .join(" "), + command.desc, + command + .args + .iter() + .map(|a| format!( + " • `{}` {} - {}", + a.name, + if a.required { "" } else { "[optional]" }, + a.description + )) + .collect::>() + .join("\n"), + examples + )) + }), + ) + .await?; + } else { + let groups = get_groups(framework); + let groups_iter = groups.iter().map(|(name, commands)| { + ( + name, + commands + .iter() + .map(|c| format!("`{}`", c)) + .collect::>() + .join(" "), + true, + ) + }); + + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().embed(|e| { + e.title("Invalid Command") + .color(THEME_COLOR) + .description("Type `/help command` to view help about a command below:") + .fields(groups_iter) + }), + ) + .await?; + } + } else { + let groups = get_groups(framework); + let groups_iter = groups.iter().map(|(name, commands)| { + ( + name, + commands + .iter() + .map(|c| format!("`{}`", c)) + .collect::>() + .join(" "), + true, + ) + }); + + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().embed(|e| { + e.title("Help") + .color(THEME_COLOR) + .description("Type `/help command` to view help about a command below:") + .fields(groups_iter) + }), + ) + .await?; + } + + Ok(()) +} + +#[command] +#[group("Information")] +#[aliases("invite")] +#[description("Get additional information on the bot")] +async fn info( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + _args: Args, +) -> CommandResult { + let current_user = ctx.cache.current_user().await; + + invoke.respond(ctx.http.clone(), CreateGenericResponse::new() + .embed(|e| e + .title("Info") + .color(THEME_COLOR) + .footer(|f| f + .text(concat!(env!("CARGO_PKG_NAME"), " ver ", env!("CARGO_PKG_VERSION")))) + .description(format!("Default prefix: `?` + +Reset prefix: `@{0} prefix ?` + +Invite me: https://discord.com/api/oauth2/authorize?client_id={1}&permissions=3165184&scope=applications.commands%20bot + +**Welcome to SoundFX!** +Developer: <@203532103185465344> +Find me on https://discord.jellywx.com/ and on https://github.com/JellyWX :) + +**Sound Credits** +\"The rain falls against the parasol\" https://freesound.org/people/straget/ +\"Heavy Rain\" https://freesound.org/people/lebaston100/ +\"Rain on Windows, Interior, A\" https://freesound.org/people/InspectorJ/ +\"Seaside Waves, Close, A\" https://freesound.org/people/InspectorJ/ +\"Small River 1 - Fast - Close\" https://freesound.org/people/Pfannkuchn/ + +**An online dashboard is available!** Visit https://soundfx.jellywx.com/dashboard +There is a maximum sound limit per user. This can be removed by subscribing at **https://patreon.com/jellywx**", current_user.name, current_user.id.as_u64())))).await?; + + Ok(()) +} diff --git a/src/cmds/manage.rs b/src/cmds/manage.rs new file mode 100644 index 0000000..d22eb24 --- /dev/null +++ b/src/cmds/manage.rs @@ -0,0 +1,343 @@ +use regex_command_attr::command; + +use serenity::{ + client::Context, + framework::standard::CommandResult, + model::id::{GuildId, RoleId}, +}; + +use crate::{ + framework::{Args, CommandInvoke, CreateGenericResponse}, + sound::Sound, + MySQL, MAX_SOUNDS, PATREON_GUILD, PATREON_ROLE, +}; + +use std::time::Duration; + +#[command("upload")] +#[group("Manage")] +#[description("Upload a new sound to the bot")] +#[arg( + name = "name", + description = "Name to upload sound to", + kind = "String", + required = true +)] +pub async fn upload_new_sound( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + args: Args, +) -> CommandResult { + fn is_numeric(s: &String) -> bool { + for char in s.chars() { + if char.is_digit(10) { + continue; + } else { + return false; + } + } + true + } + + let new_name = args + .named("name") + .map(|n| n.to_string()) + .unwrap_or(String::new()); + + if !new_name.is_empty() && new_name.len() <= 20 { + if !is_numeric(&new_name) { + let pool = ctx + .data + .read() + .await + .get::() + .cloned() + .expect("Could not get SQLPool from data"); + + // need to check the name is not currently in use by the user + let count_name = + Sound::count_named_user_sounds(invoke.author_id().0, &new_name, pool.clone()) + .await?; + if count_name > 0 { + invoke.respond(ctx.http.clone(), CreateGenericResponse::new().content("You are already using that name. Please choose a unique name for your upload.")).await?; + } else { + // need to check how many sounds user currently has + let count = Sound::count_user_sounds(invoke.author_id().0, pool.clone()).await?; + let mut permit_upload = true; + + // need to check if user is patreon or nah + if count >= *MAX_SOUNDS { + let patreon_guild_member = GuildId(*PATREON_GUILD) + .member(ctx, invoke.author_id()) + .await; + + if let Ok(member) = patreon_guild_member { + permit_upload = member.roles.contains(&RoleId(*PATREON_ROLE)); + } else { + permit_upload = false; + } + } + + if permit_upload { + let attachment = if let Some(attachment) = invoke + .msg() + .map(|m| m.attachments.get(0).map(|a| a.url.clone())) + .flatten() + { + Some(attachment) + } else { + invoke.respond(ctx.http.clone(), CreateGenericResponse::new().content("Please now upload an audio file under 1MB in size (larger files will be automatically trimmed):")).await?; + + let reply = invoke + .channel_id() + .await_reply(&ctx) + .author_id(invoke.author_id()) + .timeout(Duration::from_secs(120)) + .await; + + match reply { + Some(reply_msg) => { + if let Some(attachment) = reply_msg.attachments.get(0) { + Some(attachment.url.clone()) + } else { + invoke.followup(ctx.http.clone(), CreateGenericResponse::new().content("Please upload 1 attachment following your upload command. Aborted")).await?; + + None + } + } + + None => { + invoke + .followup( + ctx.http.clone(), + CreateGenericResponse::new() + .content("Upload timed out. Please redo the command"), + ) + .await?; + + None + } + } + }; + + if let Some(url) = attachment { + match Sound::create_anon( + &new_name, + url.as_str(), + invoke.guild_id().unwrap().0, + invoke.author_id().0, + pool, + ) + .await + { + Ok(_) => { + invoke + .followup( + ctx.http.clone(), + CreateGenericResponse::new() + .content("Sound has been uploaded"), + ) + .await?; + } + + Err(e) => { + println!("Error occurred during upload: {:?}", e); + invoke + .followup( + ctx.http.clone(), + CreateGenericResponse::new() + .content("Sound failed to upload."), + ) + .await?; + } + } + } + } else { + invoke.respond( + ctx.http.clone(), + CreateGenericResponse::new().content(format!( + "You have reached the maximum number of sounds ({}). Either delete some with `?delete` or join our Patreon for unlimited uploads at **https://patreon.com/jellywx**", + *MAX_SOUNDS, + ))).await?; + } + } + } else { + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new() + .content("Please ensure the sound name contains a non-numerical character"), + ) + .await?; + } + } else { + invoke.respond(ctx.http.clone(), CreateGenericResponse::new().content("Usage: `?upload `. Please ensure the name provided is less than 20 characters in length")).await?; + } + + Ok(()) +} + +#[command("delete")] +#[group("Manage")] +#[description("Delete a sound you have uploaded")] +#[arg( + name = "query", + description = "Delete sound with the specified name or ID", + kind = "String", + required = true +)] +pub async fn delete_sound( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + args: Args, +) -> CommandResult { + let pool = ctx + .data + .read() + .await + .get::() + .cloned() + .expect("Could not get SQLPool from data"); + + let uid = invoke.author_id().0; + let gid = invoke.guild_id().unwrap().0; + + let name = args + .named("query") + .map(|s| s.to_owned()) + .unwrap_or(String::new()); + + let sound_vec = Sound::search_for_sound(&name, gid, uid, pool.clone(), true).await?; + let sound_result = sound_vec.first(); + + match sound_result { + Some(sound) => { + if sound.uploader_id != Some(uid) && sound.server_id != gid { + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().content( + "You can only delete sounds from this guild or that you have uploaded.", + ), + ) + .await?; + } else { + let has_perms = { + if let Ok(member) = invoke.member(&ctx).await { + if let Ok(perms) = member.permissions(&ctx).await { + perms.manage_guild() + } else { + false + } + } else { + false + } + }; + + if sound.uploader_id == Some(uid) || has_perms { + sound.delete(pool).await?; + + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().content("Sound has been deleted"), + ) + .await?; + } else { + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().content( + "Only server admins can delete sounds uploaded by other users.", + ), + ) + .await?; + } + } + } + + None => { + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().content("Sound could not be found by that name."), + ) + .await?; + } + } + + Ok(()) +} + +#[command("public")] +#[group("Manage")] +#[description("Change a sound between public and private")] +#[arg( + name = "query", + kind = "String", + description = "Sound name or ID to change the privacy setting of", + required = true +)] +pub async fn change_public( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + args: Args, +) -> CommandResult { + let pool = ctx + .data + .read() + .await + .get::() + .cloned() + .expect("Could not get SQLPool from data"); + + let uid = invoke.author_id().as_u64().to_owned(); + + let name = args.named("query").unwrap(); + let gid = *invoke.guild_id().unwrap().as_u64(); + + let mut sound_vec = Sound::search_for_sound(name, gid, uid, pool.clone(), true).await?; + let sound_result = sound_vec.first_mut(); + + match sound_result { + Some(sound) => { + if sound.uploader_id != Some(uid) { + invoke.respond(ctx.http.clone(), CreateGenericResponse::new().content("You can only change the visibility of sounds you have uploaded. Use `?list me` to view your sounds")).await?; + } else { + if sound.public { + sound.public = false; + + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new() + .content("Sound has been set to private 🔒"), + ) + .await?; + } else { + sound.public = true; + + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().content("Sound has been set to public 🔓"), + ) + .await?; + } + + sound.commit(pool).await? + } + } + + None => { + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().content("Sound could not be found by that name."), + ) + .await?; + } + } + + Ok(()) +} diff --git a/src/cmds/mod.rs b/src/cmds/mod.rs new file mode 100644 index 0000000..1a8aa9c --- /dev/null +++ b/src/cmds/mod.rs @@ -0,0 +1,6 @@ +pub mod info; +pub mod manage; +pub mod play; +pub mod search; +pub mod settings; +pub mod stop; diff --git a/src/cmds/play.rs b/src/cmds/play.rs new file mode 100644 index 0000000..2151145 --- /dev/null +++ b/src/cmds/play.rs @@ -0,0 +1,405 @@ +use regex_command_attr::command; + +use serenity::{ + builder::CreateActionRow, + client::Context, + framework::standard::CommandResult, + model::interactions::{ButtonStyle, InteractionResponseType}, +}; + +use songbird::{ + create_player, ffmpeg, + input::{cached::Memory, Input}, + Event, +}; + +use crate::{ + event_handlers::RestartTrack, + framework::{Args, CommandInvoke, CreateGenericResponse}, + guild_data::CtxGuildData, + join_channel, play_cmd, + sound::Sound, + AudioIndex, MySQL, +}; + +use std::{convert::TryFrom, time::Duration}; + +#[command] +#[aliases("p")] +#[required_permissions(Managed)] +#[group("Play")] +#[description("Play a sound in your current voice channel")] +#[arg( + name = "query", + description = "Play sound with the specified name or ID", + kind = "String", + required = true +)] +#[example("`/play ubercharge` - play sound with name \"ubercharge\" ")] +#[example("`/play 13002` - play sound with ID 13002")] +pub async fn play( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + args: Args, +) -> CommandResult { + let guild = invoke.guild(ctx.cache.clone()).await.unwrap(); + + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new() + .content(play_cmd(ctx, guild, invoke.author_id(), args, false).await), + ) + .await?; + + Ok(()) +} + +#[command("loop")] +#[required_permissions(Managed)] +#[group("Play")] +#[description("Play a sound on loop in your current voice channel")] +#[arg( + name = "query", + description = "Play sound with the specified name or ID", + kind = "String", + required = true +)] +#[example("`/loop rain` - loop sound with name \"rain\" ")] +#[example("`/loop 13002` - play sound with ID 13002")] +pub async fn loop_play( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + args: Args, +) -> CommandResult { + let guild = invoke.guild(ctx.cache.clone()).await.unwrap(); + + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new() + .content(play_cmd(ctx, guild, invoke.author_id(), args, true).await), + ) + .await?; + + Ok(()) +} + +#[command("ambience")] +#[required_permissions(Managed)] +#[group("Play")] +#[description("Play ambient sound in your current voice channel")] +#[arg( + name = "name", + description = "Play sound with the specified name", + kind = "String", + required = false +)] +#[example("`/ambience rain on tent` - play the ambient sound \"rain on tent\" ")] +pub async fn play_ambience( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + args: Args, +) -> CommandResult { + let guild = invoke.guild(ctx.cache.clone()).await.unwrap(); + + let channel_to_join = guild + .voice_states + .get(&invoke.author_id()) + .and_then(|voice_state| voice_state.channel_id); + + match channel_to_join { + Some(user_channel) => { + let search_name = args.named("name").unwrap().to_lowercase(); + let audio_index = ctx.data.read().await.get::().cloned().unwrap(); + + if let Some(filename) = audio_index.get(&search_name) { + let (track, track_handler) = create_player( + Input::try_from( + Memory::new(ffmpeg(format!("audio/{}", filename)).await.unwrap()).unwrap(), + ) + .unwrap(), + ); + + let (call_handler, _) = join_channel(ctx, guild.clone(), user_channel).await; + let guild_data = ctx.guild_data(guild).await.unwrap(); + + { + let mut lock = call_handler.lock().await; + + lock.play(track); + } + + let _ = track_handler.set_volume(guild_data.read().await.volume as f32 / 100.0); + let _ = track_handler.add_event( + Event::Periodic( + track_handler.metadata().duration.unwrap() - Duration::from_millis(200), + None, + ), + RestartTrack {}, + ); + + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new() + .content(format!("Playing ambience **{}**", search_name)), + ) + .await?; + } else { + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().embed(|e| { + e.title("Not Found").description(format!( + "Could not find ambience sound by name **{}** + +__Available ambience sounds:__ +{}", + search_name, + audio_index + .keys() + .into_iter() + .map(|i| i.as_str()) + .collect::>() + .join("\n") + )) + }), + ) + .await?; + } + } + + None => { + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().content("You are not in a voice chat!"), + ) + .await?; + } + } + + Ok(()) +} + +#[command("soundboard")] +#[aliases("board")] +#[group("Play")] +#[description("Get a menu of sounds with buttons to play them")] +#[arg( + name = "1", + description = "Query for sound button 1", + kind = "String", + required = false +)] +#[arg( + name = "2", + description = "Query for sound button 2", + kind = "String", + required = false +)] +#[arg( + name = "3", + description = "Query for sound button 3", + kind = "String", + required = false +)] +#[arg( + name = "4", + description = "Query for sound button 4", + kind = "String", + required = false +)] +#[arg( + name = "5", + description = "Query for sound button 5", + kind = "String", + required = false +)] +#[arg( + name = "6", + description = "Query for sound button 6", + kind = "String", + required = false +)] +#[arg( + name = "7", + description = "Query for sound button 7", + kind = "String", + required = false +)] +#[arg( + name = "8", + description = "Query for sound button 8", + kind = "String", + required = false +)] +#[arg( + name = "9", + description = "Query for sound button 9", + kind = "String", + required = false +)] +#[arg( + name = "10", + description = "Query for sound button 10", + kind = "String", + required = false +)] +#[arg( + name = "11", + description = "Query for sound button 11", + kind = "String", + required = false +)] +#[arg( + name = "12", + description = "Query for sound button 12", + kind = "String", + required = false +)] +#[arg( + name = "13", + description = "Query for sound button 13", + kind = "String", + required = false +)] +#[arg( + name = "14", + description = "Query for sound button 14", + kind = "String", + required = false +)] +#[arg( + name = "15", + description = "Query for sound button 15", + kind = "String", + required = false +)] +#[arg( + name = "16", + description = "Query for sound button 16", + kind = "String", + required = false +)] +#[arg( + name = "17", + description = "Query for sound button 17", + kind = "String", + required = false +)] +#[arg( + name = "18", + description = "Query for sound button 18", + kind = "String", + required = false +)] +#[arg( + name = "19", + description = "Query for sound button 19", + kind = "String", + required = false +)] +#[arg( + name = "20", + description = "Query for sound button 20", + kind = "String", + required = false +)] +#[arg( + name = "21", + description = "Query for sound button 21", + kind = "String", + required = false +)] +#[arg( + name = "22", + description = "Query for sound button 22", + kind = "String", + required = false +)] +#[arg( + name = "23", + description = "Query for sound button 23", + kind = "String", + required = false +)] +#[arg( + name = "24", + description = "Query for sound button 24", + kind = "String", + required = false +)] +#[arg( + name = "25", + description = "Query for sound button 25", + kind = "String", + required = false +)] +#[example("`/soundboard ubercharge` - create a soundboard with a button for the \"ubercharge\" sound effect")] +#[example("`/soundboard 57000 24119 2 1002 13202` - create a soundboard with 5 buttons, for sounds with the IDs presented")] +pub async fn soundboard( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + args: Args, +) -> CommandResult { + if let Some(interaction) = invoke.interaction() { + let _ = interaction + .create_interaction_response(&ctx, |r| { + r.kind(InteractionResponseType::DeferredChannelMessageWithSource) + }) + .await; + } + + let pool = ctx + .data + .read() + .await + .get::() + .cloned() + .expect("Could not get SQLPool from data"); + + let mut sounds = vec![]; + + for n in 1..25 { + let search = Sound::search_for_sound( + args.named(&n.to_string()).unwrap_or(&"".to_string()), + invoke.guild_id().unwrap(), + invoke.author_id(), + pool.clone(), + true, + ) + .await?; + + if let Some(sound) = search.first() { + sounds.push(sound.clone()); + } + } + + invoke + .followup( + ctx.http.clone(), + CreateGenericResponse::new() + .content("**Play a sound:**") + .components(|c| { + for row in sounds.as_slice().chunks(5) { + let mut action_row: CreateActionRow = Default::default(); + for sound in row { + action_row.create_button(|b| { + b.style(ButtonStyle::Primary) + .label(&sound.name) + .custom_id(sound.id) + }); + } + + c.add_action_row(action_row); + } + + c + }), + ) + .await?; + + Ok(()) +} diff --git a/src/cmds/search.rs b/src/cmds/search.rs new file mode 100644 index 0000000..2335cb5 --- /dev/null +++ b/src/cmds/search.rs @@ -0,0 +1,214 @@ +use regex_command_attr::command; + +use serenity::{client::Context, framework::standard::CommandResult}; + +use crate::{ + framework::{Args, CommandInvoke, CreateGenericResponse}, + sound::Sound, + MySQL, +}; + +fn format_search_results(search_results: Vec) -> CreateGenericResponse { + let mut current_character_count = 0; + let title = "Public sounds matching filter:"; + + let field_iter = search_results + .iter() + .take(25) + .map(|item| { + ( + &item.name, + format!("ID: {}\nPlays: {}", item.id, item.plays), + true, + ) + }) + .filter(|item| { + current_character_count += item.0.len() + item.1.len(); + + current_character_count <= serenity::constants::MESSAGE_CODE_LIMIT - title.len() + }); + + CreateGenericResponse::new().embed(|e| e.title(title).fields(field_iter)) +} + +#[command("list")] +#[group("Search")] +#[description("Show the sounds uploaded by you or to your server")] +#[arg( + name = "me", + description = "Whether to list your sounds or server sounds (default: server)", + kind = "Boolean", + required = false +)] +pub async fn list_sounds( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + args: Args, +) -> CommandResult { + let pool = ctx + .data + .read() + .await + .get::() + .cloned() + .expect("Could not get SQLPool from data"); + + let sounds; + let mut message_buffer; + + if args.named("me").map(|i| i.to_owned()) == Some("me".to_string()) { + sounds = Sound::get_user_sounds(invoke.author_id(), pool).await?; + + message_buffer = "All your sounds: ".to_string(); + } else { + sounds = Sound::get_guild_sounds(invoke.guild_id().unwrap(), pool).await?; + + message_buffer = "All sounds on this server: ".to_string(); + } + + for sound in sounds { + message_buffer.push_str( + format!( + "**{}** ({}), ", + sound.name, + if sound.public { "🔓" } else { "🔒" } + ) + .as_str(), + ); + + if message_buffer.len() > 2000 { + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().content(message_buffer), + ) + .await?; + + message_buffer = "".to_string(); + } + } + + if message_buffer.len() > 0 { + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().content(message_buffer), + ) + .await?; + } + + Ok(()) +} + +#[command("search")] +#[group("Search")] +#[description("Search for sounds")] +#[arg( + name = "query", + kind = "String", + description = "Sound name to search for", + required = true +)] +pub async fn search_sounds( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + args: Args, +) -> CommandResult { + let pool = ctx + .data + .read() + .await + .get::() + .cloned() + .expect("Could not get SQLPool from data"); + + let query = args.named("query").unwrap(); + + let search_results = Sound::search_for_sound( + query, + invoke.guild_id().unwrap(), + invoke.author_id(), + pool, + false, + ) + .await?; + + invoke + .respond(ctx.http.clone(), format_search_results(search_results)) + .await?; + + Ok(()) +} + +#[command("popular")] +#[group("Search")] +#[description("Show popular sounds")] +pub async fn show_popular_sounds( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + _args: Args, +) -> CommandResult { + let pool = ctx + .data + .read() + .await + .get::() + .cloned() + .expect("Could not get SQLPool from data"); + + let search_results = sqlx::query_as_unchecked!( + Sound, + " +SELECT name, id, plays, public, server_id, uploader_id + FROM sounds + WHERE public = 1 + ORDER BY plays DESC + LIMIT 25 + " + ) + .fetch_all(&pool) + .await?; + + invoke + .respond(ctx.http.clone(), format_search_results(search_results)) + .await?; + + Ok(()) +} + +#[command("random")] +#[group("Search")] +#[description("Show a page of random sounds")] +pub async fn show_random_sounds( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + _args: Args, +) -> CommandResult { + let pool = ctx + .data + .read() + .await + .get::() + .cloned() + .expect("Could not get SQLPool from data"); + + let search_results = sqlx::query_as_unchecked!( + Sound, + " +SELECT name, id, plays, public, server_id, uploader_id + FROM sounds + WHERE public = 1 + ORDER BY rand() + LIMIT 25 + " + ) + .fetch_all(&pool) + .await + .unwrap(); + + invoke + .respond(ctx.http.clone(), format_search_results(search_results)) + .await?; + + Ok(()) +} diff --git a/src/cmds/settings.rs b/src/cmds/settings.rs new file mode 100644 index 0000000..6d41f7f --- /dev/null +++ b/src/cmds/settings.rs @@ -0,0 +1,351 @@ +use regex_command_attr::command; + +use serenity::{client::Context, framework::standard::CommandResult}; + +use crate::{ + framework::{Args, CommandInvoke, CreateGenericResponse}, + guild_data::CtxGuildData, + sound::{JoinSoundCtx, Sound}, + MySQL, +}; + +#[command("volume")] +#[aliases("vol")] +#[required_permissions(Managed)] +#[group("Settings")] +#[description("Change the bot's volume in this server")] +#[arg( + name = "volume", + description = "New volume for the bot to use", + kind = "Integer", + required = false +)] +pub async fn change_volume( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + args: Args, +) -> CommandResult { + let pool = ctx + .data + .read() + .await + .get::() + .cloned() + .expect("Could not get SQLPool from data"); + + let guild_data_opt = ctx.guild_data(invoke.guild_id().unwrap()).await; + let guild_data = guild_data_opt.unwrap(); + + if let Some(volume) = args.named("volume").map(|i| i.parse::().ok()).flatten() { + guild_data.write().await.volume = volume; + + guild_data.read().await.commit(pool).await?; + + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().content(format!("Volume changed to {}%", volume)), + ) + .await?; + } else { + let read = guild_data.read().await; + + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().content(format!( + "Current server volume: {vol}%. Change the volume with `/volume `", + vol = read.volume + )), + ) + .await?; + } + + Ok(()) +} + +#[command("prefix")] +#[required_permissions(Restricted)] +#[allow_slash(false)] +#[group("Settings")] +#[description("Change the prefix of the bot for using non-slash commands")] +#[arg( + name = "prefix", + kind = "String", + description = "The new prefix to use for the bot", + required = true +)] +pub async fn change_prefix( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + args: Args, +) -> CommandResult { + let pool = ctx + .data + .read() + .await + .get::() + .cloned() + .expect("Could not get SQLPool from data"); + + let guild_data; + + { + let guild_data_opt = ctx.guild_data(invoke.guild_id().unwrap()).await; + + guild_data = guild_data_opt.unwrap(); + } + + if let Some(prefix) = args.named("prefix") { + if prefix.len() <= 5 { + let reply = format!("Prefix changed to `{}`", prefix); + + { + guild_data.write().await.prefix = prefix.to_string(); + } + + { + let read = guild_data.read().await; + + read.commit(pool).await?; + } + + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().content(reply), + ) + .await?; + } else { + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new() + .content("Prefix must be less than 5 characters long"), + ) + .await?; + } + } else { + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().content(format!( + "Usage: `{prefix}prefix `", + prefix = guild_data.read().await.prefix + )), + ) + .await?; + } + + Ok(()) +} + +#[command("roles")] +#[required_permissions(Restricted)] +#[allow_slash(false)] +#[group("Settings")] +#[description("Change the roles allowed to use the bot")] +pub async fn set_allowed_roles( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + args: Args, +) -> CommandResult { + let msg = invoke.msg().unwrap(); + let guild_id = *msg.guild_id.unwrap().as_u64(); + + let pool = ctx + .data + .read() + .await + .get::() + .cloned() + .expect("Could not get SQLPool from data"); + + if args.is_empty() { + let roles = sqlx::query!( + " +SELECT role + FROM roles + WHERE guild_id = ? + ", + guild_id + ) + .fetch_all(&pool) + .await?; + + let all_roles = roles + .iter() + .map(|i| format!("<@&{}>", i.role.to_string())) + .collect::>() + .join(", "); + + msg.channel_id.say(&ctx, format!("Usage: `?roles `. Current roles: {}", all_roles)).await?; + } else { + sqlx::query!( + " +DELETE FROM roles + WHERE guild_id = ? + ", + guild_id + ) + .execute(&pool) + .await?; + + if msg.mention_roles.len() > 0 { + for role in msg.mention_roles.iter().map(|r| *r.as_u64()) { + sqlx::query!( + " +INSERT INTO roles (guild_id, role) + VALUES + (?, ?) + ", + guild_id, + role + ) + .execute(&pool) + .await?; + } + + msg.channel_id + .say(&ctx, "Specified roles whitelisted") + .await?; + } else { + sqlx::query!( + " +INSERT INTO roles (guild_id, role) + VALUES + (?, ?) + ", + guild_id, + guild_id + ) + .execute(&pool) + .await?; + + msg.channel_id + .say(&ctx, "Role whitelisting disabled") + .await?; + } + } + + Ok(()) +} + +#[command("greet")] +#[group("Settings")] +#[description("Set a join sound")] +#[arg( + name = "query", + kind = "String", + description = "Name or ID of sound to set as your greet sound", + required = false +)] +pub async fn set_greet_sound( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + args: Args, +) -> CommandResult { + let pool = ctx + .data + .read() + .await + .get::() + .cloned() + .expect("Could not get SQLPool from data"); + + let query = args + .named("query") + .map(|s| s.to_owned()) + .unwrap_or(String::new()); + let user_id = invoke.author_id(); + + if query.len() == 0 { + ctx.update_join_sound(user_id, None).await; + + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().content("Your greet sound has been unset."), + ) + .await?; + } else { + let sound_vec = Sound::search_for_sound( + &query, + invoke.guild_id().unwrap(), + user_id, + pool.clone(), + true, + ) + .await?; + + match sound_vec.first() { + Some(sound) => { + ctx.update_join_sound(user_id, Some(sound.id)).await; + + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().content(format!( + "Greet sound has been set to {} (ID {})", + sound.name, sound.id + )), + ) + .await?; + } + + None => { + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new() + .content("Could not find a sound by that name."), + ) + .await?; + } + } + } + + Ok(()) +} + +#[command("allow_greet")] +#[group("Settings")] +#[description("Configure whether users should be able to use join sounds")] +#[required_permissions(Restricted)] +pub async fn allow_greet_sounds( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + _args: Args, +) -> CommandResult { + let pool = ctx + .data + .read() + .await + .get::() + .cloned() + .expect("Could not acquire SQL pool from data"); + + let guild_data_opt = ctx.guild_data(invoke.guild_id().unwrap()).await; + + if let Ok(guild_data) = guild_data_opt { + let current = guild_data.read().await.allow_greets; + + { + guild_data.write().await.allow_greets = !current; + } + + guild_data.read().await.commit(pool).await?; + + invoke + .respond( + ctx.http.clone(), + CreateGenericResponse::new().content(format!( + "Greet sounds have been {}abled in this server", + if !current { "en" } else { "dis" } + )), + ) + .await?; + } + + Ok(()) +} diff --git a/src/cmds/stop.rs b/src/cmds/stop.rs new file mode 100644 index 0000000..eac7e5c --- /dev/null +++ b/src/cmds/stop.rs @@ -0,0 +1,56 @@ +use regex_command_attr::command; + +use serenity::{client::Context, framework::standard::CommandResult}; + +use crate::framework::{Args, CommandInvoke, CreateGenericResponse}; + +use songbird; + +#[command("stop")] +#[required_permissions(Managed)] +#[group("Stop")] +#[description("Stop the bot from playing")] +pub async fn stop_playing( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + _args: Args, +) -> CommandResult { + let guild_id = invoke.guild_id().unwrap(); + + let songbird = songbird::get(ctx).await.unwrap(); + let call_opt = songbird.get(guild_id); + + if let Some(call) = call_opt { + let mut lock = call.lock().await; + + lock.stop(); + } + + invoke + .respond(ctx.http.clone(), CreateGenericResponse::new().content("👍")) + .await?; + + Ok(()) +} + +#[command] +#[aliases("dc")] +#[required_permissions(Managed)] +#[group("Stop")] +#[description("Disconnect the bot")] +pub async fn disconnect( + ctx: &Context, + invoke: &(dyn CommandInvoke + Sync + Send), + _args: Args, +) -> CommandResult { + let guild_id = invoke.guild_id().unwrap(); + + let songbird = songbird::get(ctx).await.unwrap(); + let _ = songbird.leave(guild_id).await; + + invoke + .respond(ctx.http.clone(), CreateGenericResponse::new().content("👍")) + .await?; + + Ok(()) +} diff --git a/src/framework.rs b/src/framework.rs index a4035ee..9bb93f2 100644 --- a/src/framework.rs +++ b/src/framework.rs @@ -70,10 +70,6 @@ impl Args { Self { args } } - pub fn len(&self) -> usize { - self.args.len() - } - pub fn is_empty(&self) -> bool { self.args.is_empty() } @@ -345,7 +341,7 @@ pub struct Command { pub desc: &'static str, pub examples: &'static [&'static str], - pub group: Option<&'static str>, + pub group: &'static str, pub allow_slash: bool, pub required_permissions: PermissionLevel, @@ -440,7 +436,7 @@ impl fmt::Debug for Command { pub struct RegexFramework { pub commands: HashMap, - commands_: HashSet<&'static Command>, + pub commands_: HashSet<&'static Command>, command_matcher: Regex, default_prefix: String, client_id: u64, diff --git a/src/main.rs b/src/main.rs index 74e6c27..6b66413 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ #[macro_use] extern crate lazy_static; +mod cmds; mod error; mod event_handlers; mod framework; @@ -8,37 +9,25 @@ mod guild_data; mod sound; use crate::{ - event_handlers::{Handler, RestartTrack}, - framework::{Args, CommandInvoke, CreateGenericResponse, RegexFramework}, + event_handlers::Handler, + framework::{Args, RegexFramework}, guild_data::{CtxGuildData, GuildData}, - sound::{JoinSoundCtx, Sound}, + sound::Sound, }; use log::info; -use regex_command_attr::command; - use serenity::{ - builder::CreateActionRow, client::{bridge::gateway::GatewayIntents, Client, Context}, - framework::standard::CommandResult, http::Http, model::{ guild::Guild, - id::{ChannelId, GuildId, RoleId, UserId}, - interactions::ButtonStyle, + id::{ChannelId, GuildId, UserId}, }, - prelude::*, + prelude::{Mutex, TypeMapKey}, }; -use songbird::{ - create_player, - error::JoinResult, - ffmpeg, - input::{cached::Memory, Input}, - tracks::TrackHandle, - Call, Event, SerenityInit, -}; +use songbird::{create_player, error::JoinResult, tracks::TrackHandle, Call, SerenityInit}; use sqlx::mysql::MySqlPool; @@ -46,9 +35,8 @@ use dotenv::dotenv; use dashmap::DashMap; -use std::{collections::HashMap, convert::TryFrom, env, sync::Arc, time::Duration}; +use std::{collections::HashMap, env, sync::Arc}; -use serenity::model::prelude::InteractionResponseType; use tokio::sync::{MutexGuard, RwLock}; struct MySQL; @@ -152,6 +140,65 @@ async fn join_channel( (call, res) } +async fn play_cmd(ctx: &Context, guild: Guild, user_id: UserId, args: Args, loop_: bool) -> String { + let guild_id = guild.id; + + let channel_to_join = guild + .voice_states + .get(&user_id) + .and_then(|voice_state| voice_state.channel_id); + + match channel_to_join { + Some(user_channel) => { + let search_term = args.named("query").unwrap(); + + let pool = ctx + .data + .read() + .await + .get::() + .cloned() + .expect("Could not get SQLPool from data"); + + let mut sound_vec = + Sound::search_for_sound(search_term, guild_id, user_id, pool.clone(), true) + .await + .unwrap(); + + let sound_res = sound_vec.first_mut(); + + match sound_res { + Some(sound) => { + { + let (call_handler, _) = + join_channel(ctx, guild.clone(), user_channel).await; + + let guild_data = ctx.guild_data(guild_id).await.unwrap(); + + let mut lock = call_handler.lock().await; + + play_audio( + sound, + guild_data.read().await.volume, + &mut lock, + pool, + loop_, + ) + .await + .unwrap(); + } + + format!("Playing sound {} with ID {}", sound.name, sound.id) + } + + None => "Couldn't find sound by term provided".to_string(), + } + } + + None => "You are not in a voice chat!".to_string(), + } +} + // entry point #[tokio::main] async fn main() -> Result<(), Box> { @@ -187,34 +234,32 @@ async fn main() -> Result<(), Box> { .case_insensitive(true) .ignore_bots(true) // info commands - .add_command(&HELP_COMMAND) - .add_command(&INFO_COMMAND) - .add_command(&INFO_COMMAND) - .add_command(&INFO_COMMAND) + .add_command(&cmds::info::HELP_COMMAND) + .add_command(&cmds::info::INFO_COMMAND) // play commands - .add_command(&LOOP_PLAY_COMMAND) - .add_command(&PLAY_COMMAND) - .add_command(&STOP_PLAYING_COMMAND) - .add_command(&DISCONNECT_COMMAND) - .add_command(&SOUNDBOARD_COMMAND) + .add_command(&cmds::play::LOOP_PLAY_COMMAND) + .add_command(&cmds::play::PLAY_COMMAND) + .add_command(&cmds::play::SOUNDBOARD_COMMAND) + .add_command(&cmds::stop::STOP_PLAYING_COMMAND) + .add_command(&cmds::stop::DISCONNECT_COMMAND) // sound management commands - .add_command(&UPLOAD_NEW_SOUND_COMMAND) - .add_command(&DELETE_SOUND_COMMAND) - .add_command(&LIST_SOUNDS_COMMAND) - .add_command(&CHANGE_PUBLIC_COMMAND) + .add_command(&cmds::manage::UPLOAD_NEW_SOUND_COMMAND) + .add_command(&cmds::manage::DELETE_SOUND_COMMAND) + .add_command(&cmds::manage::CHANGE_PUBLIC_COMMAND) // setting commands - .add_command(&CHANGE_PREFIX_COMMAND) - .add_command(&SET_ALLOWED_ROLES_COMMAND) - .add_command(&CHANGE_VOLUME_COMMAND) - .add_command(&ALLOW_GREET_SOUNDS_COMMAND) - .add_command(&SET_GREET_SOUND_COMMAND) + .add_command(&cmds::settings::CHANGE_PREFIX_COMMAND) + .add_command(&cmds::settings::SET_ALLOWED_ROLES_COMMAND) + .add_command(&cmds::settings::CHANGE_VOLUME_COMMAND) + .add_command(&cmds::settings::ALLOW_GREET_SOUNDS_COMMAND) + .add_command(&cmds::settings::SET_GREET_SOUND_COMMAND) // search commands - .add_command(&SEARCH_SOUNDS_COMMAND) - .add_command(&SHOW_POPULAR_SOUNDS_COMMAND) - .add_command(&SHOW_RANDOM_SOUNDS_COMMAND); + .add_command(&cmds::search::LIST_SOUNDS_COMMAND) + .add_command(&cmds::search::SEARCH_SOUNDS_COMMAND) + .add_command(&cmds::search::SHOW_POPULAR_SOUNDS_COMMAND) + .add_command(&cmds::search::SHOW_RANDOM_SOUNDS_COMMAND); if audio_index.is_some() { - framework = framework.add_command(&PLAY_AMBIENCE_COMMAND); + framework = framework.add_command(&cmds::play::PLAY_AMBIENCE_COMMAND); } framework = framework.build(); @@ -298,1471 +343,3 @@ async fn main() -> Result<(), Box> { Ok(()) } - -#[command] -#[description("Get information on the commands of the bot")] -#[arg( - name = "command", - description = "Get help for a specific command", - kind = "String", - required = false -)] -async fn help( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - args: Args, -) -> CommandResult { - if let Some(command_name) = args.named("command") { - let framework = ctx - .data - .read() - .await - .get::() - .cloned() - .unwrap(); - - if let Some(command) = framework.commands.get(command_name) { - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().embed(|e| { - e.title(format!("{} Help", command_name)) - .color(THEME_COLOR) - .description(format!( - "**Aliases** -{} - -**Overview** - • {} - -**Arguments** -{} - -**Examples** -{}", - command - .names - .iter() - .map(|n| format!("`{}`", n)) - .collect::>() - .join(" "), - command.desc, - command - .args - .iter() - .map(|a| format!( - " • `{}` {} - {}", - a.name, - if a.required { "" } else { "[optional]" }, - a.description - )) - .collect::>() - .join("\n"), - command - .examples - .iter() - .map(|e| format!(" • {}", e)) - .collect::>() - .join("\n") - )) - }), - ) - .await?; - } else { - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().embed(|e| { - e.title("Invalid Command") - .color(THEME_COLOR) - .description("") - }), - ) - .await?; - } - } else { - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new() - .embed(|e| e.title("Help").color(THEME_COLOR).description("")), - ) - .await?; - } - - Ok(()) -} - -#[command] -#[aliases("p")] -#[required_permissions(Managed)] -#[description("Play a sound in your current voice channel")] -#[arg( - name = "query", - description = "Play sound with the specified name or ID", - kind = "String", - required = true -)] -async fn play( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - args: Args, -) -> CommandResult { - let guild = invoke.guild(ctx.cache.clone()).await.unwrap(); - - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new() - .content(play_cmd(ctx, guild, invoke.author_id(), args, false).await), - ) - .await?; - - Ok(()) -} - -#[command("loop")] -#[required_permissions(Managed)] -#[description("Play a sound on loop in your current voice channel")] -#[arg( - name = "query", - description = "Play sound with the specified name or ID", - kind = "String", - required = true -)] -async fn loop_play( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - args: Args, -) -> CommandResult { - let guild = invoke.guild(ctx.cache.clone()).await.unwrap(); - - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new() - .content(play_cmd(ctx, guild, invoke.author_id(), args, true).await), - ) - .await?; - - Ok(()) -} - -async fn play_cmd(ctx: &Context, guild: Guild, user_id: UserId, args: Args, loop_: bool) -> String { - let guild_id = guild.id; - - let channel_to_join = guild - .voice_states - .get(&user_id) - .and_then(|voice_state| voice_state.channel_id); - - match channel_to_join { - Some(user_channel) => { - let search_term = args.named("query").unwrap(); - - let pool = ctx - .data - .read() - .await - .get::() - .cloned() - .expect("Could not get SQLPool from data"); - - let mut sound_vec = - Sound::search_for_sound(search_term, guild_id, user_id, pool.clone(), true) - .await - .unwrap(); - - let sound_res = sound_vec.first_mut(); - - match sound_res { - Some(sound) => { - { - let (call_handler, _) = - join_channel(ctx, guild.clone(), user_channel).await; - - let guild_data = ctx.guild_data(guild_id).await.unwrap(); - - let mut lock = call_handler.lock().await; - - play_audio( - sound, - guild_data.read().await.volume, - &mut lock, - pool, - loop_, - ) - .await - .unwrap(); - } - - format!("Playing sound {} with ID {}", sound.name, sound.id) - } - - None => "Couldn't find sound by term provided".to_string(), - } - } - - None => "You are not in a voice chat!".to_string(), - } -} - -#[command("ambience")] -#[required_permissions(Managed)] -#[description("Play ambient sound in your current voice channel")] -#[arg( - name = "name", - description = "Play sound with the specified name", - kind = "String", - required = false -)] -async fn play_ambience( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - args: Args, -) -> CommandResult { - let guild = invoke.guild(ctx.cache.clone()).await.unwrap(); - - let channel_to_join = guild - .voice_states - .get(&invoke.author_id()) - .and_then(|voice_state| voice_state.channel_id); - - match channel_to_join { - Some(user_channel) => { - let search_name = args.named("name").unwrap().to_lowercase(); - let audio_index = ctx.data.read().await.get::().cloned().unwrap(); - - if let Some(filename) = audio_index.get(&search_name) { - let (track, track_handler) = create_player( - Input::try_from( - Memory::new(ffmpeg(format!("audio/{}", filename)).await.unwrap()).unwrap(), - ) - .unwrap(), - ); - - let (call_handler, _) = join_channel(ctx, guild.clone(), user_channel).await; - let guild_data = ctx.guild_data(guild).await.unwrap(); - - { - let mut lock = call_handler.lock().await; - - lock.play(track); - } - - let _ = track_handler.set_volume(guild_data.read().await.volume as f32 / 100.0); - let _ = track_handler.add_event( - Event::Periodic( - track_handler.metadata().duration.unwrap() - Duration::from_millis(200), - None, - ), - RestartTrack {}, - ); - - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new() - .content(format!("Playing ambience **{}**", search_name)), - ) - .await?; - } else { - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().embed(|e| { - e.title("Not Found").description(format!( - "Could not find ambience sound by name **{}** - -__Available ambience sounds:__ -{}", - search_name, - audio_index - .keys() - .into_iter() - .map(|i| i.as_str()) - .collect::>() - .join("\n") - )) - }), - ) - .await?; - } - } - - None => { - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().content("You are not in a voice chat!"), - ) - .await?; - } - } - - Ok(()) -} - -#[command("stop")] -#[required_permissions(Managed)] -#[description("Stop the bot from playing")] -async fn stop_playing( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - _args: Args, -) -> CommandResult { - let guild_id = invoke.guild_id().unwrap(); - - let songbird = songbird::get(ctx).await.unwrap(); - let call_opt = songbird.get(guild_id); - - if let Some(call) = call_opt { - let mut lock = call.lock().await; - - lock.stop(); - } - - invoke - .respond(ctx.http.clone(), CreateGenericResponse::new().content("👍")) - .await?; - - Ok(()) -} - -#[command] -#[aliases("dc")] -#[required_permissions(Managed)] -#[description("Disconnect the bot")] -async fn disconnect( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - _args: Args, -) -> CommandResult { - let guild_id = invoke.guild_id().unwrap(); - - let songbird = songbird::get(ctx).await.unwrap(); - let _ = songbird.leave(guild_id).await; - - invoke - .respond(ctx.http.clone(), CreateGenericResponse::new().content("👍")) - .await?; - - Ok(()) -} - -#[command] -#[aliases("invite")] -#[description("Get additional information on the bot")] -async fn info( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - _args: Args, -) -> CommandResult { - let current_user = ctx.cache.current_user().await; - - invoke.respond(ctx.http.clone(), CreateGenericResponse::new() - .embed(|e| e - .title("Info") - .color(THEME_COLOR) - .footer(|f| f - .text(concat!(env!("CARGO_PKG_NAME"), " ver ", env!("CARGO_PKG_VERSION")))) - .description(format!("Default prefix: `?` - -Reset prefix: `@{0} prefix ?` - -Invite me: https://discord.com/api/oauth2/authorize?client_id={1}&permissions=3165184&scope=applications.commands%20bot - -**Welcome to SoundFX!** -Developer: <@203532103185465344> -Find me on https://discord.jellywx.com/ and on https://github.com/JellyWX :) - -**Sound Credits** -\"The rain falls against the parasol\" https://freesound.org/people/straget/ -\"Heavy Rain\" https://freesound.org/people/lebaston100/ -\"Rain on Windows, Interior, A\" https://freesound.org/people/InspectorJ/ -\"Seaside Waves, Close, A\" https://freesound.org/people/InspectorJ/ -\"Small River 1 - Fast - Close\" https://freesound.org/people/Pfannkuchn/ - -**An online dashboard is available!** Visit https://soundfx.jellywx.com/dashboard -There is a maximum sound limit per user. This can be removed by subscribing at **https://patreon.com/jellywx**", current_user.name, current_user.id.as_u64())))).await?; - - Ok(()) -} - -#[command("volume")] -#[aliases("vol")] -#[required_permissions(Managed)] -#[description("Change the bot's volume in this server")] -#[arg( - name = "volume", - description = "New volume for the bot to use", - kind = "Integer", - required = false -)] -async fn change_volume( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - args: Args, -) -> CommandResult { - let pool = ctx - .data - .read() - .await - .get::() - .cloned() - .expect("Could not get SQLPool from data"); - - let guild_data_opt = ctx.guild_data(invoke.guild_id().unwrap()).await; - let guild_data = guild_data_opt.unwrap(); - - if let Some(volume) = args.named("volume").map(|i| i.parse::().ok()).flatten() { - guild_data.write().await.volume = volume; - - guild_data.read().await.commit(pool).await?; - - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().content(format!("Volume changed to {}%", volume)), - ) - .await?; - } else { - let read = guild_data.read().await; - - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().content(format!( - "Current server volume: {vol}%. Change the volume with `/volume `", - vol = read.volume - )), - ) - .await?; - } - - Ok(()) -} - -#[command("prefix")] -#[required_permissions(Restricted)] -#[allow_slash(false)] -#[arg( - name = "prefix", - kind = "String", - description = "The new prefix to use for the bot", - required = true -)] -async fn change_prefix( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - args: Args, -) -> CommandResult { - let pool = ctx - .data - .read() - .await - .get::() - .cloned() - .expect("Could not get SQLPool from data"); - - let guild_data; - - { - let guild_data_opt = ctx.guild_data(invoke.guild_id().unwrap()).await; - - guild_data = guild_data_opt.unwrap(); - } - - if let Some(prefix) = args.named("prefix") { - if prefix.len() <= 5 { - let reply = format!("Prefix changed to `{}`", prefix); - - { - guild_data.write().await.prefix = prefix.to_string(); - } - - { - let read = guild_data.read().await; - - read.commit(pool).await?; - } - - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().content(reply), - ) - .await?; - } else { - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new() - .content("Prefix must be less than 5 characters long"), - ) - .await?; - } - } else { - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().content(format!( - "Usage: `{prefix}prefix `", - prefix = guild_data.read().await.prefix - )), - ) - .await?; - } - - Ok(()) -} - -#[command("upload")] -#[description("Upload a new sound to the bot")] -#[arg( - name = "name", - description = "Name to upload sound to", - kind = "String", - required = true -)] -async fn upload_new_sound( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - args: Args, -) -> CommandResult { - fn is_numeric(s: &String) -> bool { - for char in s.chars() { - if char.is_digit(10) { - continue; - } else { - return false; - } - } - true - } - - let new_name = args - .named("name") - .map(|n| n.to_string()) - .unwrap_or(String::new()); - - if !new_name.is_empty() && new_name.len() <= 20 { - if !is_numeric(&new_name) { - let pool = ctx - .data - .read() - .await - .get::() - .cloned() - .expect("Could not get SQLPool from data"); - - // need to check the name is not currently in use by the user - let count_name = - Sound::count_named_user_sounds(invoke.author_id().0, &new_name, pool.clone()) - .await?; - if count_name > 0 { - invoke.respond(ctx.http.clone(), CreateGenericResponse::new().content("You are already using that name. Please choose a unique name for your upload.")).await?; - } else { - // need to check how many sounds user currently has - let count = Sound::count_user_sounds(invoke.author_id().0, pool.clone()).await?; - let mut permit_upload = true; - - // need to check if user is patreon or nah - if count >= *MAX_SOUNDS { - let patreon_guild_member = GuildId(*PATREON_GUILD) - .member(ctx, invoke.author_id()) - .await; - - if let Ok(member) = patreon_guild_member { - permit_upload = member.roles.contains(&RoleId(*PATREON_ROLE)); - } else { - permit_upload = false; - } - } - - if permit_upload { - let attachment = if let Some(attachment) = invoke - .msg() - .map(|m| m.attachments.get(0).map(|a| a.url.clone())) - .flatten() - { - Some(attachment) - } else { - invoke.respond(ctx.http.clone(), CreateGenericResponse::new().content("Please now upload an audio file under 1MB in size (larger files will be automatically trimmed):")).await?; - - let reply = invoke - .channel_id() - .await_reply(&ctx) - .author_id(invoke.author_id()) - .timeout(Duration::from_secs(120)) - .await; - - match reply { - Some(reply_msg) => { - if let Some(attachment) = reply_msg.attachments.get(0) { - Some(attachment.url.clone()) - } else { - invoke.followup(ctx.http.clone(), CreateGenericResponse::new().content("Please upload 1 attachment following your upload command. Aborted")).await?; - - None - } - } - - None => { - invoke - .followup( - ctx.http.clone(), - CreateGenericResponse::new() - .content("Upload timed out. Please redo the command"), - ) - .await?; - - None - } - } - }; - - if let Some(url) = attachment { - match Sound::create_anon( - &new_name, - url.as_str(), - invoke.guild_id().unwrap().0, - invoke.author_id().0, - pool, - ) - .await - { - Ok(_) => { - invoke - .followup( - ctx.http.clone(), - CreateGenericResponse::new() - .content("Sound has been uploaded"), - ) - .await?; - } - - Err(e) => { - println!("Error occurred during upload: {:?}", e); - invoke - .followup( - ctx.http.clone(), - CreateGenericResponse::new() - .content("Sound failed to upload."), - ) - .await?; - } - } - } - } else { - invoke.respond( - ctx.http.clone(), - CreateGenericResponse::new().content(format!( - "You have reached the maximum number of sounds ({}). Either delete some with `?delete` or join our Patreon for unlimited uploads at **https://patreon.com/jellywx**", - *MAX_SOUNDS, - ))).await?; - } - } - } else { - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new() - .content("Please ensure the sound name contains a non-numerical character"), - ) - .await?; - } - } else { - invoke.respond(ctx.http.clone(), CreateGenericResponse::new().content("Usage: `?upload `. Please ensure the name provided is less than 20 characters in length")).await?; - } - - Ok(()) -} - -#[command("roles")] -#[required_permissions(Restricted)] -#[allow_slash(false)] -async fn set_allowed_roles( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - args: Args, -) -> CommandResult { - let msg = invoke.msg().unwrap(); - let guild_id = *msg.guild_id.unwrap().as_u64(); - - let pool = ctx - .data - .read() - .await - .get::() - .cloned() - .expect("Could not get SQLPool from data"); - - if args.is_empty() { - let roles = sqlx::query!( - " -SELECT role - FROM roles - WHERE guild_id = ? - ", - guild_id - ) - .fetch_all(&pool) - .await?; - - let all_roles = roles - .iter() - .map(|i| format!("<@&{}>", i.role.to_string())) - .collect::>() - .join(", "); - - msg.channel_id.say(&ctx, format!("Usage: `?roles `. Current roles: {}", all_roles)).await?; - } else { - sqlx::query!( - " -DELETE FROM roles - WHERE guild_id = ? - ", - guild_id - ) - .execute(&pool) - .await?; - - if msg.mention_roles.len() > 0 { - for role in msg.mention_roles.iter().map(|r| *r.as_u64()) { - sqlx::query!( - " -INSERT INTO roles (guild_id, role) - VALUES - (?, ?) - ", - guild_id, - role - ) - .execute(&pool) - .await?; - } - - msg.channel_id - .say(&ctx, "Specified roles whitelisted") - .await?; - } else { - sqlx::query!( - " -INSERT INTO roles (guild_id, role) - VALUES - (?, ?) - ", - guild_id, - guild_id - ) - .execute(&pool) - .await?; - - msg.channel_id - .say(&ctx, "Role whitelisting disabled") - .await?; - } - } - - Ok(()) -} - -#[command("list")] -#[description("Show the sounds uploaded by you or to your server")] -#[arg( - name = "me", - description = "Whether to list your sounds or server sounds (default: server)", - kind = "Boolean", - required = false -)] -async fn list_sounds( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - args: Args, -) -> CommandResult { - let pool = ctx - .data - .read() - .await - .get::() - .cloned() - .expect("Could not get SQLPool from data"); - - let sounds; - let mut message_buffer; - - if args.named("me").map(|i| i.to_owned()) == Some("me".to_string()) { - sounds = Sound::get_user_sounds(invoke.author_id(), pool).await?; - - message_buffer = "All your sounds: ".to_string(); - } else { - sounds = Sound::get_guild_sounds(invoke.guild_id().unwrap(), pool).await?; - - message_buffer = "All sounds on this server: ".to_string(); - } - - for sound in sounds { - message_buffer.push_str( - format!( - "**{}** ({}), ", - sound.name, - if sound.public { "🔓" } else { "🔒" } - ) - .as_str(), - ); - - if message_buffer.len() > 2000 { - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().content(message_buffer), - ) - .await?; - - message_buffer = "".to_string(); - } - } - - if message_buffer.len() > 0 { - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().content(message_buffer), - ) - .await?; - } - - Ok(()) -} - -#[command("soundboard")] -#[aliases("board")] -#[description("Get a menu of sounds with buttons to play them")] -#[arg( - name = "1", - description = "Query for sound button 1", - kind = "String", - required = false -)] -#[arg( - name = "2", - description = "Query for sound button 2", - kind = "String", - required = false -)] -#[arg( - name = "3", - description = "Query for sound button 3", - kind = "String", - required = false -)] -#[arg( - name = "4", - description = "Query for sound button 4", - kind = "String", - required = false -)] -#[arg( - name = "5", - description = "Query for sound button 5", - kind = "String", - required = false -)] -#[arg( - name = "6", - description = "Query for sound button 6", - kind = "String", - required = false -)] -#[arg( - name = "7", - description = "Query for sound button 7", - kind = "String", - required = false -)] -#[arg( - name = "8", - description = "Query for sound button 8", - kind = "String", - required = false -)] -#[arg( - name = "9", - description = "Query for sound button 9", - kind = "String", - required = false -)] -#[arg( - name = "10", - description = "Query for sound button 10", - kind = "String", - required = false -)] -#[arg( - name = "11", - description = "Query for sound button 11", - kind = "String", - required = false -)] -#[arg( - name = "12", - description = "Query for sound button 12", - kind = "String", - required = false -)] -#[arg( - name = "13", - description = "Query for sound button 13", - kind = "String", - required = false -)] -#[arg( - name = "14", - description = "Query for sound button 14", - kind = "String", - required = false -)] -#[arg( - name = "15", - description = "Query for sound button 15", - kind = "String", - required = false -)] -#[arg( - name = "16", - description = "Query for sound button 16", - kind = "String", - required = false -)] -#[arg( - name = "17", - description = "Query for sound button 17", - kind = "String", - required = false -)] -#[arg( - name = "18", - description = "Query for sound button 18", - kind = "String", - required = false -)] -#[arg( - name = "19", - description = "Query for sound button 19", - kind = "String", - required = false -)] -#[arg( - name = "20", - description = "Query for sound button 20", - kind = "String", - required = false -)] -#[arg( - name = "21", - description = "Query for sound button 21", - kind = "String", - required = false -)] -#[arg( - name = "22", - description = "Query for sound button 22", - kind = "String", - required = false -)] -#[arg( - name = "23", - description = "Query for sound button 23", - kind = "String", - required = false -)] -#[arg( - name = "24", - description = "Query for sound button 24", - kind = "String", - required = false -)] -#[arg( - name = "25", - description = "Query for sound button 25", - kind = "String", - required = false -)] -async fn soundboard( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - args: Args, -) -> CommandResult { - if let Some(interaction) = invoke.interaction() { - let _ = interaction - .create_interaction_response(&ctx, |r| { - r.kind(InteractionResponseType::DeferredChannelMessageWithSource) - }) - .await; - } - - let pool = ctx - .data - .read() - .await - .get::() - .cloned() - .expect("Could not get SQLPool from data"); - - let mut sounds = vec![]; - - for n in 1..25 { - let search = Sound::search_for_sound( - args.named(&n.to_string()).unwrap_or(&"".to_string()), - invoke.guild_id().unwrap(), - invoke.author_id(), - pool.clone(), - true, - ) - .await?; - - if let Some(sound) = search.first() { - sounds.push(sound.clone()); - } - } - - invoke - .followup( - ctx.http.clone(), - CreateGenericResponse::new() - .content("**Play a sound:**") - .components(|c| { - for row in sounds.as_slice().chunks(5) { - let mut action_row: CreateActionRow = Default::default(); - for sound in row { - action_row.create_button(|b| { - b.style(ButtonStyle::Primary) - .label(&sound.name) - .custom_id(sound.id) - }); - } - - c.add_action_row(action_row); - } - - c - }), - ) - .await?; - - Ok(()) -} - -#[command("public")] -#[description("Change a sound between public and private")] -#[arg( - name = "query", - kind = "String", - description = "Sound name or ID to change the privacy setting of", - required = true -)] -async fn change_public( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - args: Args, -) -> CommandResult { - let pool = ctx - .data - .read() - .await - .get::() - .cloned() - .expect("Could not get SQLPool from data"); - - let uid = invoke.author_id().as_u64().to_owned(); - - let name = args.named("query").unwrap(); - let gid = *invoke.guild_id().unwrap().as_u64(); - - let mut sound_vec = Sound::search_for_sound(name, gid, uid, pool.clone(), true).await?; - let sound_result = sound_vec.first_mut(); - - match sound_result { - Some(sound) => { - if sound.uploader_id != Some(uid) { - invoke.respond(ctx.http.clone(), CreateGenericResponse::new().content("You can only change the visibility of sounds you have uploaded. Use `?list me` to view your sounds")).await?; - } else { - if sound.public { - sound.public = false; - - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new() - .content("Sound has been set to private 🔒"), - ) - .await?; - } else { - sound.public = true; - - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().content("Sound has been set to public 🔓"), - ) - .await?; - } - - sound.commit(pool).await? - } - } - - None => { - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().content("Sound could not be found by that name."), - ) - .await?; - } - } - - Ok(()) -} - -#[command("delete")] -#[description("Delete a sound you have uploaded")] -#[arg( - name = "query", - description = "Delete sound with the specified name or ID", - kind = "String", - required = true -)] -async fn delete_sound( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - args: Args, -) -> CommandResult { - let pool = ctx - .data - .read() - .await - .get::() - .cloned() - .expect("Could not get SQLPool from data"); - - let uid = invoke.author_id().0; - let gid = invoke.guild_id().unwrap().0; - - let name = args - .named("query") - .map(|s| s.to_owned()) - .unwrap_or(String::new()); - - let sound_vec = Sound::search_for_sound(&name, gid, uid, pool.clone(), true).await?; - let sound_result = sound_vec.first(); - - match sound_result { - Some(sound) => { - if sound.uploader_id != Some(uid) && sound.server_id != gid { - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().content( - "You can only delete sounds from this guild or that you have uploaded.", - ), - ) - .await?; - } else { - let has_perms = { - if let Ok(member) = invoke.member(&ctx).await { - if let Ok(perms) = member.permissions(&ctx).await { - perms.manage_guild() - } else { - false - } - } else { - false - } - }; - - if sound.uploader_id == Some(uid) || has_perms { - sound.delete(pool).await?; - - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().content("Sound has been deleted"), - ) - .await?; - } else { - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().content( - "Only server admins can delete sounds uploaded by other users.", - ), - ) - .await?; - } - } - } - - None => { - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().content("Sound could not be found by that name."), - ) - .await?; - } - } - - Ok(()) -} - -fn format_search_results(search_results: Vec) -> CreateGenericResponse { - let mut current_character_count = 0; - let title = "Public sounds matching filter:"; - - let field_iter = search_results - .iter() - .take(25) - .map(|item| { - ( - &item.name, - format!("ID: {}\nPlays: {}", item.id, item.plays), - true, - ) - }) - .filter(|item| { - current_character_count += item.0.len() + item.1.len(); - - current_character_count <= 2048 - title.len() - }); - - CreateGenericResponse::new().embed(|e| e.title(title).fields(field_iter)) -} - -#[command("search")] -#[description("Search for sounds")] -#[arg( - name = "query", - kind = "String", - description = "Sound name to search for", - required = true -)] -async fn search_sounds( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - args: Args, -) -> CommandResult { - let pool = ctx - .data - .read() - .await - .get::() - .cloned() - .expect("Could not get SQLPool from data"); - - let query = args.named("query").unwrap(); - - let search_results = Sound::search_for_sound( - query, - invoke.guild_id().unwrap(), - invoke.author_id(), - pool, - false, - ) - .await?; - - invoke - .respond(ctx.http.clone(), format_search_results(search_results)) - .await?; - - Ok(()) -} - -#[command("popular")] -#[description("Show popular sounds")] -async fn show_popular_sounds( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - _args: Args, -) -> CommandResult { - let pool = ctx - .data - .read() - .await - .get::() - .cloned() - .expect("Could not get SQLPool from data"); - - let search_results = sqlx::query_as_unchecked!( - Sound, - " -SELECT name, id, plays, public, server_id, uploader_id - FROM sounds - WHERE public = 1 - ORDER BY plays DESC - LIMIT 25 - " - ) - .fetch_all(&pool) - .await?; - - invoke - .respond(ctx.http.clone(), format_search_results(search_results)) - .await?; - - Ok(()) -} - -#[command("random")] -#[description("Show a page of random sounds")] -async fn show_random_sounds( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - _args: Args, -) -> CommandResult { - let pool = ctx - .data - .read() - .await - .get::() - .cloned() - .expect("Could not get SQLPool from data"); - - let search_results = sqlx::query_as_unchecked!( - Sound, - " -SELECT name, id, plays, public, server_id, uploader_id - FROM sounds - WHERE public = 1 - ORDER BY rand() - LIMIT 25 - " - ) - .fetch_all(&pool) - .await - .unwrap(); - - invoke - .respond(ctx.http.clone(), format_search_results(search_results)) - .await?; - - Ok(()) -} - -#[command("greet")] -#[description("Set a join sound")] -#[arg( - name = "query", - kind = "String", - description = "Name or ID of sound to set as your greet sound", - required = false -)] -async fn set_greet_sound( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - args: Args, -) -> CommandResult { - let pool = ctx - .data - .read() - .await - .get::() - .cloned() - .expect("Could not get SQLPool from data"); - - let query = args - .named("query") - .map(|s| s.to_owned()) - .unwrap_or(String::new()); - let user_id = invoke.author_id(); - - if query.len() == 0 { - ctx.update_join_sound(user_id, None).await; - - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().content("Your greet sound has been unset."), - ) - .await?; - } else { - let sound_vec = Sound::search_for_sound( - &query, - invoke.guild_id().unwrap(), - user_id, - pool.clone(), - true, - ) - .await?; - - match sound_vec.first() { - Some(sound) => { - ctx.update_join_sound(user_id, Some(sound.id)).await; - - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().content(format!( - "Greet sound has been set to {} (ID {})", - sound.name, sound.id - )), - ) - .await?; - } - - None => { - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new() - .content("Could not find a sound by that name."), - ) - .await?; - } - } - } - - Ok(()) -} - -#[command("allow_greet")] -#[description("Configure whether users should be able to use join sounds")] -#[required_permissions(Restricted)] -async fn allow_greet_sounds( - ctx: &Context, - invoke: &(dyn CommandInvoke + Sync + Send), - _args: Args, -) -> CommandResult { - let pool = ctx - .data - .read() - .await - .get::() - .cloned() - .expect("Could not acquire SQL pool from data"); - - let guild_data_opt = ctx.guild_data(invoke.guild_id().unwrap()).await; - - if let Ok(guild_data) = guild_data_opt { - let current = guild_data.read().await.allow_greets; - - { - guild_data.write().await.allow_greets = !current; - } - - guild_data.read().await.commit(pool).await?; - - invoke - .respond( - ctx.http.clone(), - CreateGenericResponse::new().content(format!( - "Greet sounds have been {}abled in this server", - if !current { "en" } else { "dis" } - )), - ) - .await?; - } - - Ok(()) -} From a38e4c808e0408d1be19b6ef46add5a0749d4903 Mon Sep 17 00:00:00 2001 From: jellywx Date: Fri, 25 Jun 2021 23:13:11 +0100 Subject: [PATCH 5/9] replaced allow_slash with a method to disallow text commands for soundboard. made string argument selector stricter --- regex_command_attr/src/attributes.rs | 14 +++++- regex_command_attr/src/lib.rs | 6 +-- regex_command_attr/src/structures.rs | 52 +++++++++++++++++++++- src/cmds/info.rs | 52 ++++++++++++++++------ src/cmds/manage.rs | 3 ++ src/cmds/play.rs | 4 +- src/cmds/search.rs | 2 + src/cmds/settings.rs | 13 ++++-- src/framework.rs | 65 ++++++++++++++++++---------- 9 files changed, 164 insertions(+), 47 deletions(-) diff --git a/regex_command_attr/src/attributes.rs b/regex_command_attr/src/attributes.rs index 856eefd..f9522b3 100644 --- a/regex_command_attr/src/attributes.rs +++ b/regex_command_attr/src/attributes.rs @@ -5,7 +5,7 @@ use syn::parse::{Error, Result}; use syn::spanned::Spanned; use syn::{Attribute, Ident, Lit, LitStr, Meta, NestedMeta, Path}; -use crate::structures::{ApplicationCommandOptionType, Arg, PermissionLevel}; +use crate::structures::{ApplicationCommandOptionType, Arg, CommandKind, PermissionLevel}; use crate::util::{AsOption, LitExt}; #[derive(Debug, Clone, Copy, PartialEq)] @@ -321,6 +321,18 @@ impl AttributeOption for PermissionLevel { } } +impl AttributeOption for CommandKind { + fn parse(values: Values) -> Result { + validate(&values, &[ValueKind::SingleList])?; + + Ok(values + .literals + .get(0) + .map(|(_, l)| CommandKind::from_str(&*l.to_str()).unwrap()) + .unwrap()) + } +} + impl AttributeOption for Arg { fn parse(values: Values) -> Result { validate(&values, &[ValueKind::EqualsList])?; diff --git a/regex_command_attr/src/lib.rs b/regex_command_attr/src/lib.rs index be33c48..2ae6b0f 100644 --- a/regex_command_attr/src/lib.rs +++ b/regex_command_attr/src/lib.rs @@ -70,7 +70,7 @@ pub fn command(attr: TokenStream, input: TokenStream) -> TokenStream { aliases; group; required_permissions; - allow_slash + kind ]); } } @@ -82,7 +82,7 @@ pub fn command(attr: TokenStream, input: TokenStream) -> TokenStream { group, examples, required_permissions, - allow_slash, + kind, mut cmd_args, } = options; @@ -152,7 +152,7 @@ pub fn command(attr: TokenStream, input: TokenStream) -> TokenStream { group: #group, examples: &[#(#examples),*], required_permissions: #required_permissions, - allow_slash: #allow_slash, + kind: #kind, args: &[#(&#arg_idents),*], }; diff --git a/regex_command_attr/src/structures.rs b/regex_command_attr/src/structures.rs index 36e9331..302a0b0 100644 --- a/regex_command_attr/src/structures.rs +++ b/regex_command_attr/src/structures.rs @@ -214,6 +214,55 @@ impl ToTokens for PermissionLevel { } } +#[derive(Debug)] +pub enum CommandKind { + Slash, + Both, + Text, +} + +impl Default for CommandKind { + fn default() -> Self { + Self::Both + } +} + +impl CommandKind { + pub fn from_str(s: &str) -> Option { + Some(match s.to_uppercase().as_str() { + "SLASH" => Self::Slash, + "BOTH" => Self::Both, + "TEXT" => Self::Text, + _ => return None, + }) + } +} + +impl ToTokens for CommandKind { + fn to_tokens(&self, stream: &mut TokenStream2) { + let path = quote!(crate::framework::CommandKind); + let variant; + + match self { + Self::Slash => { + variant = quote!(Slash); + } + + Self::Both => { + variant = quote!(Both); + } + + Self::Text => { + variant = quote!(Text); + } + } + + stream.extend(quote! { + #path::#variant + }); + } +} + #[derive(Debug)] pub(crate) enum ApplicationCommandOptionType { SubCommand, @@ -293,7 +342,7 @@ pub(crate) struct Options { pub group: String, pub examples: Vec, pub required_permissions: PermissionLevel, - pub allow_slash: bool, + pub kind: CommandKind, pub cmd_args: Vec, } @@ -301,7 +350,6 @@ impl Options { #[inline] pub fn new() -> Self { Self { - allow_slash: true, group: "Other".to_string(), ..Default::default() } diff --git a/src/cmds/info.rs b/src/cmds/info.rs index 7b82717..b5843c6 100644 --- a/src/cmds/info.rs +++ b/src/cmds/info.rs @@ -7,6 +7,7 @@ use crate::{ THEME_COLOR, }; +use crate::framework::CommandKind; use std::{collections::HashMap, sync::Arc}; #[command] @@ -62,6 +63,28 @@ pub async fn help( ) }; + let args = if command.args.is_empty() { + "**Arguments** + • *This command has no arguments*" + .to_string() + } else { + format!( + "**Arguments** +{}", + command + .args + .iter() + .map(|a| format!( + " • `{}` {} - {}", + a.name, + if a.required { "" } else { "[optional]" }, + a.description + )) + .collect::>() + .join("\n") + ) + }; + invoke .respond( ctx.http.clone(), @@ -69,15 +92,28 @@ pub async fn help( e.title(format!("{} Help", command_name)) .color(THEME_COLOR) .description(format!( - "**Aliases** + "**Available In** +`Slash Commands` {} +` Text Commands` {} + +**Aliases** {} **Overview** • {} -**Arguments** {} {}", + if command.kind != CommandKind::Text { + "✅" + } else { + "❎" + }, + if command.kind != CommandKind::Slash { + "✅" + } else { + "❎" + }, command .names .iter() @@ -85,17 +121,7 @@ pub async fn help( .collect::>() .join(" "), command.desc, - command - .args - .iter() - .map(|a| format!( - " • `{}` {} - {}", - a.name, - if a.required { "" } else { "[optional]" }, - a.description - )) - .collect::>() - .join("\n"), + args, examples )) }), diff --git a/src/cmds/manage.rs b/src/cmds/manage.rs index d22eb24..594b4b6 100644 --- a/src/cmds/manage.rs +++ b/src/cmds/manage.rs @@ -186,6 +186,7 @@ pub async fn upload_new_sound( kind = "String", required = true )] +#[example("`/delete beep` - delete the sound with the name \"beep\"")] pub async fn delete_sound( ctx: &Context, invoke: &(dyn CommandInvoke + Sync + Send), @@ -278,6 +279,8 @@ pub async fn delete_sound( description = "Sound name or ID to change the privacy setting of", required = true )] +#[example("`/public 12` - change sound with ID 12 to private")] +#[example("`/public 12` - change sound with ID 12 back to public")] pub async fn change_public( ctx: &Context, invoke: &(dyn CommandInvoke + Sync + Send), diff --git a/src/cmds/play.rs b/src/cmds/play.rs index 2151145..d3e6b37 100644 --- a/src/cmds/play.rs +++ b/src/cmds/play.rs @@ -184,14 +184,14 @@ __Available ambience sounds:__ } #[command("soundboard")] -#[aliases("board")] #[group("Play")] +#[kind(Slash)] #[description("Get a menu of sounds with buttons to play them")] #[arg( name = "1", description = "Query for sound button 1", kind = "String", - required = false + required = true )] #[arg( name = "2", diff --git a/src/cmds/search.rs b/src/cmds/search.rs index 2335cb5..9a77985 100644 --- a/src/cmds/search.rs +++ b/src/cmds/search.rs @@ -40,6 +40,8 @@ fn format_search_results(search_results: Vec) -> CreateGenericResponse { kind = "Boolean", required = false )] +#[example("`/list` - list sounds uploaded to the server you're in")] +#[example("`/list [me: True]` - list sounds you have uploaded across all servers")] pub async fn list_sounds( ctx: &Context, invoke: &(dyn CommandInvoke + Sync + Send), diff --git a/src/cmds/settings.rs b/src/cmds/settings.rs index 6d41f7f..ddfb97e 100644 --- a/src/cmds/settings.rs +++ b/src/cmds/settings.rs @@ -20,6 +20,9 @@ use crate::{ kind = "Integer", required = false )] +#[example("`/volume` - check the volume on the current server")] +#[example("`/volume 100` - reset the volume on the current server")] +#[example("`/volume 10` - set the volume on the current server to 10%")] pub async fn change_volume( ctx: &Context, invoke: &(dyn CommandInvoke + Sync + Send), @@ -66,7 +69,7 @@ pub async fn change_volume( #[command("prefix")] #[required_permissions(Restricted)] -#[allow_slash(false)] +#[kind(Text)] #[group("Settings")] #[description("Change the prefix of the bot for using non-slash commands")] #[arg( @@ -97,7 +100,7 @@ pub async fn change_prefix( } if let Some(prefix) = args.named("prefix") { - if prefix.len() <= 5 { + if prefix.len() <= 5 && !prefix.is_empty() { let reply = format!("Prefix changed to `{}`", prefix); { @@ -142,7 +145,7 @@ pub async fn change_prefix( #[command("roles")] #[required_permissions(Restricted)] -#[allow_slash(false)] +#[kind(Text)] #[group("Settings")] #[description("Change the roles allowed to use the bot")] pub async fn set_allowed_roles( @@ -240,6 +243,8 @@ INSERT INTO roles (guild_id, role) description = "Name or ID of sound to set as your greet sound", required = false )] +#[example("`/greet` - remove your join sound")] +#[example("`/greet 1523` - set your join sound to sound with ID 1523")] pub async fn set_greet_sound( ctx: &Context, invoke: &(dyn CommandInvoke + Sync + Send), @@ -312,6 +317,8 @@ pub async fn set_greet_sound( #[group("Settings")] #[description("Configure whether users should be able to use join sounds")] #[required_permissions(Restricted)] +#[example("`/allow_greet` - disable greet sounds in the server")] +#[example("`/allow_greet` - re-enable greet sounds in the server")] pub async fn allow_greet_sounds( ctx: &Context, invoke: &(dyn CommandInvoke + Sync + Send), diff --git a/src/framework.rs b/src/framework.rs index 9bb93f2..13beec0 100644 --- a/src/framework.rs +++ b/src/framework.rs @@ -309,6 +309,13 @@ pub enum PermissionLevel { Restricted, } +#[derive(Debug, PartialEq)] +pub enum CommandKind { + Slash, + Both, + Text, +} + #[derive(Debug)] pub struct Arg { pub name: &'static str, @@ -320,7 +327,7 @@ pub struct Arg { impl Arg { pub fn to_regex(&self) -> String { match self.kind { - ApplicationCommandOptionType::String => format!(r#"(?P<{}>.*?)"#, self.name), + ApplicationCommandOptionType::String => format!(r#"(?P<{}>.+?)"#, self.name), ApplicationCommandOptionType::Integer => format!(r#"(?P<{}>\d+)"#, self.name), ApplicationCommandOptionType::Boolean => format!(r#"(?P<{0}>{0})?"#, self.name), ApplicationCommandOptionType::User => format!(r#"<(@|@!)(?P<{}>\d+)>"#, self.name), @@ -343,7 +350,7 @@ pub struct Command { pub examples: &'static [&'static str], pub group: &'static str, - pub allow_slash: bool, + pub kind: CommandKind, pub required_permissions: PermissionLevel, pub args: &'static [&'static Arg], } @@ -528,7 +535,11 @@ impl RegexFramework { .flatten() .map(|v| GuildId(v)) { - for command in self.commands_.iter().filter(|c| c.allow_slash) { + for command in self + .commands_ + .iter() + .filter(|c| c.kind != CommandKind::Text) + { guild_id .create_application_command(&http, |a| { a.name(command.names[0]).description(command.desc); @@ -577,7 +588,11 @@ impl RegexFramework { } } - for command in self.commands_.iter().filter(|c| c.allow_slash) { + for command in self + .commands_ + .iter() + .filter(|c| c.kind != CommandKind::Text) + { let already_created = if let Some(current_command) = current_commands .iter() .find(|curr| curr.name == command.names[0]) @@ -752,27 +767,31 @@ impl Framework for RegexFramework { .get(&full_match.name("cmd").unwrap().as_str().to_lowercase()) .unwrap(); - let args = full_match - .name("args") - .map(|m| m.as_str()) - .unwrap_or("") - .to_string(); + if command.kind != CommandKind::Slash { + let args = full_match + .name("args") + .map(|m| m.as_str()) + .unwrap_or("") + .to_string(); - let member = guild.member(&ctx, &msg.author).await.unwrap(); + let member = guild.member(&ctx, &msg.author).await.unwrap(); - if command.check_permissions(&ctx, &guild, &member).await { - (command.fun)(&ctx, &msg, Args::from(&args, command.args)) - .await - .unwrap(); - } else if command.required_permissions == PermissionLevel::Managed { - let _ = msg.channel_id.say(&ctx, "You must either be an Admin or have a role specified in `?roles` to do this command").await; - } else if command.required_permissions - == PermissionLevel::Restricted - { - let _ = msg - .channel_id - .say(&ctx, "You must be an Admin to do this command") - .await; + if command.check_permissions(&ctx, &guild, &member).await { + (command.fun)(&ctx, &msg, Args::from(&args, command.args)) + .await + .unwrap(); + } else if command.required_permissions + == PermissionLevel::Managed + { + let _ = msg.channel_id.say(&ctx, "You must either be an Admin or have a role specified in `?roles` to do this command").await; + } else if command.required_permissions + == PermissionLevel::Restricted + { + let _ = msg + .channel_id + .say(&ctx, "You must be an Admin to do this command") + .await; + } } } From 5dc15211818c5ae46c2211ab7fccd73a932cc149 Mon Sep 17 00:00:00 2001 From: jellywx Date: Sun, 27 Jun 2021 12:52:25 +0100 Subject: [PATCH 6/9] set the permissions correctly on soundboard cmd --- src/cmds/play.rs | 7 ++++--- src/event_handlers.rs | 4 ++-- src/main.rs | 8 +++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/cmds/play.rs b/src/cmds/play.rs index d3e6b37..55583cc 100644 --- a/src/cmds/play.rs +++ b/src/cmds/play.rs @@ -17,7 +17,7 @@ use crate::{ event_handlers::RestartTrack, framework::{Args, CommandInvoke, CreateGenericResponse}, guild_data::CtxGuildData, - join_channel, play_cmd, + join_channel, play_from_query, sound::Sound, AudioIndex, MySQL, }; @@ -48,7 +48,7 @@ pub async fn play( .respond( ctx.http.clone(), CreateGenericResponse::new() - .content(play_cmd(ctx, guild, invoke.author_id(), args, false).await), + .content(play_from_query(ctx, guild, invoke.author_id(), args, false).await), ) .await?; @@ -78,7 +78,7 @@ pub async fn loop_play( .respond( ctx.http.clone(), CreateGenericResponse::new() - .content(play_cmd(ctx, guild, invoke.author_id(), args, true).await), + .content(play_from_query(ctx, guild, invoke.author_id(), args, true).await), ) .await?; @@ -184,6 +184,7 @@ __Available ambience sounds:__ } #[command("soundboard")] +#[required_permissions(Managed)] #[group("Play")] #[kind(Slash)] #[description("Get a menu of sounds with buttons to play them")] diff --git a/src/event_handlers.rs b/src/event_handlers.rs index 6b3be41..7174750 100644 --- a/src/event_handlers.rs +++ b/src/event_handlers.rs @@ -1,7 +1,7 @@ use crate::{ framework::RegexFramework, guild_data::CtxGuildData, - join_channel, play_audio, play_cmd, + join_channel, play_audio, play_from_query, sound::{JoinSoundCtx, Sound}, MySQL, ReqwestClient, }; @@ -208,7 +208,7 @@ SELECT name, id, plays, public, server_id, uploader_id }; args.args.insert("query".to_string(), data.custom_id); - play_cmd( + play_from_query( &ctx, interaction.guild(ctx.cache.clone()).await.unwrap(), member.user.id, diff --git a/src/main.rs b/src/main.rs index 6b66413..99111d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -140,7 +140,13 @@ async fn join_channel( (call, res) } -async fn play_cmd(ctx: &Context, guild: Guild, user_id: UserId, args: Args, loop_: bool) -> String { +async fn play_from_query( + ctx: &Context, + guild: Guild, + user_id: UserId, + args: Args, + loop_: bool, +) -> String { let guild_id = guild.id; let channel_to_join = guild From 00565690bcfaea7d0a109a1b1a90be881b397af5 Mon Sep 17 00:00:00 2001 From: jellywx Date: Wed, 21 Jul 2021 18:30:43 +0100 Subject: [PATCH 7/9] fix for stage channels --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 83c048a..702ac53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1837,7 +1837,7 @@ dependencies = [ [[package]] name = "soundfx-rs" -version = "1.3.0" +version = "1.3.1" dependencies = [ "dashmap", "dotenv", diff --git a/Cargo.toml b/Cargo.toml index 6660e5b..ff7c5e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "soundfx-rs" -version = "1.3.0" +version = "1.3.1" authors = ["jellywx "] edition = "2018" diff --git a/src/main.rs b/src/main.rs index 99111d7..04d4c00 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,7 @@ use serenity::{ client::{bridge::gateway::GatewayIntents, Client, Context}, http::Http, model::{ + channel::Channel, guild::Guild, id::{ChannelId, GuildId, UserId}, }, @@ -137,6 +138,12 @@ async fn join_channel( let _ = call.lock().await.deafen(true).await; } + if let Some(Channel::Guild(channel)) = channel_id.to_channel_cached(&ctx).await { + channel + .edit_voice_state(&ctx, ctx.cache.current_user().await, |v| v.suppress(false)) + .await; + } + (call, res) } From 9db0265f5eb3b85ea664bb48c983ceae47313869 Mon Sep 17 00:00:00 2001 From: jellywx Date: Tue, 3 Aug 2021 09:01:10 +0100 Subject: [PATCH 8/9] fix roles command --- src/cmds/settings.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cmds/settings.rs b/src/cmds/settings.rs index ddfb97e..3149a6c 100644 --- a/src/cmds/settings.rs +++ b/src/cmds/settings.rs @@ -148,6 +148,12 @@ pub async fn change_prefix( #[kind(Text)] #[group("Settings")] #[description("Change the roles allowed to use the bot")] +#[arg( + name = "roles", + kind = "String", + description = "The role mentions to enlist", + required = true +)] pub async fn set_allowed_roles( ctx: &Context, invoke: &(dyn CommandInvoke + Sync + Send), From 7354646c890554e2491122215ab7eefad8eece3f Mon Sep 17 00:00:00 2001 From: jellywx Date: Fri, 13 Aug 2021 14:20:45 +0100 Subject: [PATCH 9/9] updated serenity and songbird versions to latest --- Cargo.lock | 750 ++++++++++----------------- Cargo.toml | 6 +- regex_command_attr/src/structures.rs | 4 +- src/cmds/info.rs | 2 +- src/cmds/manage.rs | 2 +- src/cmds/play.rs | 8 +- src/event_handlers.rs | 78 ++- src/framework.rs | 151 +++--- src/main.rs | 6 +- 9 files changed, 406 insertions(+), 601 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 702ac53..ad59cf8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "adler" version = "1.0.2" @@ -8,11 +10,12 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aead" -version = "0.3.2" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fc95d1bdb8e6666b2b217308eeeb09f2d6728d104be3e31916cc74d15420331" +checksum = "6e3e798aa0c8239776f54415bc06f3d74b1850f3f830b45c35cfc80556973f70" dependencies = [ "generic-array", + "rand_core", ] [[package]] @@ -21,7 +24,7 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98" dependencies = [ - "getrandom 0.2.3", + "getrandom", "once_cell", "version_check", ] @@ -35,6 +38,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "arrayvec" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9" +dependencies = [ + "nodrop", +] + [[package]] name = "arrayvec" version = "0.5.2" @@ -43,31 +55,15 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "async-trait" -version = "0.1.50" +version = "0.1.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b98e84bbb4cbcdd97da190ba0c58a1bb0de2c1fdf67d159e192ed766aeca722" +checksum = "44318e776df68115a881de9a8fd1b9e53368d7a4a5ce4cc48517da3393233a5e" dependencies = [ "proc-macro2", "quote", "syn", ] -[[package]] -name = "async-tungstenite" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7cc5408453d37e2b1c6f01d8078af1da58b6cfa6a80fa2ede3bd2b9a6ada9c4" -dependencies = [ - "futures-io", - "futures-util", - "log 0.4.14", - "pin-project", - "tokio", - "tokio-rustls", - "tungstenite 0.11.1", - "webpki-roots 0.20.0", -] - [[package]] name = "async-tungstenite" version = "0.13.1" @@ -76,12 +72,12 @@ checksum = "07b30ef0ea5c20caaa54baea49514a206308989c68be7ecd86c7f956e4da6378" dependencies = [ "futures-io", "futures-util", - "log 0.4.14", + "log", "pin-project-lite", "tokio", "tokio-rustls", - "tungstenite 0.13.0", - "webpki-roots 0.21.1", + "tungstenite", + "webpki-roots", ] [[package]] @@ -101,7 +97,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -119,7 +115,7 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "927791de46f70facea982dbfaf19719a41ce6064443403be631a85de6a58fff9" dependencies = [ - "log 0.4.14", + "log", "pkg-config", ] @@ -135,12 +131,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" -[[package]] -name = "base64" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" - [[package]] name = "base64" version = "0.13.0" @@ -160,15 +150,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "0.5.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f67931368edf3a9a51d29886d245f1c3db2f1ef0dcc9e35ff70341b78c10d23" - -[[package]] -name = "bitflags" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "2da1976d75adbe5fbc88130ecd119529cf1cc6a93ae1546d8696ee66f0d21af1" [[package]] name = "bitvec" @@ -203,12 +187,6 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" -[[package]] -name = "bytes" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" - [[package]] name = "bytes" version = "1.0.1" @@ -217,9 +195,9 @@ checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" [[package]] name = "cc" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" +checksum = "e70cc2f62c6ce1868963827bd677764c62d07c3d9a3e1fb1177ee1a9ab199eb2" [[package]] name = "cfg-if" @@ -244,14 +222,14 @@ dependencies = [ "num-traits 0.2.14", "serde", "time", - "winapi 0.3.9", + "winapi", ] [[package]] name = "cipher" -version = "0.2.5" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" +checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" dependencies = [ "generic-array", ] @@ -259,6 +237,7 @@ dependencies = [ [[package]] name = "command_attr" version = "0.3.7" +source = "git+https://github.com/serenity-rs/serenity?branch=next#4d431726f4eb2f29a040b83fb4a18a459427c1b2" dependencies = [ "proc-macro2", "quote", @@ -290,12 +269,6 @@ dependencies = [ "libc", ] -[[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" @@ -353,6 +326,7 @@ checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c" dependencies = [ "cfg-if 1.0.0", "num_cpus", + "serde", ] [[package]] @@ -366,14 +340,12 @@ dependencies = [ [[package]] name = "discortp" -version = "0.2.2" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c0d482488c336a2164529765da3f645f26215df9c2033137ddedac333c8e2e8" +checksum = "fb66017646a48220b5ea30d63ac18bb5952f647f1a41ed755880895125d26972" dependencies = [ - "glob", "pnet_macros", "pnet_macros_support", - "syntex", ] [[package]] @@ -414,7 +386,7 @@ checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" dependencies = [ "atty", "humantime", - "log 0.4.14", + "log", "regex", "termcolor", ] @@ -433,9 +405,9 @@ dependencies = [ [[package]] name = "flume" -version = "0.10.7" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddad16e8529759736a9ce4cdf078ed702e45d3c5b0474a1c65f5149e9fa7f1eb" +checksum = "2e90cc80fad5bb391b38127896b0fa27d97e7fef74742797f4da518d67e1292f" dependencies = [ "futures-core", "futures-sink", @@ -483,9 +455,9 @@ checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" [[package]] name = "futures" -version = "0.3.15" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e7e43a803dae2fa37c1f6a8fe121e1f7bf9548b4dfc0522a42f34145dadfc27" +checksum = "1adc00f486adfc9ce99f77d717836f0c5aa84965eb0b4f051f4e83f7cab53f8b" dependencies = [ "futures-channel", "futures-core", @@ -498,9 +470,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.15" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e682a68b29a882df0545c143dc3646daefe80ba479bcdede94d5a703de2871e2" +checksum = "74ed2411805f6e4e3d9bc904c95d5d423b89b3b25dc0250aa74729de20629ff9" dependencies = [ "futures-core", "futures-sink", @@ -508,15 +480,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.15" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0402f765d8a89a26043b889b26ce3c4679d268fa6bb22cd7c6aad98340e179d1" +checksum = "af51b1b4a7fdff033703db39de8802c673eb91855f2e0d47dcf3bf2c0ef01f99" [[package]] name = "futures-executor" -version = "0.3.15" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "badaa6a909fac9e7236d0620a2f57f7664640c56575b71a7552fbd68deafab79" +checksum = "4d0d535a57b87e1ae31437b892713aee90cd2d7b0ee48727cd11fc72ef54761c" dependencies = [ "futures-core", "futures-task", @@ -525,15 +497,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.15" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1" +checksum = "0b0e06c393068f3a6ef246c75cdca793d6a46347e75286933e5e75fd2fd11582" [[package]] name = "futures-macro" -version = "0.3.15" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c40298486cdf52cc00cd6d6987892ba502c7656a16a4192a9992b1ccedd121" +checksum = "c54913bae956fb8df7f4dc6fc90362aa72e69148e3f39041fbe8742d21e0ac57" dependencies = [ "autocfg 1.0.1", "proc-macro-hack", @@ -544,21 +516,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.15" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a57bead0ceff0d6dde8f465ecd96c9338121bb7717d3e7b108059531870c4282" +checksum = "c0f30aaa67363d119812743aa5f33c201a7a66329f97d1a887022971feea4b53" [[package]] name = "futures-task" -version = "0.3.15" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a16bef9fc1a4dddb5bee51c989e3fbba26569cbb0e31f5b303c184e3dd33dae" +checksum = "bbe54a98670017f3be909561f6ad13e810d9a51f3f061b902062ca3da80799f2" [[package]] name = "futures-util" -version = "0.3.15" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "feb5c238d27e2bf94ffdfd27b2c29e3df4a68c4193bb6427384259e2bf191967" +checksum = "67eb846bfd58e44a8481a00049e82c43e0ccb5d61f8dc071057cb19249dd4d78" dependencies = [ "autocfg 1.0.1", "futures-channel", @@ -583,9 +555,9 @@ checksum = "061d3be1afec479d56fa3bd182bf966c7999ec175fcfdb87ac14d417241366c6" dependencies = [ "cc", "libc", - "log 0.4.14", + "log", "rustversion", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -598,17 +570,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - [[package]] name = "getrandom" version = "0.2.3" @@ -618,23 +579,17 @@ dependencies = [ "cfg-if 1.0.0", "js-sys", "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi", "wasm-bindgen", ] -[[package]] -name = "glob" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" - [[package]] name = "h2" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "825343c4eef0b63f541f8903f395dc5beb362a979b5799a84062527ef1e37726" dependencies = [ - "bytes 1.0.1", + "bytes", "fnv", "futures-core", "futures-sink", @@ -647,12 +602,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "hashbrown" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" - [[package]] name = "hashbrown" version = "0.11.2" @@ -668,7 +617,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7249a3129cbc1ffccd74857f81464a323a152173cdb134e0fd81bc803b29facf" dependencies = [ - "hashbrown 0.11.2", + "hashbrown", ] [[package]] @@ -682,9 +631,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] @@ -701,18 +650,18 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" dependencies = [ - "bytes 1.0.1", + "bytes", "fnv", "itoa", ] [[package]] name = "http-body" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9" +checksum = "399c583b2979440c60be0821a6199eca73bc3c8dcd9d070d75ac726e2c6186e5" dependencies = [ - "bytes 1.0.1", + "bytes", "http", "pin-project-lite", ] @@ -737,11 +686,11 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.9" +version = "0.14.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07d6baa1b441335f3ce5098ac421fb6547c46dda735ca1bc6d0153c838f9dd83" +checksum = "0b61cf2d1aebcf6e6352c97b81dc2244ca29194be1b276f5d8ad5c6330fffb11" dependencies = [ - "bytes 1.0.1", + "bytes", "futures-channel", "futures-core", "futures-util", @@ -767,7 +716,7 @@ checksum = "5f9f7a97316d44c0af9b0301e65010573a853a9fc97046d7331d7f6bc0fd5a64" dependencies = [ "futures-util", "hyper", - "log 0.4.14", + "log", "rustls", "tokio", "tokio-rustls", @@ -780,7 +729,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ - "bytes 1.0.1", + "bytes", "hyper", "native-tls", "tokio", @@ -800,21 +749,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.6.2" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" +checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" dependencies = [ "autocfg 1.0.1", - "hashbrown 0.9.1", -] - -[[package]] -name = "input_buffer" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19a8a95243d5a0398cae618ec29477c6e3cb631152be5c19481f80bc71559754" -dependencies = [ - "bytes 0.5.6", + "hashbrown", ] [[package]] @@ -823,14 +763,14 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f97967975f448f1a7ddb12b0bc41069d09ed6a1c161a92687e057325db35d413" dependencies = [ - "bytes 1.0.1", + "bytes", ] [[package]] name = "instant" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" +checksum = "bee0328b1209d157ef001c94dd85b4f8f64139adb0eac2659f4b08382b2f474d" dependencies = [ "cfg-if 1.0.0", ] @@ -849,23 +789,13 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "js-sys" -version = "0.3.51" +version = "0.3.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83bdfbace3a0e81a4253f73b49e960b053e396a11012cbd49b9b74d6a2b67062" +checksum = "ce791b7ca6638aae45be056e068fc756d871eb3b3b10b8efa62d1c9cec616752" 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" @@ -881,8 +811,8 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe" dependencies = [ - "arrayvec", - "bitflags 1.2.1", + "arrayvec 0.5.2", + "bitflags", "cfg-if 1.0.0", "ryu", "static_assertions", @@ -890,9 +820,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" +checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765" [[package]] name = "libm" @@ -909,15 +839,6 @@ 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" @@ -948,9 +869,9 @@ checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" [[package]] name = "matches" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] name = "memchr" @@ -991,10 +912,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" dependencies = [ "libc", - "log 0.4.14", + "log", "miow", "ntapi", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1003,27 +924,27 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] name = "nanorand" -version = "0.5.2" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac1378b66f7c93a1c0f8464a19bf47df8795083842e5090f4b7305973d5a22d0" +checksum = "729eb334247daa1803e0a094d0a5c55711b85571179f5ec6e53eccfdf7008958" dependencies = [ - "getrandom 0.2.3", + "getrandom", ] [[package]] name = "native-tls" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" +checksum = "48ba9f7719b5a0f42f338907614285fb5fd70e53858141f69898a1fb7203b24d" dependencies = [ "lazy_static", "libc", - "log 0.4.14", + "log", "openssl", "openssl-probe", "openssl-sys", @@ -1033,6 +954,12 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nodrop" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" + [[package]] name = "nom" version = "6.1.2" @@ -1052,7 +979,7 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1090,7 +1017,7 @@ dependencies = [ "num-integer", "num-iter", "num-traits 0.2.14", - "rand 0.8.4", + "rand", "smallvec", "zeroize", ] @@ -1163,7 +1090,7 @@ version = "0.10.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "549430950c79ae24e6d02e0b7404534ecf311d94cc9f861e9e4020187d13d885" dependencies = [ - "bitflags 1.2.1", + "bitflags", "cfg-if 1.0.0", "foreign-types", "libc", @@ -1212,7 +1139,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1221,7 +1148,7 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd56cbd21fea48d0c440b41cd69c589faacade08c992d9a54e471b79d0fd13eb" dependencies = [ - "base64 0.13.0", + "base64", "once_cell", "regex", ] @@ -1234,18 +1161,18 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pin-project" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7509cc106041c40a4518d2af7a61530e1eed0e6285296a3d8c5472806ccc4a4" +checksum = "576bc800220cc65dac09e99e97b08b358cfab6e17078de8dc5fee223bd2d0c08" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c950132583b500556b1efd71d45b319029f2b71518d979fcc208e16b42426f" +checksum = "6e8fe8163d14ce7f0cdac2e040116f22eac817edabff0be91e8aff7e9accf389" dependencies = [ "proc-macro2", "quote", @@ -1254,9 +1181,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" [[package]] name = "pin-utils" @@ -1272,37 +1199,39 @@ checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" [[package]] name = "pnet_base" -version = "0.26.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7cd5f7e15220afa66b0a9a62841ea10089f39dcaa1c29752c0b22dfc03111b5" +checksum = "25488cd551a753dcaaa6fffc9f69a7610a412dd8954425bf7ffad5f7d1156fb8" [[package]] name = "pnet_macros" -version = "0.26.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbbd5c52c6e04aa720400f9c71cd0e8bcb38cd13421d5caabd9035e9efa47de9" +checksum = "30490e0852e58402b8fae0d39897b08a24f493023a4d6cf56b2e30f31ed57548" dependencies = [ + "proc-macro2", + "quote", "regex", - "syntex", - "syntex_syntax", + "syn", ] [[package]] name = "pnet_macros_support" -version = "0.26.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daf9c5c0c36766d0a4da9ab268c0700771b8ec367b9463fd678109fa28463c5b" +checksum = "d4714e10f30cab023005adce048f2d30dd4ac4f093662abf2220855655ef8f90" dependencies = [ "pnet_base", ] [[package]] name = "poly1305" -version = "0.6.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b7456bc1ad2d4cf82b3a016be4c2ac48daf11bf990c1603ebd447fe6f30fca8" +checksum = "9fcffab1f78ebbdf4b93b68c1ffebc24037eedf271edaca795732b24e5e4e349" dependencies = [ - "cpuid-bool", + "cpufeatures", + "opaque-debug", "universal-hash", ] @@ -1326,11 +1255,11 @@ checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" [[package]] name = "proc-macro2" -version = "1.0.27" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" +checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612" dependencies = [ - "unicode-xid 0.2.2", + "unicode-xid", ] [[package]] @@ -1348,19 +1277,6 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8" -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "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.4" @@ -1368,19 +1284,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" dependencies = [ "libc", - "rand_chacha 0.3.1", - "rand_core 0.6.3", - "rand_hc 0.3.1", -] - -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core 0.5.1", + "rand_chacha", + "rand_core", + "rand_hc", ] [[package]] @@ -1390,16 +1296,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.3", -] - -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom 0.1.16", + "rand_core", ] [[package]] @@ -1408,16 +1305,7 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ - "getrandom 0.2.3", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core 0.5.1", + "getrandom", ] [[package]] @@ -1426,16 +1314,16 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" dependencies = [ - "rand_core 0.6.3", + "rand_core", ] [[package]] name = "redox_syscall" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" dependencies = [ - "bitflags 1.2.1", + "bitflags", ] [[package]] @@ -1470,7 +1358,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1479,8 +1367,8 @@ version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "246e9f61b9bb77df069a947682be06e31ac43ea37862e244a69f177694ea6d22" dependencies = [ - "base64 0.13.0", - "bytes 1.0.1", + "base64", + "bytes", "encoding_rs", "futures-core", "futures-util", @@ -1492,7 +1380,7 @@ dependencies = [ "ipnet", "js-sys", "lazy_static", - "log 0.4.14", + "log", "mime", "mime_guess", "native-tls", @@ -1509,7 +1397,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots 0.21.1", + "webpki-roots", "winreg", ] @@ -1525,14 +1413,14 @@ dependencies = [ "spin", "untrusted", "web-sys", - "winapi 0.3.9", + "winapi", ] [[package]] name = "rsa" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68ef841a26fc5d040ced0417c6c6a64ee851f42489df11cdf0218e545b6f8d28" +checksum = "7b0aeddcca1082112a6eeb43bf25fd7820b066aaf6eaef776e19d0a1febe38fe" dependencies = [ "byteorder", "digest", @@ -1542,26 +1430,20 @@ dependencies = [ "num-iter", "num-traits 0.2.14", "pem", - "rand 0.8.4", + "rand", "simple_asn1", "subtle", "zeroize", ] -[[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.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" dependencies = [ - "base64 0.13.0", - "log 0.4.14", + "base64", + "log", "ring", "sct", "webpki", @@ -1581,9 +1463,9 @@ checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] name = "salsa20" -version = "0.7.2" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "399f290ffc409596022fce5ea5d4138184be4784f2b28c62c59f0d8389059a15" +checksum = "ecbd2eb639fd7cab5804a0837fe373cc2172d15437e804c054a9fb885cb923b0" dependencies = [ "cipher", "zeroize", @@ -1596,7 +1478,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" dependencies = [ "lazy_static", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1627,7 +1509,7 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23a2ac85147a3a11d77ecf1bc7166ec0b92febfa4461c37944e180f319ece467" dependencies = [ - "bitflags 1.2.1", + "bitflags", "core-foundation", "core-foundation-sys", "libc", @@ -1646,18 +1528,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.126" +version = "1.0.127" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03" +checksum = "f03b9878abf6d14e6779d3f24f07b2cfa90352cfec4acc5aab8f1ac7f146fae8" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.126" +version = "1.0.127" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43" +checksum = "a024926d3432516606328597e0f224a51355a493b49fdd67e9209187cbe55ecc" dependencies = [ "proc-macro2", "quote", @@ -1666,9 +1548,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.64" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" +checksum = "336b10da19a12ad094b59d870ebde26a45402e5b470add4b5fd03c5048a32127" dependencies = [ "itoa", "ryu", @@ -1701,16 +1583,21 @@ dependencies = [ [[package]] name = "serenity" version = "0.10.8" +source = "git+https://github.com/serenity-rs/serenity?branch=next#4d431726f4eb2f29a040b83fb4a18a459427c1b2" dependencies = [ "async-trait", - "async-tungstenite 0.11.0", - "base64 0.13.0", - "bitflags 1.2.1", - "bytes 1.0.1", + "async-tungstenite", + "base64", + "bitflags", + "bytes", "chrono", "command_attr", + "dashmap", "flate2", "futures", + "mime", + "mime_guess", + "parking_lot", "percent-encoding", "reqwest", "serde", @@ -1726,10 +1613,9 @@ dependencies = [ [[package]] name = "serenity-voice-model" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "158aeb823791f79bbb92110212970797757fee7102784453dcb9b172a8af272b" +source = "git+https://github.com/serenity-rs/serenity?branch=next#4d431726f4eb2f29a040b83fb4a18a459427c1b2" dependencies = [ - "bitflags 1.2.1", + "bitflags", "enum_primitive", "serde", "serde_json", @@ -1738,9 +1624,9 @@ dependencies = [ [[package]] name = "sha-1" -version = "0.9.6" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c4cfa741c5832d0ef7fab46cabed29c2aae926db0b11bb2069edd8db5e64e16" +checksum = "1a0c8611594e2ab4ebbf06ec7cbbf0a99450b8570e96cbf5188b5d5f6ef18d81" dependencies = [ "block-buffer", "cfg-if 1.0.0", @@ -1773,9 +1659,9 @@ dependencies = [ [[package]] name = "simple_asn1" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc31e6cf34ad4321d3a2b8f934949b429e314519f753a77962f16c664dca8e13" +checksum = "8eb4ea60fb301dc81dfc113df680571045d375ab7345d171c5dc7d7e13107a80" dependencies = [ "chrono", "num-bigint 0.4.0", @@ -1785,9 +1671,9 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527" +checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590" [[package]] name = "smallvec" @@ -1797,20 +1683,21 @@ checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" [[package]] name = "socket2" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" +checksum = "765f090f0e423d2b55843402a07915add955e7d60657db13707a159727326cad" dependencies = [ "libc", - "winapi 0.3.9", + "winapi", ] [[package]] name = "songbird" -version = "0.1.7" +version = "0.2.0-beta.4" +source = "git+https://github.com/serenity-rs/songbird?branch=next#2a2543ebc830ba442bcd836733d52114fd1b3f8a" dependencies = [ "async-trait", - "async-tungstenite 0.13.1", + "async-tungstenite", "audiopus", "byteorder", "dashmap", @@ -1818,14 +1705,15 @@ dependencies = [ "flume", "futures", "parking_lot", - "rand 0.8.4", + "pin-project", + "rand", "serde", "serde_json", "serenity", "serenity-voice-model", "spin_sleep", - "spinning_top", "streamcatcher", + "symphonia-core", "tokio", "tracing", "tracing-futures", @@ -1837,13 +1725,13 @@ dependencies = [ [[package]] name = "soundfx-rs" -version = "1.3.1" +version = "1.4.0" dependencies = [ "dashmap", "dotenv", "env_logger", "lazy_static", - "log 0.4.14", + "log", "regex", "regex_command_attr", "reqwest", @@ -1867,14 +1755,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a98101bdc3833e192713c2af0b0dd2614f50d1cf1f7a97c5221b7aac052acc7" dependencies = [ "once_cell", - "winapi 0.3.9", + "winapi", ] [[package]] name = "spinning_top" -version = "0.2.2" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e529d73e80d64b5f2631f9035113347c578a1c9c7774b83a2b880788459ab36" +checksum = "75adad84ee84b521fb2cca2d4fd0f1dab1d8d026bda3c5bea4ca63b5f9f9293c" dependencies = [ "lock_api", ] @@ -1910,11 +1798,11 @@ checksum = "7f23af36748ec8ea8d49ef8499839907be41b0b1178a4e82b8cb45d29f531dc9" dependencies = [ "ahash", "atoi", - "base64 0.13.0", + "base64", "bigdecimal", - "bitflags 1.2.1", + "bitflags", "byteorder", - "bytes 1.0.1", + "bytes", "crossbeam-channel", "crossbeam-queue", "crossbeam-utils 0.8.5", @@ -1928,13 +1816,13 @@ dependencies = [ "hex", "itoa", "libc", - "log 0.4.14", + "log", "memchr", "num-bigint 0.3.2", "once_cell", "parking_lot", "percent-encoding", - "rand 0.8.4", + "rand", "rsa", "rustls", "sha-1", @@ -1947,7 +1835,7 @@ dependencies = [ "tokio-stream", "url", "webpki", - "webpki-roots 0.21.1", + "webpki-roots", "whoami", ] @@ -2010,80 +1898,44 @@ dependencies = [ [[package]] name = "subtle" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + +[[package]] +name = "symphonia-core" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e32b956473d98c601dac257fab8a7700d42e49fdd7a33432dd5dc7fdd2448dd" +dependencies = [ + "arrayvec 0.4.12", + "bitflags", + "byteorder", + "lazy_static", + "log", +] [[package]] name = "syn" -version = "1.0.73" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" +checksum = "1873d832550d4588c3dbc20f01361ab00bfe741048f71e3fecf145a7cc18b29c" dependencies = [ "proc-macro2", "quote", - "unicode-xid 0.2.2", + "unicode-xid", ] [[package]] name = "synstructure" -version = "0.12.4" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" +checksum = "474aaa926faa1603c40b7885a9eaea29b444d1cb2850cb7c0e37bb1a4182f4fa" dependencies = [ "proc-macro2", "quote", "syn", - "unicode-xid 0.2.2", -] - -[[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", + "unicode-xid", ] [[package]] @@ -2100,20 +1952,10 @@ checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ "cfg-if 1.0.0", "libc", - "rand 0.8.4", + "rand", "redox_syscall", "remove_dir_all", - "winapi 0.3.9", -] - -[[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", + "winapi", ] [[package]] @@ -2127,18 +1969,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.25" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa6f76457f59514c7eeb4e59d891395fab0b2fd1d40723ae737d64153392e9c6" +checksum = "93119e4feac1cbe6c798c34d3a53ea0026b0b1de6a120deef895137c0529bfe2" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.25" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a36768c0fbf1bb15eca10defa29526bda730a2376c2ab4393ccfa16fb1a318d" +checksum = "060d69a0afe7796bf42e9e2ff91f5ee691fb15c53d38b4b62a9a53eb23164745" dependencies = [ "proc-macro2", "quote", @@ -2152,14 +1994,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ "libc", - "winapi 0.3.9", + "winapi", ] [[package]] name = "tinyvec" -version = "1.2.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" +checksum = "848a1e1181b9f6753b5e96a092749e29b11d19ede67dfbbd6c7dc7e0f49b5338" dependencies = [ "tinyvec_macros", ] @@ -2172,12 +2014,12 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.7.1" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fb2ed024293bb19f7a5dc54fe83bf86532a44c12a2bb8ba40d64a4509395ca2" +checksum = "01cf844b23c6131f624accf65ce0e4e9956a8bb329400ea5bcc26ae3a5c20b0b" dependencies = [ "autocfg 1.0.1", - "bytes 1.0.1", + "bytes", "libc", "memchr", "mio", @@ -2186,14 +2028,14 @@ dependencies = [ "pin-project-lite", "signal-hook-registry", "tokio-macros", - "winapi 0.3.9", + "winapi", ] [[package]] name = "tokio-macros" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c49e3df43841dafb86046472506755d8501c5615673955f6aa17181125d13c37" +checksum = "54473be61f4ebe4efd09cec9bd5d16fa51d70ea0192213d754d2d500457db110" dependencies = [ "proc-macro2", "quote", @@ -2223,9 +2065,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8864d706fdb3cc0843a49647ac892720dac98a6eeb818b77190592cf4994066" +checksum = "7b2f3f698253f03119ac0102beaa64f67a67e08074d03a22d18784104543727f" dependencies = [ "futures-core", "pin-project-lite", @@ -2238,10 +2080,10 @@ version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1caa0b0c8d94a049db56b5acf8cba99dc0623aab1b26d5b5f5e2d945846b3592" dependencies = [ - "bytes 1.0.1", + "bytes", "futures-core", "futures-sink", - "log 0.4.14", + "log", "pin-project-lite", "tokio", ] @@ -2259,7 +2101,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" dependencies = [ "cfg-if 1.0.0", - "log 0.4.14", + "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -2301,46 +2143,27 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" -[[package]] -name = "tungstenite" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0308d80d86700c5878b9ef6321f020f29b1bb9d5ff3cab25e75e23f3a492a23" -dependencies = [ - "base64 0.12.3", - "byteorder", - "bytes 0.5.6", - "http", - "httparse", - "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", + "base64", "byteorder", - "bytes 1.0.1", + "bytes", "http", "httparse", - "input_buffer 0.4.0", - "log 0.4.14", - "rand 0.8.4", + "input_buffer", + "log", + "rand", "rustls", "sha-1", "thiserror", "url", "utf-8", "webpki", - "webpki-roots 0.21.1", + "webpki-roots", ] [[package]] @@ -2366,12 +2189,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" -dependencies = [ - "matches", -] +checksum = "246f4c42e67e7a4e3c6106ff716a5d067d4132a642840b242e357e468a2a0085" [[package]] name = "unicode-normalization" @@ -2384,15 +2204,9 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" - -[[package]] -name = "unicode-xid" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36dff09cafb4ec7c8cf0023eb0b686cb6ce65499116a12201c9e11840ca01beb" +checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" [[package]] name = "unicode-xid" @@ -2408,9 +2222,9 @@ checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" [[package]] name = "universal-hash" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402" +checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05" dependencies = [ "generic-array", "subtle", @@ -2432,6 +2246,7 @@ dependencies = [ "idna", "matches", "percent-encoding", + "serde", ] [[package]] @@ -2446,7 +2261,7 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" dependencies = [ - "getrandom 0.2.3", + "getrandom", ] [[package]] @@ -2473,16 +2288,10 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" dependencies = [ - "log 0.4.14", + "log", "try-lock", ] -[[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" @@ -2491,9 +2300,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-bindgen" -version = "0.2.74" +version = "0.2.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" +checksum = "b608ecc8f4198fe8680e2ed18eccab5f0cd4caaf3d83516fa5fb2e927fda2586" dependencies = [ "cfg-if 1.0.0", "serde", @@ -2503,13 +2312,13 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.74" +version = "0.2.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900" +checksum = "580aa3a91a63d23aac5b6b267e2d13cb4f363e31dce6c352fca4752ae12e479f" dependencies = [ "bumpalo", "lazy_static", - "log 0.4.14", + "log", "proc-macro2", "quote", "syn", @@ -2518,9 +2327,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.24" +version = "0.4.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fba7978c679d53ce2d0ac80c8c175840feb849a161664365d1287b41f2e67f1" +checksum = "16646b21c3add8e13fdb8f20172f8a28c3dbf62f45406bcff0233188226cfe0c" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -2530,9 +2339,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.74" +version = "0.2.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4" +checksum = "171ebf0ed9e1458810dfcb31f2e766ad6b3a89dbda42d8901f2b268277e5f09c" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2540,9 +2349,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.74" +version = "0.2.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97" +checksum = "6c2657dd393f03aa2a659c25c6ae18a13a4048cebd220e147933ea837efc589f" dependencies = [ "proc-macro2", "quote", @@ -2553,15 +2362,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.74" +version = "0.2.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f" +checksum = "2e0c4a743a309662d45f4ede961d7afa4ba4131a59a639f29b0069c3798bbcc2" [[package]] name = "web-sys" -version = "0.3.51" +version = "0.3.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e828417b379f3df7111d3a2a9e5753706cae29c41f7c4029ee9fd77f3e09e582" +checksum = "01c70a82d842c9979078c772d4a1344685045f1a5628f677c2b2eab4dd7d2696" dependencies = [ "js-sys", "wasm-bindgen", @@ -2577,15 +2386,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "webpki-roots" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f20dea7535251981a9670857150d571846545088359b28e4951d350bdaf179f" -dependencies = [ - "webpki", -] - [[package]] name = "webpki-roots" version = "0.21.1" @@ -2605,12 +2405,6 @@ dependencies = [ "web-sys", ] -[[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" @@ -2621,12 +2415,6 @@ 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" @@ -2639,7 +2427,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2654,7 +2442,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2665,13 +2453,13 @@ checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" [[package]] name = "xsalsa20poly1305" -version = "0.6.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0304c336e98d753428f7b3d8899d60b8a87a961ef50bdfc44af0c1bea2651ce5" +checksum = "2e0f69b133860e3614a4d4fdd6f0d7fe3219e9d67a7e8cd537676a4ebc8313db" dependencies = [ "aead", "poly1305", - "rand_core 0.5.1", + "rand_core", "salsa20", "subtle", "zeroize", diff --git a/Cargo.toml b/Cargo.toml index ff7c5e3..c39a27a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "soundfx-rs" -version = "1.3.1" +version = "1.4.0" authors = ["jellywx "] edition = "2018" [dependencies] -songbird = { path = "/home/jude/songbird" } -serenity = { path = "/home/jude/serenity", features = ["voice", "collector", "unstable_discord_api"] } +songbird = { git = "https://github.com/serenity-rs/songbird", branch = "next" } +serenity = { git = "https://github.com/serenity-rs/serenity", branch = "next", features = ["voice", "collector", "unstable_discord_api"] } sqlx = { version = "0.5", default-features = false, features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal"] } dotenv = "0.15" tokio = { version = "1", features = ["fs", "process", "io-util"] } diff --git a/regex_command_attr/src/structures.rs b/regex_command_attr/src/structures.rs index 302a0b0..0cab491 100644 --- a/regex_command_attr/src/structures.rs +++ b/regex_command_attr/src/structures.rs @@ -296,7 +296,9 @@ impl ApplicationCommandOptionType { impl ToTokens for ApplicationCommandOptionType { fn to_tokens(&self, stream: &mut TokenStream2) { - let path = quote!(serenity::model::interactions::ApplicationCommandOptionType); + let path = quote!( + serenity::model::interactions::application_command::ApplicationCommandOptionType + ); let variant = match self { ApplicationCommandOptionType::SubCommand => quote!(SubCommand), ApplicationCommandOptionType::SubCommandGroup => quote!(SubCommandGroup), diff --git a/src/cmds/info.rs b/src/cmds/info.rs index b5843c6..cf0a876 100644 --- a/src/cmds/info.rs +++ b/src/cmds/info.rs @@ -192,7 +192,7 @@ async fn info( invoke: &(dyn CommandInvoke + Sync + Send), _args: Args, ) -> CommandResult { - let current_user = ctx.cache.current_user().await; + let current_user = ctx.cache.current_user(); invoke.respond(ctx.http.clone(), CreateGenericResponse::new() .embed(|e| e diff --git a/src/cmds/manage.rs b/src/cmds/manage.rs index 594b4b6..8b1356c 100644 --- a/src/cmds/manage.rs +++ b/src/cmds/manage.rs @@ -225,7 +225,7 @@ pub async fn delete_sound( } else { let has_perms = { if let Ok(member) = invoke.member(&ctx).await { - if let Ok(perms) = member.permissions(&ctx).await { + if let Ok(perms) = member.permissions(&ctx) { perms.manage_guild() } else { false diff --git a/src/cmds/play.rs b/src/cmds/play.rs index 55583cc..7f3bcf9 100644 --- a/src/cmds/play.rs +++ b/src/cmds/play.rs @@ -4,7 +4,7 @@ use serenity::{ builder::CreateActionRow, client::Context, framework::standard::CommandResult, - model::interactions::{ButtonStyle, InteractionResponseType}, + model::interactions::{message_component::ButtonStyle, InteractionResponseType}, }; use songbird::{ @@ -42,7 +42,7 @@ pub async fn play( invoke: &(dyn CommandInvoke + Sync + Send), args: Args, ) -> CommandResult { - let guild = invoke.guild(ctx.cache.clone()).await.unwrap(); + let guild = invoke.guild(ctx.cache.clone()).unwrap(); invoke .respond( @@ -72,7 +72,7 @@ pub async fn loop_play( invoke: &(dyn CommandInvoke + Sync + Send), args: Args, ) -> CommandResult { - let guild = invoke.guild(ctx.cache.clone()).await.unwrap(); + let guild = invoke.guild(ctx.cache.clone()).unwrap(); invoke .respond( @@ -101,7 +101,7 @@ pub async fn play_ambience( invoke: &(dyn CommandInvoke + Sync + Send), args: Args, ) -> CommandResult { - let guild = invoke.guild(ctx.cache.clone()).await.unwrap(); + let guild = invoke.guild(ctx.cache.clone()).unwrap(); let channel_to_join = guild .voice_states diff --git a/src/event_handlers.rs b/src/event_handlers.rs index 7174750..d6609b2 100644 --- a/src/event_handlers.rs +++ b/src/event_handlers.rs @@ -14,7 +14,7 @@ use serenity::{ gateway::{Activity, Ready}, guild::Guild, id::GuildId, - interactions::Interaction, + interactions::{Interaction, InteractionResponseType}, voice::VoiceState, }, utils::shard_id, @@ -22,9 +22,8 @@ use serenity::{ use songbird::{Event, EventContext, EventHandler as SongbirdEventHandler}; -use crate::framework::{Args, CommandInvoke}; -use serenity::model::interactions::{InteractionData, InteractionType}; -use serenity::model::prelude::InteractionResponseType; +use crate::framework::Args; + use std::{collections::HashMap, env}; pub struct RestartTrack; @@ -63,13 +62,12 @@ impl EventHandler for Handler { async fn guild_create(&self, ctx: Context, guild: Guild, is_new: bool) { if is_new { if let Ok(token) = env::var("DISCORDBOTS_TOKEN") { - let shard_count = ctx.cache.shard_count().await; + let shard_count = ctx.cache.shard_count(); let current_shard_id = shard_id(guild.id.as_u64().to_owned(), shard_count); let guild_count = ctx .cache .guilds() - .await .iter() .filter(|g| shard_id(g.as_u64().to_owned(), shard_count) == current_shard_id) .count() as u64; @@ -91,7 +89,7 @@ impl EventHandler for Handler { .post( format!( "https://top.gg/api/bots/{}/stats", - ctx.cache.current_user_id().await.as_u64() + ctx.cache.current_user_id().as_u64() ) .as_str(), ) @@ -117,8 +115,7 @@ impl EventHandler for Handler { if let Some(past_state) = old { if let (Some(guild_id), None) = (guild_id_opt, new.channel_id) { if let Some(channel_id) = past_state.channel_id { - if let Some(Channel::Guild(channel)) = channel_id.to_channel_cached(&ctx).await - { + if let Some(Channel::Guild(channel)) = channel_id.to_channel_cached(&ctx) { if channel.members(&ctx).await.map(|m| m.len()).unwrap_or(0) <= 1 { let songbird = songbird::get(&ctx).await.unwrap(); @@ -128,7 +125,7 @@ impl EventHandler for Handler { } } } else if let (Some(guild_id), Some(user_channel)) = (guild_id_opt, new.channel_id) { - if let Some(guild) = ctx.cache.guild(guild_id).await { + if let Some(guild) = ctx.cache.guild(guild_id) { let pool = ctx .data .read() @@ -183,12 +180,12 @@ SELECT name, id, plays, public, server_id, uploader_id } async fn interaction_create(&self, ctx: Context, interaction: Interaction) { - if interaction.guild_id.is_none() { - return; - } + match interaction { + Interaction::ApplicationCommand(application_command) => { + if application_command.guild_id.is_none() { + return; + } - match interaction.kind { - InteractionType::ApplicationCommand => { let framework = ctx .data .read() @@ -197,33 +194,34 @@ SELECT name, id, plays, public, server_id, uploader_id .cloned() .expect("RegexFramework not found in context"); - framework.execute(ctx, interaction).await; + framework.execute(ctx, application_command).await; } - InteractionType::MessageComponent => { - if let (Some(InteractionData::MessageComponent(data)), Some(member)) = - (interaction.clone().data, interaction.clone().member) - { - let mut args = Args { - args: Default::default(), - }; - args.args.insert("query".to_string(), data.custom_id); - - play_from_query( - &ctx, - interaction.guild(ctx.cache.clone()).await.unwrap(), - member.user.id, - args, - false, - ) - .await; - - interaction - .create_interaction_response(ctx, |r| { - r.kind(InteractionResponseType::DeferredUpdateMessage) - }) - .await - .unwrap(); + Interaction::MessageComponent(component) => { + if component.guild_id.is_none() { + return; } + + let mut args = Args { + args: Default::default(), + }; + args.args + .insert("query".to_string(), component.data.custom_id.clone()); + + play_from_query( + &ctx, + component.guild_id.unwrap().to_guild_cached(&ctx).unwrap(), + component.user.id, + args, + false, + ) + .await; + + component + .create_interaction_response(ctx, |r| { + r.kind(InteractionResponseType::DeferredUpdateMessage) + }) + .await + .unwrap(); } _ => {} } diff --git a/src/framework.rs b/src/framework.rs index 13beec0..974693e 100644 --- a/src/framework.rs +++ b/src/framework.rs @@ -10,8 +10,12 @@ use serenity::{ channel::{Channel, GuildChannel, Message}, guild::{Guild, Member}, id::{ChannelId, GuildId, UserId}, - interactions::{ApplicationCommand, Interaction, InteractionData}, - prelude::{ApplicationCommandOptionType, InteractionResponseType}, + interactions::{ + application_command::{ + ApplicationCommand, ApplicationCommandInteraction, ApplicationCommandOptionType, + }, + InteractionResponseType, + }, }, prelude::TypeMapKey, Result as SerenityResult, @@ -126,11 +130,11 @@ impl CreateGenericResponse { pub trait CommandInvoke { fn channel_id(&self) -> ChannelId; fn guild_id(&self) -> Option; - async fn guild(&self, cache: Arc) -> Option; + fn guild(&self, cache: Arc) -> Option; fn author_id(&self) -> UserId; async fn member(&self, context: &Context) -> SerenityResult; fn msg(&self) -> Option; - fn interaction(&self) -> Option; + fn interaction(&self) -> Option; async fn respond( &self, http: Arc, @@ -153,8 +157,8 @@ impl CommandInvoke for Message { self.guild_id } - async fn guild(&self, cache: Arc) -> Option { - self.guild(cache).await + fn guild(&self, cache: Arc) -> Option { + self.guild(cache) } fn author_id(&self) -> UserId { @@ -169,7 +173,7 @@ impl CommandInvoke for Message { Some(self.clone()) } - fn interaction(&self) -> Option { + fn interaction(&self) -> Option { None } @@ -187,7 +191,10 @@ impl CommandInvoke for Message { } if let Some(components) = generic_response.components { - m.set_components(components.clone()); + m.components(|c| { + *c = components; + c + }); } m @@ -210,7 +217,10 @@ impl CommandInvoke for Message { } if let Some(components) = generic_response.components { - m.set_components(components.clone()); + m.components(|c| { + *c = components; + c + }); } m @@ -221,18 +231,18 @@ impl CommandInvoke for Message { } #[async_trait] -impl CommandInvoke for Interaction { +impl CommandInvoke for ApplicationCommandInteraction { fn channel_id(&self) -> ChannelId { - self.channel_id.unwrap() + self.channel_id } fn guild_id(&self) -> Option { self.guild_id } - async fn guild(&self, cache: Arc) -> Option { + fn guild(&self, cache: Arc) -> Option { if let Some(guild_id) = self.guild_id { - guild_id.to_guild_cached(cache).await + guild_id.to_guild_cached(cache) } else { None } @@ -250,7 +260,7 @@ impl CommandInvoke for Interaction { None } - fn interaction(&self) -> Option { + fn interaction(&self) -> Option { Some(self.clone()) } @@ -269,7 +279,10 @@ impl CommandInvoke for Interaction { } if let Some(components) = generic_response.components { - d.set_components(components.clone()); + d.components(|c| { + *c = components; + c + }); } d @@ -292,7 +305,10 @@ impl CommandInvoke for Interaction { } if let Some(components) = generic_response.components { - d.set_components(components.clone()); + d.components(|c| { + *c = components; + c + }); } d @@ -652,63 +668,64 @@ impl RegexFramework { info!("{} slash commands built! Ready to go", count); } - pub async fn execute(&self, ctx: Context, interaction: Interaction) { - if let Some(InteractionData::ApplicationCommand(data)) = interaction.data.clone() { - let command = { - let name = data.name; + pub async fn execute(&self, ctx: Context, interaction: ApplicationCommandInteraction) { + let command = { + self.commands.get(&interaction.data.name).expect(&format!( + "Received invalid command: {}", + interaction.data.name + )) + }; - self.commands - .get(&name) - .expect(&format!("Received invalid command: {}", name)) - }; + if command + .check_permissions( + &ctx, + &interaction.guild(ctx.cache.clone()).unwrap(), + &interaction.clone().member.unwrap(), + ) + .await + { + let mut args = HashMap::new(); - if command - .check_permissions( - &ctx, - &interaction.guild(ctx.cache.clone()).await.unwrap(), - &interaction.member(&ctx).await.unwrap(), - ) - .await + for arg in interaction + .data + .options + .iter() + .filter(|o| o.value.is_some()) { - let mut args = HashMap::new(); - - for arg in data.options.iter().filter(|o| o.value.is_some()) { - args.insert( - arg.name.clone(), - match arg.value.clone().unwrap() { - Value::Bool(b) => { - if b { - arg.name.clone() - } else { - String::new() - } + args.insert( + arg.name.clone(), + match arg.value.clone().unwrap() { + Value::Bool(b) => { + if b { + arg.name.clone() + } else { + String::new() } - Value::Number(n) => n.to_string(), - Value::String(s) => s, - _ => String::new(), - }, - ); - } + } + Value::Number(n) => n.to_string(), + Value::String(s) => s, + _ => String::new(), + }, + ); + } - (command.fun)(&ctx, &interaction, Args { args }) - .await - .unwrap(); - } else if command.required_permissions == PermissionLevel::Managed { - let _ = interaction + (command.fun)(&ctx, &interaction, Args { args }) + .await + .unwrap(); + } else if command.required_permissions == PermissionLevel::Managed { + let _ = interaction .respond( ctx.http.clone(), CreateGenericResponse::new().content("You must either be an Admin or have a role specified in `?roles` to do this command") ) .await; - } else if command.required_permissions == PermissionLevel::Restricted { - let _ = interaction - .respond( - ctx.http.clone(), - CreateGenericResponse::new() - .content("You must be an Admin to do this command"), - ) - .await; - } + } else if command.required_permissions == PermissionLevel::Restricted { + let _ = interaction + .respond( + ctx.http.clone(), + CreateGenericResponse::new().content("You must be an Admin to do this command"), + ) + .await; } } } @@ -725,9 +742,9 @@ impl Framework for RegexFramework { ctx: &Context, channel: &GuildChannel, ) -> SerenityResult { - let user_id = ctx.cache.current_user_id().await; + let user_id = ctx.cache.current_user_id(); - let channel_perms = channel.permissions_for_user(ctx, user_id).await?; + let channel_perms = channel.permissions_for_user(ctx, user_id)?; Ok( if channel_perms.send_messages() && channel_perms.embed_links() { @@ -754,8 +771,8 @@ impl Framework for RegexFramework { if msg.author.bot || msg.content.is_empty() { } // Guild Command - else if let (Some(guild), Some(Channel::Guild(channel))) = - (msg.guild(&ctx).await, msg.channel(&ctx).await) + else if let (Some(guild), Ok(Channel::Guild(channel))) = + (msg.guild(&ctx), msg.channel(&ctx).await) { if let Some(full_match) = self.command_matcher.captures(&msg.content) { if check_prefix(&ctx, &guild, full_match.name("prefix")).await { diff --git a/src/main.rs b/src/main.rs index 04d4c00..5546331 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,7 +110,7 @@ async fn join_channel( channel_id: ChannelId, ) -> (Arc>, JoinResult<()>) { let songbird = songbird::get(ctx).await.unwrap(); - let current_user = ctx.cache.current_user_id().await; + let current_user = ctx.cache.current_user_id(); let current_voice_state = guild .voice_states @@ -138,9 +138,9 @@ async fn join_channel( let _ = call.lock().await.deafen(true).await; } - if let Some(Channel::Guild(channel)) = channel_id.to_channel_cached(&ctx).await { + if let Some(Channel::Guild(channel)) = channel_id.to_channel_cached(&ctx) { channel - .edit_voice_state(&ctx, ctx.cache.current_user().await, |v| v.suppress(false)) + .edit_voice_state(&ctx, ctx.cache.current_user(), |v| v.suppress(false)) .await; }