From 6685163c967151b81da1864c49cc843499a62fcc Mon Sep 17 00:00:00 2001 From: moonleay Date: Sun, 19 May 2024 04:24:40 +0200 Subject: [PATCH] WIP: started working on lavalink rewrite, this is not compiling yet --- Cargo.lock | 507 ++++++++++++++------------- Cargo.toml | 5 +- src/commands/now_playing.rs | 6 +- src/commands/play.rs | 4 +- src/commands/skip.rs | 5 +- src/commands/stop.rs | 5 +- src/events/lavalink_event_handler.rs | 30 ++ src/events/mod.rs | 1 + src/main.rs | 50 ++- src/music/mod.rs | 3 +- src/music/music_events.rs | 56 --- src/music/music_manager.rs | 159 +++++---- src/music/music_queue.rs | 84 ----- src/music/preview.rs | 7 + src/util/config.rs | 4 + src/util/embed.rs | 19 +- 16 files changed, 442 insertions(+), 503 deletions(-) create mode 100644 src/events/lavalink_event_handler.rs create mode 100644 src/events/mod.rs delete mode 100644 src/music/music_events.rs delete mode 100644 src/music/music_queue.rs create mode 100644 src/music/preview.rs diff --git a/Cargo.lock b/Cargo.lock index f5d366f..c5e1094 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -51,6 +51,12 @@ dependencies = [ "libc", ] +[[package]] +name = "arc-swap" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" + [[package]] name = "arrayvec" version = "0.7.4" @@ -62,13 +68,29 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.79" +version = "0.1.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" +checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.64", +] + +[[package]] +name = "async-tungstenite" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3609af4bbf701ddaf1f6bb4e6257dff4ff8932327d0e685d3f653724c258b1ac" +dependencies = [ + "futures-io", + "futures-util", + "log", + "native-tls", + "pin-project-lite", + "tokio", + "tokio-native-tls", + "tungstenite 0.21.0", ] [[package]] @@ -93,9 +115,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" @@ -147,21 +169,21 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.15.4" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytecount" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1e5f035d16fc623ae5f74981db80a439803888314e3a555fd6f04acd51a3205" +checksum = "5ce89b21cab1437276d2650d57e971f9d548a2d9037cc231abdc0562b97498ce" [[package]] name = "bytemuck" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" +checksum = "78834c15cb5d5efe3452d58b1e8ba890dd62d21907f867f383358198e56ebca5" [[package]] name = "byteorder" @@ -177,9 +199,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "camino" -version = "1.1.6" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c59e92b5a388f549b863a7bea62612c09f24c8393560709a54558a9abdfb3b9c" +checksum = "e0ec6b951b160caa93cc0c7b209e5a3bff7aae9062213451ac99493cd844c239" dependencies = [ "serde", ] @@ -208,9 +230,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.90" +version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" [[package]] name = "cfg-if" @@ -220,9 +242,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.37" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", @@ -230,7 +252,7 @@ dependencies = [ "num-traits", "serde", "wasm-bindgen", - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -367,9 +389,9 @@ dependencies = [ [[package]] name = "data-encoding" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" +checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" [[package]] name = "deranged" @@ -435,9 +457,9 @@ dependencies = [ [[package]] name = "encoding_rs" -version = "0.8.33" +version = "0.8.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" dependencies = [ "cfg-if", ] @@ -450,9 +472,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", "windows-sys 0.52.0", @@ -475,15 +497,15 @@ checksum = "af9673d8203fcb076b19dfd17e38b3d4ae9f44959416ea532ce72415a6020365" [[package]] name = "fastrand" -version = "2.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] name = "flate2" -version = "1.0.28" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" dependencies = [ "crc32fast", "miniz_oxide", @@ -498,7 +520,7 @@ dependencies = [ "futures-core", "futures-sink", "nanorand", - "spin 0.9.8", + "spin", ] [[package]] @@ -587,7 +609,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.64", ] [[package]] @@ -655,9 +677,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.12" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "js-sys", @@ -699,9 +721,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "hermit-abi" @@ -787,7 +809,7 @@ dependencies = [ "futures-util", "http 0.2.12", "hyper", - "rustls 0.21.10", + "rustls 0.21.12", "tokio", "tokio-rustls 0.24.1", ] @@ -878,6 +900,30 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "lavalink-rs" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87676c01f7c63f255899cc2672f11a1d7d6848787cf0e6abbc6b79c839cf9f24" +dependencies = [ + "arc-swap", + "async-tungstenite", + "dashmap", + "futures", + "http 1.1.0", + "oneshot", + "reqwest", + "serde", + "serde_json", + "serde_qs", + "serenity", + "songbird", + "tokio", + "tracing", + "url", + "version_check", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -892,9 +938,9 @@ checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libredox" @@ -908,15 +954,15 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -936,6 +982,7 @@ checksum = "ff50ecb28bb86013e935fb6683ab1f6d3a20016f123c76fd4c27470076ac30f5" dependencies = [ "cfg-if", "generator", + "pin-utils", "scoped-tls", "serde", "serde_json", @@ -991,9 +1038,9 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" dependencies = [ "adler", ] @@ -1060,9 +1107,9 @@ dependencies = [ [[package]] name = "num-complex" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" dependencies = [ "num-traits", ] @@ -1084,9 +1131,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -1116,6 +1163,15 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "oneshot" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f6640c6bda7731b1fdbab747981a0f896dd1fedaf9f4a53fa237a04a84431f4" +dependencies = [ + "loom", +] + [[package]] name = "opaque-debug" version = "0.3.1" @@ -1145,7 +1201,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.64", ] [[package]] @@ -1189,9 +1245,9 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" dependencies = [ "lock_api", "parking_lot_core", @@ -1199,15 +1255,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-targets 0.48.5", + "windows-targets 0.52.5", ] [[package]] @@ -1233,7 +1289,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.64", ] [[package]] @@ -1272,7 +1328,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.58", + "syn 2.0.64", ] [[package]] @@ -1318,9 +1374,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" dependencies = [ "unicode-ident", ] @@ -1338,9 +1394,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -1386,11 +1442,11 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", ] [[package]] @@ -1474,7 +1530,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls 0.21.10", + "rustls 0.21.12", "rustls-pemfile", "serde", "serde_json", @@ -1495,21 +1551,6 @@ dependencies = [ "winreg", ] -[[package]] -name = "ring" -version = "0.16.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" -dependencies = [ - "cc", - "libc", - "once_cell", - "spin 0.5.2", - "untrusted 0.7.1", - "web-sys", - "winapi", -] - [[package]] name = "ring" version = "0.17.8" @@ -1520,8 +1561,8 @@ dependencies = [ "cfg-if", "getrandom", "libc", - "spin 0.9.8", - "untrusted 0.9.0", + "spin", + "untrusted", "windows-sys 0.52.0", ] @@ -1548,9 +1589,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustendo" @@ -1559,6 +1600,7 @@ dependencies = [ "chrono", "confy", "futures", + "lavalink-rs", "lazy_static", "reqwest", "serde", @@ -1589,9 +1631,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.32" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ "bitflags 2.5.0", "errno", @@ -1602,54 +1644,30 @@ dependencies = [ [[package]] name = "rustls" -version = "0.20.9" +version = "0.21.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", - "ring 0.16.20", - "sct", - "webpki", -] - -[[package]] -name = "rustls" -version = "0.21.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" -dependencies = [ - "log", - "ring 0.17.8", + "ring", "rustls-webpki 0.101.7", "sct", ] [[package]] name = "rustls" -version = "0.22.3" +version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99008d7ad0bbbea527ec27bddbc0e432c5b87d8175178cee68d2eec9c4a1813c" +checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" dependencies = [ "log", - "ring 0.17.8", + "ring", "rustls-pki-types", - "rustls-webpki 0.102.2", + "rustls-webpki 0.102.4", "subtle", "zeroize", ] -[[package]] -name = "rustls-native-certs" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" -dependencies = [ - "openssl-probe", - "rustls-pemfile", - "schannel", - "security-framework", -] - [[package]] name = "rustls-pemfile" version = "1.0.4" @@ -1661,9 +1679,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.4.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecd36cc4259e3e4514335c4a138c6b43171a8d61d8f5c9348f9fc7529416f247" +checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" [[package]] name = "rustls-webpki" @@ -1671,26 +1689,26 @@ version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", + "ring", + "untrusted", ] [[package]] name = "rustls-webpki" -version = "0.102.2" +version = "0.102.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "faaa0a62740bedb9b2ef5afa303da42764c012f743917351dc9a237ea1663610" +checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" dependencies = [ - "ring 0.17.8", + "ring", "rustls-pki-types", - "untrusted 0.9.0", + "untrusted", ] [[package]] name = "rustversion" -version = "1.0.14" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" [[package]] name = "rusty_pool" @@ -1707,9 +1725,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "salsa20" @@ -1756,8 +1774,8 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", + "ring", + "untrusted", ] [[package]] @@ -1772,11 +1790,11 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6" +checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", "core-foundation", "core-foundation-sys", "libc", @@ -1785,9 +1803,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef" +checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" dependencies = [ "core-foundation-sys", "libc", @@ -1795,18 +1813,18 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.22" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" dependencies = [ "serde", ] [[package]] name = "serde" -version = "1.0.197" +version = "1.0.202" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395" dependencies = [ "serde_derive", ] @@ -1834,20 +1852,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.202" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.64", ] [[package]] name = "serde_json" -version = "1.0.115" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "itoa", "ryu", @@ -1855,21 +1873,32 @@ dependencies = [ ] [[package]] -name = "serde_repr" -version = "0.1.18" +name = "serde_qs" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" +checksum = "0431a35568651e363364210c91983c1da5eb29404d9f0928b67d4ebcfa7d330c" +dependencies = [ + "percent-encoding", + "serde", + "thiserror", +] + +[[package]] +name = "serde_repr" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.64", ] [[package]] name = "serde_spanned" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" dependencies = [ "serde", ] @@ -1957,9 +1986,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" dependencies = [ "libc", ] @@ -1996,9 +2025,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", "windows-sys 0.52.0", @@ -2048,12 +2077,6 @@ dependencies = [ "uuid", ] -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - [[package]] name = "spin" version = "0.9.8" @@ -2238,9 +2261,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.58" +version = "2.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +checksum = "7ad3dee41f36859875573074334c200d1add8e4a87bb37113ebd31d926b7b11f" dependencies = [ "proc-macro2", "quote", @@ -2294,22 +2317,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.58" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.58" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.64", ] [[package]] @@ -2324,9 +2347,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.34" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", @@ -2345,9 +2368,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ "num-conv", "time-core", @@ -2394,7 +2417,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.64", ] [[package]] @@ -2407,24 +2430,13 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-rustls" -version = "0.23.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" -dependencies = [ - "rustls 0.20.9", - "tokio", - "webpki", -] - [[package]] name = "tokio-rustls" version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "rustls 0.21.10", + "rustls 0.21.12", "tokio", ] @@ -2434,7 +2446,7 @@ version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" dependencies = [ - "rustls 0.22.3", + "rustls 0.22.4", "rustls-pki-types", "tokio", ] @@ -2447,12 +2459,10 @@ checksum = "54319c93411147bced34cb5609a80e0a8e44c5999c93903a81cd866630ec0bfd" dependencies = [ "futures-util", "log", - "rustls 0.20.9", - "rustls-native-certs", + "native-tls", "tokio", - "tokio-rustls 0.23.4", + "tokio-native-tls", "tungstenite 0.18.0", - "webpki", ] [[package]] @@ -2463,9 +2473,11 @@ checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" dependencies = [ "futures-util", "log", - "rustls 0.22.3", + "native-tls", + "rustls 0.22.4", "rustls-pki-types", "tokio", + "tokio-native-tls", "tokio-rustls 0.25.0", "tungstenite 0.21.0", "webpki-roots 0.26.1", @@ -2473,23 +2485,22 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" dependencies = [ "bytes", "futures-core", "futures-sink", "pin-project-lite", "tokio", - "tracing", ] [[package]] name = "toml" -version = "0.8.12" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" +checksum = "a4e43f8cc456c9704c851ae29c67e17ef65d2c30017c17a9765b89c382dc8bba" dependencies = [ "serde", "serde_spanned", @@ -2499,18 +2510,18 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.22.9" +version = "0.22.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4" +checksum = "c127785850e8c20836d49732ae6abfa47616e60bf9d9f57c43c250361a9db96c" dependencies = [ "indexmap", "serde", @@ -2545,7 +2556,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.64", ] [[package]] @@ -2631,13 +2642,12 @@ dependencies = [ "http 0.2.12", "httparse", "log", + "native-tls", "rand", - "rustls 0.20.9", "sha1", "thiserror", "url", "utf-8", - "webpki", ] [[package]] @@ -2652,8 +2662,9 @@ dependencies = [ "http 1.1.0", "httparse", "log", + "native-tls", "rand", - "rustls 0.22.3", + "rustls 0.22.4", "rustls-pki-types", "sha1", "thiserror", @@ -2669,9 +2680,8 @@ checksum = "30be5c7e2b13b4a59e0f93344c070c23404279a318a324eece1f4384ead47d86" dependencies = [ "bitflags 1.3.2", "futures-util", + "native-tls", "rand", - "rustls 0.20.9", - "rustls-native-certs", "serde", "serde_json", "tokio", @@ -2742,7 +2752,7 @@ checksum = "905e88c2a4cc27686bd57e495121d451f027e441388a67f773be729ad4be1ea8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.64", ] [[package]] @@ -2785,12 +2795,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "untrusted" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" - [[package]] name = "untrusted" version = "0.9.0" @@ -2894,7 +2898,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.64", "wasm-bindgen-shared", ] @@ -2928,7 +2932,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.64", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2962,16 +2966,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webpki" -version = "0.22.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" -dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", -] - [[package]] name = "webpki-roots" version = "0.25.4" @@ -3005,11 +2999,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.6" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" dependencies = [ - "winapi", + "windows-sys 0.52.0", ] [[package]] @@ -3033,7 +3027,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -3051,7 +3045,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -3071,17 +3065,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm 0.52.4", - "windows_aarch64_msvc 0.52.4", - "windows_i686_gnu 0.52.4", - "windows_i686_msvc 0.52.4", - "windows_x86_64_gnu 0.52.4", - "windows_x86_64_gnullvm 0.52.4", - "windows_x86_64_msvc 0.52.4", + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] [[package]] @@ -3092,9 +3087,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" @@ -3104,9 +3099,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" @@ -3116,9 +3111,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" @@ -3128,9 +3129,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" @@ -3140,9 +3141,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" @@ -3152,9 +3153,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" @@ -3164,15 +3165,15 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" -version = "0.6.5" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" +checksum = "c3c52e9c97a68071b23e836c9380edae937f17b9c4667bd021973efc689f618d" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 064eb41..8d55e2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,11 +9,12 @@ edition = "2021" [dependencies] serenity = "0.12" -tokio = { version = "1.36", features = ["macros", "rt-multi-thread"] } +tokio = { version = "1", features = ["macros", "rt-multi-thread"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" confy = "0.6.0" -songbird = "0.4" +songbird = { version = "0.4", features = ["gateway", "serenity", "native", "driver"], default-features = false } +lavalink-rs = { version = "0.10", features = ["songbird", "serenity-native", "native-tls"], default-features = false } chrono = "0.4" reqwest = "0.11" symphonia = "0.5" diff --git a/src/commands/now_playing.rs b/src/commands/now_playing.rs index c90a3f0..f124a7a 100644 --- a/src/commands/now_playing.rs +++ b/src/commands/now_playing.rs @@ -1,9 +1,9 @@ -use crate::music::music_queue; use crate::util::embed::Embed; +use lavalink_rs::client::LavalinkClient; use serenity::all::{CommandInteraction, Context}; use serenity::builder::{CreateCommand, CreateEmbed}; -pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed { +pub async fn run(ctx: &Context, command: &CommandInteraction, llc: &LavalinkClient) -> CreateEmbed { let username = command.user.name.as_str(); let guild_id = match &command.guild_id { @@ -57,7 +57,7 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed { let position = now_handle.get_info().await.unwrap().position; - Embed::create_yt_playing(now_plaing, username, "Currently playing") + Embed::create_playing(now_plaing, username, "Currently playing") .await .field( "Position", diff --git a/src/commands/play.rs b/src/commands/play.rs index 78e44d0..18b6e86 100644 --- a/src/commands/play.rs +++ b/src/commands/play.rs @@ -1,12 +1,13 @@ use crate::music::music_manager; +use lavalink_rs::client::LavalinkClient; use serenity::all::{CommandDataOptionValue, CommandInteraction, Context}; use serenity::builder::{CreateCommand, CreateCommandOption, CreateEmbed}; use serenity::model::application::CommandOptionType; use crate::util::embed::Embed; -pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed { +pub async fn run(ctx: &Context, command: &CommandInteraction, llc: &LavalinkClient) -> CreateEmbed { let username = command.user.name.as_str(); let options = &command.data.options; @@ -39,6 +40,7 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed { music_manager::attempt_to_queue_song( ctx, + llc, guild_id, &command.user.id, &command.user.name, diff --git a/src/commands/skip.rs b/src/commands/skip.rs index e5609df..58faad1 100644 --- a/src/commands/skip.rs +++ b/src/commands/skip.rs @@ -1,9 +1,10 @@ use crate::music::music_manager; use crate::util::embed::Embed; +use lavalink_rs::client::LavalinkClient; use serenity::all::{CommandInteraction, Context}; use serenity::builder::{CreateCommand, CreateEmbed}; -pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed { +pub async fn run(ctx: &Context, command: &CommandInteraction, llc: &LavalinkClient) -> CreateEmbed { let username = command.user.name.as_str(); let guild_id = match &command.guild_id { @@ -17,7 +18,7 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed { } }; - music_manager::attempt_to_skip_current_song(ctx, guild_id, &command.user.id, &command.user.name) + music_manager::attempt_to_skip_current_song(ctx, llc, guild_id, &command.user.id, &command.user.name) .await } diff --git a/src/commands/stop.rs b/src/commands/stop.rs index 5bc6e78..326a579 100644 --- a/src/commands/stop.rs +++ b/src/commands/stop.rs @@ -1,9 +1,10 @@ use crate::music::music_manager; use crate::util::embed::Embed; +use lavalink_rs::client::LavalinkClient; use serenity::all::{CommandInteraction, Context}; use serenity::builder::{CreateCommand, CreateEmbed}; -pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed { +pub async fn run(ctx: &Context, command: &CommandInteraction, llc: &LavalinkClient) -> CreateEmbed { let username = command.user.name.as_str(); let guild_id = match &command.guild_id { @@ -17,7 +18,7 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed { } }; - music_manager::attempt_to_stop(ctx, guild_id, &command.user.id, &command.user.name).await + music_manager::attempt_to_stop(ctx, llc, guild_id, &command.user.id, &command.user.name).await } pub fn register() -> CreateCommand { diff --git a/src/events/lavalink_event_handler.rs b/src/events/lavalink_event_handler.rs new file mode 100644 index 0000000..6b6f734 --- /dev/null +++ b/src/events/lavalink_event_handler.rs @@ -0,0 +1,30 @@ +use lavalink_rs::{client::LavalinkClient, model::events}; +use serenity::all::{standard::macros::hook, Sticker}; + +#[hook] +pub async fn ready_event(client: LavalinkClient, _session_id: String, event: &events::Ready) { + client.delete_all_player_contexts().await.unwrap(); + println!("Lavalink is ready for Freddy:: {:?}", event); +} + +#[hook] +pub async fn track_start(client: LavalinkClient, _session_id: String, event: &events::TrackStart) { + +} + +#[hook] +pub async fn track_end_event(client: LavalinkClient, _session_id: String, event: &events::TrackEnd) { + +} + +#[hook] +pub async fn track_exception(client: LavalinkClient, _session_id: String, event: &events::TrackException) { + +} + +#[hook] +pub async fn track_stuck(client: LavalinkClient, _session_id: String, event: &events::TrackStuck) { + +} + + diff --git a/src/events/mod.rs b/src/events/mod.rs new file mode 100644 index 0000000..5610ef2 --- /dev/null +++ b/src/events/mod.rs @@ -0,0 +1 @@ +pub mod lavalink_event_handler; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index fb0bd4e..5dfc403 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,11 @@ mod commands; mod music; mod util; +mod events; +use lavalink_rs::client::LavalinkClient; +use lavalink_rs::model::events::Events; +use lavalink_rs::node::NodeBuilder; use serenity::all::{ CommandInteraction, CreateInteractionResponseFollowup, OnlineStatus, VoiceState, }; @@ -18,19 +22,15 @@ use util::{config, embed::Embed, user_util}; // The voice client can be retrieved in any command using `songbird::get(ctx).await`. use songbird::SerenityInit; -// YtDl requests need an HTTP client to operate -- we'll create and store our own. -use reqwest::Client as HttpClient; - -struct HttpKey; -impl TypeMapKey for HttpKey { - type Value = HttpClient; -} +use crate::events::lavalink_event_handler; // lazy static stuff. I don't like it, but it has to be here, bc it has to be @ root #[macro_use] extern crate lazy_static; -struct Handler; +struct Handler { + llc: LavalinkClient +} #[async_trait] impl EventHandler for Handler { @@ -40,10 +40,10 @@ impl EventHandler for Handler { let content = Some(match command.data.name.as_str() { "info" => commands::info::run(&ctx, &command).await, - "play" => commands::play::run(&ctx, &command).await, - "stop" => commands::stop::run(&ctx, &command).await, - "skip" => commands::skip::run(&ctx, &command).await, - "nowplaying" => commands::now_playing::run(&ctx, &command).await, + "play" => commands::play::run(&ctx, &command, &self.llc).await, + "stop" => commands::stop::run(&ctx, &command, &self.llc).await, + "skip" => commands::skip::run(&ctx, &command, &self.llc).await, + "nowplaying" => commands::now_playing::run(&ctx, &command, &self.llc).await, _ => respond_with_error(&ctx, &command).await, }); @@ -120,13 +120,35 @@ async fn main() { let status = OnlineStatus::DoNotDisturb; let activity = ActivityData::streaming("music", "https://twitch.tv/moonleaytv").unwrap(); + let node_builder = NodeBuilder { + hostname: config.lavalink_address, + password: config.lavalink_password, + is_ssl: false, + ..Default::default() + }; + + let event = Events { + ready: Some(lavalink_event_handler::ready_event), + track_start: Some(lavalink_event_handler::track_start), + track_end: Some(lavalink_event_handler::track_end_event), + track_exception: Some(lavalink_event_handler::track_exception), + track_stuck: Some(lavalink_event_handler::track_stuck), + ..Default::default() + }; + + let lavalink_client = LavalinkClient::new(event, vec![node_builder]); + tokio::spawn(async move { + lavalink_client.start().await; + }); + // Build the client let mut client = Client::builder(config.discord_token, GatewayIntents::empty()) - .event_handler(Handler) + .event_handler(Handler{ + llc: lavalink_client + }) .status(status) .activity(activity) .register_songbird() - .type_map_insert::(HttpClient::new()) .intents(GatewayIntents::all()) .await .expect("Error creating client"); diff --git a/src/music/mod.rs b/src/music/mod.rs index d99af32..e9f9def 100644 --- a/src/music/mod.rs +++ b/src/music/mod.rs @@ -1,3 +1,2 @@ -pub mod music_events; pub mod music_manager; -pub mod music_queue; +pub mod preview; \ No newline at end of file diff --git a/src/music/music_events.rs b/src/music/music_events.rs deleted file mode 100644 index f35abe9..0000000 --- a/src/music/music_events.rs +++ /dev/null @@ -1,56 +0,0 @@ -use crate::music::{music_manager, music_queue}; - -use serenity::all::{ChannelId, GuildId, Http}; -use serenity::async_trait; -use songbird::input::Compose; -use songbird::{Event, EventContext, EventHandler}; -use std::sync::Arc; - -pub struct TrackEndNotifier { - pub guild_id: GuildId, - pub channel_id: ChannelId, - pub http: Arc, - pub cmdctx: Arc, -} - -#[async_trait] -impl EventHandler for TrackEndNotifier { - async fn act(&self, ctx: &EventContext<'_>) -> Option { - // TODO: Does this need to be unsafe? - if let EventContext::Track(..) = ctx { - println!("The track ended!"); - - if music_queue::is_empty(&self.guild_id).await { - // No more songs in queue, exit the vc - let stopped = match music_manager::leave(&self.cmdctx, &self.guild_id).await { - Ok(stopped) => stopped, - Err(e) => { - println!("Cannot stop: {:?}", e); - return None; - } - }; - if stopped { - music_queue::delete_queue(&self.guild_id).await; - println!("Stopped playing successfully."); - } else { - println!("Failed to stop playing."); - } - return None; - } - let mut head = match music_queue::next(&self.guild_id).await { - Some(head) => head, - None => { - println!("Cannot get head of queue"); - return None; - } - }; - println!( - "Now playing: {}", - head.aux_metadata().await.unwrap().title.unwrap() - ); - music_manager::play_song(&self.cmdctx, &self.guild_id, &head).await; - } - - None - } -} diff --git a/src/music/music_manager.rs b/src/music/music_manager.rs index df6654c..ab400eb 100644 --- a/src/music/music_manager.rs +++ b/src/music/music_manager.rs @@ -1,17 +1,18 @@ -use crate::music::{music_events, music_queue}; use crate::util::embed::Embed; use crate::util::user_util; use crate::util::user_util::get_vc_id; -use crate::HttpKey; +use crate::music::preview::Preview; +use lavalink_rs::client::LavalinkClient; +use lavalink_rs::model::search::SearchEngines; +use lavalink_rs::model::track::TrackLoadData; +use lavalink_rs::player_context::TrackInQueue; use serenity::all::{Context, CreateEmbed, GuildId, UserId}; -use songbird::error::JoinError; -use songbird::input::YoutubeDl; -use songbird::{Event, TrackEvent}; use std::sync::Arc; /// Either queues the song, or start playing it instantly, depending on if there is already a song playing pub async fn attempt_to_queue_song( ctx: &Context, + llc: &LavalinkClient, guild_id: &GuildId, user_id: &UserId, username: &str, @@ -32,21 +33,33 @@ pub async fn attempt_to_queue_song( } }; - let manager: &Arc = &songbird::get(ctx) // TODO match + let songbird: &Arc = &songbird::get(ctx) // TODO match .await .expect("Cannot get Songbird.") .clone(); let self_channel = user_util::get_self_vc_id(ctx, guild_id).await; - if !user_util::is_self_connected_to_vc(ctx, guild_id).await { + if !user_util::is_self_connected_to_vc(ctx, &guild_id).await { // self is connected to vc, check if user is in same vc if self_channel.is_none() { // Connect to VC - manager // TODO match - .join(*guild_id, connect_to) + let handler = songbird.join_gateway(GuildId::new(guild_id.get()), connect_to).await; + // + match handler { + Ok((connection_info, _)) => { + llc.create_player_context( + guild_id.get(), + connection_info + ) .await - .expect("Cannot connect>..."); + .unwrap(); + } + + Err(why) => { + return Embed::create_error_respose(username, "Cannot join", "Could not join the channel."); + } + } } } else { let self_channel = self_channel.expect("Cannot get self channel"); // TODO: match @@ -63,87 +76,84 @@ pub async fn attempt_to_queue_song( // Get query let do_search = !query.starts_with("http"); - let http_client = { - let data = ctx.data.read().await; - data.get::() - .cloned() - .expect("Guaranteed to exist in the typemap.") + let search_query = if do_search { + match SearchEngines::YouTube.to_query(&query) { + Ok(x) => x, + Err(why) => { + return Embed::create_error_respose(username, "Cannot generate query", "Could not generate a seach query.."); + } + } + } else { // Allow piped links + query.to_string().replace("https://piped.moonleay.net/", "https://youtube.com/") }; // Create source - let src = if do_search { - YoutubeDl::new_search(http_client, query.to_string()) - } else { - YoutubeDl::new(http_client, query.to_string()) - }; + let loaded_tracks = llc.load_tracks(guild_id.get(), &search_query).await.expect("Fuck."); - let currently_playing = music_queue::get_now_playing(guild_id).await; - music_queue::add_to_queue(guild_id, src.clone()).await; - if currently_playing.is_some() { - // Add to queue - return Embed::create_yt_playing(src, username, "Added to queue").await; - } + let mut playlist_info = None; - let _query = music_queue::next(guild_id) - .await - .expect("Cannot get head of queue"); - music_queue::set_now_playing(guild_id, Some(src.clone())).await; - - let handler_lock = match manager.get(*guild_id) { - Some(handler) => handler, - None => { + let tracks: Vec = match loaded_tracks.data { + Some(TrackLoadData::Track(x)) => vec![x.into()], + Some(TrackLoadData::Search(x)) => vec![x[0].clone().into()], + Some(TrackLoadData::Playlist(x)) => { + playlist_info = Some(x.info); + x.tracks.iter().map(|x| x.clone().into()).collect() + } + _ => { return Embed::create_error_respose( username, - "Error", - "Cannot get handler of this guild.", - ); + "500: Server failure", + "Something went wrong when loading the track..."); } }; - // Start playing - let mut handler = handler_lock.lock().await; - let track_handle = handler.play_input(src.clone().into()); // TODO: Add event handlers - music_queue::set_now_playing_track_handle(guild_id, Some(track_handle)).await; - handler.add_global_event( - Event::Track(TrackEvent::End), - music_events::TrackEndNotifier { - guild_id: *guild_id, - channel_id: connect_to, - http: Arc::clone(&ctx.http), - cmdctx: Arc::new(ctx.clone()), - }, - ); + let mut response_title = ""; + let mut preview_data = None; - Embed::create_yt_playing(src, username, "Now playing").await -} + if let Some(info) = playlist_info { + response_title = "Added playlist to queue"; + preview_data = Some(Preview { + title: info.name.to_string(), + artist: None, + duration: None, + thumbnail: None, + link: None, + }); + } else { + let track = tracks[0].track.clone(); -/// Play the provided song -pub async fn play_song(ctx: &Context, guild_id: &GuildId, target: &YoutubeDl) { - let manager = &songbird::get(ctx) // TODO match - .await - .expect("Cannot get Songbird.") - .clone(); - - if !user_util::is_self_connected_to_vc(ctx, guild_id).await { - println!("Bot is not connected to a VC, cannot play."); - return; + response_title = "Added to queue"; + preview_data = Some(Preview { + title: track.info.title, + artist: Some(track.info.author), + duration: Some(track.info.length), + thumbnail: track.info.artwork_url, + link: track.info.uri + }); } - music_queue::set_now_playing(guild_id, Some(target.clone())).await; - let handler_lock = match manager.get(*guild_id) { - Some(handler) => handler, - None => return, + let player = match llc.get_player_context(guild_id.get()) { + Some(player) => player, + None => { + return Embed::create_error_respose(username, "Cannot get player", "Could not get player context."); + } }; - let mut handler = handler_lock.lock().await; - handler.stop(); // Stop playing the current song - let track_handle = handler.play_input(target.clone().into()); // TODO: Add event handlers - music_queue::set_now_playing_track_handle(guild_id, Some(track_handle)).await; + let mut q = match player.get_queue().await { + Ok(q) => q, + Err(why) => { + return Embed::create_error_respose(username, "Cannont get queue", "Could not get queue."); + } + }; + q.append(&mut tracks.into()); + + Embed::create_playing(preview_data.unwrap(), username, &response_title).await } /// Attempt to skip the song, which is currently playing. Do nothing if there is no next song pub async fn attempt_to_skip_current_song( ctx: &Context, + llc: &LavalinkClient, guild_id: &GuildId, user_id: &UserId, username: &str, @@ -201,14 +211,15 @@ pub async fn attempt_to_skip_current_song( ); } let head = head.unwrap(); - play_song(ctx, guild_id, &head).await; + play_song(ctx, guild_id, llc, &head).await; - Embed::create_yt_playing(head, username, "Song skipped; Now playing").await + Embed::create_playing(head, username, "Song skipped; Now playing").await } /// Try to clear the queue and stop playing. Also leave the vc pub async fn attempt_to_stop( ctx: &Context, + llc: &LavalinkClient, guild_id: &GuildId, user_id: &UserId, username: &str, @@ -237,7 +248,7 @@ pub async fn attempt_to_stop( ); } - let stopped = match leave(ctx, guild_id).await { + let stopped = match leave(ctx, llc, guild_id).await { Ok(stopped) => stopped, Err(e) => { println!("Error while stopping: {:?}", e); @@ -263,7 +274,7 @@ pub async fn attempt_to_stop( } /// Make the bot leave the voice channel. Returns Ok(true) if bot was connected, returns Ok(false) if bot was not connected. Returns Err if something went wrong. -pub async fn leave(ctx: &Context, guild_id: &GuildId) -> Result { +pub async fn leave(ctx: &Context, llc: &LavalinkClient, guild_id: &GuildId) -> Result { let manager = songbird::get(ctx) .await .expect("Cannot get Songbird") diff --git a/src/music/music_queue.rs b/src/music/music_queue.rs deleted file mode 100644 index 09a1cb9..0000000 --- a/src/music/music_queue.rs +++ /dev/null @@ -1,84 +0,0 @@ -use serenity::all::GuildId; -use songbird::input::YoutubeDl; -use songbird::tracks::TrackHandle; -use tokio::sync::Mutex; - -use std::collections::{HashMap, VecDeque}; -use std::sync::Arc; - -type MusicQueueItem = Arc>; - -#[derive(Debug)] -pub struct MusicQueue { - pub queue: VecDeque, - pub now_playing: Option, - pub now_playing_track_handle: Option, -} - -lazy_static! { - static ref HASHMAP: Mutex> = Mutex::new(HashMap::new()); -} - -async fn get_music_queue(guild_id: &GuildId) -> MusicQueueItem { - let mut queues = HASHMAP.lock().await; - - queues - .entry(*guild_id) - .or_insert(Arc::new(Mutex::new(MusicQueue { - queue: VecDeque::new(), - now_playing: None, - now_playing_track_handle: None, - }))) - .clone() -} - -pub async fn with_music_queue(guild_id: &GuildId, f: F) -> T -where - F: FnOnce(&mut MusicQueue) -> T, - T: Send, -{ - let queue = get_music_queue(guild_id).await; - let mut queue = queue.lock().await; - - f(&mut queue) -} - -pub async fn delete_queue(guild_id: &GuildId) { - with_music_queue(guild_id, |queue| { - queue.now_playing = None; - queue.queue.clear(); - }) - .await; -} - -pub async fn add_to_queue(guild_id: &GuildId, input: YoutubeDl) { - with_music_queue(guild_id, |queue| queue.queue.push_back(input)).await; -} - -/// Get next track in queue -pub async fn next(guild_id: &GuildId) -> Option { - with_music_queue(guild_id, |queue| queue.queue.pop_front()).await -} - -pub async fn set_now_playing(guild_id: &GuildId, now_playing: Option) { - with_music_queue(guild_id, |queue| queue.now_playing = now_playing).await; -} - -pub async fn get_now_playing(guild_id: &GuildId) -> Option { - with_music_queue(guild_id, |queue| queue.now_playing.to_owned()).await -} - -pub async fn set_now_playing_track_handle(guild_id: &GuildId, track_handle: Option) { - with_music_queue(guild_id, |queue| { - queue.now_playing_track_handle = track_handle - }) - .await -} - -pub async fn get_now_playing_track_handle(guild_id: &GuildId) -> Option { - with_music_queue(guild_id, |queue| queue.now_playing_track_handle.to_owned()).await -} - -pub async fn is_empty(guild_id: &GuildId) -> bool { - with_music_queue(guild_id, |queue| queue.queue.is_empty()).await -} diff --git a/src/music/preview.rs b/src/music/preview.rs new file mode 100644 index 0000000..a5ffe9a --- /dev/null +++ b/src/music/preview.rs @@ -0,0 +1,7 @@ +pub struct Preview { + pub title: String, + pub artist: Option, + pub duration: Option, + pub thumbnail: Option, + pub link: Option, +} \ No newline at end of file diff --git a/src/util/config.rs b/src/util/config.rs index f5dc260..acd5500 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -6,6 +6,8 @@ use std::error::Error; #[derive(Deserialize, Serialize)] pub struct Config { pub discord_token: String, + pub lavalink_address: String, + pub lavalink_password: String } const CONFIG_FILE: &str = "./data/config.json"; @@ -23,6 +25,8 @@ pub fn load() -> Result> { fn create_empty() -> fs::File { let example_config = Config { discord_token: "paste_your_token".to_string(), + lavalink_address: "paste_your_lavalink_address".to_string(), + lavalink_password: "paste_your_lavalink_password".to_string() }; let mut config_file = fs::File::create(CONFIG_FILE).unwrap(); diff --git a/src/util/embed.rs b/src/util/embed.rs index 39a0cbe..349fa11 100644 --- a/src/util/embed.rs +++ b/src/util/embed.rs @@ -2,7 +2,8 @@ use std::time::Duration; use chrono::Local; use serenity::all::{Color, CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter}; -use songbird::input::{Compose, YoutubeDl}; + +use crate::music::preview::Preview; pub struct Embed; @@ -38,23 +39,21 @@ impl Embed { ))) } - pub async fn create_yt_playing( - mut src: YoutubeDl, + pub async fn create_playing( + preview: Preview, username: &str, show_as_author: &str, ) -> CreateEmbed { let current_time = Local::now().format("%Y-%m-%d @ %H:%M:%S"); // Get metadata - let metadata = src.aux_metadata().await.expect("Cannot get metadata"); - let title = metadata.title.unwrap_or("Unknown title".to_string()); - let artist = metadata.artist.unwrap_or("Unknown artist".to_string()); - let duration = metadata.duration.unwrap_or(Duration::from_millis(0)); - let thumbnail = metadata + let title = preview.title; + let artist = preview.artist.unwrap_or("t".to_string()); + let duration = Duration::from_millis(preview.duration.unwrap_or(0)); + let thumbnail = preview .thumbnail .unwrap_or("https://http.cat/images/403.jpg".to_string()); - let link = metadata - .source_url + let link = preview.link .unwrap_or("https://piped.moonleay.net/403".to_string()); CreateEmbed::new()