diff --git a/Cargo.lock b/Cargo.lock index a105bff..525b073 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,8 +73,10 @@ dependencies = [ "futures-io", "futures-util", "log 0.4.14", + "native-tls", "pin-project", "tokio", + "tokio-native-tls", "tokio-rustls", "tungstenite 0.11.1", "webpki-roots 0.20.0", @@ -207,18 +209,6 @@ dependencies = [ "tokio-diesel", ] -[[package]] -name = "bot-serenityutils" -version = "0.2.4" -dependencies = [ - "futures", - "log 0.4.14", - "serde_json", - "serenity", - "thiserror", - "tokio", -] - [[package]] name = "bumpalo" version = "3.6.1" @@ -2167,6 +2157,20 @@ dependencies = [ "uwl", ] +[[package]] +name = "serenity-rich-interaction" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38f160ea25bd4cb331165ee7c0d0c34ea975a3d31230c251bb23f988ffc1b25e" +dependencies = [ + "futures", + "log 0.4.14", + "serde_json", + "serenity", + "thiserror", + "tokio", +] + [[package]] name = "serenity-voice-model" version = "0.1.0" @@ -2522,12 +2526,11 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tobi-rs" -version = "0.7.1" +version = "0.8.0" dependencies = [ "aspotify", "bot-coreutils", "bot-database", - "bot-serenityutils", "chrono", "chrono-tz", "colored", @@ -2547,6 +2550,7 @@ dependencies = [ "serde_derive", "serde_json", "serenity", + "serenity-rich-interaction", "songbird", "sysinfo", "thiserror", @@ -2722,6 +2726,7 @@ dependencies = [ "httparse", "input_buffer 0.3.1", "log 0.4.14", + "native-tls", "rand 0.7.3", "sha-1", "url", diff --git a/Cargo.toml b/Cargo.toml index 563c80e..179312e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tobi-rs" -version = "0.7.1" +version = "0.8.0" authors = ["trivernis "] edition = "2018" @@ -12,7 +12,7 @@ panic = 'abort' [dependencies] bot-database = {path="./bot-database"} bot-coreutils = {path="./bot-coreutils"} -bot-serenityutils = {path="./bot-serenityutils"} +serenity-rich-interaction = "0.2.2" serenity = "0.10.5" dotenv = "0.15.0" tokio = { version = "1.4.0", features = ["macros", "rt-multi-thread"] } diff --git a/Dockerfile b/Dockerfile index fa0dc9d..293a4cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,6 @@ COPY Cargo.toml Cargo.lock ./ COPY src ./src COPY bot-coreutils ./bot-coreutils COPY bot-database ./bot-database -COPY bot-serenityutils ./bot-serenityutils RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=target \ cargo build --release diff --git a/bot-serenityutils/.gitignore b/bot-serenityutils/.gitignore deleted file mode 100644 index 1de5659..0000000 --- a/bot-serenityutils/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target \ No newline at end of file diff --git a/bot-serenityutils/Cargo.lock b/bot-serenityutils/Cargo.lock deleted file mode 100644 index c4cd76e..0000000 --- a/bot-serenityutils/Cargo.lock +++ /dev/null @@ -1,1303 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async-trait" -version = "0.1.48" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36ea56748e10732c49404c153638a15ec3d6211ec5ff35d9bb20e13b93576adf" -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", - "pin-project", - "tokio", - "tokio-rustls", - "tungstenite", - "webpki-roots 0.20.0", -] - -[[package]] -name = "autocfg" -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" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" - -[[package]] -name = "bitflags" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" - -[[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array", -] - -[[package]] -name = "bot-serenityutils" -version = "0.2.1" -dependencies = [ - "futures", - "log", - "serde_json", - "serenity", - "thiserror", - "tokio", -] - -[[package]] -name = "bumpalo" -version = "3.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" - -[[package]] -name = "byteorder" -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" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" - -[[package]] -name = "cc" -version = "1.0.67" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "chrono" -version = "0.4.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" -dependencies = [ - "libc", - "num-integer", - "num-traits", - "serde", - "time", - "winapi", -] - -[[package]] -name = "command_attr" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fe1f0b69fde68f40ea2ee6ca8db23bc40d2e593db884659a65d8486032cc65b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "cpuid-bool" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" - -[[package]] -name = "crc32fast" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array", -] - -[[package]] -name = "encoding_rs" -version = "0.8.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "flate2" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd3aec53de10fe96d7d8c565eb17f2c687bb5518a2ec453b5b1252964526abe0" -dependencies = [ - "cfg-if", - "crc32fast", - "libc", - "miniz_oxide", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" -dependencies = [ - "matches", - "percent-encoding", -] - -[[package]] -name = "futures" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9d5813545e459ad3ca1bff9915e9ad7f1a47dc6a91b627ce321d5863b7dd253" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce79c6a52a299137a6013061e0cf0e688fce5d7f1bc60125f520912fdb29ec25" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "098cd1c6dda6ca01650f1a37a794245eb73181d0d4d4e955e2f3c37db7af1815" - -[[package]] -name = "futures-executor" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f6cb7042eda00f0049b1d2080aa4b93442997ee507eb3828e8bd7577f94c9d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "365a1a1fb30ea1c03a830fdb2158f5236833ac81fa0ad12fe35b29cddc35cb04" - -[[package]] -name = "futures-macro" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "668c6733a182cd7deb4f1de7ba3bf2120823835b3bcfbeacf7d2c4a773c1bb8b" -dependencies = [ - "proc-macro-hack", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5629433c555de3d82861a7a4e3794a4c40040390907cfbfd7143a92a426c23" - -[[package]] -name = "futures-task" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba7aa51095076f3ba6d9a1f702f74bd05ec65f555d70d2033d55ba8d69f581bc" - -[[package]] -name = "futures-util" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c144ad54d60f23927f0a6b6d816e4271278b64f005ad65e4e35291d2de9c025" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "proc-macro-hack", - "proc-macro-nested", - "slab", -] - -[[package]] -name = "generic-array" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - -[[package]] -name = "h2" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc018e188373e2777d0ef2467ebff62a08e66c3f5857b23c8fbec3018210dc00" -dependencies = [ - "bytes 1.0.1", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" - -[[package]] -name = "http" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" -dependencies = [ - "bytes 1.0.1", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfb77c123b4e2f72a2069aeae0b4b4949cc7e966df277813fc16347e7549737" -dependencies = [ - "bytes 1.0.1", - "http", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc35c995b9d93ec174cf9a27d425c7892722101e14993cd227fdb51d70cf9589" - -[[package]] -name = "httpdate" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" - -[[package]] -name = "hyper" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf09f61b52cfcf4c00de50df88ae423d6c02354e385a86341133b5338630ad1" -dependencies = [ - "bytes 1.0.1", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - -[[package]] -name = "hyper-rustls" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f9f7a97316d44c0af9b0301e65010573a853a9fc97046d7331d7f6bc0fd5a64" -dependencies = [ - "futures-util", - "hyper", - "log", - "rustls", - "tokio", - "tokio-rustls", - "webpki", -] - -[[package]] -name = "idna" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89829a5d69c23d348314a7ac337fe39173b61149a9864deabd260983aed48c21" -dependencies = [ - "matches", - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "indexmap" -version = "1.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" -dependencies = [ - "autocfg", - "hashbrown", -] - -[[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 = "ipnet" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" - -[[package]] -name = "itoa" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" - -[[package]] -name = "js-sys" -version = "0.3.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d99f9e3e84b8f67f846ef5b4cbbc3b1c29f6c759fcbce6f01aa0e73d932a24c" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "libc" -version = "0.2.93" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" - -[[package]] -name = "log" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "matches" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" - -[[package]] -name = "memchr" -version = "2.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" - -[[package]] -name = "mime" -version = "0.3.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" - -[[package]] -name = "mime_guess" -version = "2.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" -dependencies = [ - "mime", - "unicase", -] - -[[package]] -name = "miniz_oxide" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" -dependencies = [ - "adler", - "autocfg", -] - -[[package]] -name = "mio" -version = "0.7.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956" -dependencies = [ - "libc", - "log", - "miow", - "ntapi", - "winapi", -] - -[[package]] -name = "miow" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" -dependencies = [ - "winapi", -] - -[[package]] -name = "ntapi" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" -dependencies = [ - "winapi", -] - -[[package]] -name = "num-integer" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" -dependencies = [ - "autocfg", - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" -dependencies = [ - "autocfg", -] - -[[package]] -name = "once_cell" -version = "1.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" - -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - -[[package]] -name = "percent-encoding" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" - -[[package]] -name = "pin-project" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc174859768806e91ae575187ada95c91a29e96a98dc5d2cd9a1fed039501ba6" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a490329918e856ed1b083f244e3bfe2d8c4f336407e4ea9e1a9f479ff09049e5" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "ppv-lite86" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" - -[[package]] -name = "proc-macro-hack" -version = "0.5.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" - -[[package]] -name = "proc-macro-nested" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" - -[[package]] -name = "proc-macro2" -version = "1.0.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "quote" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom", - "libc", - "rand_chacha", - "rand_core", - "rand_hc", -] - -[[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", -] - -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core", -] - -[[package]] -name = "reqwest" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf12057f289428dbf5c591c74bf10392e4a8003f993405a902f20117019022d4" -dependencies = [ - "base64 0.13.0", - "bytes 1.0.1", - "encoding_rs", - "futures-core", - "futures-util", - "http", - "http-body", - "hyper", - "hyper-rustls", - "ipnet", - "js-sys", - "lazy_static", - "log", - "mime", - "mime_guess", - "percent-encoding", - "pin-project-lite", - "rustls", - "serde", - "serde_json", - "serde_urlencoded", - "tokio", - "tokio-rustls", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "webpki-roots 0.21.1", - "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", - "untrusted", - "web-sys", - "winapi", -] - -[[package]] -name = "rustls" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "064fd21ff87c6e87ed4506e68beb42459caa4a0e2eb144932e6776768556980b" -dependencies = [ - "base64 0.13.0", - "log", - "ring", - "sct", - "webpki", -] - -[[package]] -name = "ryu" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" - -[[package]] -name = "sct" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] -name = "serde" -version = "1.0.125" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.125" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "serde_urlencoded" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "serenity" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deead3f7ecbbbe4c249e07af17686937ccb9d7fa24ca3accd1d223e369a75272" -dependencies = [ - "async-trait", - "async-tungstenite", - "base64 0.13.0", - "bitflags", - "bytes 1.0.1", - "chrono", - "command_attr", - "flate2", - "futures", - "percent-encoding", - "reqwest", - "serde", - "serde_json", - "static_assertions", - "tokio", - "tracing", - "typemap_rev", - "url", - "uwl", -] - -[[package]] -name = "sha-1" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfebf75d25bd900fd1e7d11501efab59bc846dbc76196839663e6637bba9f25f" -dependencies = [ - "block-buffer", - "cfg-if", - "cpuid-bool", - "digest", - "opaque-debug", -] - -[[package]] -name = "slab" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" - -[[package]] -name = "socket2" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "syn" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - -[[package]] -name = "thiserror" -version = "1.0.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "time" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] - -[[package]] -name = "tinyvec" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" - -[[package]] -name = "tokio" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134af885d758d645f0f0505c9a8b3f9bf8a348fd822e112ab5248138348f1722" -dependencies = [ - "autocfg", - "bytes 1.0.1", - "libc", - "memchr", - "mio", - "pin-project-lite", - "tokio-macros", -] - -[[package]] -name = "tokio-macros" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tokio-rustls" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6" -dependencies = [ - "rustls", - "tokio", - "webpki", -] - -[[package]] -name = "tokio-util" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5143d049e85af7fbc36f5454d990e62c2df705b3589f123b71f441b6b59f443f" -dependencies = [ - "bytes 1.0.1", - "futures-core", - "futures-sink", - "log", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tower-service" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" - -[[package]] -name = "tracing" -version = "0.1.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" -dependencies = [ - "cfg-if", - "log", - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tracing-core" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "try-lock" -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", - "log", - "rand", - "sha-1", - "url", - "utf-8", -] - -[[package]] -name = "typemap_rev" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed5b74f0a24b5454580a79abb6994393b09adf0ab8070f15827cb666255de155" - -[[package]] -name = "typenum" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" - -[[package]] -name = "unicase" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" -dependencies = [ - "version_check", -] - -[[package]] -name = "unicode-bidi" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" -dependencies = [ - "matches", -] - -[[package]] -name = "unicode-normalization" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "unicode-xid" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" - -[[package]] -name = "untrusted" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" - -[[package]] -name = "url" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" -dependencies = [ - "form_urlencoded", - "idna", - "matches", - "percent-encoding", -] - -[[package]] -name = "utf-8" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7" - -[[package]] -name = "uwl" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4bf03e0ca70d626ecc4ba6b0763b934b6f2976e8c744088bb3c1d646fbb1ad0" - -[[package]] -name = "version_check" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" - -[[package]] -name = "want" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" -dependencies = [ - "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.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - -[[package]] -name = "wasm-bindgen" -version = "0.2.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83240549659d187488f91f33c0f8547cbfef0b2088bc470c116d1d260ef623d9" -dependencies = [ - "cfg-if", - "serde", - "serde_json", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae70622411ca953215ca6d06d3ebeb1e915f0f6613e3b495122878d7ebec7dae" -dependencies = [ - "bumpalo", - "lazy_static", - "log", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81b8b767af23de6ac18bf2168b690bed2902743ddf0fb39252e36f9e2bfc63ea" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e734d91443f177bfdb41969de821e15c516931c3c3db3d318fa1b68975d0f6f" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53739ff08c8a68b0fdbcd54c372b8ab800b1449ab3c9d706503bc7dd1621b2c" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9a543ae66aa233d14bb765ed9af4a33e81b8b58d1584cf1b47ff8cd0b9e4489" - -[[package]] -name = "web-sys" -version = "0.3.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a905d57e488fec8861446d3393670fb50d27a262344013181c2cdf9fff5481be" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "webpki" -version = "0.21.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" -dependencies = [ - "ring", - "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" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aabe153544e473b775453675851ecc86863d2a81d786d741f6b76778f2a48940" -dependencies = [ - "webpki", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "winreg" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" -dependencies = [ - "winapi", -] diff --git a/bot-serenityutils/Cargo.toml b/bot-serenityutils/Cargo.toml deleted file mode 100644 index a71651c..0000000 --- a/bot-serenityutils/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "bot-serenityutils" -version = "0.2.4" -authors = ["trivernis "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -serenity = "0.10.5" -tokio = "1.4.0" -thiserror = "1.0.24" -log = "0.4.14" -futures = "0.3.14" -serde_json = "1.0.64" \ No newline at end of file diff --git a/bot-serenityutils/src/core.rs b/bot-serenityutils/src/core.rs deleted file mode 100644 index ba0230e..0000000 --- a/bot-serenityutils/src/core.rs +++ /dev/null @@ -1,44 +0,0 @@ -use crate::error::SerenityUtilsResult; -use crate::menu::traits::EventDrivenMessage; -use serenity::http::Http; -use serenity::model::channel::Message; -use serenity::model::id::{ChannelId, MessageId}; -use std::sync::Arc; -use std::time::Duration; - -pub static SHORT_TIMEOUT: Duration = Duration::from_secs(5); -pub static MEDIUM_TIMEOUT: Duration = Duration::from_secs(20); -pub static LONG_TIMEOUT: Duration = Duration::from_secs(60); -pub static EXTRA_LONG_TIMEOUT: Duration = Duration::from_secs(600); - -pub type BoxedEventDrivenMessage = Box; - -#[derive(Copy, Clone, Debug, PartialOrd, PartialEq, Eq, Hash)] -pub struct MessageHandle { - pub channel_id: u64, - pub message_id: u64, -} - -impl MessageHandle { - /// Creates a new message handle - pub fn new(channel_id: ChannelId, message_id: MessageId) -> Self { - Self { - message_id: message_id.0, - channel_id: channel_id.0, - } - } - - /// Creates a new message handle from raw ids - pub fn from_raw_ids(channel_id: u64, message_id: u64) -> Self { - Self { - message_id, - channel_id, - } - } - - /// Returns the message object of the handle - pub async fn get_message(&self, http: &Arc) -> SerenityUtilsResult { - let msg = http.get_message(self.channel_id, self.message_id).await?; - Ok(msg) - } -} diff --git a/bot-serenityutils/src/ephemeral_message.rs b/bot-serenityutils/src/ephemeral_message.rs deleted file mode 100644 index a35b1b0..0000000 --- a/bot-serenityutils/src/ephemeral_message.rs +++ /dev/null @@ -1,56 +0,0 @@ -use crate::core::MessageHandle; -use crate::error::SerenityUtilsResult; -use serenity::builder::CreateMessage; -use serenity::http::Http; -use serenity::model::channel::Message; -use serenity::model::id::ChannelId; -use std::sync::Arc; -use std::time::Duration; - -pub struct EphemeralMessage; - -impl EphemeralMessage { - /// Ensures that an already existing message is - /// deleted after a certain amount of time - pub async fn create_from_message( - http: &Arc, - message: &Message, - timeout: Duration, - ) -> SerenityUtilsResult<()> { - log::debug!("Creating ephemeral message from existing message"); - let handle = MessageHandle::new(message.channel_id, message.id); - let http = Arc::clone(&http); - - log::debug!("Starting delete task"); - tokio::spawn(async move { - log::debug!("Waiting for timeout to pass"); - tokio::time::sleep(timeout).await; - log::debug!("Deleting ephemeral message"); - if let Err(e) = http - .delete_message(handle.channel_id, handle.message_id) - .await - { - log::error!("Failed to delete ephemeral message {:?}: {}", handle, e); - } - }); - - Ok(()) - } - - /// Creates a new message that is deleted after a certain amount of time - pub async fn create<'a, F>( - http: &Arc, - channel_id: ChannelId, - timeout: Duration, - f: F, - ) -> SerenityUtilsResult - where - F: for<'b> FnOnce(&'b mut CreateMessage<'a>) -> &'b mut CreateMessage<'a>, - { - log::debug!("Creating new ephemeral message"); - let msg = channel_id.send_message(http, f).await?; - Self::create_from_message(http, &msg, timeout).await?; - - Ok(msg) - } -} diff --git a/bot-serenityutils/src/error.rs b/bot-serenityutils/src/error.rs deleted file mode 100644 index 5df6e83..0000000 --- a/bot-serenityutils/src/error.rs +++ /dev/null @@ -1,18 +0,0 @@ -use thiserror::Error; - -pub type SerenityUtilsResult = Result; - -#[derive(Debug, Error)] -pub enum SerenityUtilsError { - #[error("Serenity Error: {0}")] - SerenityError(#[from] serenity::Error), - - #[error("Page {0} not found")] - PageNotFound(usize), - - #[error("Serenity Utils not fully initialized")] - Uninitialized, - - #[error("{0}")] - Msg(String), -} diff --git a/bot-serenityutils/src/lib.rs b/bot-serenityutils/src/lib.rs deleted file mode 100644 index 72861ec..0000000 --- a/bot-serenityutils/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -pub mod core; -pub mod ephemeral_message; -pub mod error; -pub mod macros; -pub mod menu; - -pub static VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/bot-serenityutils/src/macros.rs b/bot-serenityutils/src/macros.rs deleted file mode 100644 index a3d3870..0000000 --- a/bot-serenityutils/src/macros.rs +++ /dev/null @@ -1,16 +0,0 @@ -/// Forwards the error directly to the user -/// without having to accept it in any handler. -/// Can only be used in async functions that return a Result. -#[macro_export] -macro_rules! forward_error { - ($ctx:expr,$channel_id:expr,$result:expr) => { - match $result { - Err(e) => { - use bot_serenityutils::{core::SHORT_TIMEOUT, ephemeral_message::EphemeralMessage}; - $channel_id.say($ctx, format!("‼️ {}", e)).await?; - return Ok(()); - } - Ok(v) => v, - } - }; -} diff --git a/bot-serenityutils/src/menu/container.rs b/bot-serenityutils/src/menu/container.rs deleted file mode 100644 index 5bbf1fb..0000000 --- a/bot-serenityutils/src/menu/container.rs +++ /dev/null @@ -1,181 +0,0 @@ -use crate::core::{BoxedEventDrivenMessage, MessageHandle}; -use crate::error::{SerenityUtilsError, SerenityUtilsResult}; -use serenity::client::Context; -use serenity::model::prelude::*; -use serenity::prelude::TypeMapKey; -use std::collections::HashMap; -use std::sync::Arc; -use std::time::Duration; -use tokio::sync::Mutex; - -/// Container to store event driven messages in the serenity context data -pub struct EventDrivenMessageContainer; -pub type MessageRef = Arc>; -pub type EventDrivenMessagesRef = Arc>>; - -impl TypeMapKey for EventDrivenMessageContainer { - type Value = EventDrivenMessagesRef; -} - -static UPDATE_INTERVAL_SECS: u64 = 5; - -/// Starts the loop to handle message updates -pub async fn start_update_loop(ctx: &Context) { - let event_messages = get_listeners_from_context(ctx) - .await - .expect("Failed to get event message container"); - let http = Arc::clone(&ctx.http); - - tokio::task::spawn(async move { - loop { - { - log::trace!("Locking listener from update loop."); - let messages = { - let msgs_lock = event_messages.lock().await; - - msgs_lock - .iter() - .map(|(k, v)| (*k, v.clone())) - .collect::>() - }; - log::trace!("Listener locked."); - let mut frozen_messages = Vec::new(); - - for (key, msg) in messages { - let mut msg = msg.lock().await; - if let Err(e) = msg.update(&http).await { - log::error!("Failed to update message: {:?}", e); - } - if msg.is_frozen() { - frozen_messages.push(key); - } - } - { - let mut msgs_lock = event_messages.lock().await; - for key in frozen_messages { - msgs_lock.remove(&key); - } - } - } - log::trace!("Listener unlocked"); - tokio::time::sleep(Duration::from_secs(UPDATE_INTERVAL_SECS)).await; - } - }); -} - -/// To be fired from the serenity handler when a message was deleted -pub async fn handle_message_delete( - ctx: &Context, - channel_id: ChannelId, - message_id: MessageId, -) -> SerenityUtilsResult<()> { - let mut affected_messages = Vec::new(); - { - let listeners = get_listeners_from_context(ctx).await?; - log::trace!("Locking listener from handle_message_delete."); - let mut listeners_lock = listeners.lock().await; - log::trace!("Listener locked."); - - let handle = MessageHandle::new(channel_id, message_id); - if let Some(msg) = listeners_lock.get(&handle) { - affected_messages.push(Arc::clone(msg)); - listeners_lock.remove(&handle); - } - } - log::trace!("Listener unlocked"); - for msg in affected_messages { - let mut msg = msg.lock().await; - msg.on_deleted(ctx).await?; - } - - Ok(()) -} - -/// To be fired from the serenity handler when multiple messages were deleted -pub async fn handle_message_delete_bulk( - ctx: &Context, - channel_id: ChannelId, - message_ids: &Vec, -) -> SerenityUtilsResult<()> { - let mut affected_messages = Vec::new(); - { - let listeners = get_listeners_from_context(ctx).await?; - log::trace!("Locking listener from handle_message_delete_bulk."); - let mut listeners_lock = listeners.lock().await; - log::trace!("Listener locked."); - - for message_id in message_ids { - let handle = MessageHandle::new(channel_id, *message_id); - if let Some(msg) = listeners_lock.get_mut(&handle) { - affected_messages.push(Arc::clone(msg)); - listeners_lock.remove(&handle); - } - } - } - log::trace!("Listener unlocked"); - for msg in affected_messages { - let mut msg = msg.lock().await; - msg.on_deleted(ctx).await?; - } - - Ok(()) -} - -/// Fired when a reaction was added to a message -pub async fn handle_reaction_add(ctx: &Context, reaction: &Reaction) -> SerenityUtilsResult<()> { - let mut affected_messages = Vec::new(); - { - let listeners = get_listeners_from_context(ctx).await?; - log::trace!("Locking listener from handle_reaction_add."); - let mut listeners_lock = listeners.lock().await; - log::trace!("Listener locked."); - - let handle = MessageHandle::new(reaction.channel_id, reaction.message_id); - - if let Some(msg) = listeners_lock.get_mut(&handle) { - affected_messages.push(Arc::clone(&msg)); - } - } - log::trace!("Listener unlocked"); - for msg in affected_messages { - let mut msg = msg.lock().await; - msg.on_reaction_add(ctx, reaction.clone()).await?; - } - - Ok(()) -} - -/// Fired when a reaction was added to a message -pub async fn handle_reaction_remove(ctx: &Context, reaction: &Reaction) -> SerenityUtilsResult<()> { - let mut affected_messages = Vec::new(); - { - let listeners = get_listeners_from_context(ctx).await?; - log::trace!("Locking listener from handle_reaction_remove."); - let mut listeners_lock = listeners.lock().await; - log::trace!("Listener locked."); - - let handle = MessageHandle::new(reaction.channel_id, reaction.message_id); - - if let Some(msg) = listeners_lock.get_mut(&handle) { - affected_messages.push(Arc::clone(&msg)); - } - } - log::trace!("Listener unlocked"); - for msg in affected_messages { - let mut msg = msg.lock().await; - msg.on_reaction_remove(ctx, reaction.clone()).await?; - } - - Ok(()) -} - -pub async fn get_listeners_from_context( - ctx: &Context, -) -> SerenityUtilsResult { - let data = ctx.data.read().await; - let listeners = data - .get::() - .ok_or(SerenityUtilsError::Uninitialized)?; - log::trace!("Returning listener"); - Ok(listeners.clone()) -} diff --git a/bot-serenityutils/src/menu/controls.rs b/bot-serenityutils/src/menu/controls.rs deleted file mode 100644 index fab215d..0000000 --- a/bot-serenityutils/src/menu/controls.rs +++ /dev/null @@ -1,145 +0,0 @@ -use crate::error::{SerenityUtilsError, SerenityUtilsResult}; -use crate::menu::container::get_listeners_from_context; -use crate::menu::menu::Menu; -use crate::menu::typedata::HelpActiveContainer; -use crate::menu::ActionContainer; -use serde_json::json; -use serde_json::Value; -use serenity::client::Context; -use serenity::http::CacheHttp; -use serenity::model::channel::Reaction; -use std::sync::atomic::Ordering; - -/// Shows the next page in the menu -pub async fn next_page(ctx: &Context, menu: &mut Menu<'_>, _: Reaction) -> SerenityUtilsResult<()> { - log::debug!("Showing next page"); - menu.current_page = (menu.current_page + 1) % menu.pages.len(); - display_page(ctx, menu).await?; - - Ok(()) -} - -/// Shows the previous page in the menu -pub async fn previous_page( - ctx: &Context, - menu: &mut Menu<'_>, - _: Reaction, -) -> SerenityUtilsResult<()> { - log::debug!("Showing previous page"); - if menu.current_page == 0 { - menu.current_page = menu.pages.len() - 1; - } else { - menu.current_page = menu.current_page - 1; - } - display_page(ctx, menu).await?; - - Ok(()) -} - -/// Shows the previous page in the menu -pub async fn close_menu( - ctx: &Context, - menu: &mut Menu<'_>, - _: Reaction, -) -> SerenityUtilsResult<()> { - log::debug!("Closing menu"); - menu.close(ctx.http()).await?; - let listeners = get_listeners_from_context(&ctx).await?; - let mut listeners_lock = listeners.lock().await; - let message = menu.message.read().await; - listeners_lock.remove(&*message); - - Ok(()) -} - -pub async fn toggle_help( - ctx: &Context, - menu: &mut Menu<'_>, - _: Reaction, -) -> SerenityUtilsResult<()> { - log::debug!("Displaying help"); - let show_help = menu - .data - .get::() - .expect("Missing HelpActiveContainer in menu data") - .clone(); - - if show_help.load(Ordering::Relaxed) { - display_page(ctx, menu).await?; - show_help.store(false, Ordering::Relaxed); - return Ok(()); - } - let page = menu - .pages - .get(menu.current_page) - .ok_or(SerenityUtilsError::PageNotFound(menu.current_page))? - .get() - .await?; - let mut message = menu.get_message(ctx.http()).await?; - log::debug!("Building help entries"); - let mut help_entries = menu - .help_entries - .iter() - .filter_map(|(e, h)| Some((menu.controls.get(e)?, e, h))) - .collect::>(); - help_entries.sort_by_key(|(c, _, _)| c.position()); - let help_message = help_entries - .into_iter() - .map(|(_, e, h)| format!(" - {} {}", e, h)) - .collect::>() - .join("\n"); - log::trace!("Help message is {}", help_message); - - message - .edit(ctx, |m| { - m.0.clone_from(&mut page.0.clone()); - - if let Some(embed) = m.0.get_mut("embed") { - let embed = embed.as_object_mut().unwrap(); - let fields = embed - .entry("fields") - .or_insert_with(|| Value::Array(vec![])); - if let Value::Array(ref mut inner) = *fields { - inner.push(json!({ - "inline": false, - "name": "Help".to_string(), - "value": help_message, - })); - } - } else { - m.embed(|e| { - e.field("Help", help_message, false); - - e - }); - } - - m - }) - .await?; - log::debug!("Help message displayed"); - show_help.store(true, Ordering::Relaxed); - - Ok(()) -} - -/// Displays the menu page -pub async fn display_page(ctx: &Context, menu: &mut Menu<'_>) -> SerenityUtilsResult<()> { - log::debug!("Displaying page {}", menu.current_page); - let page = menu - .pages - .get(menu.current_page) - .ok_or(SerenityUtilsError::PageNotFound(menu.current_page))? - .get() - .await?; - let mut msg = menu.get_message(ctx.http()).await?; - - msg.edit(ctx, |e| { - e.0.clone_from(&mut page.0.clone()); - e - }) - .await?; - log::debug!("Page displayed"); - - Ok(()) -} diff --git a/bot-serenityutils/src/menu/menu.rs b/bot-serenityutils/src/menu/menu.rs deleted file mode 100644 index 24fd310..0000000 --- a/bot-serenityutils/src/menu/menu.rs +++ /dev/null @@ -1,447 +0,0 @@ -use crate::core::MessageHandle; -use crate::error::{SerenityUtilsError, SerenityUtilsResult}; -use crate::menu::container::get_listeners_from_context; -use crate::menu::controls::{close_menu, next_page, previous_page, toggle_help}; -use crate::menu::traits::EventDrivenMessage; -use crate::menu::typedata::HelpActiveContainer; -use crate::menu::{EventDrivenMessagesRef, Page}; -use futures::FutureExt; -use serenity::async_trait; -use serenity::client::Context; -use serenity::http::Http; -use serenity::model::channel::{Message, Reaction, ReactionType}; -use serenity::model::id::ChannelId; -use serenity::prelude::{TypeMap, TypeMapKey}; -use std::collections::HashMap; -use std::future::Future; -use std::pin::Pin; -use std::sync::atomic::AtomicBool; -use std::sync::Arc; -use std::time::{Duration, Instant}; -use tokio::sync::{Mutex, RwLock}; - -pub static NEXT_PAGE_EMOJI: &str = "➡️"; -pub static PREVIOUS_PAGE_EMOJI: &str = "⬅️"; -pub static CLOSE_MENU_EMOJI: &str = "❌"; -pub static HELP_EMOJI: &str = "❔"; - -pub type ControlActionResult<'b> = - Pin> + Send + 'b>>; - -pub type ControlActionArc = Arc< - dyn for<'b> Fn(&'b Context, &'b mut Menu<'_>, Reaction) -> ControlActionResult<'b> - + Send - + Sync, ->; - -#[derive(Clone)] -pub struct ActionContainer { - inner: ControlActionArc, - position: isize, -} - -impl ActionContainer { - /// Creates a new control action - pub fn new(position: isize, callback: F) -> Self - where - F: for<'b> Fn(&'b Context, &'b mut Menu<'_>, Reaction) -> ControlActionResult<'b> - + Send - + Sync, - { - Self { - inner: Arc::new(callback), - position, - } - } - - /// Runs the action - pub async fn run( - &self, - ctx: &Context, - menu: &mut Menu<'_>, - reaction: Reaction, - ) -> SerenityUtilsResult<()> { - self.inner.clone()(ctx, menu, reaction).await?; - Ok(()) - } - - /// Returns the position of the action - pub fn position(&self) -> isize { - self.position - } -} - -/// A menu message -pub struct Menu<'a> { - pub message: Arc>, - pub pages: Vec>, - pub current_page: usize, - pub controls: HashMap, - pub timeout: Instant, - pub sticky: bool, - pub data: TypeMap, - pub help_entries: HashMap, - closed: bool, - listeners: EventDrivenMessagesRef, -} - -impl Menu<'_> { - /// Removes all reactions from the menu - pub(crate) async fn close(&mut self, http: &Http) -> SerenityUtilsResult<()> { - log::debug!("Closing menu..."); - let handle = self.message.read().await; - http.delete_message_reactions(handle.channel_id, handle.message_id) - .await?; - self.closed = true; - Ok(()) - } - - /// Returns the message of the menu - pub async fn get_message(&self, http: &Http) -> SerenityUtilsResult { - let handle = self.message.read().await; - let msg = http - .get_message(handle.channel_id, handle.message_id) - .await?; - - Ok(msg) - } - - /// Recreates the message completely - pub async fn recreate(&self, http: &Http) -> SerenityUtilsResult<()> { - log::debug!("Recreating message"); - - let old_handle = { - let handle = self.message.read().await; - (*handle).clone() - }; - log::debug!("Getting current page"); - let current_page = self - .pages - .get(self.current_page) - .cloned() - .ok_or(SerenityUtilsError::PageNotFound(self.current_page))? - .get() - .await?; - - log::debug!("Creating new message"); - let message = http - .send_message( - old_handle.channel_id, - &serde_json::to_value(current_page.0).unwrap(), - ) - .await?; - let mut controls = self - .controls - .clone() - .into_iter() - .collect::>(); - controls.sort_by_key(|(_, a)| a.position); - - for emoji in controls.into_iter().map(|(e, _)| e) { - http.create_reaction( - message.channel_id.0, - message.id.0, - &ReactionType::Unicode(emoji.clone()), - ) - .await?; - } - log::trace!("New message is {:?}", message); - - let new_handle = { - let mut handle = self.message.write().await; - handle.message_id = message.id.0; - (*handle).clone() - }; - { - log::debug!("Changing key of message"); - let mut listeners_lock = self.listeners.lock().await; - let menu = listeners_lock.remove(&old_handle).unwrap(); - listeners_lock.insert(new_handle, menu); - } - log::debug!("Deleting original message"); - http.delete_message(old_handle.channel_id, old_handle.message_id) - .await?; - log::debug!("Message recreated"); - - Ok(()) - } -} - -#[async_trait] -impl<'a> EventDrivenMessage for Menu<'a> { - fn is_frozen(&self) -> bool { - self.closed - } - - async fn update(&mut self, http: &Http) -> SerenityUtilsResult<()> { - log::trace!("Checking for menu timeout"); - if Instant::now() >= self.timeout { - log::debug!("Menu timout reached. Closing menu."); - self.close(http).await?; - } else if self.sticky { - log::debug!("Message is sticky. Checking for new messages in channel..."); - let handle = { - let handle = self.message.read().await; - (*handle).clone() - }; - - let channel_id = ChannelId(handle.channel_id); - let messages = channel_id - .messages(http, |p| p.after(handle.message_id).limit(1)) - .await?; - log::trace!("Messages are {:?}", messages); - if messages.len() > 0 { - log::debug!("New messages in channel. Recreating..."); - self.recreate(http).await?; - } - } - - Ok(()) - } - - async fn on_reaction_add( - &mut self, - ctx: &Context, - reaction: Reaction, - ) -> SerenityUtilsResult<()> { - log::debug!("Reaction to menu added"); - let current_user = ctx.http.get_current_user().await?; - - if reaction.user_id.unwrap().0 == current_user.id.0 { - log::debug!("Reaction is from current user."); - return Ok(()); - } - let emoji_string = reaction.emoji.as_data(); - - log::debug!("Deleting user reaction."); - reaction.delete(ctx).await?; - if let Some(control) = self.controls.get(&emoji_string).cloned() { - log::debug!("Running control"); - control.run(ctx, self, reaction).await?; - } - - Ok(()) - } -} - -/// A builder for messages -pub struct MenuBuilder { - pages: Vec>, - current_page: usize, - controls: HashMap, - timeout: Duration, - sticky: bool, - data: TypeMap, - help_entries: HashMap, -} - -impl Default for MenuBuilder { - fn default() -> Self { - Self { - pages: vec![], - current_page: 0, - controls: HashMap::new(), - timeout: Duration::from_secs(60), - sticky: false, - data: TypeMap::new(), - help_entries: HashMap::new(), - } - } -} - -impl MenuBuilder { - /// Creates a new paginaton menu - pub fn new_paginator() -> Self { - log::debug!("Creating new paginator"); - let mut controls = HashMap::new(); - let mut help_entries = HashMap::new(); - controls.insert( - PREVIOUS_PAGE_EMOJI.to_string(), - ActionContainer::new(0, |c, m, r| previous_page(c, m, r).boxed()), - ); - help_entries.insert( - PREVIOUS_PAGE_EMOJI.to_string(), - "Displays the previous page".to_string(), - ); - controls.insert( - CLOSE_MENU_EMOJI.to_string(), - ActionContainer::new(1, |c, m, r| close_menu(c, m, r).boxed()), - ); - help_entries.insert( - CLOSE_MENU_EMOJI.to_string(), - "Closes the menu buttons".to_string(), - ); - controls.insert( - NEXT_PAGE_EMOJI.to_string(), - ActionContainer::new(2, |c, m, r| next_page(c, m, r).boxed()), - ); - help_entries.insert( - NEXT_PAGE_EMOJI.to_string(), - "Displays the next page".to_string(), - ); - - Self { - controls, - help_entries, - ..Default::default() - } - } - - /// Adds a page to the message builder - pub fn add_page(mut self, page: Page<'static>) -> Self { - self.pages.push(page); - - self - } - - /// Adds multiple pages to the message - pub fn add_pages(mut self, pages: I) -> Self - where - I: IntoIterator>, - { - let mut pages = pages.into_iter().collect(); - self.pages.append(&mut pages); - - self - } - - /// Adds a single control to the message - pub fn add_control(mut self, position: isize, emoji: S, action: F) -> Self - where - S: ToString, - F: for<'b> Fn(&'b Context, &'b mut Menu<'_>, Reaction) -> ControlActionResult<'b> - + Send - + Sync, - { - self.controls - .insert(emoji.to_string(), ActionContainer::new(position, action)); - - self - } - - /// Adds a single control to the message - pub fn add_controls(mut self, controls: I) -> Self - where - S: ToString, - I: IntoIterator, - { - for (position, emoji, action) in controls { - self.controls.insert( - emoji.to_string(), - ActionContainer { - position, - inner: action, - }, - ); - } - - self - } - - /// Sets the timeout for the message - pub fn timeout(mut self, timeout: Duration) -> Self { - self.timeout = timeout; - - self - } - - /// Sets the start page of the message - pub fn start_page(mut self, page: usize) -> Self { - self.current_page = page; - - self - } - - /// If the message should be sticky and always be - /// the last one in the channel - pub fn sticky(mut self, value: bool) -> Self { - self.sticky = value; - - self - } - - /// Adds data to the menu typemap - pub fn add_data(mut self, value: T::Value) -> Self - where - T: TypeMapKey, - { - self.data.insert::(value); - - self - } - - /// Adds a help entry - pub fn add_help(mut self, button: S, help: S) -> Self { - self.help_entries - .insert(button.to_string(), help.to_string()); - - self - } - - /// Turns showing help for buttons on - pub fn show_help(self) -> Self { - self.add_control(100, HELP_EMOJI, |c, m, r| Box::pin(toggle_help(c, m, r))) - .add_data::(Arc::new(AtomicBool::new(false))) - } - - /// builds the menu - pub async fn build( - self, - ctx: &Context, - channel_id: ChannelId, - ) -> SerenityUtilsResult>> { - log::debug!("Building menu..."); - let mut current_page = self - .pages - .get(self.current_page) - .ok_or(SerenityUtilsError::PageNotFound(self.current_page))? - .clone() - .get() - .await?; - - let message = channel_id.send_message(ctx, |_| &mut current_page).await?; - log::trace!("Message is {:?}", message); - let listeners = get_listeners_from_context(ctx).await?; - log::debug!("Sorting controls..."); - let mut controls = self - .controls - .clone() - .into_iter() - .collect::>(); - controls.sort_by_key(|(_, a)| a.position); - - log::debug!("Creating menu..."); - let message_handle = MessageHandle::new(message.channel_id, message.id); - let handle_lock = Arc::new(RwLock::new(message_handle)); - - let menu = Menu { - message: Arc::clone(&handle_lock), - pages: self.pages, - current_page: self.current_page, - controls: self.controls, - timeout: Instant::now() + self.timeout, - closed: false, - listeners: Arc::clone(&listeners), - sticky: self.sticky, - data: self.data, - help_entries: self.help_entries, - }; - - log::debug!("Storing menu to listeners..."); - { - let mut listeners_lock = listeners.lock().await; - log::trace!("Listeners locked."); - listeners_lock.insert(message_handle, Arc::new(Mutex::new(Box::new(menu)))); - } - - log::debug!("Adding controls..."); - for (emoji, _) in controls { - message - .react(ctx, ReactionType::Unicode(emoji.clone())) - .await?; - } - log::debug!("Menu successfully created."); - - Ok(handle_lock) - } -} diff --git a/bot-serenityutils/src/menu/mod.rs b/bot-serenityutils/src/menu/mod.rs deleted file mode 100644 index f38518b..0000000 --- a/bot-serenityutils/src/menu/mod.rs +++ /dev/null @@ -1,16 +0,0 @@ -pub(crate) mod container; -pub(crate) mod controls; -pub(crate) mod menu; -pub(crate) mod page; -pub(crate) mod traits; -pub(crate) mod typedata; - -pub use container::*; -pub use controls::*; -pub use menu::{ - ActionContainer, ControlActionArc, Menu, MenuBuilder, CLOSE_MENU_EMOJI, NEXT_PAGE_EMOJI, - PREVIOUS_PAGE_EMOJI, -}; -pub use page::*; - -pub use traits::EventDrivenMessage; diff --git a/bot-serenityutils/src/menu/page.rs b/bot-serenityutils/src/menu/page.rs deleted file mode 100644 index 91b3426..0000000 --- a/bot-serenityutils/src/menu/page.rs +++ /dev/null @@ -1,40 +0,0 @@ -use crate::error::SerenityUtilsResult; -use serenity::builder::CreateMessage; -use std::future::Future; -use std::pin::Pin; -use std::sync::Arc; - -pub type MessageBuildOutput<'b> = - Pin>> + Send + 'b>>; -pub type MessageBuilderFn<'b> = Arc MessageBuildOutput<'b> + Send + Sync>; - -#[derive(Clone)] -/// A page that stores a builder function for message pages -/// or static pages -pub enum Page<'b> { - Builder(MessageBuilderFn<'b>), - Static(CreateMessage<'b>), -} - -impl<'b> Page<'b> { - /// Creates a new page with the given builder function - pub fn new_builder(builder_fn: F) -> Self - where - F: Fn() -> MessageBuildOutput<'b> + Send + Sync, - { - Self::Builder(Arc::new(builder_fn)) - } - - /// Creates a new page with a static message - pub fn new_static(page: CreateMessage<'b>) -> Self { - Self::Static(page) - } - - /// Returns the CreateMessage of the page - pub async fn get(&self) -> SerenityUtilsResult> { - match self { - Page::Builder(b) => b().await, - Page::Static(inner) => Ok(inner.clone()), - } - } -} diff --git a/bot-serenityutils/src/menu/traits.rs b/bot-serenityutils/src/menu/traits.rs deleted file mode 100644 index 9493033..0000000 --- a/bot-serenityutils/src/menu/traits.rs +++ /dev/null @@ -1,40 +0,0 @@ -use crate::error::SerenityUtilsResult; -use serenity::client::Context; -use serenity::http::Http; -use serenity::{async_trait, model::prelude::*}; - -#[async_trait] -pub trait EventDrivenMessage: Send + Sync { - /// Returns if a message has been frozen and won't handle any further events - fn is_frozen(&self) -> bool { - false - } - - /// Fired periodically - async fn update(&mut self, _http: &Http) -> SerenityUtilsResult<()> { - Ok(()) - } - - /// Fired when the message was deleted - async fn on_deleted(&mut self, _ctx: &Context) -> SerenityUtilsResult<()> { - Ok(()) - } - - /// Fired when a reaction was added to the message - async fn on_reaction_add( - &mut self, - _ctx: &Context, - _reaction: Reaction, - ) -> SerenityUtilsResult<()> { - Ok(()) - } - - /// Fired when a reaction was removed from the message - async fn on_reaction_remove( - &mut self, - _ctx: &Context, - _reaction: Reaction, - ) -> SerenityUtilsResult<()> { - Ok(()) - } -} diff --git a/bot-serenityutils/src/menu/typedata.rs b/bot-serenityutils/src/menu/typedata.rs deleted file mode 100644 index c2d6a59..0000000 --- a/bot-serenityutils/src/menu/typedata.rs +++ /dev/null @@ -1,9 +0,0 @@ -use serenity::prelude::TypeMapKey; -use std::sync::atomic::AtomicBool; -use std::sync::Arc; - -pub struct HelpActiveContainer; - -impl TypeMapKey for HelpActiveContainer { - type Value = Arc; -} diff --git a/src/client.rs b/src/client.rs index 51e3eb4..386dda2 100644 --- a/src/client.rs +++ b/src/client.rs @@ -11,16 +11,16 @@ use serenity::Client; use songbird::SerenityInit; use crate::commands::*; -use crate::handler::Handler; +use crate::handler::{get_raw_event_handler, Handler}; use crate::providers::music::lavalink::{Lavalink, LavalinkHandler}; use crate::utils::context_data::{ get_database_from_context, DatabaseContainer, MusicPlayers, Store, StoreData, }; use crate::utils::error::{BotError, BotResult}; -use bot_serenityutils::menu::EventDrivenMessageContainer; use lavalink_rs::LavalinkClient; use serenity::framework::standard::buckets::LimitedFor; -use serenity::http::Http; +use serenity_rich_interaction::menu::EventDrivenMessageContainer; +use serenity_rich_interaction::RegisterRichInteractions; use std::env; use std::sync::Arc; use std::time::SystemTime; @@ -29,15 +29,23 @@ use tokio::sync::Mutex; pub async fn get_client() -> BotResult { let token = env::var("BOT_TOKEN").map_err(|_| BotError::MissingToken)?; let database = get_database()?; - let http = Http::new_with_token(&token); - let current_application = http.get_current_application_info().await?; let client = Client::builder(token) + .register_rich_interactions_with(get_raw_event_handler()) .event_handler(Handler) .framework(get_framework().await) .register_songbird() + .type_map_insert::(StoreData::new()) + .type_map_insert::(database) + .type_map_insert::(HashMap::new()) .await?; let data = client.data.clone(); + let current_application = client + .cache_and_http + .http + .get_current_application_info() + .await?; + let lava_client = LavalinkClient::builder(current_application.id.0) .set_host(env::var("LAVALINK_HOST").unwrap_or("172.0.0.1".to_string())) .set_password(env::var("LAVALINK_PASSWORD").expect("Missing lavalink password")) @@ -51,10 +59,6 @@ pub async fn get_client() -> BotResult { .await?; { let mut data = client.data.write().await; - data.insert::(StoreData::new()); - data.insert::(database); - data.insert::(Arc::new(Mutex::new(HashMap::new()))); - data.insert::(HashMap::new()); data.insert::(Arc::new(lava_client)); } diff --git a/src/commands/misc/add_media.rs b/src/commands/misc/add_media.rs index 76b3767..21e1abb 100644 --- a/src/commands/misc/add_media.rs +++ b/src/commands/misc/add_media.rs @@ -1,11 +1,11 @@ use crate::utils::context_data::get_database_from_context; use bot_coreutils::url; -use bot_serenityutils::core::SHORT_TIMEOUT; -use bot_serenityutils::ephemeral_message::EphemeralMessage; use serenity::client::Context; use serenity::framework::standard::macros::command; use serenity::framework::standard::{Args, CommandResult}; use serenity::model::channel::Message; +use serenity_rich_interaction::core::SHORT_TIMEOUT; +use serenity_rich_interaction::ephemeral_message::EphemeralMessage; #[command] #[description("Adds media to the database")] diff --git a/src/commands/misc/clear.rs b/src/commands/misc/clear.rs index b62e41c..2d174fa 100644 --- a/src/commands/misc/clear.rs +++ b/src/commands/misc/clear.rs @@ -1,11 +1,11 @@ -use bot_serenityutils::core::SHORT_TIMEOUT; -use bot_serenityutils::ephemeral_message::EphemeralMessage; use futures::future::BoxFuture; use serenity::client::Context; use serenity::framework::standard::macros::command; use serenity::framework::standard::{Args, CommandResult}; use serenity::model::channel::Message; use serenity::Result as SerenityResult; +use serenity_rich_interaction::core::SHORT_TIMEOUT; +use serenity_rich_interaction::ephemeral_message::EphemeralMessage; #[command] #[description("Clears the chat (maximum 100 messages)")] diff --git a/src/commands/misc/time.rs b/src/commands/misc/time.rs index b2a8f36..06ede59 100644 --- a/src/commands/misc/time.rs +++ b/src/commands/misc/time.rs @@ -17,13 +17,13 @@ async fn time(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { let second_timezone = args.single::().ok(); let from_timezone: Tz = if let Some(first) = &first_timezone { - forward_error!(ctx, msg.channel_id, first.parse::()) + crate::forward_error!(ctx, msg.channel_id, first.parse::()) } else { Tz::UTC }; let to_timezone = if let Some(second) = &second_timezone { - forward_error!(ctx, msg.channel_id, second.parse::()) + crate::forward_error!(ctx, msg.channel_id, second.parse::()) } else { Tz::UTC }; @@ -33,7 +33,7 @@ async fn time(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { } else { let now = Utc::now(); if second_timezone.is_some() { - forward_error!( + crate::forward_error!( ctx, msg.channel_id, from_timezone.datetime_from_str( @@ -43,7 +43,7 @@ async fn time(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { ) } else { let timezone: Tz = "UTC".parse().unwrap(); - forward_error!( + crate::forward_error!( ctx, msg.channel_id, timezone.datetime_from_str( diff --git a/src/commands/music/clear_queue.rs b/src/commands/music/clear_queue.rs index bd1db27..1318d40 100644 --- a/src/commands/music/clear_queue.rs +++ b/src/commands/music/clear_queue.rs @@ -1,13 +1,13 @@ use serenity::client::Context; use serenity::framework::standard::macros::command; -use serenity::framework::standard::{CommandResult, CommandError}; +use serenity::framework::standard::{CommandError, CommandResult}; use serenity::model::channel::Message; use crate::commands::common::handle_autodelete; use crate::commands::music::{get_music_player_for_guild, DJ_CHECK}; -use bot_serenityutils::core::SHORT_TIMEOUT; -use bot_serenityutils::ephemeral_message::EphemeralMessage; use crate::messages::music::no_voicechannel::create_no_voicechannel_message; +use serenity_rich_interaction::core::SHORT_TIMEOUT; +use serenity_rich_interaction::ephemeral_message::EphemeralMessage; #[command] #[only_in(guilds)] diff --git a/src/commands/music/equalize.rs b/src/commands/music/equalize.rs index c338984..54d4264 100644 --- a/src/commands/music/equalize.rs +++ b/src/commands/music/equalize.rs @@ -6,8 +6,8 @@ use serenity::prelude::*; use crate::commands::common::handle_autodelete; use crate::commands::music::{get_music_player_for_guild, DJ_CHECK}; use crate::messages::music::no_voicechannel::create_no_voicechannel_message; -use bot_serenityutils::core::{MEDIUM_TIMEOUT, SHORT_TIMEOUT}; -use bot_serenityutils::ephemeral_message::EphemeralMessage; +use serenity_rich_interaction::core::{MEDIUM_TIMEOUT, SHORT_TIMEOUT}; +use serenity_rich_interaction::ephemeral_message::EphemeralMessage; #[command] #[only_in(guilds)] diff --git a/src/commands/music/join.rs b/src/commands/music/join.rs index 544e61f..04bea04 100644 --- a/src/commands/music/join.rs +++ b/src/commands/music/join.rs @@ -6,9 +6,9 @@ use serenity::model::channel::Message; use crate::commands::common::handle_autodelete; use crate::commands::music::{get_channel_for_author, get_music_player_for_guild, is_dj}; use crate::providers::music::player::MusicPlayer; -use bot_serenityutils::core::SHORT_TIMEOUT; -use bot_serenityutils::ephemeral_message::EphemeralMessage; use serenity::model::id::ChannelId; +use serenity_rich_interaction::core::SHORT_TIMEOUT; +use serenity_rich_interaction::ephemeral_message::EphemeralMessage; #[command] #[only_in(guilds)] @@ -21,14 +21,14 @@ async fn join(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { if is_dj(ctx, guild.id, &msg.author).await? { ChannelId(arg) } else { - forward_error!( + crate::forward_error!( ctx, msg.channel_id, get_channel_for_author(&msg.author.id, &guild) ) } } else { - forward_error!( + crate::forward_error!( ctx, msg.channel_id, get_channel_for_author(&msg.author.id, &guild) diff --git a/src/commands/music/leave.rs b/src/commands/music/leave.rs index 740e67c..155e834 100644 --- a/src/commands/music/leave.rs +++ b/src/commands/music/leave.rs @@ -6,8 +6,8 @@ use serenity::model::channel::Message; use crate::commands::common::handle_autodelete; use crate::commands::music::DJ_CHECK; use crate::utils::context_data::MusicPlayers; -use bot_serenityutils::core::SHORT_TIMEOUT; -use bot_serenityutils::ephemeral_message::EphemeralMessage; +use serenity_rich_interaction::core::SHORT_TIMEOUT; +use serenity_rich_interaction::ephemeral_message::EphemeralMessage; #[command] #[only_in(guilds)] diff --git a/src/commands/music/move_song.rs b/src/commands/music/move_song.rs index 434ec50..383674c 100644 --- a/src/commands/music/move_song.rs +++ b/src/commands/music/move_song.rs @@ -1,12 +1,12 @@ use crate::commands::common::handle_autodelete; use crate::commands::music::{get_music_player_for_guild, DJ_CHECK}; use crate::messages::music::no_voicechannel::create_no_voicechannel_message; -use bot_serenityutils::core::SHORT_TIMEOUT; -use bot_serenityutils::ephemeral_message::EphemeralMessage; use serenity::client::Context; use serenity::framework::standard::macros::command; use serenity::framework::standard::{Args, CommandError, CommandResult}; use serenity::model::channel::Message; +use serenity_rich_interaction::core::SHORT_TIMEOUT; +use serenity_rich_interaction::ephemeral_message::EphemeralMessage; #[command] #[description("Moves a song in the queue from one position to a new one")] diff --git a/src/commands/music/pause.rs b/src/commands/music/pause.rs index 99862c4..6259cf4 100644 --- a/src/commands/music/pause.rs +++ b/src/commands/music/pause.rs @@ -6,8 +6,8 @@ use serenity::prelude::*; use crate::commands::common::handle_autodelete; use crate::commands::music::{get_music_player_for_guild, DJ_CHECK}; use crate::messages::music::no_voicechannel::create_no_voicechannel_message; -use bot_serenityutils::core::SHORT_TIMEOUT; -use bot_serenityutils::ephemeral_message::EphemeralMessage; +use serenity_rich_interaction::core::SHORT_TIMEOUT; +use serenity_rich_interaction::ephemeral_message::EphemeralMessage; #[command] #[only_in(guilds)] diff --git a/src/commands/music/remove_song.rs b/src/commands/music/remove_song.rs index 7537fc5..28fd480 100644 --- a/src/commands/music/remove_song.rs +++ b/src/commands/music/remove_song.rs @@ -1,12 +1,12 @@ use crate::commands::common::handle_autodelete; -use crate::commands::music::{get_music_player_for_guild, DJ_CHECK}; +use crate::commands::music::{get_music_player_for_guild, DJ_CHECK}; use crate::messages::music::no_voicechannel::create_no_voicechannel_message; -use bot_serenityutils::core::SHORT_TIMEOUT; -use bot_serenityutils::ephemeral_message::EphemeralMessage; use serenity::client::Context; use serenity::framework::standard::macros::command; use serenity::framework::standard::{Args, CommandError, CommandResult}; use serenity::model::channel::Message; +use serenity_rich_interaction::core::SHORT_TIMEOUT; +use serenity_rich_interaction::ephemeral_message::EphemeralMessage; #[command] #[description("Removes a song from the queue")] diff --git a/src/commands/music/shuffle.rs b/src/commands/music/shuffle.rs index 5980cca..37b155a 100644 --- a/src/commands/music/shuffle.rs +++ b/src/commands/music/shuffle.rs @@ -6,8 +6,8 @@ use serenity::model::channel::Message; use crate::commands::common::handle_autodelete; use crate::commands::music::{get_music_player_for_guild, DJ_CHECK}; use crate::messages::music::no_voicechannel::create_no_voicechannel_message; -use bot_serenityutils::core::SHORT_TIMEOUT; -use bot_serenityutils::ephemeral_message::EphemeralMessage; +use serenity_rich_interaction::core::SHORT_TIMEOUT; +use serenity_rich_interaction::ephemeral_message::EphemeralMessage; #[command] #[only_in(guilds)] diff --git a/src/commands/music/skip.rs b/src/commands/music/skip.rs index f16333d..dbf2bb0 100644 --- a/src/commands/music/skip.rs +++ b/src/commands/music/skip.rs @@ -6,8 +6,8 @@ use serenity::model::channel::Message; use crate::commands::common::handle_autodelete; use crate::commands::music::{get_music_player_for_guild, DJ_CHECK}; use crate::messages::music::no_voicechannel::create_no_voicechannel_message; -use bot_serenityutils::core::SHORT_TIMEOUT; -use bot_serenityutils::ephemeral_message::EphemeralMessage; +use serenity_rich_interaction::core::SHORT_TIMEOUT; +use serenity_rich_interaction::ephemeral_message::EphemeralMessage; #[command] #[only_in(guilds)] diff --git a/src/handler.rs b/src/handler.rs index 99fa0e7..70baed9 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -1,95 +1,48 @@ use serenity::async_trait; use serenity::client::Context; -use serenity::model::channel::Reaction; +use serenity::model::channel::GuildChannel; use serenity::model::event::ResumedEvent; use serenity::model::gateway::{Activity, Ready}; use serenity::model::guild::Member; -use serenity::model::id::{ChannelId, GuildId, MessageId}; +use serenity::model::id::{ChannelId, GuildId}; use serenity::model::voice::VoiceState; use serenity::prelude::*; use crate::commands::music::get_music_player_for_guild; +use crate::utils::context_data::MusicPlayers; use crate::utils::delete_messages_from_database; -use bot_serenityutils::menu::{ - handle_message_delete, handle_message_delete_bulk, handle_reaction_add, handle_reaction_remove, - start_update_loop, -}; - -pub(crate) struct Handler; - -#[async_trait] -impl EventHandler for Handler { - async fn cache_ready(&self, ctx: Context, _: Vec) { - log::info!("Cache Ready"); - start_update_loop(&ctx).await; - if let Err(e) = delete_messages_from_database(&ctx).await { - log::error!("Failed to delete expired messages {:?}", e); - } - } - - /// Fired when a message was deleted - async fn message_delete( - &self, - ctx: Context, - channel_id: ChannelId, - message_id: MessageId, - _: Option, - ) { - tokio::spawn(async move { - log::trace!("Handling message delete event"); - if let Err(e) = handle_message_delete(&ctx, channel_id, message_id).await { - log::error!("Failed to handle event: {:?}", e); - } - log::trace!("Message delete event handled"); - }); - } - - /// Fired when multiple messages were deleted - async fn message_delete_bulk( - &self, - ctx: Context, - channel_id: ChannelId, - message_ids: Vec, - _: Option, - ) { - tokio::spawn(async move { - log::trace!("Handling message delete bulk event"); - if let Err(e) = handle_message_delete_bulk(&ctx, channel_id, &message_ids).await { - log::error!("Failed to handle event: {:?}", e); - } - log::debug!("Message delte bulk event handled"); +use serenity::model::event; +use serenity_rich_interaction::events::RichEventHandler; +use serenity_rich_interaction::Result; + +/// Returns the raw event handler built from a rich event handler +pub fn get_raw_event_handler() -> RichEventHandler { + let mut handler = RichEventHandler::default(); + handler + .add_event(|ctx, e: &event::ReadyEvent| Box::pin(ready(ctx, &e.ready))) + .add_event(|_ctx, _: &event::ResumedEvent| { + Box::pin(async { + log::info!("Reconnected to Gateway"); + Ok(()) + }) }); - } - /// Fired when a reaction was added to a message - async fn reaction_add(&self, ctx: Context, reaction: Reaction) { - tokio::spawn(async move { - log::trace!("Handling reaction add event..."); - if let Err(e) = handle_reaction_add(&ctx, &reaction).await { - log::error!("Failed to handle event: {:?}", e); - } - log::trace!("Reaction add event handled"); - }); - } + handler +} - /// Fired when a reaction was added to a message - async fn reaction_remove(&self, ctx: Context, reaction: Reaction) { - tokio::spawn(async move { - log::trace!("Handling reaction remove event"); - if let Err(e) = handle_reaction_remove(&ctx, &reaction).await { - log::error!("Failed to handle event: {:?}", e); - } - log::trace!("Reaction remove event handled"); - }); - } +async fn ready(ctx: &Context, _: &Ready) -> Result<()> { + log::info!("Ready"); + delete_messages_from_database(&ctx).await?; + let prefix = std::env::var("BOT_PREFIX").unwrap_or("~!".to_string()); + ctx.set_activity(Activity::listening(format!("{}help", prefix).as_str())) + .await; + Ok(()) +} - async fn ready(&self, ctx: Context, ready: Ready) { - log::info!("Connected as {}", ready.user.name); - let prefix = dotenv::var("BOT_PREFIX").unwrap_or("~!".to_string()); - ctx.set_activity(Activity::listening(format!("{}help", prefix).as_str())) - .await; - } +pub(crate) struct Handler; +#[async_trait] +impl EventHandler for Handler { async fn resume(&self, _: Context, _: ResumedEvent) { log::info!("Reconnected to gateway") } @@ -109,12 +62,12 @@ impl EventHandler for Handler { return; }; - if let Some(old_id) = old_state.and_then(|c| c.channel_id) { - member_count = get_own_channel_member_count(&ctx, &old_id).await; + if let Some(old_id) = old_state.clone().and_then(|c| c.channel_id) { + member_count = get_own_channel_member_count(&ctx, old_id).await; } if member_count.is_none() { if let Some(new_id) = new_state.channel_id { - member_count = get_own_channel_member_count(&ctx, &new_id).await; + member_count = get_own_channel_member_count(&ctx, new_id).await; } } @@ -126,14 +79,29 @@ impl EventHandler for Handler { player.set_leave_flag(count == 0); } } + // handle disconnects + if let (Some(state), None) = (old_state, new_state.channel_id) { + let current_user = ctx.cache.current_user().await; + + if state.user_id == current_user.id { + let mut data = ctx.data.write().await; + let players = data.get_mut::().unwrap(); + + if let Some(player) = players.remove(&guild_id.0) { + let mut player = player.lock().await; + let _ = player.delete_now_playing().await; + let _ = player.stop().await; + } + } + } } } /// Returns the number of members in the channel if it's the bots voice channel -async fn get_own_channel_member_count(ctx: &Context, channel_id: &ChannelId) -> Option { - let channel = ctx.http.get_channel(channel_id.0).await.ok()?; - let guild_channel = channel.guild()?; - let current_user = ctx.http.get_current_user().await.ok()?; +async fn get_own_channel_member_count(ctx: &Context, channel_id: ChannelId) -> Option { + let guild_channel = get_guild_channel(ctx, channel_id).await?; + + let current_user = ctx.cache.current_user().await; let members = guild_channel.members(&ctx).await.ok()?; let own_channel = members @@ -148,3 +116,12 @@ async fn get_own_channel_member_count(ctx: &Context, channel_id: &ChannelId) -> Some(members.len()) } + +/// Returns the guild channel for a guild ID +async fn get_guild_channel(ctx: &Context, channel_id: ChannelId) -> Option { + if let Some(channel) = ctx.cache.channel(channel_id).await { + return channel.guild(); + } + let channel = ctx.http.get_channel(channel_id.0).await.ok()?; + channel.guild() +} diff --git a/src/main.rs b/src/main.rs index 8e9fd01..1f9a387 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,12 @@ use crate::client::get_client; use crate::utils::logging::init_logger; -#[macro_use] -extern crate bot_serenityutils; - mod client; mod commands; mod handler; mod messages; mod providers; +#[macro_use] mod utils; pub static VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/src/messages/gifs.rs b/src/messages/gifs.rs index d74a4ea..c6c7c94 100644 --- a/src/messages/gifs.rs +++ b/src/messages/gifs.rs @@ -1,9 +1,9 @@ use crate::utils::error::BotResult; use bot_database::models::Media; -use bot_serenityutils::menu::{MenuBuilder, Page}; use serenity::builder::CreateMessage; use serenity::client::Context; use serenity::model::id::ChannelId; +use serenity_rich_interaction::menu::{MenuBuilder, Page}; use std::time::Duration; /// Creates a new gifs embed diff --git a/src/messages/mod.rs b/src/messages/mod.rs index 43c3c2f..1d4e4a4 100644 --- a/src/messages/mod.rs +++ b/src/messages/mod.rs @@ -1,7 +1,7 @@ use crate::utils::context_data::get_database_from_context; use crate::utils::error::BotResult; -use bot_serenityutils::core::MessageHandle; use serenity::client::Context; +use serenity_rich_interaction::core::MessageHandle; use std::time::{Duration, SystemTime}; pub mod gifs; diff --git a/src/messages/music/equalizer.rs b/src/messages/music/equalizer.rs index 9fc6bae..25b5810 100644 --- a/src/messages/music/equalizer.rs +++ b/src/messages/music/equalizer.rs @@ -1,13 +1,13 @@ use crate::commands::music::is_dj; use crate::providers::music::player::MusicPlayer; use crate::utils::error::BotResult; -use bot_serenityutils::core::EXTRA_LONG_TIMEOUT; -use bot_serenityutils::error::SerenityUtilsResult; -use bot_serenityutils::menu::{display_page, Menu, MenuBuilder, Page}; use serenity::builder::{CreateEmbed, CreateMessage}; use serenity::client::Context; use serenity::model::channel::Reaction; use serenity::model::id::ChannelId; +use serenity_rich_interaction::core::EXTRA_LONG_TIMEOUT; +use serenity_rich_interaction::menu::{display_page, Menu, MenuBuilder, Page}; +use serenity_rich_interaction::Result as SerenityUtilsResult; use std::sync::atomic::{AtomicU8, Ordering}; use std::sync::Arc; use tokio::sync::Mutex; diff --git a/src/messages/music/no_voicechannel.rs b/src/messages/music/no_voicechannel.rs index 9616cd9..bc5cdc1 100644 --- a/src/messages/music/no_voicechannel.rs +++ b/src/messages/music/no_voicechannel.rs @@ -1,8 +1,8 @@ use crate::utils::error::BotResult; -use bot_serenityutils::core::SHORT_TIMEOUT; -use bot_serenityutils::ephemeral_message::EphemeralMessage; use serenity::http::Http; use serenity::model::prelude::ChannelId; +use serenity_rich_interaction::core::SHORT_TIMEOUT; +use serenity_rich_interaction::ephemeral_message::EphemeralMessage; use std::sync::Arc; /// Creates a not in a voicechannel message diff --git a/src/messages/music/now_playing.rs b/src/messages/music/now_playing.rs index 01b2182..b8bf4b2 100644 --- a/src/messages/music/now_playing.rs +++ b/src/messages/music/now_playing.rs @@ -11,12 +11,12 @@ use crate::providers::music::player::MusicPlayer; use crate::providers::music::queue::Song; use crate::utils::context_data::{DatabaseContainer, MusicPlayers, Store}; use crate::utils::error::*; -use bot_serenityutils::core::MessageHandle; -use bot_serenityutils::error::SerenityUtilsResult; -use bot_serenityutils::menu::{Menu, MenuBuilder, Page}; use serenity::builder::CreateMessage; use serenity::client::Context; use serenity::model::channel::Reaction; +use serenity_rich_interaction::core::MessageHandle; +use serenity_rich_interaction::menu::{Menu, MenuBuilder, Page}; +use serenity_rich_interaction::Result as SerenityUtilsResult; use std::env; use std::time::Duration; use tokio::sync::{Mutex, RwLock}; diff --git a/src/messages/music/queue.rs b/src/messages/music/queue.rs index 30bc135..9a870e7 100644 --- a/src/messages/music/queue.rs +++ b/src/messages/music/queue.rs @@ -1,9 +1,9 @@ use crate::providers::music::queue::Song; use crate::utils::error::BotResult; -use bot_serenityutils::menu::{MenuBuilder, Page}; use serenity::builder::CreateMessage; use serenity::client::Context; use serenity::model::id::ChannelId; +use serenity_rich_interaction::menu::{MenuBuilder, Page}; use std::time::Duration; /// Creates a new queue menu diff --git a/src/messages/sauce.rs b/src/messages/sauce.rs index 527ae24..6235993 100644 --- a/src/messages/sauce.rs +++ b/src/messages/sauce.rs @@ -7,8 +7,8 @@ use serenity::{model::channel::Message, prelude::*}; use bot_coreutils::url::get_domain_for_url; use crate::utils::error::BotResult; -use bot_serenityutils::menu::{MenuBuilder, Page}; use rand::prelude::SliceRandom; +use serenity_rich_interaction::menu::{MenuBuilder, Page}; use std::time::Duration; static MAX_RESULTS: usize = 6; diff --git a/src/providers/music/lavalink.rs b/src/providers/music/lavalink.rs index ea10954..f5e9813 100644 --- a/src/providers/music/lavalink.rs +++ b/src/providers/music/lavalink.rs @@ -1,6 +1,6 @@ use crate::utils::context_data::MusicPlayers; use lavalink_rs::gateway::LavalinkEventHandler; -use lavalink_rs::model::{TrackFinish, TrackStart}; +use lavalink_rs::model::{PlayerUpdate, Stats, TrackFinish, TrackStart}; use lavalink_rs::LavalinkClient; use serenity::async_trait; use serenity::prelude::TypeMapKey; @@ -17,6 +17,7 @@ impl LavalinkEventHandler for LavalinkHandler { async fn track_start(&self, _client: LavalinkClient, event: TrackStart) { log::info!("Track started!\nGuild: {}", event.guild_id); } + async fn track_finish(&self, _: LavalinkClient, event: TrackFinish) { log::info!("Track finished!\nGuild: {}", event.guild_id); let player = { @@ -35,6 +36,14 @@ impl LavalinkEventHandler for LavalinkHandler { } } } + + async fn player_update(&self, _: LavalinkClient, event: PlayerUpdate) { + log::debug!("Received player update event: {:?}", event); + } + + async fn stats(&self, _: LavalinkClient, event: Stats) { + log::debug!("Received stats event: {:?}", event); + } } pub struct Lavalink; diff --git a/src/providers/music/player.rs b/src/providers/music/player.rs index 5ae9c1e..6a57481 100644 --- a/src/providers/music/player.rs +++ b/src/providers/music/player.rs @@ -4,8 +4,6 @@ use crate::providers::music::lyrics::get_lyrics; use crate::providers::music::queue::MusicQueue; use crate::utils::context_data::MusicPlayers; use crate::utils::error::{BotError, BotResult}; -use bot_serenityutils::core::{MessageHandle, SHORT_TIMEOUT}; -use bot_serenityutils::ephemeral_message::EphemeralMessage; use lavalink_rs::LavalinkClient; use serenity::prelude::TypeMap; use serenity::{ @@ -13,6 +11,8 @@ use serenity::{ http::Http, model::id::{ChannelId, GuildId}, }; +use serenity_rich_interaction::core::{MessageHandle, SHORT_TIMEOUT}; +use serenity_rich_interaction::ephemeral_message::EphemeralMessage; use songbird::Songbird; use std::mem; use std::sync::Arc; @@ -60,9 +60,14 @@ impl MusicPlayer { msg_channel_id: ChannelId, ) -> BotResult>> { let manager = songbird::get(ctx).await.unwrap(); - let (_, connection) = manager.join_gateway(guild_id, voice_channel_id).await; + let (handler, connection) = manager.join_gateway(guild_id, voice_channel_id).await; let connection = connection?; + { + let mut handler = handler.lock().await; + handler.deafen(true).await?; + } + let player = { let mut data = ctx.data.write().await; let client = data.get::().unwrap(); diff --git a/src/utils/error.rs b/src/utils/error.rs index ebdc370..3172fea 100644 --- a/src/utils/error.rs +++ b/src/utils/error.rs @@ -1,5 +1,5 @@ -use bot_serenityutils::error::SerenityUtilsError; use lavalink_rs::error::LavalinkError; +use serenity_rich_interaction::Error as SerenityUtilsError; use thiserror::Error; pub type BotResult = Result; @@ -34,7 +34,7 @@ pub enum BotError { CliInject, #[error("Serenity Utils Error: {0}")] - SerenityUtils(#[from] bot_serenityutils::error::SerenityUtilsError), + SerenityUtils(#[from] serenity_rich_interaction::Error), #[error("Track Error: {0}")] TrackError(#[from] songbird::error::TrackError), diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 7958565..d3c9670 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -12,6 +12,19 @@ pub(crate) mod context_data; pub(crate) mod error; pub(crate) mod logging; +#[macro_export] +macro_rules! forward_error { + ($ctx:expr,$channel_id:expr,$result:expr) => { + match $result { + Err(e) => { + $channel_id.say($ctx, format!("‼️ {}", e)).await?; + return Ok(()); + } + Ok(v) => v, + } + }; +} + /// Returns the message the given message is a reply to or the message sent before that pub async fn get_previous_message_or_reply( ctx: &Context,