From 7130fb9b7ae59db19641ff07362283f0d453828f Mon Sep 17 00:00:00 2001 From: Fridella <43757589+fdnt7@users.noreply.github.com> Date: Sat, 8 Jun 2024 01:56:58 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=9C=20Internals=20Overhaul=20(#18)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Bumped to `0.7.0`, removed all `Deref`s, enabled LTO * Internals Overhaul * Introduced Flakes integrations, updated to `vergen-git2` `1.0.0-beta.2` --- .envrc | 11 +- .gitignore | 3 +- Cargo.lock | 987 ++-- Cargo.toml | 3 + devenv.lock | 161 - devenv.nix | 73 - devenv.yaml | 8 - flake.lock | 482 ++ flake.nix | 116 + lavalink/application.yml | 2 +- lyra/Cargo.lock | 4115 ----------------- lyra/Cargo.toml | 27 +- lyra/build.rs | 19 +- lyra/src/bot/command.rs | 3 +- lyra/src/bot/command/check.rs | 1036 ++--- lyra/src/bot/command/declare.rs | 93 +- lyra/src/bot/command/model.rs | 55 +- lyra/src/bot/command/model/ctx.rs | 255 +- .../src/bot/command/model/ctx/autocomplete.rs | 5 +- .../src/bot/command/model/ctx/command_data.rs | 50 +- lyra/src/bot/command/model/ctx/menu.rs | 53 +- lyra/src/bot/command/model/ctx/message.rs | 7 +- lyra/src/bot/command/model/ctx/modal.rs | 13 +- lyra/src/bot/command/poll.rs | 60 +- lyra/src/bot/command/require.rs | 203 + lyra/src/bot/command/util.rs | 83 +- lyra/src/bot/component/config/access.rs | 116 +- lyra/src/bot/component/config/access/clear.rs | 6 +- lyra/src/bot/component/config/access/edit.rs | 217 +- lyra/src/bot/component/config/access/mode.rs | 11 +- lyra/src/bot/component/config/access/view.rs | 7 +- lyra/src/bot/component/config/now_playing.rs | 11 +- lyra/src/bot/component/connection.rs | 13 +- lyra/src/bot/component/connection/join.rs | 68 +- lyra/src/bot/component/connection/leave.rs | 30 +- lyra/src/bot/component/queue.rs | 50 +- lyra/src/bot/component/queue/clear.rs | 26 +- lyra/src/bot/component/queue/fair_queue.rs | 15 +- lyra/src/bot/component/queue/move.rs | 43 +- lyra/src/bot/component/queue/play.rs | 139 +- lyra/src/bot/component/queue/remove.rs | 43 +- lyra/src/bot/component/queue/remove_range.rs | 33 +- lyra/src/bot/component/queue/repeat.rs | 32 +- lyra/src/bot/component/queue/shuffle.rs | 21 +- lyra/src/bot/component/tuning.rs | 61 +- lyra/src/bot/component/tuning/equaliser.rs | 4 +- .../bot/component/tuning/equaliser/custom.rs | 16 +- .../src/bot/component/tuning/equaliser/off.rs | 11 +- .../bot/component/tuning/equaliser/preset.rs | 14 +- lyra/src/bot/component/tuning/filter.rs | 29 +- .../bot/component/tuning/filter/all_off.rs | 23 +- .../component/tuning/filter/channel_mix.rs | 22 +- .../bot/component/tuning/filter/distortion.rs | 22 +- .../bot/component/tuning/filter/low_pass.rs | 32 +- lyra/src/bot/component/tuning/filter/pitch.rs | 17 +- .../bot/component/tuning/filter/pitch/down.rs | 17 +- .../bot/component/tuning/filter/pitch/set.rs | 20 +- .../bot/component/tuning/filter/pitch/up.rs | 17 +- .../bot/component/tuning/filter/rotation.rs | 22 +- .../bot/component/tuning/filter/tremolo.rs | 20 +- .../bot/component/tuning/filter/vibrato.rs | 20 +- lyra/src/bot/component/tuning/speed.rs | 23 +- lyra/src/bot/component/tuning/volume.rs | 3 +- lyra/src/bot/component/tuning/volume/down.rs | 23 +- lyra/src/bot/component/tuning/volume/set.rs | 24 +- .../component/tuning/volume/toggle_mute.rs | 11 +- lyra/src/bot/component/tuning/volume/up.rs | 30 +- lyra/src/bot/core/const.rs | 100 +- lyra/src/bot/core/model.rs | 6 +- lyra/src/bot/core/model/interaction.rs | 46 +- lyra/src/bot/error.rs | 7 + lyra/src/bot/error/command.rs | 14 +- lyra/src/bot/error/command/check.rs | 9 +- lyra/src/bot/ext/image.rs | 40 +- lyra/src/bot/ext/util.rs | 36 +- lyra/src/bot/gateway.rs | 2 +- lyra/src/bot/gateway/guild.rs | 3 +- lyra/src/bot/gateway/interaction.rs | 52 +- lyra/src/bot/gateway/model.rs | 9 +- lyra/src/bot/gateway/shard.rs | 7 +- lyra/src/bot/gateway/voice.rs | 9 +- lyra/src/bot/lavalink.rs | 8 +- lyra/src/bot/lavalink/model.rs | 236 +- lyra/src/bot/lavalink/model/connection.rs | 9 +- lyra/src/bot/lavalink/model/queue.rs | 83 +- lyra/src/bot/lavalink/plugin.rs | 2 - lyra/src/bot/lavalink/track.rs | 8 +- lyra/src/bot/runner.rs | 29 +- lyra_proc/Cargo.toml | 2 +- lyra_proc/src/config_access.rs | 2 +- lyra_proc/src/model.rs | 9 - 91 files changed, 3274 insertions(+), 6739 deletions(-) delete mode 100644 devenv.lock delete mode 100644 devenv.nix delete mode 100644 devenv.yaml create mode 100644 flake.lock create mode 100644 flake.nix delete mode 100644 lyra/Cargo.lock create mode 100644 lyra/src/bot/command/require.rs diff --git a/.envrc b/.envrc index 5bf8fc1..ac18306 100644 --- a/.envrc +++ b/.envrc @@ -1,3 +1,10 @@ -source_url "https://raw.githubusercontent.com/cachix/devenv/95f329d49a8a5289d31e0982652f7058a189bfca/direnvrc" "sha256-d+8cBpDfDBj41inrADaJt+bDWhOktwslgoP5YiGJ1v0=" +if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs=" +fi -use devenv \ No newline at end of file +nix_direnv_watch_file flake.nix +nix_direnv_watch_file flake.lock +if ! use flake . --impure +then + echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2 +fi diff --git a/.gitignore b/.gitignore index 360e650..d585425 100644 --- a/.gitignore +++ b/.gitignore @@ -6,8 +6,7 @@ lavalink/plugins lavalink/Lavalink.jar # Devenv -.devenv* -devenv.local.nix +.devenv # direnv .direnv diff --git a/Cargo.lock b/Cargo.lock index 3a071ba..c8c5088 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -195,26 +195,6 @@ dependencies = [ "alloc-stdlib", ] -[[package]] -name = "bstr" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706" -dependencies = [ - "memchr", - "regex-automata 0.4.6", - "serde", -] - -[[package]] -name = "btoi" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dd6407f73a9b8b6162d8a2ef999fe6afd7cc15902ebf42c5cd296addf17e0ad" -dependencies = [ - "num-traits", -] - [[package]] name = "bumpalo" version = "3.16.0" @@ -282,6 +262,11 @@ name = "cc" version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" +dependencies = [ + "jobserver", + "libc", + "once_cell", +] [[package]] name = "cfg-if" @@ -303,12 +288,6 @@ dependencies = [ "windows-targets 0.52.5", ] -[[package]] -name = "clru" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbd0f76e066e64fdc5631e3bb46381254deab9ef1158292f27c8c57e3bf3fe59" - [[package]] name = "color-eyre" version = "0.6.3" @@ -418,9 +397,9 @@ checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" [[package]] name = "crc32fast" -version = "1.4.0" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" dependencies = [ "cfg-if", ] @@ -469,6 +448,41 @@ dependencies = [ "typenum", ] +[[package]] +name = "darling" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 1.0.109", +] + +[[package]] +name = "darling_macro" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" +dependencies = [ + "darling_core", + "quote", + "syn 1.0.109", +] + [[package]] name = "dashmap" version = "5.5.3" @@ -508,6 +522,37 @@ dependencies = [ "powerfmt", ] +[[package]] +name = "derive_builder" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f59169f400d8087f238c5c0c7db6a28af18681717f3b623227d92f397e938c7" +dependencies = [ + "derive_builder_macro", +] + +[[package]] +name = "derive_builder_core" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4ec317cc3e7ef0928b0ca6e4a634a4d6c001672ae210438cf114a83e56b018d" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "derive_builder_macro" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "870368c3fb35b8031abb378861d4460f573b92238ec2152c927a21f77e3e0127" +dependencies = [ + "derive_builder_core", + "syn 1.0.109", +] + [[package]] name = "digest" version = "0.10.7" @@ -538,12 +583,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "dunce" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" - [[package]] name = "either" version = "1.12.0" @@ -602,12 +641,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd2e7510819d6fbf51a5545c8f922716ecfb14df168a3242f7d33e0239efe6a1" -[[package]] -name = "faster-hex" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2a2b11eda1d40935b26cf18f6833c526845ae8c41e58d09af6adeb6f0269183" - [[package]] name = "fastrand" version = "2.1.0" @@ -623,24 +656,6 @@ dependencies = [ "simd-adler32", ] -[[package]] -name = "filetime" -version = "0.2.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall 0.4.1", - "windows-sys 0.52.0", -] - -[[package]] -name = "finl_unicode" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" - [[package]] name = "flate2" version = "1.0.30" @@ -745,7 +760,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.66", ] [[package]] @@ -795,15 +810,16 @@ dependencies = [ [[package]] name = "generator" -version = "0.7.5" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc16584ff22b460a382b7feec54b23d2908d858152e5739a120b949293bd74e" +checksum = "186014d53bc231d0090ef8d6f03e0920c54d85a5ed22f4f2f74315ec56cf83fb" dependencies = [ "cc", + "cfg-if", "libc", "log", "rustversion", - "windows 0.48.0", + "windows 0.54.0", ] [[package]] @@ -827,6 +843,18 @@ dependencies = [ "wasi", ] +[[package]] +name = "getset" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e45727250e75cc04ff2846a66397da8ef2b3db8e40e0cef4df67950a07621eb9" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "gif" version = "0.13.1" @@ -844,505 +872,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "gix" -version = "0.57.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dd025382892c7b500a9ce1582cd803f9c2ebfe44aff52e9c7f86feee7ced75e" -dependencies = [ - "gix-actor", - "gix-commitgraph", - "gix-config", - "gix-date", - "gix-diff", - "gix-discover", - "gix-features", - "gix-fs", - "gix-glob", - "gix-hash", - "gix-hashtable", - "gix-index", - "gix-lock", - "gix-macros", - "gix-object", - "gix-odb", - "gix-pack", - "gix-path", - "gix-ref", - "gix-refspec", - "gix-revision", - "gix-revwalk", - "gix-sec", - "gix-tempfile", - "gix-trace", - "gix-traverse", - "gix-url", - "gix-utils", - "gix-validate", - "once_cell", - "parking_lot", - "signal-hook", - "smallvec", - "thiserror", - "unicode-normalization", -] - -[[package]] -name = "gix-actor" -version = "0.29.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da27b5ab4ab5c75ff891dccd48409f8cc53c28a79480f1efdd33184b2dc1d958" -dependencies = [ - "bstr", - "btoi", - "gix-date", - "itoa", - "thiserror", - "winnow 0.5.40", -] - -[[package]] -name = "gix-bitmap" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a371db66cbd4e13f0ed9dc4c0fea712d7276805fccc877f77e96374d317e87ae" -dependencies = [ - "thiserror", -] - -[[package]] -name = "gix-chunk" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45c8751169961ba7640b513c3b24af61aa962c967aaf04116734975cd5af0c52" -dependencies = [ - "thiserror", -] - -[[package]] -name = "gix-commitgraph" -version = "0.23.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8dcbf434951fa477063e05fea59722615af70dc2567377e58c2f7853b010fc" -dependencies = [ - "bstr", - "gix-chunk", - "gix-features", - "gix-hash", - "memmap2", - "thiserror", -] - -[[package]] -name = "gix-config" -version = "0.33.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "367304855b369cadcac4ee5fb5a3a20da9378dd7905106141070b79f85241079" -dependencies = [ - "bstr", - "gix-config-value", - "gix-features", - "gix-glob", - "gix-path", - "gix-ref", - "gix-sec", - "memchr", - "once_cell", - "smallvec", - "thiserror", - "unicode-bom", - "winnow 0.5.40", -] - -[[package]] -name = "gix-config-value" -version = "0.14.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbd06203b1a9b33a78c88252a625031b094d9e1b647260070c25b09910c0a804" -dependencies = [ - "bitflags 2.5.0", - "bstr", - "gix-path", - "libc", - "thiserror", -] - -[[package]] -name = "gix-date" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "367ee9093b0c2b04fd04c5c7c8b6a1082713534eab537597ae343663a518fa99" -dependencies = [ - "bstr", - "itoa", - "thiserror", - "time", -] - -[[package]] -name = "gix-diff" -version = "0.39.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6a0454f8c42d686f17e7f084057c717c082b7dbb8209729e4e8f26749eb93a" -dependencies = [ - "bstr", - "gix-hash", - "gix-object", - "thiserror", -] - -[[package]] -name = "gix-discover" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8d7b2896edc3d899d28a646ccc6df729827a6600e546570b2783466404a42d6" -dependencies = [ - "bstr", - "dunce", - "gix-hash", - "gix-path", - "gix-ref", - "gix-sec", - "thiserror", -] - -[[package]] -name = "gix-features" -version = "0.37.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d50270e8dcc665f30ba0735b17984b9535bdf1e646c76e638e007846164d57af" -dependencies = [ - "crc32fast", - "flate2", - "gix-hash", - "gix-trace", - "libc", - "once_cell", - "prodash", - "sha1_smol", - "thiserror", - "walkdir", -] - -[[package]] -name = "gix-fs" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7555c23a005537434bbfcb8939694e18cad42602961d0de617f8477cc2adecdd" -dependencies = [ - "gix-features", -] - -[[package]] -name = "gix-glob" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae6232f18b262770e343dcdd461c0011c9b9ae27f0c805e115012aa2b902c1b8" -dependencies = [ - "bitflags 2.5.0", - "bstr", - "gix-features", - "gix-path", -] - -[[package]] -name = "gix-hash" -version = "0.14.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93d7df7366121b5018f947a04d37f034717e113dcf9ccd85c34b58e57a74d5e" -dependencies = [ - "faster-hex", - "thiserror", -] - -[[package]] -name = "gix-hashtable" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ddf80e16f3c19ac06ce415a38b8591993d3f73aede049cb561becb5b3a8e242" -dependencies = [ - "gix-hash", - "hashbrown", - "parking_lot", -] - -[[package]] -name = "gix-index" -version = "0.28.2" +name = "git2" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e50e63df6c8d4137f7fb882f27643b3a9756c468a1a2cdbe1ce443010ca8778" +checksum = "232e6a7bfe35766bf715e55a88b39a700596c0ccfd88cd3680b4cdb40d66ef70" dependencies = [ "bitflags 2.5.0", - "bstr", - "btoi", - "filetime", - "gix-bitmap", - "gix-features", - "gix-fs", - "gix-hash", - "gix-lock", - "gix-object", - "gix-traverse", - "itoa", "libc", - "memmap2", - "rustix", - "smallvec", - "thiserror", -] - -[[package]] -name = "gix-lock" -version = "12.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40a439397f1e230b54cf85d52af87e5ea44cc1e7748379785d3f6d03d802b00" -dependencies = [ - "gix-tempfile", - "gix-utils", - "thiserror", -] - -[[package]] -name = "gix-macros" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dff438f14e67e7713ab9332f5fd18c8f20eb7eb249494f6c2bf170522224032" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.65", -] - -[[package]] -name = "gix-object" -version = "0.40.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c89402e8faa41b49fde348665a8f38589e461036475af43b6b70615a6a313a2" -dependencies = [ - "bstr", - "btoi", - "gix-actor", - "gix-date", - "gix-features", - "gix-hash", - "gix-validate", - "itoa", - "smallvec", - "thiserror", - "winnow 0.5.40", -] - -[[package]] -name = "gix-odb" -version = "0.56.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46ae6da873de41c6c2b73570e82c571b69df5154dcd8f46dfafc6687767c33b1" -dependencies = [ - "arc-swap", - "gix-date", - "gix-features", - "gix-hash", - "gix-object", - "gix-pack", - "gix-path", - "gix-quote", - "parking_lot", - "tempfile", - "thiserror", -] - -[[package]] -name = "gix-pack" -version = "0.46.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "782b4d42790a14072d5c400deda9851f5765f50fe72bca6dece0da1cd6f05a9a" -dependencies = [ - "clru", - "gix-chunk", - "gix-features", - "gix-hash", - "gix-hashtable", - "gix-object", - "gix-path", - "gix-tempfile", - "memmap2", - "parking_lot", - "smallvec", - "thiserror", -] - -[[package]] -name = "gix-path" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23623cf0f475691a6d943f898c4d0b89f5c1a2a64d0f92bce0e0322ee6528783" -dependencies = [ - "bstr", - "gix-trace", - "home", - "once_cell", - "thiserror", -] - -[[package]] -name = "gix-quote" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbff4f9b9ea3fa7a25a70ee62f545143abef624ac6aa5884344e70c8b0a1d9ff" -dependencies = [ - "bstr", - "gix-utils", - "thiserror", -] - -[[package]] -name = "gix-ref" -version = "0.40.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64d9bd1984638d8f3511a2fcbe84fcedb8a5b5d64df677353620572383f42649" -dependencies = [ - "gix-actor", - "gix-date", - "gix-features", - "gix-fs", - "gix-hash", - "gix-lock", - "gix-object", - "gix-path", - "gix-tempfile", - "gix-validate", - "memmap2", - "thiserror", - "winnow 0.5.40", -] - -[[package]] -name = "gix-refspec" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be219df5092c1735abb2a53eccdf775e945eea6986ee1b6e7a5896dccc0be704" -dependencies = [ - "bstr", - "gix-hash", - "gix-revision", - "gix-validate", - "smallvec", - "thiserror", -] - -[[package]] -name = "gix-revision" -version = "0.25.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa78e1df3633bc937d4db15f8dca2abdb1300ca971c0fabcf9fa97e38cf4cd9f" -dependencies = [ - "bstr", - "gix-date", - "gix-hash", - "gix-hashtable", - "gix-object", - "gix-revwalk", - "gix-trace", - "thiserror", -] - -[[package]] -name = "gix-revwalk" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "702de5fe5c2bbdde80219f3a8b9723eb927466e7ecd187cfd1b45d986408e45f" -dependencies = [ - "gix-commitgraph", - "gix-date", - "gix-hash", - "gix-hashtable", - "gix-object", - "smallvec", - "thiserror", -] - -[[package]] -name = "gix-sec" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fddc27984a643b20dd03e97790555804f98cf07404e0e552c0ad8133266a79a1" -dependencies = [ - "bitflags 2.5.0", - "gix-path", - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "gix-tempfile" -version = "12.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8ef376d718b1f5f119b458e21b00fbf576bc9d4e26f8f383d29f5ffe3ba3eaa" -dependencies = [ - "gix-fs", - "libc", - "once_cell", - "parking_lot", - "signal-hook", - "signal-hook-registry", - "tempfile", -] - -[[package]] -name = "gix-trace" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f924267408915fddcd558e3f37295cc7d6a3e50f8bd8b606cee0808c3915157e" - -[[package]] -name = "gix-traverse" -version = "0.36.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65109e445ba7a409b48f34f570a4d7db72eade1dc1bcff81990a490e86c07161" -dependencies = [ - "gix-commitgraph", - "gix-date", - "gix-hash", - "gix-hashtable", - "gix-object", - "gix-revwalk", - "smallvec", - "thiserror", -] - -[[package]] -name = "gix-url" -version = "0.26.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f0f17cceb7552a231d1fec690bc2740c346554e3be6f5d2c41dfa809594dc44" -dependencies = [ - "bstr", - "gix-features", - "gix-path", - "home", - "thiserror", + "libgit2-sys", + "log", "url", ] -[[package]] -name = "gix-utils" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35192df7fd0fa112263bad8021e2df7167df4cc2a6e6d15892e1e55621d3d4dc" -dependencies = [ - "fastrand", - "unicode-normalization", -] - -[[package]] -name = "gix-validate" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e39fc6e06044985eac19dd34d474909e517307582e462b2eb4c8fa51b6241545" -dependencies = [ - "bstr", - "thiserror", -] - [[package]] name = "glob" version = "0.3.1" @@ -1521,15 +1062,15 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.27.1" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "908bb38696d7a037a01ebcc68a00634112ac2bbf8ca74e30a2c3d2f4f021302b" +checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" dependencies = [ "futures-util", "http", "hyper", "hyper-util", - "rustls 0.23.7", + "rustls 0.23.9", "rustls-native-certs", "rustls-pki-types", "tokio", @@ -1539,9 +1080,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.3" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" +checksum = "7b875924a60b96e5d7b9ae7b066540b1dd1cbd90d1828f54c92e02a283351c56" dependencies = [ "bytes", "futures-channel", @@ -1568,7 +1109,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -1580,6 +1121,12 @@ dependencies = [ "cc", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "0.5.0" @@ -1647,6 +1194,15 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "jobserver" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e" +dependencies = [ + "libc", +] + [[package]] name = "jpeg-decoder" version = "0.3.1" @@ -1686,7 +1242,7 @@ dependencies = [ "http", "http-body-util", "hyper", - "hyper-rustls 0.27.1", + "hyper-rustls 0.27.2", "hyper-util", "lavalink_rs_macros", "oneshot", @@ -1709,7 +1265,7 @@ checksum = "426ef2204d4fa6806fa6a00fdd747f7312645fcd30cf9208a5bdfeec6f3b9a41" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.66", ] [[package]] @@ -1727,6 +1283,18 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +[[package]] +name = "libgit2-sys" +version = "0.16.2+1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee4126d8b4ee5c9d9ea891dd875cfdc1e9d0950437179104b183d7d8a74d24e8" +dependencies = [ + "cc", + "libc", + "libz-sys", + "pkg-config", +] + [[package]] name = "libm" version = "0.2.8" @@ -1746,11 +1314,12 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.16" +version = "1.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e143b5e666b2695d28f6bca6497720813f699c9602dd7f5cac91008b8ada7f9" +checksum = "c15da26e5af7e25c90b37a2d75cdbf940cf4a55316de9d84c679c9b8bfabf82e" dependencies = [ "cc", + "libc", "pkg-config", "vcpkg", ] @@ -1788,9 +1357,9 @@ checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "loom" -version = "0.5.6" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff50ecb28bb86013e935fb6683ab1f6d3a20016f123c76fd4c27470076ac30f5" +checksum = "419e0dc8046cb947daa77eb95ae174acfbddb7673b4151f56d1eed8e93fbfaca" dependencies = [ "cfg-if", "generator", @@ -1802,9 +1371,10 @@ dependencies = [ [[package]] name = "lyra" -version = "0.6.0" +version = "0.7.0" dependencies = [ "aho-corasick", + "anyhow", "bitflags 2.5.0", "chrono", "color-eyre", @@ -1820,12 +1390,12 @@ dependencies = [ "itertools 0.13.0", "kmeans_colors", "lavalink-rs", - "lazy_static", "linkify", "log", "lyra_proc", "mixbox", "palette", + "paste", "rand", "rayon", "regex", @@ -1848,18 +1418,18 @@ dependencies = [ "twilight-util", "twilight-validate", "unicode-segmentation", - "vergen", + "vergen-git2", ] [[package]] name = "lyra_proc" -version = "0.6.0" +version = "0.7.0" dependencies = [ "heck 0.5.0", "itertools 0.13.0", "quote", "serde", - "syn 2.0.65", + "syn 2.0.66", "toml", ] @@ -1888,15 +1458,6 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" -[[package]] -name = "memmap2" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe751422e4a8caa417e13c3ea66452215d7d63e19e604f4980461212f3ae1322" -dependencies = [ - "libc", -] - [[package]] name = "minimal-lexical" version = "0.2.1" @@ -2051,9 +1612,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "oneshot" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f6640c6bda7731b1fdbab747981a0f896dd1fedaf9f4a53fa237a04a84431f4" +checksum = "071d1cf3298ad8e543dca18217d198cb6a3884443d204757b9624b935ef09fa0" dependencies = [ "loom", ] @@ -2105,14 +1666,14 @@ dependencies = [ "by_address", "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.66", ] [[package]] name = "parking_lot" -version = "0.12.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", "parking_lot_core", @@ -2169,7 +1730,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.66", ] [[package]] @@ -2237,19 +1798,46 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] -name = "proc-macro2" -version = "1.0.83" +name = "proc-macro-crate" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b33eb56c327dec362a9e55b3ad14f9d2f0904fb5a5b03b513ab5465399e9f43" +checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" dependencies = [ - "unicode-ident", + "toml_edit 0.21.1", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", ] [[package]] -name = "prodash" -version = "28.0.0" +name = "proc-macro-error-attr" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "744a264d26b88a6a7e37cbad97953fa233b94d585236310bcbc88474b4092d79" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] [[package]] name = "quote" @@ -2415,9 +2003,9 @@ dependencies = [ [[package]] name = "rstest" -version = "0.19.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5316d2a1479eeef1ea21e7f9ddc67c191d497abc8fc3ba2467857abbb68330" +checksum = "9afd55a67069d6e434a95161415f5beeada95a01c7b815508a82dcb0e1593682" dependencies = [ "futures", "futures-timer", @@ -2427,18 +2015,19 @@ dependencies = [ [[package]] name = "rstest_macros" -version = "0.19.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04a9df72cc1f67020b0d63ad9bfe4a323e459ea7eb68e03bd9824db49f9a4c25" +checksum = "4165dfae59a39dd41d8dec720d3cbfbc71f69744efb480a3920f5d4e0cc6798d" dependencies = [ "cfg-if", "glob", + "proc-macro-crate", "proc-macro2", "quote", "regex", "relative-path", "rustc_version", - "syn 2.0.65", + "syn 2.0.66", "unicode-ident", ] @@ -2497,9 +2086,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.7" +version = "0.23.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebbbdb961df0ad3f2652da8f3fdc4b36122f568f968f45ad3316f26c025c677b" +checksum = "a218f0f6d05669de4eabfb24f31ce802035c952429d037507b4a4a39f0e60c5b" dependencies = [ "once_cell", "ring", @@ -2580,15 +2169,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - [[package]] name = "schannel" version = "0.1.23" @@ -2654,9 +2234,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.202" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] @@ -2673,13 +2253,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.202" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.66", ] [[package]] @@ -2712,7 +2292,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.66", ] [[package]] @@ -2761,16 +2341,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "signal-hook" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" -dependencies = [ - "libc", - "signal-hook-registry", -] - [[package]] name = "signal-hook-registry" version = "1.4.2" @@ -3062,15 +2632,21 @@ dependencies = [ [[package]] name = "stringprep" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb41d74e231a107a1b4ee36bd1214b11285b77768d2e3824aedafa988fd36ee6" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" dependencies = [ - "finl_unicode", "unicode-bidi", "unicode-normalization", + "unicode-properties", ] +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "subtle" version = "2.5.0" @@ -3090,9 +2666,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.65" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2863d96a84c6439701d7a38f9de935ec562c8832cc55d1dde0f513b52fad106" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", @@ -3142,7 +2718,7 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.66", ] [[package]] @@ -3216,9 +2792,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.37.0" +version = "1.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" dependencies = [ "backtrace", "bytes", @@ -3234,13 +2810,13 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.66", ] [[package]] @@ -3260,7 +2836,7 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" dependencies = [ - "rustls 0.23.7", + "rustls 0.23.9", "rustls-pki-types", "tokio", ] @@ -3331,14 +2907,14 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4e43f8cc456c9704c851ae29c67e17ef65d2c30017c17a9765b89c382dc8bba" +checksum = "6f49eb2ab21d2f26bd6db7bf383edc527a7ebaee412d17af4d40fdccd442f335" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit", + "toml_edit 0.22.14", ] [[package]] @@ -3352,15 +2928,26 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.13" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c127785850e8c20836d49732ae6abfa47616e60bf9d9f57c43c250361a9db96c" +checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow 0.5.40", +] + +[[package]] +name = "toml_edit" +version = "0.22.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f21c7aaf97f1bd9ca9d4f9e73b0a6c74bd5afef56f2bc931943a6e1c37e04e38" dependencies = [ "indexmap", "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.8", + "winnow 0.6.12", ] [[package]] @@ -3376,7 +2963,6 @@ dependencies = [ "tokio", "tower-layer", "tower-service", - "tracing", ] [[package]] @@ -3411,7 +2997,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.66", ] [[package]] @@ -3591,7 +3177,7 @@ checksum = "e6c07ac7c9d2d086291765ceecafcd52ce6dc33ab0ade02e06509eb416d88470" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.66", ] [[package]] @@ -3675,12 +3261,6 @@ version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" -[[package]] -name = "unicode-bom" -version = "2.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eec5d1121208364f6793f7d2e222bf75a915c19557537745b195b253dd64217" - [[package]] name = "unicode-ident" version = "1.0.12" @@ -3696,6 +3276,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-properties" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4259d9d4425d9f0661581b804cb85fe66a4c631cadd8f490d1c13a35d5d9291" + [[package]] name = "unicode-segmentation" version = "1.11.0" @@ -3757,37 +3343,55 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "vergen" -version = "8.3.1" +version = "9.0.0-beta.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e27d6bdd219887a9eadd19e1c34f32e47fa332301184935c6d9bca26f3cca525" +checksum = "107dc53b443fe8cc380798abb75ad6b7038281165109afea1f1b28bb47047ed5" dependencies = [ "anyhow", "cargo_metadata", - "cfg-if", - "gix", + "derive_builder", + "getset", "regex", "rustc_version", "rustversion", "sysinfo", "time", + "vergen-lib", ] [[package]] -name = "version_check" -version = "0.9.4" +name = "vergen-git2" +version = "1.0.0-beta.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "8875c5d71074bb67118774e3d795ab6fe77c3ae3161cb54e19104cabc49487f1" +dependencies = [ + "anyhow", + "derive_builder", + "git2", + "rustversion", + "time", + "vergen", + "vergen-lib", +] [[package]] -name = "walkdir" -version = "2.5.0" +name = "vergen-lib" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +checksum = "26ebfba72ba904559f25f41ea1512335b5a46459084258cea0857549d9645187" dependencies = [ - "same-file", - "winapi-util", + "anyhow", + "derive_builder", + "getset", + "rustversion", ] +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "want" version = "0.3.1" @@ -3830,7 +3434,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.66", "wasm-bindgen-shared", ] @@ -3852,7 +3456,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.66", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3901,15 +3505,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" -dependencies = [ - "windows-sys 0.52.0", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -3918,20 +3513,21 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.48.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" dependencies = [ - "windows-targets 0.48.5", + "windows-core 0.52.0", + "windows-targets 0.52.5", ] [[package]] name = "windows" -version = "0.52.0" +version = "0.54.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" +checksum = "9252e5725dbed82865af151df558e754e4a3c2c30818359eb17465f1346a1b49" dependencies = [ - "windows-core", + "windows-core 0.54.0", "windows-targets 0.52.5", ] @@ -3944,6 +3540,25 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "windows-core" +version = "0.54.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12661b9c89351d684a50a8a643ce5f608e20243b9fb84687800163429f161d65" +dependencies = [ + "windows-result", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-result" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "749f0da9cc72d82e600d8d2e44cadd0b9eedb9038f71a1c58556ac1c5791813b" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -4094,9 +3709,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.8" +version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c52e9c97a68071b23e836c9380edae937f17b9c4667bd021973efc689f618d" +checksum = "41ff33f391015ecab21cd092389215eb265ef9496a9a07b6bee7d3529831deda" dependencies = [ "memchr", ] @@ -4118,14 +3733,14 @@ checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.66", ] [[package]] name = "zeroize" -version = "1.7.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" [[package]] name = "zune-core" diff --git a/Cargo.toml b/Cargo.toml index 8a5d1b0..b41b28b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,6 @@ resolver = "2" [profile.dev.package.sqlx-macros] opt-level = 3 + +[profile.release] +lto = true diff --git a/devenv.lock b/devenv.lock deleted file mode 100644 index dfe2f8d..0000000 --- a/devenv.lock +++ /dev/null @@ -1,161 +0,0 @@ -{ - "nodes": { - "devenv": { - "locked": { - "dir": "src/modules", - "lastModified": 1716992392, - "owner": "cachix", - "repo": "devenv", - "rev": "2a8b6262ae00fc2f8b1b3a6ac35fdc0779085ee1", - "treeHash": "24309487ae9d41d1a7d788ac4c75ecb495eacab1", - "type": "github" - }, - "original": { - "dir": "src/modules", - "owner": "cachix", - "repo": "devenv", - "type": "github" - } - }, - "fenix": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ], - "rust-analyzer-src": "rust-analyzer-src" - }, - "locked": { - "lastModified": 1716877613, - "owner": "nix-community", - "repo": "fenix", - "rev": "08ea8011dd25421c104a5f44d16a713a27d93fde", - "treeHash": "7761561b72987080be37f0ce1a8e4f4e1fda0da2", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "fenix", - "type": "github" - } - }, - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1696426674, - "owner": "edolstra", - "repo": "flake-compat", - "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", - "treeHash": "2addb7b71a20a25ea74feeaf5c2f6a6b30898ecb", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "gitignore": { - "inputs": { - "nixpkgs": [ - "pre-commit-hooks", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1709087332, - "owner": "hercules-ci", - "repo": "gitignore.nix", - "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", - "treeHash": "ca14199cabdfe1a06a7b1654c76ed49100a689f9", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "gitignore.nix", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1716977621, - "owner": "cachix", - "repo": "devenv-nixpkgs", - "rev": "4267e705586473d3e5c8d50299e71503f16a6fb6", - "treeHash": "6d9f1f7ca0faf1bc2eeb397c78a49623260d3412", - "type": "github" - }, - "original": { - "owner": "cachix", - "ref": "rolling", - "repo": "devenv-nixpkgs", - "type": "github" - } - }, - "nixpkgs-stable": { - "locked": { - "lastModified": 1716633019, - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "9d29cd266cebf80234c98dd0b87256b6be0af44e", - "treeHash": "9c88f2c9f0cdeaddeb5d49c2faaf65b936fc11d3", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-23.11", - "repo": "nixpkgs", - "type": "github" - } - }, - "pre-commit-hooks": { - "inputs": { - "flake-compat": "flake-compat", - "gitignore": "gitignore", - "nixpkgs": [ - "nixpkgs" - ], - "nixpkgs-stable": "nixpkgs-stable" - }, - "locked": { - "lastModified": 1716213921, - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "rev": "0e8fcc54b842ad8428c9e705cb5994eaf05c26a0", - "treeHash": "17b9f9f9983467bcff247b09761dca9831d3d3be", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "type": "github" - } - }, - "root": { - "inputs": { - "devenv": "devenv", - "fenix": "fenix", - "nixpkgs": "nixpkgs", - "pre-commit-hooks": "pre-commit-hooks" - } - }, - "rust-analyzer-src": { - "flake": false, - "locked": { - "lastModified": 1716828004, - "owner": "rust-lang", - "repo": "rust-analyzer", - "rev": "b32f181f477576bb203879f7539608f3327b6178", - "treeHash": "4b8a01567abe7a8fc5561563aa52ac6c029fb31d", - "type": "github" - }, - "original": { - "owner": "rust-lang", - "ref": "nightly", - "repo": "rust-analyzer", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/devenv.nix b/devenv.nix deleted file mode 100644 index 8b13f44..0000000 --- a/devenv.nix +++ /dev/null @@ -1,73 +0,0 @@ -{ - pkgs, - lib, - config, - inputs, - ... -}: { - # https://devenv.sh/basics/ - # env.GREET = "devenv"; - - # https://devenv.sh/packages/ - packages = with pkgs; [ - git - clang - mold - codespell - act - sqlx-cli - pgcli - ]; - - # https://devenv.sh/scripts/ - # scripts.hello.exec = ""; - - enterShell = '' - git --version - ''; - - # https://devenv.sh/tests/ - enterTest = '' - echo "Running tests" - git --version | grep "2.42.0" - ''; - - # https://devenv.sh/services/ - services.postgres = { - enable = true; - package = pkgs.postgresql_15; - initialDatabases = [{name = "mydb";}]; - extensions = extensions: [ - extensions.postgis - extensions.timescaledb - ]; - settings.shared_preload_libraries = "timescaledb"; - initialScript = "CREATE EXTENSION IF NOT EXISTS timescaledb;"; - listen_addresses = "localhost"; - }; - - # https://devenv.sh/languages/ - languages.nix.enable = true; - languages.java = { - enable = true; - jdk.package = pkgs.jdk17; - }; - languages.rust = { - enable = true; - channel = "stable"; - mold.enable = true; - }; - - # Enable Codespaces Integration - # https://devenv.sh/integrations/codespaces-devcontainer/ - devcontainer.enable = true; - - # https://devenv.sh/pre-commit-hooks/ - # pre-commit.hooks.shellcheck.enable = true; - - # https://devenv.sh/processes/ - processes.lavalink.exec = "scripts/lavalink"; - - # See full reference at https://devenv.sh/reference/options/ - dotenv.enable = true; -} diff --git a/devenv.yaml b/devenv.yaml deleted file mode 100644 index 2bbabf4..0000000 --- a/devenv.yaml +++ /dev/null @@ -1,8 +0,0 @@ -inputs: - nixpkgs: - url: github:cachix/devenv-nixpkgs/rolling - fenix: - url: github:nix-community/fenix - inputs: - nixpkgs: - follows: nixpkgs diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..5b5ddce --- /dev/null +++ b/flake.lock @@ -0,0 +1,482 @@ +{ + "nodes": { + "cachix": { + "inputs": { + "devenv": "devenv_2", + "flake-compat": [ + "devenv", + "flake-compat" + ], + "nixpkgs": [ + "devenv", + "nixpkgs" + ], + "pre-commit-hooks": [ + "devenv", + "pre-commit-hooks" + ] + }, + "locked": { + "lastModified": 1712055811, + "narHash": "sha256-7FcfMm5A/f02yyzuavJe06zLa9hcMHsagE28ADcmQvk=", + "owner": "cachix", + "repo": "cachix", + "rev": "02e38da89851ec7fec3356a5c04bc8349cae0e30", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "cachix", + "type": "github" + } + }, + "devenv": { + "inputs": { + "cachix": "cachix", + "flake-compat": "flake-compat_2", + "nix": "nix_2", + "nixpkgs": [ + "nixpkgs" + ], + "pre-commit-hooks": "pre-commit-hooks" + }, + "locked": { + "lastModified": 1717698746, + "narHash": "sha256-Bt/q+zyBpI3Uwd6HGTvZSPvRR2DoaHXtvfFULeXP/aI=", + "owner": "cachix", + "repo": "devenv", + "rev": "866ecadab5d92cdbb296723f67fa464d01401d9a", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "devenv_2": { + "inputs": { + "flake-compat": [ + "devenv", + "cachix", + "flake-compat" + ], + "nix": "nix", + "nixpkgs": "nixpkgs", + "poetry2nix": "poetry2nix", + "pre-commit-hooks": [ + "devenv", + "cachix", + "pre-commit-hooks" + ] + }, + "locked": { + "lastModified": 1708704632, + "narHash": "sha256-w+dOIW60FKMaHI1q5714CSibk99JfYxm0CzTinYWr+Q=", + "owner": "cachix", + "repo": "devenv", + "rev": "2ee4450b0f4b95a1b90f2eb5ffea98b90e48c196", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "python-rewrite", + "repo": "devenv", + "type": "github" + } + }, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1717741716, + "narHash": "sha256-v71DDu2gb02iBIAhUwu5mQZNtYD45QcbEqahqsOCCyU=", + "owner": "nix-community", + "repo": "fenix", + "rev": "05f2a8ae62c45637b20d162fa2dd450b79e71c27", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "devenv", + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nix": { + "inputs": { + "flake-compat": "flake-compat", + "nixpkgs": [ + "devenv", + "cachix", + "devenv", + "nixpkgs" + ], + "nixpkgs-regression": "nixpkgs-regression" + }, + "locked": { + "lastModified": 1712911606, + "narHash": "sha256-BGvBhepCufsjcUkXnEEXhEVjwdJAwPglCC2+bInc794=", + "owner": "domenkozar", + "repo": "nix", + "rev": "b24a9318ea3f3600c1e24b4a00691ee912d4de12", + "type": "github" + }, + "original": { + "owner": "domenkozar", + "ref": "devenv-2.21", + "repo": "nix", + "type": "github" + } + }, + "nix-github-actions": { + "inputs": { + "nixpkgs": [ + "devenv", + "cachix", + "devenv", + "poetry2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1688870561, + "narHash": "sha256-4UYkifnPEw1nAzqqPOTL2MvWtm3sNGw1UTYTalkTcGY=", + "owner": "nix-community", + "repo": "nix-github-actions", + "rev": "165b1650b753316aa7f1787f3005a8d2da0f5301", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-github-actions", + "type": "github" + } + }, + "nix_2": { + "inputs": { + "flake-compat": [ + "devenv", + "flake-compat" + ], + "nixpkgs": [ + "devenv", + "nixpkgs" + ], + "nixpkgs-regression": "nixpkgs-regression_2" + }, + "locked": { + "lastModified": 1712911606, + "narHash": "sha256-BGvBhepCufsjcUkXnEEXhEVjwdJAwPglCC2+bInc794=", + "owner": "domenkozar", + "repo": "nix", + "rev": "b24a9318ea3f3600c1e24b4a00691ee912d4de12", + "type": "github" + }, + "original": { + "owner": "domenkozar", + "ref": "devenv-2.21", + "repo": "nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1692808169, + "narHash": "sha256-x9Opq06rIiwdwGeK2Ykj69dNc2IvUH1fY55Wm7atwrE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9201b5ff357e781bf014d0330d18555695df7ba8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-regression": { + "locked": { + "lastModified": 1643052045, + "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + } + }, + "nixpkgs-regression_2": { + "locked": { + "lastModified": 1643052045, + "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1710695816, + "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "614b4613980a522ba49f0d194531beddbb7220d3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1716977621, + "narHash": "sha256-Q1UQzYcMJH4RscmpTkjlgqQDX5yi1tZL0O345Ri6vXQ=", + "owner": "cachix", + "repo": "devenv-nixpkgs", + "rev": "4267e705586473d3e5c8d50299e71503f16a6fb6", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "rolling", + "repo": "devenv-nixpkgs", + "type": "github" + } + }, + "poetry2nix": { + "inputs": { + "flake-utils": "flake-utils", + "nix-github-actions": "nix-github-actions", + "nixpkgs": [ + "devenv", + "cachix", + "devenv", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1692876271, + "narHash": "sha256-IXfZEkI0Mal5y1jr6IRWMqK8GW2/f28xJenZIPQqkY0=", + "owner": "nix-community", + "repo": "poetry2nix", + "rev": "d5006be9c2c2417dafb2e2e5034d83fabd207ee3", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "poetry2nix", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": [ + "devenv", + "flake-compat" + ], + "flake-utils": "flake-utils_2", + "gitignore": "gitignore", + "nixpkgs": [ + "devenv", + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1713775815, + "narHash": "sha256-Wu9cdYTnGQQwtT20QQMg7jzkANKQjwBD9iccfGKkfls=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "2ac4dcbf55ed43f3be0bae15e181f08a57af24a4", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "devenv": "devenv", + "fenix": "fenix", + "nixpkgs": "nixpkgs_2", + "systems": "systems_3" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1717583671, + "narHash": "sha256-+lRAmz92CNUxorqWusgJbL9VE1eKCnQQojglRemzwkw=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "48bbdd6a74f3176987d5c809894ac33957000d19", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..cc2047d --- /dev/null +++ b/flake.nix @@ -0,0 +1,116 @@ +{ + inputs = { + nixpkgs.url = "github:cachix/devenv-nixpkgs/rolling"; + systems.url = "github:nix-systems/default"; + devenv = { + url = "github:cachix/devenv"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + nixConfig = { + extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="; + extra-substituters = "https://devenv.cachix.org"; + }; + + outputs = { + self, + nixpkgs, + devenv, + systems, + ... + } @ inputs: let + forEachSystem = nixpkgs.lib.genAttrs (import systems); + in { + packages = forEachSystem (system: { + devenv-up = self.devShells.${system}.default.config.procfileScript; + }); + + devShells = + forEachSystem + (system: let + pkgs = nixpkgs.legacyPackages.${system}; + in { + default = devenv.lib.mkShell { + inherit inputs pkgs; + modules = [ + { + # https://devenv.sh/basics/ + # env.GREET = "devenv"; + + # https://devenv.sh/packages/ + packages = with pkgs; [ + git + clang + mold + codespell + act + sqlx-cli + pgcli + ]; + + # https://devenv.sh/scripts/ + # scripts.hello.exec = ""; + + enterShell = '' + ''; + + # https://devenv.sh/tests/ + enterTest = '' + ''; + + # https://devenv.sh/services/ + services.postgres = { + enable = true; + package = pkgs.postgresql_15; + initialDatabases = [{name = "mydb";}]; + extensions = extensions: [ + extensions.postgis + extensions.timescaledb + ]; + settings.shared_preload_libraries = "timescaledb"; + initialScript = "CREATE EXTENSION IF NOT EXISTS timescaledb;"; + listen_addresses = "localhost"; + }; + + # https://devenv.sh/languages/ + languages.nix.enable = true; + languages.java = { + enable = true; + jdk.package = pkgs.jdk17; + }; + languages.rust = { + enable = true; + channel = "stable"; + mold.enable = true; + }; + + # Enable Codespaces Integration + # https://devenv.sh/integrations/codespaces-devcontainer/ + devcontainer.enable = true; + + # https://devenv.sh/pre-commit-hooks/ + # pre-commit.hooks.shellcheck.enable = true; + + # https://devenv.sh/processes/ + processes.lavalink.exec = "scripts/lavalink"; + + processes.database-setup.exec = '' + while ! "./scripts/database" + do + : + done + ''; + + # See full reference at https://devenv.sh/reference/options/ + # dotenv.enable = true; + } + ]; + }; + }); + }; +} diff --git a/lavalink/application.yml b/lavalink/application.yml index aefabbb..45faf2d 100644 --- a/lavalink/application.yml +++ b/lavalink/application.yml @@ -43,7 +43,7 @@ lavalink: twitch: true vimeo: true http: true - local: true + local: false bufferDurationMs: 400 # The duration of the NAS buffer. Higher values fare better against longer GC pauses frameBufferDurationMs: 5000 # How many milliseconds of audio to keep buffered opusEncodingQuality: 10 # Opus encoder quality. Valid values range from 0 to 10, where 10 is best quality but is the most expensive on the CPU. diff --git a/lyra/Cargo.lock b/lyra/Cargo.lock deleted file mode 100644 index bd4ddf6..0000000 --- a/lyra/Cargo.lock +++ /dev/null @@ -1,4115 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "ahash" -version = "0.8.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d713b3834d76b85304d4d525563c1276e2e30dc97cc67bfb4585a4a29fc2c89f" -dependencies = [ - "cfg-if", - "getrandom", - "once_cell", - "version_check", - "zerocopy", -] - -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - -[[package]] -name = "alloc-no-stdlib" -version = "2.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" - -[[package]] -name = "alloc-stdlib" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" -dependencies = [ - "alloc-no-stdlib", -] - -[[package]] -name = "allocator-api2" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" - -[[package]] -name = "android-tzdata" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" - -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - -[[package]] -name = "anyhow" -version = "1.0.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1" - -[[package]] -name = "approx" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" -dependencies = [ - "num-traits", -] - -[[package]] -name = "arc-swap" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bddcadddf5e9015d310179a59bb28c4d4b9920ad0f11e8e14dbadf654890c9a6" - -[[package]] -name = "atoi" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" -dependencies = [ - "num-traits", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "backtrace" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "base64" -version = "0.21.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" - -[[package]] -name = "base64" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" -dependencies = [ - "serde", -] - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "brotli" -version = "3.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d640d25bc63c50fb1f0b545ffd80207d2e10a4c965530809b40ba3386825c391" -dependencies = [ - "alloc-no-stdlib", - "alloc-stdlib", - "brotli-decompressor", -] - -[[package]] -name = "brotli-decompressor" -version = "2.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e2e4afe60d7dd600fdd3de8d0f08c2b7ec039712e3b6137ff98b7004e82de4f" -dependencies = [ - "alloc-no-stdlib", - "alloc-stdlib", -] - -[[package]] -name = "bstr" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c48f0051a4b4c5e0b6d365cd04af53aeaa209e3cc15ec2cdb69e73cc87fbd0dc" -dependencies = [ - "memchr", - "regex-automata 0.4.5", - "serde", -] - -[[package]] -name = "btoi" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dd6407f73a9b8b6162d8a2ef999fe6afd7cc15902ebf42c5cd296addf17e0ad" -dependencies = [ - "num-traits", -] - -[[package]] -name = "bumpalo" -version = "3.15.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea184aa71bb362a1157c896979544cc23974e08fd265f29ea96b59f0b4a555b" - -[[package]] -name = "by_address" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64fa3c856b712db6612c019f14756e64e4bcea13337a6b33b696333a9eaa2d06" - -[[package]] -name = "bytemuck" -version = "1.14.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2ef034f05691a48569bd920a96c81b9d91bbad1ab5ac7c4616c1f6ef36cb79f" - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "camino" -version = "1.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c59e92b5a388f549b863a7bea62612c09f24c8393560709a54558a9abdfb3b9c" -dependencies = [ - "serde", -] - -[[package]] -name = "cargo-platform" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "694c8807f2ae16faecc43dc17d74b3eb042482789fd0eb64b39a2e04e087053f" -dependencies = [ - "serde", -] - -[[package]] -name = "cargo_metadata" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d886547e41f740c616ae73108f6eb70afe6d940c7bc697cb30f13daec073037" -dependencies = [ - "camino", - "cargo-platform", - "semver", - "serde", - "serde_json", - "thiserror", -] - -[[package]] -name = "cc" -version = "1.0.87" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3286b845d0fccbdd15af433f61c5970e711987036cb468f437ff6badd70f4e24" - -[[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.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" -dependencies = [ - "android-tzdata", - "iana-time-zone", - "js-sys", - "num-traits", - "wasm-bindgen", - "windows-targets 0.52.3", -] - -[[package]] -name = "clru" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8191fa7302e03607ff0e237d4246cc043ff5b3cb9409d995172ba3bea16b807" - -[[package]] -name = "color-eyre" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55146f5e46f237f7423d74111267d4597b59b0dad0ffaf7303bce9945d843ad5" -dependencies = [ - "backtrace", - "color-spantrace", - "eyre", - "indenter", - "once_cell", - "owo-colors", - "tracing-error", -] - -[[package]] -name = "color-spantrace" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd6be1b2a7e382e2b98b43b2adcca6bb0e465af0bdd38123873ae61eb17a72c2" -dependencies = [ - "once_cell", - "owo-colors", - "tracing-core", - "tracing-error", -] - -[[package]] -name = "color_quant" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" - -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - -[[package]] -name = "const-str" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3618cccc083bb987a415d85c02ca6c9994ea5b44731ec28b9ecf09658655fba9" - -[[package]] -name = "const_panic" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6051f239ecec86fde3410901ab7860d458d160371533842974fc61f96d15879b" -dependencies = [ - "const_panic_proc_macros", - "typewit", -] - -[[package]] -name = "const_panic_proc_macros" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "395398edf7e8b0a812e905c150c438520ab077c4f9f931556302c48dd4e8ada9" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", - "unicode-xid", -] - -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" - -[[package]] -name = "cpufeatures" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" -dependencies = [ - "libc", -] - -[[package]] -name = "crc" -version = "3.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" -dependencies = [ - "crc-catalog", -] - -[[package]] -name = "crc-catalog" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" - -[[package]] -name = "crc32fast" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-queue" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown", - "lock_api", - "once_cell", - "parking_lot_core", -] - -[[package]] -name = "data-encoding" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" - -[[package]] -name = "der" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" -dependencies = [ - "const-oid", - "pem-rfc7468", - "zeroize", -] - -[[package]] -name = "deranged" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" -dependencies = [ - "powerfmt", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "const-oid", - "crypto-common", - "subtle", -] - -[[package]] -name = "dotenvy" -version = "0.15.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" - -[[package]] -name = "dotenvy_macro" -version = "0.15.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0235d912a8c749f4e0c9f18ca253b4c28cfefc1d2518096016d6e3230b6424" -dependencies = [ - "dotenvy", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "dunce" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" - -[[package]] -name = "either" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" -dependencies = [ - "serde", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "etcetera" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" -dependencies = [ - "cfg-if", - "home", - "windows-sys 0.48.0", -] - -[[package]] -name = "event-listener" -version = "2.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" - -[[package]] -name = "eyre" -version = "0.6.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" -dependencies = [ - "indenter", - "once_cell", -] - -[[package]] -name = "fast-srgb8" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd2e7510819d6fbf51a5545c8f922716ecfb14df168a3242f7d33e0239efe6a1" - -[[package]] -name = "faster-hex" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2a2b11eda1d40935b26cf18f6833c526845ae8c41e58d09af6adeb6f0269183" -dependencies = [ - "serde", -] - -[[package]] -name = "fastrand" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" - -[[package]] -name = "fdeflate" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f9bfee30e4dedf0ab8b422f03af778d9612b63f502710fc500a334ebe2de645" -dependencies = [ - "simd-adler32", -] - -[[package]] -name = "filetime" -version = "0.2.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "windows-sys 0.52.0", -] - -[[package]] -name = "finl_unicode" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" - -[[package]] -name = "flate2" -version = "1.0.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" -dependencies = [ - "crc32fast", - "libz-sys", - "miniz_oxide", -] - -[[package]] -name = "flume" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" -dependencies = [ - "futures-core", - "futures-sink", - "spin 0.9.8", -] - -[[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.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-intrusive" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" -dependencies = [ - "futures-core", - "lock_api", - "parking_lot", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.58", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-timer" -version = "3.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "fuzzy-matcher" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54614a3312934d066701a80f20f15fa3b56d67ac7722b39eea5b4c9dd1d66c94" -dependencies = [ - "thread_local", -] - -[[package]] -name = "generator" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc16584ff22b460a382b7feec54b23d2908d858152e5739a120b949293bd74e" -dependencies = [ - "cc", - "libc", - "log", - "rustversion", - "windows 0.48.0", -] - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getrandom" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "gif" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb2d69b19215e18bb912fa30f7ce15846e301408695e44e0ef719f1da9e19f2" -dependencies = [ - "color_quant", - "weezl", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "gix" -version = "0.57.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dd025382892c7b500a9ce1582cd803f9c2ebfe44aff52e9c7f86feee7ced75e" -dependencies = [ - "gix-actor", - "gix-commitgraph", - "gix-config", - "gix-date", - "gix-diff", - "gix-discover", - "gix-features", - "gix-fs", - "gix-glob", - "gix-hash", - "gix-hashtable", - "gix-index", - "gix-lock", - "gix-macros", - "gix-object", - "gix-odb", - "gix-pack", - "gix-path", - "gix-ref", - "gix-refspec", - "gix-revision", - "gix-revwalk", - "gix-sec", - "gix-tempfile", - "gix-trace", - "gix-traverse", - "gix-url", - "gix-utils", - "gix-validate", - "once_cell", - "parking_lot", - "signal-hook", - "smallvec", - "thiserror", - "unicode-normalization", -] - -[[package]] -name = "gix-actor" -version = "0.29.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da27b5ab4ab5c75ff891dccd48409f8cc53c28a79480f1efdd33184b2dc1d958" -dependencies = [ - "bstr", - "btoi", - "gix-date", - "itoa", - "thiserror", - "winnow 0.5.34", -] - -[[package]] -name = "gix-bitmap" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b6cd0f246180034ddafac9b00a112f19178135b21eb031b3f79355891f7325" -dependencies = [ - "thiserror", -] - -[[package]] -name = "gix-chunk" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "003ec6deacf68076a0c157271a127e0bb2c031c1a41f7168cbe5d248d9b85c78" -dependencies = [ - "thiserror", -] - -[[package]] -name = "gix-commitgraph" -version = "0.23.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8dcbf434951fa477063e05fea59722615af70dc2567377e58c2f7853b010fc" -dependencies = [ - "bstr", - "gix-chunk", - "gix-features", - "gix-hash", - "memmap2", - "thiserror", -] - -[[package]] -name = "gix-config" -version = "0.33.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "367304855b369cadcac4ee5fb5a3a20da9378dd7905106141070b79f85241079" -dependencies = [ - "bstr", - "gix-config-value", - "gix-features", - "gix-glob", - "gix-path", - "gix-ref", - "gix-sec", - "memchr", - "once_cell", - "smallvec", - "thiserror", - "unicode-bom", - "winnow 0.5.34", -] - -[[package]] -name = "gix-config-value" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74ab5d22bc21840f4be0ba2e78df947ba14d8ba6999ea798f86b5bdb999edd0c" -dependencies = [ - "bitflags 2.5.0", - "bstr", - "gix-path", - "libc", - "thiserror", -] - -[[package]] -name = "gix-date" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17077f0870ac12b55d2eed9cb3f56549e40def514c8a783a0a79177a8a76b7c5" -dependencies = [ - "bstr", - "itoa", - "thiserror", - "time", -] - -[[package]] -name = "gix-diff" -version = "0.39.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6a0454f8c42d686f17e7f084057c717c082b7dbb8209729e4e8f26749eb93a" -dependencies = [ - "bstr", - "gix-hash", - "gix-object", - "thiserror", -] - -[[package]] -name = "gix-discover" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8d7b2896edc3d899d28a646ccc6df729827a6600e546570b2783466404a42d6" -dependencies = [ - "bstr", - "dunce", - "gix-hash", - "gix-path", - "gix-ref", - "gix-sec", - "thiserror", -] - -[[package]] -name = "gix-features" -version = "0.37.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d50270e8dcc665f30ba0735b17984b9535bdf1e646c76e638e007846164d57af" -dependencies = [ - "crc32fast", - "flate2", - "gix-hash", - "gix-trace", - "libc", - "once_cell", - "prodash", - "sha1_smol", - "thiserror", - "walkdir", -] - -[[package]] -name = "gix-fs" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7555c23a005537434bbfcb8939694e18cad42602961d0de617f8477cc2adecdd" -dependencies = [ - "gix-features", -] - -[[package]] -name = "gix-glob" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae6232f18b262770e343dcdd461c0011c9b9ae27f0c805e115012aa2b902c1b8" -dependencies = [ - "bitflags 2.5.0", - "bstr", - "gix-features", - "gix-path", -] - -[[package]] -name = "gix-hash" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0ed89cdc1dce26685c80271c4287077901de3c3dd90234d5fa47c22b2268653" -dependencies = [ - "faster-hex", - "thiserror", -] - -[[package]] -name = "gix-hashtable" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebe47d8c0887f82355e2e9e16b6cecaa4d5e5346a7a474ca78ff94de1db35a5b" -dependencies = [ - "gix-hash", - "hashbrown", - "parking_lot", -] - -[[package]] -name = "gix-index" -version = "0.28.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e50e63df6c8d4137f7fb882f27643b3a9756c468a1a2cdbe1ce443010ca8778" -dependencies = [ - "bitflags 2.5.0", - "bstr", - "btoi", - "filetime", - "gix-bitmap", - "gix-features", - "gix-fs", - "gix-hash", - "gix-lock", - "gix-object", - "gix-traverse", - "itoa", - "libc", - "memmap2", - "rustix", - "smallvec", - "thiserror", -] - -[[package]] -name = "gix-lock" -version = "12.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40a439397f1e230b54cf85d52af87e5ea44cc1e7748379785d3f6d03d802b00" -dependencies = [ - "gix-tempfile", - "gix-utils", - "thiserror", -] - -[[package]] -name = "gix-macros" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d75e7ab728059f595f6ddc1ad8771b8d6a231971ae493d9d5948ecad366ee8bb" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.58", -] - -[[package]] -name = "gix-object" -version = "0.40.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c89402e8faa41b49fde348665a8f38589e461036475af43b6b70615a6a313a2" -dependencies = [ - "bstr", - "btoi", - "gix-actor", - "gix-date", - "gix-features", - "gix-hash", - "gix-validate", - "itoa", - "smallvec", - "thiserror", - "winnow 0.5.34", -] - -[[package]] -name = "gix-odb" -version = "0.56.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46ae6da873de41c6c2b73570e82c571b69df5154dcd8f46dfafc6687767c33b1" -dependencies = [ - "arc-swap", - "gix-date", - "gix-features", - "gix-hash", - "gix-object", - "gix-pack", - "gix-path", - "gix-quote", - "parking_lot", - "tempfile", - "thiserror", -] - -[[package]] -name = "gix-pack" -version = "0.46.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "782b4d42790a14072d5c400deda9851f5765f50fe72bca6dece0da1cd6f05a9a" -dependencies = [ - "clru", - "gix-chunk", - "gix-features", - "gix-hash", - "gix-hashtable", - "gix-object", - "gix-path", - "gix-tempfile", - "memmap2", - "parking_lot", - "smallvec", - "thiserror", -] - -[[package]] -name = "gix-path" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69e0b521a5c345b7cd6a81e3e6f634407360a038c8b74ba14c621124304251b8" -dependencies = [ - "bstr", - "gix-trace", - "home", - "once_cell", - "thiserror", -] - -[[package]] -name = "gix-quote" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d1b102957d975c6eb56c2b7ad9ac7f26d117299b910812b2e9bf086ec43496d" -dependencies = [ - "bstr", - "gix-utils", - "thiserror", -] - -[[package]] -name = "gix-ref" -version = "0.40.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64d9bd1984638d8f3511a2fcbe84fcedb8a5b5d64df677353620572383f42649" -dependencies = [ - "gix-actor", - "gix-date", - "gix-features", - "gix-fs", - "gix-hash", - "gix-lock", - "gix-object", - "gix-path", - "gix-tempfile", - "gix-validate", - "memmap2", - "thiserror", - "winnow 0.5.34", -] - -[[package]] -name = "gix-refspec" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be219df5092c1735abb2a53eccdf775e945eea6986ee1b6e7a5896dccc0be704" -dependencies = [ - "bstr", - "gix-hash", - "gix-revision", - "gix-validate", - "smallvec", - "thiserror", -] - -[[package]] -name = "gix-revision" -version = "0.25.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa78e1df3633bc937d4db15f8dca2abdb1300ca971c0fabcf9fa97e38cf4cd9f" -dependencies = [ - "bstr", - "gix-date", - "gix-hash", - "gix-hashtable", - "gix-object", - "gix-revwalk", - "gix-trace", - "thiserror", -] - -[[package]] -name = "gix-revwalk" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "702de5fe5c2bbdde80219f3a8b9723eb927466e7ecd187cfd1b45d986408e45f" -dependencies = [ - "gix-commitgraph", - "gix-date", - "gix-hash", - "gix-hashtable", - "gix-object", - "smallvec", - "thiserror", -] - -[[package]] -name = "gix-sec" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "022592a0334bdf77c18c06e12a7c0eaff28845c37e73c51a3e37d56dd495fb35" -dependencies = [ - "bitflags 2.5.0", - "gix-path", - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "gix-tempfile" -version = "12.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8ef376d718b1f5f119b458e21b00fbf576bc9d4e26f8f383d29f5ffe3ba3eaa" -dependencies = [ - "gix-fs", - "libc", - "once_cell", - "parking_lot", - "signal-hook", - "signal-hook-registry", - "tempfile", -] - -[[package]] -name = "gix-trace" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b202d766a7fefc596e2cc6a89cda8ad8ad733aed82da635ac120691112a9b1" - -[[package]] -name = "gix-traverse" -version = "0.36.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65109e445ba7a409b48f34f570a4d7db72eade1dc1bcff81990a490e86c07161" -dependencies = [ - "gix-commitgraph", - "gix-date", - "gix-hash", - "gix-hashtable", - "gix-object", - "gix-revwalk", - "smallvec", - "thiserror", -] - -[[package]] -name = "gix-url" -version = "0.26.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f0f17cceb7552a231d1fec690bc2740c346554e3be6f5d2c41dfa809594dc44" -dependencies = [ - "bstr", - "gix-features", - "gix-path", - "home", - "thiserror", - "url", -] - -[[package]] -name = "gix-utils" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60157a15b9f14b11af1c6817ad7a93b10b50b4e5136d98a127c46a37ff16eeb6" -dependencies = [ - "fastrand", - "unicode-normalization", -] - -[[package]] -name = "gix-validate" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac7cc36f496bd5d96cdca0f9289bb684480725d40db60f48194aa7723b883854" -dependencies = [ - "bstr", - "thiserror", -] - -[[package]] -name = "glob" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" - -[[package]] -name = "h2" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "816ec7294445779408f36fe57bc5b7fc1cf59664059096c65f905c1c61f58069" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.14.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" -dependencies = [ - "ahash", - "allocator-api2", -] - -[[package]] -name = "hashlink" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" -dependencies = [ - "hashbrown", -] - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - -[[package]] -name = "hermit-abi" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "379dada1584ad501b383485dd706b8afb7a70fcbc7f4da7d780638a5a6124a60" - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "hkdf" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" -dependencies = [ - "hmac", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - -[[package]] -name = "home" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "http" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" -dependencies = [ - "bytes", - "http", -] - -[[package]] -name = "http-body-util" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" -dependencies = [ - "bytes", - "futures-core", - "http", - "http-body", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" - -[[package]] -name = "hyper" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "186548d73ac615b32a73aafe38fb4f56c0d340e110e5a200bcadbaf2e199263a" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "itoa", - "pin-project-lite", - "smallvec", - "tokio", - "want", -] - -[[package]] -name = "hyper-rustls" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0bea761b46ae2b24eb4aef630d8d1c398157b6fc29e6350ecf090a0b70c952c" -dependencies = [ - "futures-util", - "http", - "hyper", - "hyper-util", - "rustls 0.22.2", - "rustls-native-certs", - "rustls-pki-types", - "tokio", - "tokio-rustls 0.25.0", - "tower-service", -] - -[[package]] -name = "hyper-rustls" -version = "0.27.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "908bb38696d7a037a01ebcc68a00634112ac2bbf8ca74e30a2c3d2f4f021302b" -dependencies = [ - "futures-util", - "http", - "hyper", - "hyper-util", - "rustls 0.23.5", - "rustls-native-certs", - "rustls-pki-types", - "tokio", - "tokio-rustls 0.26.0", - "tower-service", -] - -[[package]] -name = "hyper-util" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "http", - "http-body", - "hyper", - "pin-project-lite", - "socket2", - "tokio", - "tower", - "tower-service", - "tracing", -] - -[[package]] -name = "iana-time-zone" -version = "0.1.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "wasm-bindgen", - "windows-core", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", -] - -[[package]] -name = "idna" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "image" -version = "0.25.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd54d660e773627692c524beaad361aca785a4f9f5730ce91f42aabe5bce3d11" -dependencies = [ - "bytemuck", - "byteorder", - "color_quant", - "gif", - "num-traits", - "png", - "tiff", - "zune-core", - "zune-jpeg", -] - -[[package]] -name = "indenter" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" - -[[package]] -name = "indexmap" -version = "2.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "233cf39063f058ea2caae4091bf4a3ef70a653afbc026f5c4a4135d114e3c177" -dependencies = [ - "equivalent", - "hashbrown", -] - -[[package]] -name = "itertools" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" -dependencies = [ - "either", -] - -[[package]] -name = "itertools" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" - -[[package]] -name = "jpeg-decoder" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" - -[[package]] -name = "js-sys" -version = "0.3.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "kmeans_colors" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9a15ffb2811dc35dd7efefc227cf208a68eb8abc76be325d6319eba37747894" -dependencies = [ - "num-traits", - "palette", - "rand", - "rand_chacha", -] - -[[package]] -name = "lavalink-rs" -version = "0.12.0" -source = "git+https://gitlab.com/vicky5124/lavalink-rs?rev=56fd9191#56fd919119c7ae0ce3172012578ce8afbf79513c" -dependencies = [ - "arc-swap", - "bytes", - "dashmap", - "futures", - "http", - "http-body-util", - "hyper", - "hyper-rustls 0.27.1", - "hyper-util", - "lavalink_rs_macros", - "oneshot", - "serde", - "serde_json", - "serde_qs", - "tokio", - "tokio-tungstenite", - "tracing", - "twilight-model", - "urlencoding", - "version_check", -] - -[[package]] -name = "lavalink_rs_macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "426ef2204d4fa6806fa6a00fdd747f7312645fcd30cf9208a5bdfeec6f3b9a41" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.58", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -dependencies = [ - "spin 0.5.2", -] - -[[package]] -name = "libc" -version = "0.2.153" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" - -[[package]] -name = "libm" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" - -[[package]] -name = "libsqlite3-sys" -version = "0.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4e226dcd58b4be396f7bd3c20da8fdee2911400705297ba7d2d7cc2c30f716" -dependencies = [ - "cc", - "pkg-config", - "vcpkg", -] - -[[package]] -name = "libz-sys" -version = "1.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "037731f5d3aaa87a5675e895b63ddff1a87624bc29f77004ea829809654e48f6" -dependencies = [ - "cc", - "pkg-config", - "vcpkg", -] - -[[package]] -name = "linkify" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1dfa36d52c581e9ec783a7ce2a5e0143da6237be5811a0b3153fedfdbe9f780" -dependencies = [ - "memchr", -] - -[[package]] -name = "linux-raw-sys" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" - -[[package]] -name = "lock_api" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" - -[[package]] -name = "loom" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff50ecb28bb86013e935fb6683ab1f6d3a20016f123c76fd4c27470076ac30f5" -dependencies = [ - "cfg-if", - "generator", - "pin-utils", - "scoped-tls", - "tracing", - "tracing-subscriber", -] - -[[package]] -name = "lyra" -version = "0.6.0" -dependencies = [ - "aho-corasick", - "bitflags 2.5.0", - "chrono", - "color-eyre", - "const-str", - "const_panic", - "dashmap", - "dotenvy", - "dotenvy_macro", - "futures", - "fuzzy-matcher", - "heck 0.5.0", - "image", - "itertools 0.13.0", - "kmeans_colors", - "lavalink-rs", - "lazy_static", - "linkify", - "log", - "lyra_proc", - "mixbox", - "palette", - "rand", - "rayon", - "regex", - "rstest", - "serde", - "serde_json", - "sqlx", - "thiserror", - "tokio", - "tracing", - "tracing-subscriber", - "twilight", - "twilight-cache-inmemory", - "twilight-gateway", - "twilight-http", - "twilight-interactions", - "twilight-mention", - "twilight-model", - "twilight-standby", - "twilight-util", - "twilight-validate", - "unicode-segmentation", - "vergen", -] - -[[package]] -name = "lyra_proc" -version = "0.6.0" -dependencies = [ - "heck 0.5.0", - "itertools 0.13.0", - "quote", - "serde", - "syn 2.0.58", - "toml", -] - -[[package]] -name = "matchers" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" -dependencies = [ - "regex-automata 0.1.10", -] - -[[package]] -name = "md-5" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" -dependencies = [ - "cfg-if", - "digest", -] - -[[package]] -name = "memchr" -version = "2.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" - -[[package]] -name = "memmap2" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe751422e4a8caa417e13c3ea66452215d7d63e19e604f4980461212f3ae1322" -dependencies = [ - "libc", -] - -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", - "simd-adler32", -] - -[[package]] -name = "mio" -version = "0.8.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "mixbox" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dc7072c6974f853e367c55d051cdee335ca9116ccc55a1f905de0892a6560c6" -dependencies = [ - "libm", -] - -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - -[[package]] -name = "ntapi" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" -dependencies = [ - "winapi", -] - -[[package]] -name = "nu-ansi-term" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" -dependencies = [ - "overload", - "winapi", -] - -[[package]] -name = "num-bigint-dig" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" -dependencies = [ - "byteorder", - "lazy_static", - "libm", - "num-integer", - "num-iter", - "num-traits", - "rand", - "smallvec", - "zeroize", -] - -[[package]] -name = "num-conv" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" - -[[package]] -name = "num-integer" -version = "0.1.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-iter" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" -dependencies = [ - "autocfg", - "libm", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "num_threads" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" -dependencies = [ - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "oneshot" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f6640c6bda7731b1fdbab747981a0f896dd1fedaf9f4a53fa237a04a84431f4" -dependencies = [ - "loom", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "ordered-float" -version = "2.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f19d67e5a2795c94e73e0bb1cc1a7edeb2e28efd39e2e1c9b7a40c1108b11c" -dependencies = [ - "num-traits", -] - -[[package]] -name = "overload" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" - -[[package]] -name = "owo-colors" -version = "3.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" - -[[package]] -name = "palette" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cbf71184cc5ecc2e4e1baccdb21026c20e5fc3dcf63028a086131b3ab00b6e6" -dependencies = [ - "approx", - "fast-srgb8", - "palette_derive", -] - -[[package]] -name = "palette_derive" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5030daf005bface118c096f510ffb781fc28f9ab6a32ab224d8631be6851d30" -dependencies = [ - "by_address", - "proc-macro2", - "quote", - "syn 2.0.58", -] - -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.48.5", -] - -[[package]] -name = "paste" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" - -[[package]] -name = "pem-rfc7468" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" -dependencies = [ - "base64ct", -] - -[[package]] -name = "percent-encoding" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" - -[[package]] -name = "pin-project" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.58", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "pkcs1" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" -dependencies = [ - "der", - "pkcs8", - "spki", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - -[[package]] -name = "pkg-config" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - -[[package]] -name = "png" -version = "0.17.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06e4b0d3d1312775e782c86c91a111aa1f910cbb65e1337f9975b5f9a554b5e1" -dependencies = [ - "bitflags 1.3.2", - "crc32fast", - "fdeflate", - "flate2", - "miniz_oxide", -] - -[[package]] -name = "powerfmt" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" - -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - -[[package]] -name = "proc-macro2" -version = "1.0.78" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "prodash" -version = "28.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "744a264d26b88a6a7e37cbad97953fa233b94d585236310bcbc88474b4092d79" - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rayon" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" -dependencies = [ - "crossbeam-deque", - "crossbeam-utils", -] - -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "regex" -version = "1.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata 0.4.5", - "regex-syntax 0.8.2", -] - -[[package]] -name = "regex-automata" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" -dependencies = [ - "regex-syntax 0.6.29", -] - -[[package]] -name = "regex-automata" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax 0.8.2", -] - -[[package]] -name = "regex-syntax" -version = "0.6.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" - -[[package]] -name = "regex-syntax" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" - -[[package]] -name = "relative-path" -version = "1.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e898588f33fdd5b9420719948f9f2a32c922a246964576f71ba7f24f80610fbc" - -[[package]] -name = "ring" -version = "0.17.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" -dependencies = [ - "cc", - "cfg-if", - "getrandom", - "libc", - "spin 0.9.8", - "untrusted", - "windows-sys 0.52.0", -] - -[[package]] -name = "rsa" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d0e5124fcb30e76a7e79bfee683a2746db83784b86289f6251b54b7950a0dfc" -dependencies = [ - "const-oid", - "digest", - "num-bigint-dig", - "num-integer", - "num-traits", - "pkcs1", - "pkcs8", - "rand_core", - "signature", - "spki", - "subtle", - "zeroize", -] - -[[package]] -name = "rstest" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5316d2a1479eeef1ea21e7f9ddc67c191d497abc8fc3ba2467857abbb68330" -dependencies = [ - "futures", - "futures-timer", - "rstest_macros", - "rustc_version", -] - -[[package]] -name = "rstest_macros" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04a9df72cc1f67020b0d63ad9bfe4a323e459ea7eb68e03bd9824db49f9a4c25" -dependencies = [ - "cfg-if", - "glob", - "proc-macro2", - "quote", - "regex", - "relative-path", - "rustc_version", - "syn 2.0.58", - "unicode-ident", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" - -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver", -] - -[[package]] -name = "rustix" -version = "0.38.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" -dependencies = [ - "bitflags 2.5.0", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] - -[[package]] -name = "rustls" -version = "0.21.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" -dependencies = [ - "ring", - "rustls-webpki 0.101.7", - "sct", -] - -[[package]] -name = "rustls" -version = "0.22.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87c9956bd9807afa1f77e0f7594af32566e830e088a5576d27c5b6f30f49d41" -dependencies = [ - "log", - "ring", - "rustls-pki-types", - "rustls-webpki 0.102.2", - "subtle", - "zeroize", -] - -[[package]] -name = "rustls" -version = "0.23.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afabcee0551bd1aa3e18e5adbf2c0544722014b899adb31bd186ec638d3da97e" -dependencies = [ - "once_cell", - "ring", - "rustls-pki-types", - "rustls-webpki 0.102.2", - "subtle", - "zeroize", -] - -[[package]] -name = "rustls-native-certs" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f1fb85efa936c42c6d5fc28d2629bb51e4b2f4b8a5211e297d599cc5a093792" -dependencies = [ - "openssl-probe", - "rustls-pemfile 2.1.2", - "rustls-pki-types", - "schannel", - "security-framework", -] - -[[package]] -name = "rustls-pemfile" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" -dependencies = [ - "base64 0.21.7", -] - -[[package]] -name = "rustls-pemfile" -version = "2.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" -dependencies = [ - "base64 0.22.0", - "rustls-pki-types", -] - -[[package]] -name = "rustls-pki-types" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "048a63e5b3ac996d78d402940b5fa47973d2d080c6c6fffa1d0f19c4445310b7" - -[[package]] -name = "rustls-webpki" -version = "0.101.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] -name = "rustls-webpki" -version = "0.102.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "faaa0a62740bedb9b2ef5afa303da42764c012f743917351dc9a237ea1663610" -dependencies = [ - "ring", - "rustls-pki-types", - "untrusted", -] - -[[package]] -name = "rustversion" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" - -[[package]] -name = "ryu" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" - -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "schannel" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "scoped-tls" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "sct" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] -name = "security-framework" -version = "2.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "semver" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" -dependencies = [ - "serde", -] - -[[package]] -name = "serde" -version = "1.0.202" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde-value" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c" -dependencies = [ - "ordered-float", - "serde", -] - -[[package]] -name = "serde_derive" -version = "1.0.202" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.58", -] - -[[package]] -name = "serde_json" -version = "1.0.117" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "serde_qs" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd34f36fe4c5ba9654417139a9b3a20d2e1de6012ee678ad14d240c22c78d8d6" -dependencies = [ - "percent-encoding", - "serde", - "thiserror", -] - -[[package]] -name = "serde_repr" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.58", -] - -[[package]] -name = "serde_spanned" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" -dependencies = [ - "serde", -] - -[[package]] -name = "sha1" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sha1_smol" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" - -[[package]] -name = "sha2" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sharded-slab" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "signal-hook" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" -dependencies = [ - "libc", - "signal-hook-registry", -] - -[[package]] -name = "signal-hook-registry" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" -dependencies = [ - "libc", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "simd-adler32" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" - -[[package]] -name = "simdutf8" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" - -[[package]] -name = "socket2" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", -] - -[[package]] -name = "sqlformat" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce81b7bd7c4493975347ef60d8c7e8b742d4694f4c49f93e0a12ea263938176c" -dependencies = [ - "itertools 0.12.1", - "nom", - "unicode_categories", -] - -[[package]] -name = "sqlx" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9a2ccff1a000a5a59cd33da541d9f2fdcd9e6e8229cc200565942bff36d0aaa" -dependencies = [ - "sqlx-core", - "sqlx-macros", - "sqlx-mysql", - "sqlx-postgres", - "sqlx-sqlite", -] - -[[package]] -name = "sqlx-core" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24ba59a9342a3d9bab6c56c118be528b27c9b60e490080e9711a04dccac83ef6" -dependencies = [ - "ahash", - "atoi", - "byteorder", - "bytes", - "crc", - "crossbeam-queue", - "either", - "event-listener", - "futures-channel", - "futures-core", - "futures-intrusive", - "futures-io", - "futures-util", - "hashlink", - "hex", - "indexmap", - "log", - "memchr", - "once_cell", - "paste", - "percent-encoding", - "rustls 0.21.10", - "rustls-pemfile 1.0.4", - "serde", - "serde_json", - "sha2", - "smallvec", - "sqlformat", - "thiserror", - "tokio", - "tokio-stream", - "tracing", - "url", - "webpki-roots", -] - -[[package]] -name = "sqlx-macros" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea40e2345eb2faa9e1e5e326db8c34711317d2b5e08d0d5741619048a803127" -dependencies = [ - "proc-macro2", - "quote", - "sqlx-core", - "sqlx-macros-core", - "syn 1.0.109", -] - -[[package]] -name = "sqlx-macros-core" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5833ef53aaa16d860e92123292f1f6a3d53c34ba8b1969f152ef1a7bb803f3c8" -dependencies = [ - "dotenvy", - "either", - "heck 0.4.1", - "hex", - "once_cell", - "proc-macro2", - "quote", - "serde", - "serde_json", - "sha2", - "sqlx-core", - "sqlx-mysql", - "sqlx-postgres", - "sqlx-sqlite", - "syn 1.0.109", - "tempfile", - "tokio", - "url", -] - -[[package]] -name = "sqlx-mysql" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ed31390216d20e538e447a7a9b959e06ed9fc51c37b514b46eb758016ecd418" -dependencies = [ - "atoi", - "base64 0.21.7", - "bitflags 2.5.0", - "byteorder", - "bytes", - "crc", - "digest", - "dotenvy", - "either", - "futures-channel", - "futures-core", - "futures-io", - "futures-util", - "generic-array", - "hex", - "hkdf", - "hmac", - "itoa", - "log", - "md-5", - "memchr", - "once_cell", - "percent-encoding", - "rand", - "rsa", - "serde", - "sha1", - "sha2", - "smallvec", - "sqlx-core", - "stringprep", - "thiserror", - "tracing", - "whoami", -] - -[[package]] -name = "sqlx-postgres" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c824eb80b894f926f89a0b9da0c7f435d27cdd35b8c655b114e58223918577e" -dependencies = [ - "atoi", - "base64 0.21.7", - "bitflags 2.5.0", - "byteorder", - "crc", - "dotenvy", - "etcetera", - "futures-channel", - "futures-core", - "futures-io", - "futures-util", - "hex", - "hkdf", - "hmac", - "home", - "itoa", - "log", - "md-5", - "memchr", - "once_cell", - "rand", - "serde", - "serde_json", - "sha2", - "smallvec", - "sqlx-core", - "stringprep", - "thiserror", - "tracing", - "whoami", -] - -[[package]] -name = "sqlx-sqlite" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b244ef0a8414da0bed4bb1910426e890b19e5e9bccc27ada6b797d05c55ae0aa" -dependencies = [ - "atoi", - "flume", - "futures-channel", - "futures-core", - "futures-executor", - "futures-intrusive", - "futures-util", - "libsqlite3-sys", - "log", - "percent-encoding", - "serde", - "sqlx-core", - "tracing", - "url", - "urlencoding", -] - -[[package]] -name = "stringprep" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb41d74e231a107a1b4ee36bd1214b11285b77768d2e3824aedafa988fd36ee6" -dependencies = [ - "finl_unicode", - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "sysinfo" -version = "0.30.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb4f3438c8f6389c864e61221cbc97e9bca98b4daf39a5beb7bea660f528bb2" -dependencies = [ - "cfg-if", - "core-foundation-sys", - "libc", - "ntapi", - "once_cell", - "windows 0.52.0", -] - -[[package]] -name = "tempfile" -version = "3.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a365e8cd18e44762ef95d87f284f4b5cd04107fec2ff3052bd6a3e6069669e67" -dependencies = [ - "cfg-if", - "fastrand", - "rustix", - "windows-sys 0.52.0", -] - -[[package]] -name = "thiserror" -version = "1.0.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.58", -] - -[[package]] -name = "thread_local" -version = "1.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" -dependencies = [ - "cfg-if", - "once_cell", -] - -[[package]] -name = "tiff" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba1310fcea54c6a9a4fd1aad794ecc02c31682f6bfbecdf460bf19533eed1e3e" -dependencies = [ - "flate2", - "jpeg-decoder", - "weezl", -] - -[[package]] -name = "time" -version = "0.3.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" -dependencies = [ - "deranged", - "itoa", - "libc", - "num-conv", - "num_threads", - "powerfmt", - "serde", - "time-core", - "time-macros", -] - -[[package]] -name = "time-core" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" - -[[package]] -name = "time-macros" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" -dependencies = [ - "num-conv", - "time-core", -] - -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.58", -] - -[[package]] -name = "tokio-rustls" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" -dependencies = [ - "rustls 0.22.2", - "rustls-pki-types", - "tokio", -] - -[[package]] -name = "tokio-rustls" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" -dependencies = [ - "rustls 0.23.5", - "rustls-pki-types", - "tokio", -] - -[[package]] -name = "tokio-stream" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tokio-tungstenite" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" -dependencies = [ - "futures-util", - "log", - "rustls 0.22.2", - "rustls-native-certs", - "rustls-pki-types", - "tokio", - "tokio-rustls 0.25.0", - "tungstenite", -] - -[[package]] -name = "tokio-util" -version = "0.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", - "tracing", -] - -[[package]] -name = "tokio-websockets" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b069bad86dda43d908b4221fe04fe49d2ed8e0a24d319a5c6a8d250e76fe15b" -dependencies = [ - "base64 0.21.7", - "bytes", - "fastrand", - "futures-core", - "futures-sink", - "http", - "httparse", - "ring", - "rustls-native-certs", - "rustls-pki-types", - "sha1_smol", - "simdutf8", - "tokio", - "tokio-rustls 0.25.0", - "tokio-util", - "tracing", -] - -[[package]] -name = "toml" -version = "0.8.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4e43f8cc456c9704c851ae29c67e17ef65d2c30017c17a9765b89c382dc8bba" -dependencies = [ - "serde", - "serde_spanned", - "toml_datetime", - "toml_edit", -] - -[[package]] -name = "toml_datetime" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" -dependencies = [ - "serde", -] - -[[package]] -name = "toml_edit" -version = "0.22.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c127785850e8c20836d49732ae6abfa47616e60bf9d9f57c43c250361a9db96c" -dependencies = [ - "indexmap", - "serde", - "serde_spanned", - "toml_datetime", - "winnow 0.6.8", -] - -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite", - "tokio", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower-layer" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" - -[[package]] -name = "tower-service" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" - -[[package]] -name = "tracing" -version = "0.1.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" -dependencies = [ - "log", - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.58", -] - -[[package]] -name = "tracing-core" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" -dependencies = [ - "once_cell", - "valuable", -] - -[[package]] -name = "tracing-error" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" -dependencies = [ - "tracing", - "tracing-subscriber", -] - -[[package]] -name = "tracing-log" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" -dependencies = [ - "log", - "once_cell", - "tracing-core", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" -dependencies = [ - "matchers", - "nu-ansi-term", - "once_cell", - "regex", - "sharded-slab", - "smallvec", - "thread_local", - "tracing", - "tracing-core", - "tracing-log", -] - -[[package]] -name = "try-lock" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" - -[[package]] -name = "tungstenite" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1" -dependencies = [ - "byteorder", - "bytes", - "data-encoding", - "http", - "httparse", - "log", - "rand", - "rustls 0.22.2", - "rustls-pki-types", - "sha1", - "thiserror", - "url", - "utf-8", -] - -[[package]] -name = "twilight" -version = "0.16.0-rc.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f917ea79e3c1cb325a5cd060e8d3b9f6872ae124a3e1e1192c0e17b3b0a20132" - -[[package]] -name = "twilight-cache-inmemory" -version = "0.16.0-rc.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a997fdd14e32ebbe80ee87887720e756efed0a7dbf97bd1170eb7c9a3956378b" -dependencies = [ - "bitflags 2.5.0", - "dashmap", - "serde", - "twilight-model", - "twilight-util", -] - -[[package]] -name = "twilight-gateway" -version = "0.16.0-rc.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b3edd60e2b95ec0d651c475dacad8a75e4780d900f8f2ea0f4c215182d920fc" -dependencies = [ - "bitflags 2.5.0", - "fastrand", - "flate2", - "futures-core", - "futures-sink", - "serde", - "serde_json", - "tokio", - "tokio-websockets", - "tracing", - "twilight-gateway-queue", - "twilight-http", - "twilight-model", -] - -[[package]] -name = "twilight-gateway-queue" -version = "0.16.0-rc.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d30e99f204d3803b47c679214ba9e9527cfb1dd0b0deccbe821f7e4682d9a2" -dependencies = [ - "tokio", - "tracing", -] - -[[package]] -name = "twilight-http" -version = "0.16.0-rc.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a03a8133c9ae23510aa6bbe81ca7c4d5bc6fc45c52075d350fd0578b71397413" -dependencies = [ - "brotli", - "fastrand", - "http", - "http-body-util", - "hyper", - "hyper-rustls 0.26.0", - "hyper-util", - "percent-encoding", - "serde", - "serde_json", - "tokio", - "tracing", - "twilight-http-ratelimiting", - "twilight-model", - "twilight-validate", -] - -[[package]] -name = "twilight-http-ratelimiting" -version = "0.16.0-rc.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f814c51752ba6838d3b32e82638176de9679e9a2a084a65251b7879281bdc6" -dependencies = [ - "tokio", - "tracing", -] - -[[package]] -name = "twilight-interactions" -version = "0.16.0-rc.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc671758050eefe63e2b87f6af2fc1807ac3ac373bbafff1ae1a4cc4af6cb722" -dependencies = [ - "twilight-interactions-derive", - "twilight-model", -] - -[[package]] -name = "twilight-interactions-derive" -version = "0.16.0-rc.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c07ac7c9d2d086291765ceecafcd52ce6dc33ab0ade02e06509eb416d88470" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.58", -] - -[[package]] -name = "twilight-mention" -version = "0.16.0-rc.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dc35d15fbaf51d2a4a0ca961e746bca9a01f26f338f99d9134c15b6561b4c5b" -dependencies = [ - "twilight-model", -] - -[[package]] -name = "twilight-model" -version = "0.16.0-rc.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eaf296e6aa8784699046bb1ceb33f3c684a59c4657c2b159eb4ec1e1ce44a49" -dependencies = [ - "bitflags 2.5.0", - "serde", - "serde-value", - "serde_repr", - "time", -] - -[[package]] -name = "twilight-standby" -version = "0.16.0-rc.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e968572b4e0c2b0e7a05b4b31b1cbc767c7ec0df0407410045ae8c267af6e1fd" -dependencies = [ - "dashmap", - "futures-core", - "tokio", - "tracing", - "twilight-model", -] - -[[package]] -name = "twilight-util" -version = "0.16.0-rc.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8a5a519ea63090a9e009974bf25e8cb3be9284da7248011ed37377d4180295" -dependencies = [ - "twilight-model", - "twilight-validate", -] - -[[package]] -name = "twilight-validate" -version = "0.16.0-rc.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d71bf2b683421a1674080e821eef108a35cef841ed73562f835bc5cdd478b49" -dependencies = [ - "twilight-model", -] - -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "typewit" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6fb9ae6a3cafaf0a5d14c2302ca525f9ae8e07a0f0e6949de88d882c37a6e24" -dependencies = [ - "typewit_proc_macros", -] - -[[package]] -name = "typewit_proc_macros" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e36a83ea2b3c704935a01b4642946aadd445cea40b10935e3f8bd8052b8193d6" - -[[package]] -name = "unicode-bidi" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" - -[[package]] -name = "unicode-bom" -version = "2.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eec5d1121208364f6793f7d2e222bf75a915c19557537745b195b253dd64217" - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-normalization" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "unicode-segmentation" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "unicode_categories" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" - -[[package]] -name = "untrusted" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" - -[[package]] -name = "url" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - -[[package]] -name = "urlencoding" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" - -[[package]] -name = "utf-8" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" - -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - -[[package]] -name = "vergen" -version = "8.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e27d6bdd219887a9eadd19e1c34f32e47fa332301184935c6d9bca26f3cca525" -dependencies = [ - "anyhow", - "cargo_metadata", - "cfg-if", - "gix", - "regex", - "rustc_version", - "rustversion", - "sysinfo", - "time", -] - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "walkdir" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" -dependencies = [ - "same-file", - "winapi-util", -] - -[[package]] -name = "want" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" -dependencies = [ - "try-lock", -] - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wasm-bindgen" -version = "0.2.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn 2.0.58", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.58", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" - -[[package]] -name = "webpki-roots" -version = "0.25.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" - -[[package]] -name = "weezl" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" - -[[package]] -name = "whoami" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22fc3756b8a9133049b26c7f61ab35416c130e8c09b660f5b3958b446f52cc50" - -[[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-util" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" -dependencies = [ - "winapi", -] - -[[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 = "windows" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" -dependencies = [ - "windows-core", - "windows-targets 0.52.3", -] - -[[package]] -name = "windows-core" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" -dependencies = [ - "windows-targets 0.52.3", -] - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.3", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d380ba1dc7187569a8a9e91ed34b8ccfc33123bbacb8c0aed2d1ad7f3ef2dc5f" -dependencies = [ - "windows_aarch64_gnullvm 0.52.3", - "windows_aarch64_msvc 0.52.3", - "windows_i686_gnu 0.52.3", - "windows_i686_msvc 0.52.3", - "windows_x86_64_gnu 0.52.3", - "windows_x86_64_gnullvm 0.52.3", - "windows_x86_64_msvc 0.52.3", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68e5dcfb9413f53afd9c8f86e56a7b4d86d9a2fa26090ea2dc9e40fba56c6ec6" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dab469ebbc45798319e69eebf92308e541ce46760b49b18c6b3fe5e8965b30f" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a4e9b6a7cac734a8b4138a4e1044eac3404d8326b6c0f939276560687a033fb" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b0ec9c422ca95ff34a78755cfa6ad4a51371da2a5ace67500cf7ca5f232c58" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "704131571ba93e89d7cd43482277d6632589b18ecf4468f591fbae0a8b101614" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42079295511643151e98d61c38c0acc444e52dd42ab456f7ccfd5152e8ecf21c" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0770833d60a970638e989b3fa9fd2bb1aaadcf88963d1659fd7d9990196ed2d6" - -[[package]] -name = "winnow" -version = "0.5.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7cf47b659b318dccbd69cc4797a39ae128f533dce7902a1096044d1967b9c16" -dependencies = [ - "memchr", -] - -[[package]] -name = "winnow" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c52e9c97a68071b23e836c9380edae937f17b9c4667bd021973efc689f618d" -dependencies = [ - "memchr", -] - -[[package]] -name = "zerocopy" -version = "0.7.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.58", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" - -[[package]] -name = "zune-core" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f423a2c17029964870cfaabb1f13dfab7d092a62a29a89264f4d36990ca414a" - -[[package]] -name = "zune-jpeg" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec866b44a2a1fd6133d363f073ca1b179f438f99e7e5bfb1e33f7181facfe448" -dependencies = [ - "zune-core", -] diff --git a/lyra/Cargo.toml b/lyra/Cargo.toml index 5499f05..8fd0ada 100644 --- a/lyra/Cargo.toml +++ b/lyra/Cargo.toml @@ -2,7 +2,7 @@ name = "lyra" readme = "../README.md" description = "A featureful, self-hostable Discord music bot." -version = "0.6.0" +version = "0.7.0" edition = "2021" license = "GPL-3.0" repository = "https://github.com/lyra-music/lyra" @@ -10,23 +10,26 @@ authors = ["fdnt7"] build = "build.rs" [build-dependencies] -vergen = { version = "8.3.1", features = [ +anyhow = "*" +vergen-git2 = { version = "1.0.0-beta.2", features = [ "build", "cargo", - "git", - "gitoxide", "rustc", "si", ] } [lints.rust] -unsafe_code = "forbid" +# dead_code = "allow" +unsafe_op_in_unsafe_fn = "forbid" +# unsafe_code = "forbid" [lints.clippy] -enum_glob_use = "deny" +multiple_unsafe_ops_per_block = "forbid" +undocumented_unsafe_blocks = "forbid" +enum_glob_use = "forbid" +unwrap_used = "forbid" pedantic = { level = "deny", priority = -1 } nursery = { level = "deny", priority = -1 } -unwrap_used = "deny" cast_possible_truncation = "allow" cast_possible_wrap = "allow" @@ -38,6 +41,7 @@ module_name_repetitions = "allow" [dependencies] lyra_proc = { path = "../lyra_proc" } +paste = "1.0.15" const-str = "0.5.7" const_panic = { version = "0.2.8", features = ["derive"] } heck = "0.5.0" @@ -46,17 +50,17 @@ unicode-segmentation = "1.11.0" dashmap = "5.5.3" dotenvy = "0.15.7" dotenvy_macro = "0.15.7" -thiserror = "1.0.60" +thiserror = "1.0.61" color-eyre = "0.6.3" -rstest = "0.19.0" +rstest = "0.21.0" futures = "0.3.30" -tokio = { version = "1.37.0", features = [ +tokio = { version = "1.38.0", features = [ "sync", "signal", "rt-multi-thread", "macros", ] } -serde = "1.0.202" +serde = "1.0.203" serde_json = "1.0.117" regex = "1.10.4" linkify = "0.10.0" @@ -67,7 +71,6 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } rand = "0.8.5" itertools = "0.13.0" rayon = "1.10.0" -lazy_static = "1.4.0" chrono = "0.4.38" sqlx = { version = "0.7.4", features = ["postgres", "runtime-tokio-rustls"] } mixbox = "2.0.0" diff --git a/lyra/build.rs b/lyra/build.rs index d35a056..8382530 100644 --- a/lyra/build.rs +++ b/lyra/build.rs @@ -1,10 +1,13 @@ -fn main() { - vergen::EmitBuilder::builder() - .all_build() - .all_cargo() - .all_git() - .all_rustc() - .all_sysinfo() +pub fn main() { + emit().unwrap_or_else(|e| panic!("emit error: {e:?}")); +} + +fn emit() -> Result<(), anyhow::Error> { + vergen_git2::Emitter::default() + .add_instructions(&vergen_git2::BuildBuilder::all_build()?)? + .add_instructions(&vergen_git2::CargoBuilder::all_cargo()?)? + .add_instructions(&vergen_git2::Git2Builder::all_git()?)? + .add_instructions(&vergen_git2::RustcBuilder::all_rustc()?)? + .add_instructions(&vergen_git2::SysinfoBuilder::all_sysinfo()?)? .emit() - .unwrap_or_else(|e| panic!("emit error: {e:?}")); } diff --git a/lyra/src/bot/command.rs b/lyra/src/bot/command.rs index 2a89525..7d64638 100644 --- a/lyra/src/bot/command.rs +++ b/lyra/src/bot/command.rs @@ -3,6 +3,7 @@ pub mod declare; pub mod macros; pub mod model; pub mod poll; +pub mod require; pub mod util; -pub use model::{AutocompleteCtx, MessageCtx, ModalCtx, SlashCtx}; +pub use model::{AutocompleteCtx, MessageCtx, SlashCtx}; diff --git a/lyra/src/bot/command/check.rs b/lyra/src/bot/command/check.rs index 8d5c445..ec71e1c 100644 --- a/lyra/src/bot/command/check.rs +++ b/lyra/src/bot/command/check.rs @@ -1,50 +1,62 @@ use std::{ collections::hash_map::DefaultHasher, hash::{Hash, Hasher}, - marker::PhantomData, + // marker::PhantomData, num::NonZeroUsize, sync::Arc, time::Duration, }; -use twilight_cache_inmemory::{model::CachedVoiceState, Reference}; use twilight_model::{ channel::{message::MessageFlags, ChannelType}, guild::Permissions, - id::{ - marker::{ChannelMarker, GuildMarker, UserMarker}, - Id, - }, + id::{marker::ChannelMarker, Id}, }; use crate::bot::{ command::model::{Ctx, CtxKind}, component::config::access::CalculatorBuilder, core::{ - model::{AuthorPermissionsAware, BotState, CacheAware, OwnedBotStateAware}, + model::{ + AuthorIdAware, + AuthorPermissionsAware, + BotState, + // CacheAware, + OwnedBotStateAware, + }, traced, }, error::{ - self, + // self, command::check::{ - self, AlternateVoteResponse, SendSupersededWinNoticeError, UserOnlyInError, + self, AlternateVoteResponse, PollResolvableError, SendSupersededWinNoticeError, + UserOnlyInError, }, - lavalink::NoPlayerError, - Cache as CacheError, InVoiceWithSomeoneElse as InVoiceWithSomeoneElseError, - InVoiceWithoutUser as InVoiceWithoutUserError, NotInVoice as NotInVoiceError, - NotPlaying as NotPlayingError, NotUsersTrack as NotUsersTrackError, - Suppressed as SuppressedError, UserNotAccessManager as UserNotAccessManagerError, - UserNotAllowed as UserNotAllowedError, UserNotDj as UserNotDjError, + CacheResult, + InVoiceWithSomeoneElse as InVoiceWithSomeoneElseError, + InVoiceWithoutUser as InVoiceWithoutUserError, + NotUsersTrack as NotUsersTrackError, + UserNotAccessManager as UserNotAccessManagerError, + UserNotAllowed as UserNotAllowedError, + UserNotDj as UserNotDjError, UserNotStageManager as UserNotStageManagerError, }, - gateway::{ExpectedGuildIdAware, GuildIdAware}, + gateway::GuildIdAware, lavalink::{ - self, CorrectTrackInfo, DelegateMethods, Event, LavalinkAware, PlayerAware, QueueItem, + self, + CorrectTrackInfo, + // DelegateMethods, + Event, + LavalinkAware, + // PlayerAware, + QueueItem, }, }; use super::{ - model::RespondViaMessage, poll, poll::Resolution as PollResolution, poll::Topic as PollTopic, + model::{GuildCtx, RespondViaMessage}, + poll::{self, Resolution as PollResolution, Topic as PollTopic}, + require::{self, someone_else_in, CachelessInVoice, InVoice}, }; pub const DJ_PERMISSIONS: Permissions = Permissions::MOVE_MEMBERS.union(Permissions::MUTE_MEMBERS); @@ -55,8 +67,6 @@ pub const STAGE_MANAGER_PERMISSIONS: Permissions = Permissions::MANAGE_CHANNELS .union(Permissions::MUTE_MEMBERS) .union(Permissions::MOVE_MEMBERS); -type InVoiceResult<'a> = Reference<'a, (Id, Id), CachedVoiceState>; - pub fn does_user_have_permissions( permissions: Permissions, ctx: &impl AuthorPermissionsAware, @@ -97,23 +107,24 @@ pub fn user_is_stage_manager( } pub async fn user_allowed_in(ctx: &Ctx) -> Result<(), check::UserAllowedError> { - let Some(guild_id) = ctx.get_guild_id() else { + let Some(weak) = require::guild_weak(ctx).ok() else { return Ok(()); }; - if user_is_access_manager(ctx).is_ok() { + if user_is_access_manager(&weak).is_ok() { return Ok(()); } let channel = ctx.channel(); - let mut access_calculator_builder = CalculatorBuilder::new(guild_id, ctx.db().clone()) + let mut access_calculator_builder = CalculatorBuilder::new(weak.guild_id(), ctx.db().clone()) .user(ctx.author_id()) - .roles(ctx.member().roles.iter()); + .roles(weak.member().roles.iter()); match channel.kind { ChannelType::PublicThread | ChannelType::PrivateThread | ChannelType::AnnouncementThread => { - let parent_id = channel.parent_id.expect("threads always have a parent id"); + // SAFETY: `channel.kind` is of type threads, so `parent_id` is present + let parent_id = unsafe { channel.parent_id.unwrap_unchecked() }; access_calculator_builder = access_calculator_builder .thread(channel.id) .text_channel(parent_id); @@ -143,7 +154,7 @@ pub async fn user_allowed_in(ctx: &Ctx) -> Result<(), check::UserA pub async fn user_allowed_to_use( channel_id: Id, channel_parent_id: Option>, - ctx: &Ctx, + ctx: &GuildCtx, ) -> Result<(), check::UserAllowedError> { if user_is_access_manager(ctx).is_ok() { return Ok(()); @@ -165,265 +176,126 @@ pub async fn user_allowed_to_use( Ok(()) } -pub fn in_voice(ctx: &Ctx) -> Result, NotInVoiceError> { - let result = ctx.current_voice_state().ok_or(NotInVoiceError)?; - Ok(InVoice { result, ctx }) +pub struct InVoiceWithUserResult<'a> { + in_voice: InVoice<'a>, + kind: InVoiceWithUserResultKind, } -pub struct InVoice<'a, T: CtxKind> { - result: InVoiceResult<'a>, - ctx: &'a Ctx, +pub enum InVoiceWithUserResultKind { + UserIsDj, + ToBeDetermined, } -pub fn user_in( +pub fn noone_else_in( channel_id: Id, - ctx: &Ctx, -) -> Result, InVoiceWithoutUserError> { + ctx: &GuildCtx, +) -> Result<(), check::UserOnlyInError> { if is_user_dj(ctx) { - return Ok(InVoiceWithUserResult::Exempted); - } - - let result = ctx - .cache() - .voice_state(ctx.author_id(), ctx.guild_id()) - .filter(|voice_state| voice_state.channel_id() == channel_id) - .ok_or(InVoiceWithoutUserError(channel_id))?; - - Ok(InVoiceWithUserResult::ToBeDetermined(InVoiceWithUser { - result, - ctx, - })) -} - -fn someone_else_in(channel_id: Id, ctx: &Ctx) -> Option { - ctx.cache() - .voice_channel_states(channel_id) - .map(|mut states| { - states.any(|v| { - !ctx.cache() - .user(v.user_id()) - .expect("user should be in the cache") - .bot - && v.user_id() != ctx.author_id() - }) - }) -} - -impl<'a, T: CtxKind> InVoice<'a, T> { - pub fn channel_id(&self) -> Id { - self.result.channel_id() - } - - pub fn with_user(self) -> Result, InVoiceWithoutUserError> { - if is_user_dj(self.ctx) { - return Ok(InVoiceWithUserResult::Exempted); - } - - let ctx = self.ctx; - let channel_id = self.channel_id(); - let result = ctx - .cache() - .voice_state(ctx.author_id(), ctx.guild_id()) - .filter(|voice_state| voice_state.channel_id() == channel_id) - .ok_or(InVoiceWithoutUserError(channel_id))?; - - Ok(InVoiceWithUserResult::ToBeDetermined(InVoiceWithUser { - result, - ctx, - })) + return Ok(()); } - pub fn with_someone_else(self) -> Result<(), check::InVoiceWithSomeoneElseError> { - let channel_id = self.channel_id(); - - if !someone_else_in(channel_id, self.ctx).ok_or(CacheError)? { - Err(error::InVoiceWithoutSomeoneElse(channel_id))?; - } - Ok(()) + if someone_else_in(channel_id, ctx)? { + Err(InVoiceWithSomeoneElseError(channel_id))?; } + Ok(()) } -pub struct InVoiceWithUser<'a, T: CtxKind> { - result: InVoiceResult<'a>, - ctx: &'a Ctx, +pub struct PollStarterInfo { + topic: PollTopic, + error: PollResolvableError, + in_voice: CachelessInVoice, } -pub enum InVoiceWithUserResult<'a, T: CtxKind> { - Exempted, - ToBeDetermined(InVoiceWithUser<'a, T>), +pub enum PollStarter { + NotRequired, + Required(PollStarterInfo), } -pub fn noone_else_in( - channel_id: Id, - ctx: &Ctx, -) -> Result<(), check::UserOnlyInError> { - if is_user_dj(ctx) { - return Ok(()); - } +impl PollStarter { + pub async fn start( + self, + ctx: &mut GuildCtx, + ) -> Result<(), check::HandlePollError> { + if let Self::Required(s) = self { + return handle_poll(s.error, &s.topic, ctx, &s.in_voice).await; + }; - if someone_else_in(channel_id, ctx).ok_or(CacheError)? { - Err(InVoiceWithSomeoneElseError(channel_id))?; + Ok(()) } - Ok(()) } -impl<'a, T: CtxKind> InVoiceWithUserResult<'a, T> { +impl<'a> InVoiceWithUserResult<'a> { pub fn only(self) -> Result<(), check::UserOnlyInError> { - let InVoiceWithUserResult::ToBeDetermined(result) = self else { + if matches!(self.kind, InVoiceWithUserResultKind::UserIsDj) { return Ok(()); - }; - let channel_id = result.result.channel_id(); + } + let InVoiceWithUserResult { in_voice, .. } = self; + let channel_id = in_voice.channel_id(); - if someone_else_in(channel_id, result.ctx).ok_or(CacheError)? { + if someone_else_in(channel_id, &in_voice)? { Err(InVoiceWithSomeoneElseError(channel_id))?; } Ok(()) } -} - -pub fn in_voice_with_user( - ctx: &Ctx, -) -> Result, check::InVoiceWithUserError> { - Ok(in_voice(ctx)?.with_user()?) -} - -pub fn in_voice_with_user_only( - ctx: &Ctx, -) -> Result<(), check::InVoiceWithUserOnlyError> { - Ok(in_voice(ctx)?.with_user()?.only()?) -} -pub fn not_suppressed(ctx: &Ctx) -> Result<(), check::NotSuppressedError> { - let voice_state = ctx.current_voice_state().ok_or(CacheError)?; - let voice_state_channel = ctx - .cache() - .channel(voice_state.channel_id()) - .ok_or(CacheError)?; - - if voice_state.mute() { - Err(SuppressedError::Muted)?; - } - let speaker_in_stage = - voice_state.suppress() && matches!(voice_state_channel.kind, ChannelType::GuildStageVoice); - drop(voice_state); + pub fn only_else_poll(self, topic: PollTopic) -> CacheResult { + let in_voice = From::from(&self.in_voice); + let Err(error) = self.only() else { + return Ok(PollStarter::NotRequired); + }; - if speaker_in_stage { - Err(SuppressedError::NotSpeaker)?; + match error { + check::UserOnlyInError::InVoiceWithSomeoneElse(e) => { + Ok(PollStarter::Required(PollStarterInfo { + topic, + error: check::PollResolvableError::InVoiceWithSomeoneElse(e), + in_voice, + })) + } + check::UserOnlyInError::Cache(e) => Err(e)?, + } } - Ok(()) } -pub async fn queue_not_empty(ctx: &Ctx) -> Result<(), error::QueueEmpty> { - let guild_id = ctx.guild_id(); - if ctx - .lavalink() - .player_data(guild_id) - .read() - .await - .queue() - .is_empty() - { - return Err(error::QueueEmpty); +pub fn in_voice_with_user( + in_voice: InVoice<'_>, +) -> Result, InVoiceWithoutUserError> { + if is_user_dj(&in_voice) { + return Ok(InVoiceWithUserResult { + in_voice, + kind: InVoiceWithUserResultKind::UserIsDj, + }); } - Ok(()) -} + let channel_id = in_voice.channel_id(); + in_voice + .cache + .voice_state(in_voice.author_id, in_voice.guild_id()) + .filter(|voice_state| voice_state.channel_id() == channel_id) + .ok_or(InVoiceWithoutUserError(channel_id))?; -async fn currently_playing(ctx: &Ctx) -> Result { - let guild_id = ctx.guild_id(); - let lavalink = ctx.lavalink(); - let data = lavalink.player_data(guild_id); - let data_r = data.read().await; - let queue = data_r.queue(); - let (current, index) = queue.current_and_index().ok_or(NotPlayingError)?; - - let requester = current.requester(); - let position = NonZeroUsize::new(index + 1).expect("index + 1 is non-zero"); - let title = current.track().info.corrected_title().into(); - let channel_id = lavalink.connection(guild_id).channel_id; - - Ok(CurrentlyPlaying { - requester, - position, - title, - channel_id, - context: CurrentlyPlayingContext::new_via(ctx), + Ok(InVoiceWithUserResult { + in_voice, + kind: InVoiceWithUserResultKind::ToBeDetermined, }) } -struct CurrentlyPlayingContext { - author_id: Id, - author_permissions: Permissions, -} - -impl CurrentlyPlayingContext { - fn new_via(ctx: &Ctx) -> Self { - Self { - author_id: ctx.author_id(), - author_permissions: ctx.author_permissions(), - } - } -} - -impl AuthorPermissionsAware for CurrentlyPlayingContext { - fn author_permissions(&self) -> Permissions { - self.author_permissions - } -} - -struct CurrentlyPlaying { - requester: Id, - position: NonZeroUsize, - title: Arc, - channel_id: Id, - context: CurrentlyPlayingContext, -} - -impl CurrentlyPlaying { - pub fn users_track(&self) -> Result<(), NotUsersTrackError> { - let Self { - requester, - position, - title, - channel_id, - context: ctx, - } = self; - - if is_user_dj(ctx) { - return Ok(()); - } - - if *requester == ctx.author_id { - return Err(NotUsersTrackError { - requester: *requester, - position: *position, - title: title.clone(), - channel_id: *channel_id, - }); - } - Ok(()) - } - - pub fn paused(&self) -> Result<(), error::Paused> { - todo!() - } - - pub fn stopped(&self) -> Result<(), error::Stopped> { - todo!() +pub fn all_users_track( + positions: impl Iterator, + in_voice_with_user: InVoiceWithUserResult, + queue: &lavalink::Queue, + ctx: &impl AuthorIdAware, +) -> Result<(), check::UsersTrackError> { + if let (Some((position, track)), Err(e)) = ( + positions + .map(|p| (p, &queue[p.get() - 1])) + .find(|(_, t)| t.requester() != ctx.author_id()), + in_voice_with_user.only(), + ) { + return Err(impl_users_track(position, track, e)); } -} -async fn currently_playing_users_track( - ctx: &Ctx, -) -> Result<(), check::CurrentlyPlayingUsersTrackError> { - Ok(currently_playing(ctx).await?.users_track()?) -} - -async fn queue_seekable(ctx: &Ctx) -> Result<(), check::QueueSeekableError> { - Ok(currently_playing(ctx) - .await - .map_err(|_| error::QueueNotSeekable)? - .users_track()?) + Ok(()) } fn impl_users_track( @@ -447,11 +319,11 @@ fn impl_users_track( .into() } -pub fn users_track( +pub fn users_track( position: NonZeroUsize, - in_voice_with_user: InVoiceWithUserResult, + in_voice_with_user: InVoiceWithUserResult, queue: &lavalink::Queue, - ctx: &Ctx, + ctx: &impl AuthorIdAware, ) -> Result<(), check::UsersTrackError> { if let Err(e) = in_voice_with_user.only() { let track = &queue[position.get() - 1]; @@ -463,301 +335,383 @@ pub fn users_track( Ok(()) } -pub fn all_users_track( - positions: impl Iterator, - in_voice_with_user: InVoiceWithUserResult, - queue: &lavalink::Queue, - ctx: &Ctx, -) -> Result<(), check::UsersTrackError> { - if let (Some((position, track)), Err(e)) = ( - positions - .map(|p| (p, &queue[p.get() - 1])) - .find(|(_, t)| t.requester() != ctx.author_id()), - in_voice_with_user.only(), - ) { - return Err(impl_users_track(position, track, e)); - } - - Ok(()) -} - -pub fn player_exist(ctx: &impl PlayerAware) -> Result<(), NoPlayerError> { - ctx.get_player().ok_or(NoPlayerError)?; - Ok(()) -} - -#[allow(clippy::struct_excessive_bools)] -struct Checks { - in_voice_with_user: InVoiceWithUserFlag, - queue_not_empty: bool, - not_suppressed: bool, - currently_playing: CurrentlyPlayingFlag, - player_stopped: bool, - player_paused: bool, -} - -impl Checks { - const fn new() -> Self { - Self { - in_voice_with_user: InVoiceWithUserFlag::Skip, - queue_not_empty: false, - not_suppressed: false, - currently_playing: CurrentlyPlayingFlag::Skip, - player_stopped: false, - player_paused: false, - } - } -} - -enum InVoiceWithUserFlag { - Skip, - CheckOnly(bool), -} - -enum CurrentlyPlayingFlag { - Skip, - CheckUsersTrack(bool), - CheckQueueSeekable, -} - -pub struct Voice; -pub trait VoiceMarker {} -impl VoiceMarker for Voice {} - -pub struct Queue; -pub trait QueueMarker {} -impl QueueMarker for Queue {} - -pub struct Playing; -pub trait PlayingMarker {} -impl PlayingMarker for Playing {} - -pub struct Null; -impl VoiceMarker for Null {} -impl QueueMarker for Null {} -impl PlayingMarker for Null {} - -pub struct CheckerBuilder { - checks: Checks, - poll_topic: Option, - in_voice_with_user: PhantomData C>, - queue_not_empty: PhantomData Q>, - currently_playing: PhantomData P>, -} - -impl CheckerBuilder { - pub const fn new() -> Self { - Self { - checks: Checks::new(), - poll_topic: None, - in_voice_with_user: PhantomData:: Null>, - queue_not_empty: PhantomData:: Null>, - currently_playing: PhantomData:: Null>, - } - } - - pub const fn in_voice_with_user(mut self) -> CheckerBuilder { - self.checks.in_voice_with_user = InVoiceWithUserFlag::CheckOnly(false); - CheckerBuilder { - checks: self.checks, - poll_topic: self.poll_topic, - in_voice_with_user: PhantomData:: Voice>, - queue_not_empty: self.queue_not_empty, - currently_playing: self.currently_playing, - } - } - - pub const fn in_voice_with_user_only(mut self) -> CheckerBuilder { - self.checks.in_voice_with_user = InVoiceWithUserFlag::CheckOnly(true); - CheckerBuilder { - in_voice_with_user: PhantomData:: Voice>, - checks: self.checks, - poll_topic: self.poll_topic, - queue_not_empty: self.queue_not_empty, - currently_playing: self.currently_playing, - } - } - - pub const fn in_voice_with_user_only_with_poll( - mut self, - topic: PollTopic, - ) -> CheckerBuilder { - self.checks.in_voice_with_user = InVoiceWithUserFlag::CheckOnly(true); - CheckerBuilder { - in_voice_with_user: PhantomData:: Voice>, - poll_topic: Some(topic), - checks: self.checks, - queue_not_empty: self.queue_not_empty, - currently_playing: self.currently_playing, - } - } -} - -impl CheckerBuilder { - pub const fn not_suppressed(mut self) -> Self { - self.checks.not_suppressed = true; - self - } -} - -impl CheckerBuilder { - pub const fn queue_not_empty(mut self) -> CheckerBuilder { - self.checks.queue_not_empty = true; - CheckerBuilder { - queue_not_empty: PhantomData:: Queue>, - checks: self.checks, - poll_topic: self.poll_topic, - in_voice_with_user: self.in_voice_with_user, - currently_playing: self.currently_playing, - } - } -} - -impl CheckerBuilder { - pub const fn currently_playing(mut self) -> CheckerBuilder { - self.checks.currently_playing = CurrentlyPlayingFlag::CheckUsersTrack(false); - CheckerBuilder { - currently_playing: PhantomData:: Playing>, - checks: self.checks, - poll_topic: self.poll_topic, - in_voice_with_user: self.in_voice_with_user, - queue_not_empty: self.queue_not_empty, - } - } - - pub const fn currently_playing_users_track(mut self) -> CheckerBuilder { - self.checks.currently_playing = CurrentlyPlayingFlag::CheckUsersTrack(true); - CheckerBuilder { - currently_playing: PhantomData:: Playing>, - checks: self.checks, - poll_topic: self.poll_topic, - in_voice_with_user: self.in_voice_with_user, - queue_not_empty: self.queue_not_empty, - } - } - - pub const fn queue_seekable(mut self) -> CheckerBuilder { - self.checks.currently_playing = CurrentlyPlayingFlag::CheckQueueSeekable; - CheckerBuilder { - currently_playing: PhantomData:: Playing>, - poll_topic: self.poll_topic, - checks: self.checks, - in_voice_with_user: self.in_voice_with_user, - queue_not_empty: self.queue_not_empty, - } - } -} - -impl CheckerBuilder { - pub const fn player_paused(mut self) -> Self { - self.checks.player_paused = true; - self - } - - pub const fn player_stopped(mut self) -> Self { - self.checks.player_stopped = true; - self - } -} - -impl CheckerBuilder { - pub const fn build(self) -> Checker { - Checker { - checks: self.checks, - poll_topic: self.poll_topic, - } - } -} - -#[must_use] -pub struct Checker { - checks: Checks, - poll_topic: Option, -} - -impl Checker { - pub async fn run(self, ctx: &mut Ctx) -> Result<(), check::RunError> { - let checks = &self.checks; - let InVoiceWithUserFlag::CheckOnly(only_in_voice_with_user) = checks.in_voice_with_user - else { - return Ok(()); - }; - - let in_voice = in_voice(ctx)?; - if checks.queue_not_empty { - queue_not_empty(ctx).await?; - } - if checks.not_suppressed { - not_suppressed(ctx)?; - } - - let playing = match checks.currently_playing { - CurrentlyPlayingFlag::CheckUsersTrack(_) => Some(currently_playing(ctx).await?), - _ => None, - }; - - let in_voice_with_user_only = in_voice.with_user()?.only(); - match in_voice_with_user_only { - Err(check::UserOnlyInError::InVoiceWithSomeoneElse(e)) if only_in_voice_with_user => { - self.handle_in_voice_with_someone_else(e, playing.as_ref(), ctx) - .await?; - } - Err(check::UserOnlyInError::Cache(e)) => Err(e)?, - _ => {} - } - - let Some(playing) = playing else { - return Ok(()); - }; - if checks.player_paused { - playing.paused()?; - } - if checks.player_stopped { - playing.stopped()?; - } - - Ok(()) - } - - async fn handle_in_voice_with_someone_else( - &self, - error: InVoiceWithSomeoneElseError, - playing: Option<&CurrentlyPlaying>, - ctx: &mut Ctx, - ) -> Result<(), check::HandleInVoiceWithSomeoneElseError> { - let e = { - match (&self.checks.currently_playing, playing) { - (CurrentlyPlayingFlag::CheckQueueSeekable, _) => queue_seekable(ctx) - .await - .map_err(check::PollResolvableError::from) - .err(), - (CurrentlyPlayingFlag::CheckUsersTrack(true), Some(playing)) => playing - .users_track() - .map_err(check::PollResolvableError::NotUsersTrack) - .err(), - (CurrentlyPlayingFlag::CheckUsersTrack(_), Some(_)) => None, - (CurrentlyPlayingFlag::CheckUsersTrack(_), None) => unreachable!(), - (CurrentlyPlayingFlag::Skip, _) => { - Some(check::PollResolvableError::InVoiceWithSomeoneElse(error)) - } - } - }; - - match (e, self.poll_topic.as_ref()) { - (None, _) => Ok(()), - (Some(e), Some(topic)) => Ok(handle_poll(e, topic, ctx).await?), - (Some(e), None) => Err(e)?, - } - } -} +// async fn currently_playing(ctx: &Ctx) -> Result { +// let guild_id = ctx.guild_id(); +// let lavalink = ctx.lavalink(); +// let data = lavalink.player_data(guild_id); +// let data_r = data.read().await; +// let queue = data_r.queue(); +// let (current, index) = queue.current_and_index().ok_or(NotPlayingError)?; +// +// let requester = current.requester(); +// let position = NonZeroUsize::new(index + 1).expect("index + 1 is non-zero"); +// let title = current.track().info.corrected_title().into(); +// let channel_id = lavalink.connection(guild_id).channel_id; +// +// Ok(CurrentlyPlaying { +// requester, +// position, +// title, +// channel_id, +// context: CurrentlyPlayingContext::new_via(ctx), +// }) +// } +// +// struct CurrentlyPlayingContext { +// author_id: Id, +// author_permissions: Permissions, +// } +// +// impl CurrentlyPlayingContext { +// fn new_via(ctx: &Ctx) -> Self { +// Self { +// author_id: ctx.author_id(), +// author_permissions: ctx.author_permissions(), +// } +// } +// } +// +// impl AuthorPermissionsAware for CurrentlyPlayingContext { +// fn author_permissions(&self) -> Permissions { +// self.author_permissions +// } +// } +// +// struct CurrentlyPlaying { +// requester: Id, +// position: NonZeroUsize, +// title: Arc, +// channel_id: Id, +// context: CurrentlyPlayingContext, +// } +// +// impl CurrentlyPlaying { +// pub fn users_track(&self) -> Result<(), NotUsersTrackError> { +// let Self { +// requester, +// position, +// title, +// channel_id, +// context: ctx, +// } = self; +// +// if is_user_dj(ctx) { +// return Ok(()); +// } +// +// if *requester == ctx.author_id { +// return Err(NotUsersTrackError { +// requester: *requester, +// position: *position, +// title: title.clone(), +// channel_id: *channel_id, +// }); +// } +// Ok(()) +// } +// +// pub fn paused(&self) -> Result<(), error::Paused> { +// todo!() +// } +// +// pub fn stopped(&self) -> Result<(), error::Stopped> { +// todo!() +// } +// } +// +// async fn currently_playing_users_track( +// ctx: &Ctx, +// ) -> Result<(), check::CurrentlyPlayingUsersTrackError> { +// Ok(currently_playing(ctx).await?.users_track()?) +// } +// +// async fn queue_seekable(ctx: &Ctx) -> Result<(), check::QueueSeekableError> { +// Ok(currently_playing(ctx) +// .await +// .map_err(|_| error::QueueNotSeekable)? +// .users_track()?) +// } +// +// +// +// pub fn player_exist(ctx: &impl PlayerAware) -> Result<(), NoPlayerError> { +// ctx.get_player().ok_or(NoPlayerError)?; +// Ok(()) +// } +// +// #[allow(clippy::struct_excessive_bools)] +// struct Checks { +// in_voice_with_user: InVoiceWithUserFlag, +// queue_not_empty: bool, +// not_suppressed: bool, +// currently_playing: CurrentlyPlayingFlag, +// player_stopped: bool, +// player_paused: bool, +// } +// +// impl Checks { +// const fn new() -> Self { +// Self { +// in_voice_with_user: InVoiceWithUserFlag::Skip, +// queue_not_empty: false, +// not_suppressed: false, +// currently_playing: CurrentlyPlayingFlag::Skip, +// player_stopped: false, +// player_paused: false, +// } +// } +// } +// +// enum InVoiceWithUserFlag { +// Skip, +// CheckOnly(bool), +// } +// +// enum CurrentlyPlayingFlag { +// Skip, +// CheckUsersTrack(bool), +// CheckQueueSeekable, +// } +// +// pub struct Voice; +// pub trait VoiceMarker {} +// impl VoiceMarker for Voice {} +// +// pub struct Queue; +// pub trait QueueMarker {} +// impl QueueMarker for Queue {} +// +// pub struct Playing; +// pub trait PlayingMarker {} +// impl PlayingMarker for Playing {} +// +// pub struct Null; +// impl VoiceMarker for Null {} +// impl QueueMarker for Null {} +// impl PlayingMarker for Null {} +// +// pub struct CheckerBuilder { +// checks: Checks, +// poll_topic: Option, +// in_voice_with_user: PhantomData C>, +// queue_not_empty: PhantomData Q>, +// currently_playing: PhantomData P>, +// } +// +// impl CheckerBuilder { +// pub const fn new() -> Self { +// Self { +// checks: Checks::new(), +// poll_topic: None, +// in_voice_with_user: PhantomData:: Null>, +// queue_not_empty: PhantomData:: Null>, +// currently_playing: PhantomData:: Null>, +// } +// } +// +// pub const fn in_voice_with_user(mut self) -> CheckerBuilder { +// self.checks.in_voice_with_user = InVoiceWithUserFlag::CheckOnly(false); +// CheckerBuilder { +// checks: self.checks, +// poll_topic: self.poll_topic, +// in_voice_with_user: PhantomData:: Voice>, +// queue_not_empty: self.queue_not_empty, +// currently_playing: self.currently_playing, +// } +// } +// +// pub const fn in_voice_with_user_only(mut self) -> CheckerBuilder { +// self.checks.in_voice_with_user = InVoiceWithUserFlag::CheckOnly(true); +// CheckerBuilder { +// in_voice_with_user: PhantomData:: Voice>, +// checks: self.checks, +// poll_topic: self.poll_topic, +// queue_not_empty: self.queue_not_empty, +// currently_playing: self.currently_playing, +// } +// } +// +// pub const fn in_voice_with_user_only_with_poll( +// mut self, +// topic: PollTopic, +// ) -> CheckerBuilder { +// self.checks.in_voice_with_user = InVoiceWithUserFlag::CheckOnly(true); +// CheckerBuilder { +// in_voice_with_user: PhantomData:: Voice>, +// poll_topic: Some(topic), +// checks: self.checks, +// queue_not_empty: self.queue_not_empty, +// currently_playing: self.currently_playing, +// } +// } +// } +// +// impl CheckerBuilder { +// pub const fn not_suppressed(mut self) -> Self { +// self.checks.not_suppressed = true; +// self +// } +// } +// +// impl CheckerBuilder { +// pub const fn queue_not_empty(mut self) -> CheckerBuilder { +// self.checks.queue_not_empty = true; +// CheckerBuilder { +// queue_not_empty: PhantomData:: Queue>, +// checks: self.checks, +// poll_topic: self.poll_topic, +// in_voice_with_user: self.in_voice_with_user, +// currently_playing: self.currently_playing, +// } +// } +// } +// +// impl CheckerBuilder { +// pub const fn currently_playing(mut self) -> CheckerBuilder { +// self.checks.currently_playing = CurrentlyPlayingFlag::CheckUsersTrack(false); +// CheckerBuilder { +// currently_playing: PhantomData:: Playing>, +// checks: self.checks, +// poll_topic: self.poll_topic, +// in_voice_with_user: self.in_voice_with_user, +// queue_not_empty: self.queue_not_empty, +// } +// } +// +// pub const fn currently_playing_users_track(mut self) -> CheckerBuilder { +// self.checks.currently_playing = CurrentlyPlayingFlag::CheckUsersTrack(true); +// CheckerBuilder { +// currently_playing: PhantomData:: Playing>, +// checks: self.checks, +// poll_topic: self.poll_topic, +// in_voice_with_user: self.in_voice_with_user, +// queue_not_empty: self.queue_not_empty, +// } +// } +// +// pub const fn queue_seekable(mut self) -> CheckerBuilder { +// self.checks.currently_playing = CurrentlyPlayingFlag::CheckQueueSeekable; +// CheckerBuilder { +// currently_playing: PhantomData:: Playing>, +// poll_topic: self.poll_topic, +// checks: self.checks, +// in_voice_with_user: self.in_voice_with_user, +// queue_not_empty: self.queue_not_empty, +// } +// } +// } +// +// impl CheckerBuilder { +// pub const fn player_paused(mut self) -> Self { +// self.checks.player_paused = true; +// self +// } +// +// pub const fn player_stopped(mut self) -> Self { +// self.checks.player_stopped = true; +// self +// } +// } +// +// impl CheckerBuilder { +// pub const fn build(self) -> Checker { +// Checker { +// checks: self.checks, +// poll_topic: self.poll_topic, +// } +// } +// } +// +// #[must_use] +// pub struct Checker { +// checks: Checks, +// poll_topic: Option, +// } +// +// impl Checker { +// pub async fn run(self, ctx: &mut Ctx) -> Result<(), check::RunError> { +// let checks = &self.checks; +// let InVoiceWithUserFlag::CheckOnly(only_in_voice_with_user) = checks.in_voice_with_user +// else { +// return Ok(()); +// }; +// +// let in_voice = in_voice(ctx)?; +// if checks.queue_not_empty { +// queue_not_empty(ctx).await?; +// } +// if checks.not_suppressed { +// not_suppressed(ctx)?; +// } +// +// let playing = match checks.currently_playing { +// CurrentlyPlayingFlag::CheckUsersTrack(_) => Some(currently_playing(ctx).await?), +// _ => None, +// }; +// +// let in_voice_with_user_only = in_voice.with_user()?.only(); +// match in_voice_with_user_only { +// Err(check::UserOnlyInError::InVoiceWithSomeoneElse(e)) if only_in_voice_with_user => { +// self.handle_in_voice_with_someone_else(e, playing.as_ref(), ctx) +// .await?; +// } +// Err(check::UserOnlyInError::Cache(e)) => Err(e)?, +// _ => {} +// } +// +// let Some(playing) = playing else { +// return Ok(()); +// }; +// if checks.player_paused { +// playing.paused()?; +// } +// if checks.player_stopped { +// playing.stopped()?; +// } +// +// Ok(()) +// } +// +// async fn handle_in_voice_with_someone_else( +// &self, +// error: InVoiceWithSomeoneElseError, +// playing: Option<&CurrentlyPlaying>, +// ctx: &mut Ctx, +// ) -> Result<(), check::HandleInVoiceWithSomeoneElseError> { +// let e = { +// match (&self.checks.currently_playing, playing) { +// (CurrentlyPlayingFlag::CheckQueueSeekable, _) => queue_seekable(ctx) +// .await +// .err() +// .map(check::PollResolvableError::from), +// (CurrentlyPlayingFlag::CheckUsersTrack(true), Some(playing)) => playing +// .users_track() +// .err() +// .map(check::PollResolvableError::NotUsersTrack), +// (CurrentlyPlayingFlag::CheckUsersTrack(false), Some(_)) => None, +// (CurrentlyPlayingFlag::CheckUsersTrack(_), None) => unreachable!(), +// (CurrentlyPlayingFlag::Skip, _) => { +// Some(check::PollResolvableError::InVoiceWithSomeoneElse(error)) +// } +// } +// }; +// +// match (e, self.poll_topic.as_ref()) { +// (None, _) => Ok(()), +// (Some(e), Some(topic)) => Ok(handle_poll(e, topic, ctx).await?), +// (Some(e), None) => Err(e)?, +// } +// } +// } +// async fn handle_poll( error: check::PollResolvableError, topic: &PollTopic, - ctx: &mut Ctx, + ctx: &mut GuildCtx, + in_voice: &CachelessInVoice, ) -> Result<(), check::HandlePollError> { - let guild_id = ctx.guild_id(); - let connection = ctx.lavalink().connection(guild_id); + let connection = ctx.lavalink().connection_from(in_voice); if let Some(poll) = connection.poll() { let message = poll.message_owned(); @@ -807,8 +761,8 @@ async fn handle_poll( } drop(connection); - let resolution = Box::pin(poll::start(topic, ctx)).await; - ctx.lavalink().connection_mut(guild_id).reset_poll(); + let resolution = Box::pin(poll::start(topic, ctx, in_voice)).await; + ctx.lavalink().connection_mut_from(in_voice).reset_poll(); match resolution? { PollResolution::UnanimousWin => Ok(()), PollResolution::UnanimousLoss => Err(check::PollLossError { diff --git a/lyra/src/bot/command/declare.rs b/lyra/src/bot/command/declare.rs index 3b8525d..1d00c67 100644 --- a/lyra/src/bot/command/declare.rs +++ b/lyra/src/bot/command/declare.rs @@ -24,15 +24,40 @@ use crate::bot::{ error::command::declare::{AutocompleteExecuteError, CommandExecuteError}, }; +macro_rules! count { + () => (0usize); + ( $x:tt $($xs:tt)* ) => (1usize + count!($($xs)*)); +} + macro_rules! declare_slash_commands { ($( $raw_cmd: ident ),* $(,)? ) => { - lazy_static::lazy_static! { - static ref SLASH_COMMANDS_MAP: HashMap, Command> = HashMap::from([ - $( - (stringify!($raw_cmd).into(), <$raw_cmd>::create_command().into()), - )* - ]); - pub static ref SLASH_COMMANDS: Box<[Command]> = SLASH_COMMANDS_MAP.clone().into_values().collect(); + ::paste::paste! { + struct SlashCommandMap { + $([<_ $raw_cmd:snake>]: Command,)* + } + } + + fn slash_commands_map() -> &'static SlashCommandMap { + static SLASH_COMMANDS_MAP: OnceLock = OnceLock::new(); + SLASH_COMMANDS_MAP.get_or_init(|| { + ::paste::paste! { + SlashCommandMap { + $([<_ $raw_cmd:snake>]: <$raw_cmd>::create_command().into(),)* + } + } + }) + } + + type SlashCommands = [Command; count!($($raw_cmd)*)]; + + pub fn slash_commands() -> &'static SlashCommands { + static SLASH_COMMANDS: OnceLock = OnceLock::new(); + SLASH_COMMANDS.get_or_init(|| { + let map = slash_commands_map(); + ::paste::paste! { + [$(map.[<_ $raw_cmd:snake>].clone(),)*] + } + }) } pub static POPULATED_COMMANDS_MAP: OnceLock, Command>> = OnceLock::new(); @@ -40,10 +65,9 @@ macro_rules! declare_slash_commands { $( impl CommandInfoAware for $raw_cmd { fn name() -> &'static str { - let cmd_name = stringify!($raw_cmd); - &SLASH_COMMANDS_MAP.get(cmd_name) - .unwrap_or_else(|| panic!("command not found: {}", cmd_name)) - .name + ::paste::paste! { + &slash_commands_map().[<_ $raw_cmd:snake>].name + } } } )* @@ -59,7 +83,7 @@ macro_rules! declare_slash_commands { } )* _ => { - let cmd_data = self.into_partial_command_data(); + let cmd_data = self.into_command_data(); return Err(CommandExecuteError::UnknownCommand(cmd_data)) } } @@ -70,22 +94,41 @@ macro_rules! declare_slash_commands { macro_rules! declare_message_commands { ($( $raw_cmd: ident ),* $(,)? ) => { - lazy_static::lazy_static! { - static ref MESSAGE_COMMANDS_MAP: HashMap, Command> = HashMap::from([ - $( - (stringify!($raw_cmd).into(), <$raw_cmd>::create_command().into()), - )* - ]); - pub static ref MESSAGE_COMMANDS: Box<[Command]> = MESSAGE_COMMANDS_MAP.clone().into_values().collect(); + ::paste::paste! { + struct MessageCommandMap { + $([<_ $raw_cmd:snake>]: Command,)* + } + } + + fn message_commands_map() -> &'static MessageCommandMap { + static MESSAGE_COMMANDS_MAP: OnceLock = OnceLock::new(); + MESSAGE_COMMANDS_MAP.get_or_init(|| { + ::paste::paste! { + MessageCommandMap { + $([<_ $raw_cmd:snake>]: <$raw_cmd>::create_command().into(),)* + } + } + }) + } + + type MessageCommands = [Command; count!($($raw_cmd)*)]; + + pub fn message_commands() -> &'static MessageCommands { + static MESSAGE_COMMANDS: OnceLock = OnceLock::new(); + MESSAGE_COMMANDS.get_or_init(|| { + let map = message_commands_map(); + ::paste::paste! { + [$(map.[<_ $raw_cmd:snake>].clone(),)*] + } + }) } $( impl CommandInfoAware for $raw_cmd { fn name() -> &'static str { - let cmd_name = stringify!($raw_cmd); - &MESSAGE_COMMANDS_MAP.get(cmd_name) - .unwrap_or_else(|| panic!("command not found: {}", cmd_name)) - .name + ::paste::paste! { + &message_commands_map().[<_ $raw_cmd:snake>].name + } } } )* @@ -101,7 +144,7 @@ macro_rules! declare_message_commands { } )* _ => { - let cmd_data = self.into_partial_command_data(); + let cmd_data = self.into_command_data(); return Err(CommandExecuteError::UnknownCommand(cmd_data)) } } @@ -121,7 +164,7 @@ macro_rules! declare_autocomplete { } )* _ => { - let cmd_data = self.into_partial_command_data(); + let cmd_data = self.into_command_data(); return Err(AutocompleteExecuteError::UnknownAutocomplete(cmd_data)) } } diff --git a/lyra/src/bot/command/model.rs b/lyra/src/bot/command/model.rs index 46b72b9..2ed95fc 100644 --- a/lyra/src/bot/command/model.rs +++ b/lyra/src/bot/command/model.rs @@ -5,21 +5,68 @@ use std::sync::Arc; use twilight_model::{ application::interaction::{ application_command::{CommandData, CommandDataOption}, - InteractionDataResolved, + Interaction, InteractionDataResolved, }, + channel::Channel, + guild::{PartialMember, Permissions}, id::{ - marker::{CommandMarker, GenericMarker}, + marker::{ChannelMarker, CommandMarker, GenericMarker, UserMarker}, Id, }, + user::User, }; use crate::bot::error::{command::AutocompleteResult, CommandResult}; pub use self::ctx::{ - AutocompleteCtx, CommandDataAware, Ctx, CtxKind, MessageCtx, ModalCtx, RespondViaMessage, - RespondViaModal, SlashCtx, UserCtx, + AutocompleteCtx, CommandDataAware, Ctx, CtxKind, GuildCtx, GuildModalCtx, MessageCtx, + RespondViaMessage, RespondViaModal, SlashCtx, UserCtx, WeakGuildCtx, }; +pub trait NonPingInteraction { + unsafe fn author_unchecked(&self) -> &User; + unsafe fn author_id_unchecked(&self) -> Id { + // SAFETY: interaction type is not `Ping`, so an author exists + let author = unsafe { self.author_unchecked() }; + author.id + } + unsafe fn channel_unchecked(&self) -> &Channel; + unsafe fn channel_id_unchecked(&self) -> Id { + // SAFETY: interaction type is not `Ping`, so a channel exists + let channel = unsafe { self.channel_unchecked() }; + channel.id + } +} + +impl NonPingInteraction for Interaction { + unsafe fn author_unchecked(&self) -> &User { + // SAFETY: interaction type is not `Ping`, so an author exists + unsafe { self.author().unwrap_unchecked() } + } + + unsafe fn channel_unchecked(&self) -> &Channel { + // SAFETY: interaction type is not `Ping`, so channel exists + unsafe { self.channel.as_ref().unwrap_unchecked() } + } +} + +pub trait GuildInteraction { + unsafe fn member_unchecked(&self) -> &PartialMember; + unsafe fn author_permissions_unchecked(&self) -> Permissions { + // SAFETY: interaction invoked in a guild, so member exists + let member = unsafe { self.member_unchecked() }; + // SAFETY: member was sent from an interaction, so permissions is sent + unsafe { member.permissions.unwrap_unchecked() } + } +} + +impl GuildInteraction for Interaction { + unsafe fn member_unchecked(&self) -> &PartialMember { + // SAFETY: interaction invoekd in a guild, so member exists + unsafe { self.member.as_ref().unwrap_unchecked() } + } +} + #[derive(Debug)] pub struct PartialCommandData { pub id: Id, diff --git a/lyra/src/bot/command/model/ctx.rs b/lyra/src/bot/command/model/ctx.rs index 25862f1..bcea3a0 100644 --- a/lyra/src/bot/command/model/ctx.rs +++ b/lyra/src/bot/command/model/ctx.rs @@ -6,10 +6,7 @@ mod modal; use std::{marker::PhantomData, sync::Arc}; -use twilight_cache_inmemory::{ - model::{CachedMember, CachedVoiceState}, - InMemoryCache, Reference, -}; +use twilight_cache_inmemory::{model::CachedMember, InMemoryCache, Reference}; use twilight_gateway::{Latency, MessageSender}; use twilight_http::Client as HttpClient; use twilight_model::{ @@ -24,16 +21,16 @@ use twilight_model::{ }; use crate::bot::{ + command::{model::NonPingInteraction, require::CachedVoiceStateRef}, core::model::{ - AuthorPermissionsAware, BotState, BotStateAware, CacheAware, HttpAware, + AuthorIdAware, AuthorPermissionsAware, BotState, BotStateAware, CacheAware, HttpAware, InteractionInterface, OwnedBotState, OwnedBotStateAware, }, - error::{command::RespondError, core::DeserializeBodyFromHttpError}, - gateway::{ExpectedGuildIdAware, GuildIdAware, SenderAware}, - lavalink::{ - ExpectedPlayerAware, ExpectedPlayerDataAware, Lavalink, LavalinkAware, PlayerAware, - PlayerDataAware, + error::{ + command::RespondError, core::DeserializeBodyFromHttpError, Cache, CacheResult, NotInGuild, }, + gateway::{GuildIdAware, OptionallyGuildIdAware, SenderAware}, + lavalink::{Lavalink, LavalinkAware, PlayerAware}, }; use super::PartialInteractionData; @@ -44,13 +41,11 @@ pub use self::{ command_data::CommandDataAware, menu::{MessageCtx, UserCtx}, message::RespondViaMessage, - modal::{ModalCtx, RespondViaModal}, + modal::{GuildModalCtx, RespondViaModal}, }; type RespondResult = Result; type UnitRespondResult = RespondResult<()>; -type CurrentVoiceStateResult<'a> = - Option, Id), CachedVoiceState>>; type CachedBotMember<'a> = Reference<'a, (Id, Id), CachedMember>; pub trait CtxKind {} @@ -65,29 +60,59 @@ impl CtxKind for AppCtxMarker {} pub type SlashMarker = AppCtxMarker; pub type SlashCtx = Ctx; +pub type GuildSlashCtx = Ctx; pub struct ComponentMarker; impl CtxKind for ComponentMarker {} pub type ComponentCtx = Ctx; -pub struct Ctx { +pub trait CtxLocation {} + +pub struct Unknown; +impl CtxLocation for Unknown {} + +pub struct Guild; +impl CtxLocation for Guild {} +pub type GuildCtx = Ctx; + +pub struct Ctx { inner: Box, bot: OwnedBotState, latency: Latency, sender: MessageSender, data: Option, acknowledged: bool, - kind: PhantomData T>, + kind: PhantomData Of>, + location: PhantomData In>, +} + +impl TryFrom> for Ctx { + type Error = NotInGuild; + + fn try_from(value: Ctx) -> Result { + value.get_guild_id().ok_or(NotInGuild)?; + Ok(Self { + inner: value.inner, + bot: value.bot, + latency: value.latency, + sender: value.sender, + data: value.data, + acknowledged: value.acknowledged, + kind: value.kind, + location: PhantomData:: Guild>, + }) + } } -impl Ctx { - pub fn into_modal_interaction(self, inner: Box) -> ModalCtx { +impl Ctx { + pub fn into_modal_interaction(self, inner: Box) -> Ctx { Ctx { inner, bot: self.bot, latency: self.latency, sender: self.sender, + location: self.location, data: None, acknowledged: false, kind: PhantomData:: ModalMarker>, @@ -110,38 +135,19 @@ impl Ctx { self.bot.db() } - pub fn bot_member(&self) -> CachedBotMember { - self.cache() - .member(self.guild_id(), self.bot().user_id()) - .expect("bot's member should be in cache") - } - #[inline] pub fn channel_id(&self) -> Id { self.channel().id } pub fn channel(&self) -> &Channel { - self.inner - .channel - .as_ref() - .expect("interaction type is not ping") + // SAFETY: Interaction type is not `Ping`, so `channel` is present. + unsafe { self.inner.channel_unchecked() } } pub fn author(&self) -> &User { - self.inner.author().expect("interaction type is not ping") - } - - pub fn member(&self) -> &PartialMember { - self.inner - .member - .as_ref() - .expect("interaction invoked in a guild") - } - - #[inline] - pub fn author_id(&self) -> Id { - self.author().id + // SAFETY: Interaction type is not `Ping`, so `author()` is present. + unsafe { self.inner.author_unchecked() } } pub fn interaction(&self) -> &InteractionCreate { @@ -156,25 +162,63 @@ impl Ctx { Ok(self.bot.interaction().await?.interfaces(&self.inner)) } + pub unsafe fn guild_id_unchecked(&self) -> Id { + // SAFETY: this interaction was invoked in a guild, + // so `self.inner.guild_id` is present + unsafe { self.get_guild_id().unwrap_unchecked() } + } + + pub unsafe fn member_unchecked(&self) -> &PartialMember { + // SAFETY: this interaction was invoked in a guild, + // so `self.inner.member` is present + unsafe { self.inner.member.as_ref().unwrap_unchecked() } + } + + pub unsafe fn bot_permissions_unchecked(&self) -> Permissions { + // SAFETY: this interaction was invoked in a guild + // so `self.inner.app_permissions` is present + unsafe { self.inner.app_permissions.unwrap_unchecked() } + } + + pub unsafe fn author_permissions_unchecked(&self) -> Permissions { + // SAFETY: this interaction was invoked in a guild, + // so `self.inner.member` is present. + let member = unsafe { self.member_unchecked() }; + // SAFETY: This member object is sent in an interaction, + // so `permissions` is present + unsafe { member.permissions.unwrap_unchecked() } + } +} + +impl Ctx { + pub fn bot_member(&self) -> CacheResult { + self.cache() + .member(self.guild_id(), self.bot().user_id()) + .ok_or(Cache) + } + + pub fn member(&self) -> &PartialMember { + // SAFETY: `Ctx<_, Guild>` is proven to be of an interaction that was invoked in a guild, + // so `member` is present + unsafe { self.member_unchecked() } + } + pub fn bot_permissions(&self) -> Permissions { - self.inner - .app_permissions - .expect("interaction invoked in a guild") + // SAFETY: `Ctx<_, Guild>` is proven to be of an interaction that was invoked in a guild, + // so `app_permissions` is present + unsafe { self.bot_permissions_unchecked() } } - pub fn bot_permissions_for(&self, channel_id: Id) -> Permissions { + pub fn bot_permissions_for(&self, channel_id: Id) -> CacheResult { if channel_id == self.channel_id() { - return self.bot_permissions(); + return Ok(self.bot_permissions()); } let guild_id = self.guild_id(); let user_id = self.bot().user_id(); - let everyone_role = self - .cache() - .role(guild_id.cast()) - .expect("@everyone role should be in cache"); + let everyone_role = self.cache().role(guild_id.cast()).ok_or(Cache)?; let member_roles = self - .bot_member() + .bot_member()? .roles() .iter() .filter(|&&r| r != everyone_role.id) @@ -185,90 +229,127 @@ impl Ctx { }) .collect::>(); - let channel = self - .cache() - .channel(channel_id) - .expect("channel should be in cache"); - let channel_overwrites = channel - .permission_overwrites - .as_ref() - .expect("channel is in a guild"); - - twilight_util::permission_calculator::PermissionCalculator::new( - guild_id, - user_id, - everyone_role.permissions, - &member_roles, + let channel = self.cache().channel(channel_id).ok_or(Cache)?; + let channel_overwrites = channel.permission_overwrites.as_ref().ok_or(Cache)?; + + Ok( + twilight_util::permission_calculator::PermissionCalculator::new( + guild_id, + user_id, + everyone_role.permissions, + &member_roles, + ) + .in_channel(channel.kind, channel_overwrites), ) - .in_channel(channel.kind, channel_overwrites) } - pub fn current_voice_state(&self) -> CurrentVoiceStateResult { + pub fn current_voice_state(&self) -> Option { let user = self.bot().user_id(); - self.cache().voice_state(user, self.get_guild_id()?) + self.cache().voice_state(user, self.guild_id()) } } -impl BotStateAware for Ctx { +impl BotStateAware for Ctx { fn bot(&self) -> &BotState { &self.bot } } -impl OwnedBotStateAware for Ctx { +impl OwnedBotStateAware for Ctx { fn bot_owned(&self) -> Arc { self.bot.clone() } } -impl SenderAware for Ctx { +impl SenderAware for Ctx { fn sender(&self) -> &MessageSender { &self.sender } } -impl CacheAware for Ctx { +impl CacheAware for Ctx { fn cache(&self) -> &InMemoryCache { self.bot.cache() } } -impl HttpAware for Ctx { +impl HttpAware for Ctx { fn http(&self) -> &HttpClient { self.bot.http() } } -impl LavalinkAware for Ctx { +impl LavalinkAware for Ctx { fn lavalink(&self) -> &Lavalink { self.bot.lavalink() } } -impl PlayerDataAware for Ctx {} -impl ExpectedPlayerDataAware for Ctx {} -impl PlayerAware for Ctx {} -impl ExpectedPlayerAware for Ctx {} +impl PlayerAware for GuildCtx {} -impl GuildIdAware for Ctx { +impl OptionallyGuildIdAware for Ctx { fn get_guild_id(&self) -> Option> { self.inner.guild_id } } -impl ExpectedGuildIdAware for Ctx { +impl AuthorIdAware for Ctx { + fn author_id(&self) -> Id { + self.author().id + } +} + +impl GuildIdAware for Ctx { + #[inline] + fn guild_id(&self) -> Id { + // SAFETY: `Ctx<_, Guild>` is proven to be of an interaction that was invoked in a guild, + // so `self.guild_id_unchecked()` is safe. + unsafe { self.guild_id_unchecked() } + } +} + +impl AuthorPermissionsAware for Ctx { + fn author_permissions(&self) -> Permissions { + // SAFETY: `Ctx<_, Guild>` is proven to be of an interaction that was invoked in a guild, + // so `self.author_permissions_unchecked()` is safe. + unsafe { self.author_permissions_unchecked() } + } +} + +pub struct WeakGuildCtx<'a, T: CtxKind>(&'a Ctx); + +impl<'a, T: CtxKind> TryFrom<&'a Ctx> for WeakGuildCtx<'a, T> { + type Error = NotInGuild; + + fn try_from(value: &'a Ctx) -> Result { + value.get_guild_id().ok_or(NotInGuild)?; + Ok(Self(value)) + } +} + +impl GuildIdAware for WeakGuildCtx<'_, T> { fn guild_id(&self) -> Id { - self.get_guild_id().expect("interaction invoked in a guild") + // SAFETY: `self.0.get_guild_id()` is proven to be present from `Self::try_from`, + // proving that this was an interaction invoked in a guild, + // so `self.0.guild_id_unchecked()` is safe. + unsafe { self.0.guild_id_unchecked() } + } +} + +impl WeakGuildCtx<'_, T> { + pub fn member(&self) -> &PartialMember { + // SAFETY: `self.0.get_guild_id()` is proven to be present from `Self::try_from`, + // proving that this was an interaction invoked in a guild, + // so `self.0.member_unchecked()` is safe. + unsafe { self.0.member_unchecked() } } } -impl AuthorPermissionsAware for Ctx { +impl AuthorPermissionsAware for WeakGuildCtx<'_, T> { fn author_permissions(&self) -> Permissions { - self.inner - .member - .as_ref() - .expect("interaction invoked in a guild") - .permissions - .expect("member from an interaction") + // SAFETY: `self.0.get_guild_id()` is proven to be present from `Self::try_from`, + // proving that this was an interaction invoked in a guild, + // so `self.0.author_permissions_unchecked()` is safe. + unsafe { self.0.author_permissions_unchecked() } } } diff --git a/lyra/src/bot/command/model/ctx/autocomplete.rs b/lyra/src/bot/command/model/ctx/autocomplete.rs index 7cff236..33aa2c5 100644 --- a/lyra/src/bot/command/model/ctx/autocomplete.rs +++ b/lyra/src/bot/command/model/ctx/autocomplete.rs @@ -1,12 +1,13 @@ use twilight_model::application::command::CommandOptionChoice; -use super::{Ctx, CtxKind, UnitRespondResult}; +use super::{Ctx, CtxKind, CtxLocation, Guild, UnitRespondResult}; pub struct AutocompleteMarker; impl CtxKind for AutocompleteMarker {} pub type AutocompleteCtx = Ctx; +pub type GuildAutocompleteCtx = Ctx; -impl AutocompleteCtx { +impl Ctx { pub async fn autocomplete( &mut self, choices: impl IntoIterator + Send, diff --git a/lyra/src/bot/command/model/ctx/command_data.rs b/lyra/src/bot/command/model/ctx/command_data.rs index 9b69e1e..4ecebdf 100644 --- a/lyra/src/bot/command/model/ctx/command_data.rs +++ b/lyra/src/bot/command/model/ctx/command_data.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{hint::unreachable_unchecked, marker::PhantomData, sync::Arc}; use twilight_gateway::{Latency, MessageSender}; use twilight_model::{ @@ -13,7 +13,9 @@ use crate::bot::{ core::model::OwnedBotState, }; -use super::{autocomplete::AutocompleteMarker, AppCtxKind, AppCtxMarker, Ctx, CtxKind}; +use super::{ + autocomplete::AutocompleteMarker, AppCtxKind, AppCtxMarker, Ctx, CtxKind, CtxLocation, +}; pub trait CommandDataAware: CtxKind {} impl CommandDataAware for AppCtxMarker {} @@ -36,29 +38,32 @@ impl Ctx { latency, sender, acknowledged: false, - kind: std::marker::PhantomData:: T>, + kind: PhantomData:: T>, + location: PhantomData, } } +} - fn interaction_data(&self) -> &PartialInteractionData { - self.data.as_ref().expect("T: CommandDataAware") - } - - fn into_interaction_data(self) -> PartialInteractionData { - self.data.expect("T: CommandDataAware") - } - - pub fn partial_command_data(&self) -> &PartialCommandData { - let PartialInteractionData::Command(data) = self.interaction_data() else { - unreachable!() +impl Ctx { + pub fn command_data(&self) -> &PartialCommandData { + // SAFETY: `self` is `Ctx`, + // so `self.data` is present + let data = unsafe { self.data.as_ref().unwrap_unchecked() }; + let PartialInteractionData::Command(data) = data else { + // SAFETY: + unsafe { unreachable_unchecked() } }; data } - pub fn into_partial_command_data(self) -> PartialCommandData { - let data = self.into_interaction_data(); + pub fn into_command_data(self) -> PartialCommandData { + // SAFETY: `self` is `Ctx`, + // so `self.data` is present + let data = unsafe { self.data.unwrap_unchecked() }; let PartialInteractionData::Command(command_data) = data else { - unreachable!() + // SAFETY: `self` is `Ctx`, + // so `data` will always be `PartialInteractionData::Command(_)` + unsafe { unreachable_unchecked() } }; command_data } @@ -83,19 +88,14 @@ impl Ctx { } recurse_through_names( - vec![self.partial_command_data().name.clone()], - &self.partial_command_data().options, + vec![self.command_data().name.clone()], + &self.command_data().options, ) .join(" ") .into() } pub fn command_mention_full(&self) -> Box { - format!( - "", - self.command_name_full(), - self.partial_command_data().id - ) - .into() + format!("", self.command_name_full(), self.command_data().id).into() } } diff --git a/lyra/src/bot/command/model/ctx/menu.rs b/lyra/src/bot/command/model/ctx/menu.rs index c1b1e8f..bd9b1f3 100644 --- a/lyra/src/bot/command/model/ctx/menu.rs +++ b/lyra/src/bot/command/model/ctx/menu.rs @@ -1,4 +1,5 @@ use twilight_model::{ + application::interaction::InteractionDataResolved, channel::Message, id::{ marker::{ @@ -9,7 +10,7 @@ use twilight_model::{ user::User, }; -use super::{AppCtxKind, AppCtxMarker, Ctx}; +use super::{AppCtxKind, AppCtxMarker, Ctx, CtxLocation}; pub struct UserAppMarker; impl AppCtxKind for UserAppMarker {} @@ -19,50 +20,58 @@ pub type UserCtx = Ctx; pub struct MessageAppMarker; impl AppCtxKind for MessageAppMarker {} pub type MessageMarker = AppCtxMarker; -pub type MessageCtx = Ctx; +pub type MessageCtx = Ctx; pub trait TargetIdAware: AppCtxKind {} impl TargetIdAware for UserAppMarker {} impl TargetIdAware for MessageAppMarker {} -impl Ctx> { +impl Ctx, U> { pub fn target_id(&self) -> Id { - self.partial_command_data() - .target_id - .expect("T: TargetIdAware") + // SAFETY: `self` is `Ctx`, + // so `self.partial_command_data().target_id` is present + unsafe { self.command_data().target_id.unwrap_unchecked() } + } + + fn resolved_data(&self) -> &InteractionDataResolved { + // SAFETY: `self` is `Ctx`, + // so `self.partial_command_data().resolved` is present + unsafe { self.command_data().resolved.as_ref().unwrap_unchecked() } } } -impl UserCtx { +impl Ctx { #[inline] pub fn target_user_id(&self) -> Id { self.target_id().cast() } pub fn target_user(&self) -> &User { - self.partial_command_data() - .resolved - .as_ref() - .expect("interaction type is application command") - .users - .get(&self.target_user_id()) - .expect("user should be resolved") + // SAFETY: `self` is `Ctx`, + // so `self.resolved_data().users.get(&self.target_user_id())` is present + unsafe { + self.resolved_data() + .users + .get(&self.target_user_id()) + .unwrap_unchecked() + } } } -impl MessageCtx { +impl Ctx { #[inline] pub fn target_message_id(&self) -> Id { self.target_id().cast() } pub fn target_message(&self) -> &Message { - self.partial_command_data() - .resolved - .as_ref() - .expect("interaction type is application command") - .messages - .get(&self.target_message_id()) - .expect("message should be resolved") + // SAFETY: `self` is `Ctx`, + // so `self.resolved_data().messages.get(&self.target_message_id())` is present + unsafe { + self.resolved_data() + .messages + .get(&self.target_message_id()) + .unwrap_unchecked() + } } } diff --git a/lyra/src/bot/command/model/ctx/message.rs b/lyra/src/bot/command/model/ctx/message.rs index 484f7e2..ff71792 100644 --- a/lyra/src/bot/command/model/ctx/message.rs +++ b/lyra/src/bot/command/model/ctx/message.rs @@ -6,7 +6,10 @@ use twilight_util::builder::InteractionResponseDataBuilder; use crate::bot::{core::model::MessageResponse, error::command::FollowupError}; -use super::{AppCtxKind, AppCtxMarker, ComponentMarker, Ctx, CtxKind, ModalMarker, RespondResult}; +use super::{ + AppCtxKind, AppCtxMarker, ComponentMarker, Ctx, CtxKind, CtxLocation, ModalMarker, + RespondResult, +}; type MessageRespondResult = RespondResult; type MessageFollowupResult = Result; @@ -16,7 +19,7 @@ impl RespondViaMessage for AppCtxMarker {} impl RespondViaMessage for ModalMarker {} impl RespondViaMessage for ComponentMarker {} -impl Ctx { +impl Ctx { fn base_response_data_builder() -> InteractionResponseDataBuilder { InteractionResponseDataBuilder::new().allowed_mentions(AllowedMentions::default()) } diff --git a/lyra/src/bot/command/model/ctx/modal.rs b/lyra/src/bot/command/model/ctx/modal.rs index 924889d..135beed 100644 --- a/lyra/src/bot/command/model/ctx/modal.rs +++ b/lyra/src/bot/command/model/ctx/modal.rs @@ -3,26 +3,31 @@ use twilight_model::{ channel::message::Component, }; -use super::{AppCtxKind, AppCtxMarker, ComponentMarker, Ctx, CtxKind, UnitRespondResult}; +use super::{ + AppCtxKind, AppCtxMarker, ComponentMarker, Ctx, CtxKind, CtxLocation, Guild, UnitRespondResult, +}; pub struct ModalMarker; impl CtxKind for ModalMarker {} pub type ModalCtx = Ctx; +pub type GuildModalCtx = Ctx; pub trait RespondViaModal: CtxKind {} impl RespondViaModal for AppCtxMarker {} impl RespondViaModal for ComponentMarker {} -impl Ctx { +impl Ctx { pub fn submit_data(&self) -> &ModalInteractionData { let Some(InteractionData::ModalSubmit(ref data)) = self.inner.data else { - unreachable!() + // SAFETY: `self` is `Ctx`, + // so `self.inner.data` will always be `InteractionData::ModalSubmit(_)` + unsafe { std::hint::unreachable_unchecked() } }; data } } -impl Ctx { +impl Ctx { pub async fn modal( &mut self, custom_id: impl Into + Send, diff --git a/lyra/src/bot/command/poll.rs b/lyra/src/bot/command/poll.rs index 2d0b7ac..4d86108 100644 --- a/lyra/src/bot/command/poll.rs +++ b/lyra/src/bot/command/poll.rs @@ -29,7 +29,7 @@ use twilight_util::builder::embed::{ use crate::bot::{ command::macros::{caut, hid, nope}, core::{ - model::{BotStateAware, CacheAware, HttpAware}, + model::{AuthorIdAware, BotStateAware, CacheAware, HttpAware}, r#const::{ colours, poll::{BASE, DOWNVOTE, RATIO_BAR_SIZE, UPVOTE}, @@ -40,12 +40,13 @@ use crate::bot::{ Cache as CacheError, }, ext::util::hex_to_rgb, - gateway::ExpectedGuildIdAware, + gateway::GuildIdAware, lavalink::{Event, EventRecvResult, LavalinkAware}, }; use super::{ - model::{Ctx, RespondViaMessage}, + model::{GuildCtx, GuildInteraction, NonPingInteraction, RespondViaMessage}, + require::CachelessInVoice, util::{AvatarUrlAware, DefaultAvatarUrlAware, GuildAvatarUrlAware, MessageLinkAware}, }; @@ -73,7 +74,7 @@ impl std::fmt::Display for Topic { } }, }; - write!(f, "{message}") + f.write_str(message) } } @@ -135,7 +136,7 @@ impl Vote { impl std::fmt::Display for Vote { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let s = if self.0 { "Agree" } else { "Disagree" }; - write!(f, "{s}") + f.write_str(s) } } @@ -196,18 +197,17 @@ struct WaitForPollActionsContext<'a> { } fn handle_interactions(inter: Interaction, upvote_button_id: &String) -> PollAction { - let user_id = inter.author_id().expect("interaction from a guild"); + // SAFETY: interaction is not of type `Ping`, so author exists + let user_id = unsafe { inter.author_id_unchecked() }; let Some(InteractionData::MessageComponent(ref component)) = inter.data else { - unreachable!() + // SAFETY: interaction is of type `MessageComponent`, + // so interaction data must also be of type `MessageComponent` + unsafe { std::hint::unreachable_unchecked() } }; - let voter_permissions = inter - .member - .as_ref() - .expect("interaction from a guild") - .permissions - .expect("member from an interaction"); + // SAFETY: interaction invoked in a guild, so author permissions exists + let voter_permissions = unsafe { inter.author_permissions_unchecked() }; match ( super::check::is_user_dj(&Voter::new(voter_permissions)), @@ -223,7 +223,10 @@ fn handle_interactions(inter: Interaction, upvote_button_id: &String) -> PollAct } } -fn get_author_info(guild_id: Id, ctx: &Ctx) -> (&str, String) { +fn get_author_info( + guild_id: Id, + ctx: &GuildCtx, +) -> (&str, String) { let author_name = ctx .member() .nick @@ -314,13 +317,13 @@ fn generate_latent_embed_colours() -> LatentEmbedColours { } fn get_users_in_voice( - ctx: &Ctx, - guild_id: Id, + ctx: &GuildCtx, + in_voice: &CachelessInVoice, ) -> Result>, CacheError> { let users_in_voice = ctx .cache() - .voice_channel_states(ctx.lavalink().connection(guild_id).channel_id) - .expect("bot is in voice") + .voice_channel_states(ctx.lavalink().connection_from(in_voice).channel_id) + .ok_or(CacheError)? .map(|v| ctx.cache().user(v.user_id()).ok_or(CacheError)) .filter_map_ok(|u| (!u.bot).then_some(u.id)) .collect::, _>>()?; @@ -435,7 +438,8 @@ async fn update_embed( pub async fn start( topic: &Topic, - ctx: &mut Ctx, + ctx: &mut GuildCtx, + in_voice: &CachelessInVoice, ) -> Result { let guild_id = ctx.guild_id(); @@ -443,7 +447,7 @@ pub async fn start( let embed_latent = generate_latent_embed_colours(); let (upvote_button_id, row) = generate_upvote_button_id_and_row(); - let users_in_voice = get_users_in_voice(ctx, guild_id)?; + let users_in_voice = get_users_in_voice(ctx, in_voice)?; let votes = HashMap::from([(ctx.author_id(), Vote(true))]); let threshold = ((users_in_voice.len() + 1) as f64 / 2.).round() as usize; @@ -465,7 +469,7 @@ pub async fn start( let message_id = message.id(); { ctx.lavalink() - .connection_mut(guild_id) + .connection_mut_from(in_voice) .set_poll(Poll::new(topic, message.clone())); } let components = &mut ctx @@ -492,7 +496,7 @@ pub async fn start( votes, threshold, embed_ctx, - guild_id, + in_voice, )) .await?) } @@ -531,14 +535,14 @@ fn generate_poll_description(votes: &HashMap, Vote>, threshold: u async fn wait_for_votes( mut poll_ctx: WaitForPollActionsContext<'_>, - ctx: &Ctx, + ctx: &GuildCtx, users_in_voice: HashSet>, mut votes: HashMap, Vote>, threshold: usize, embed_ctx: UpdatePollEmbedContext, - guild_id: Id, + in_voice: &CachelessInVoice, ) -> Result { - let mut rx = ctx.lavalink().connection(guild_id).subscribe(); + let mut rx = ctx.lavalink().connection_from(in_voice).subscribe(); loop { let poll_stream = wait_for_poll_actions(&mut rx, &mut poll_ctx); match tokio::time::timeout(Duration::from_secs(30), poll_stream).await { @@ -582,7 +586,8 @@ async fn wait_for_votes( PollAction::AlternateCast(user_id) => { if !users_in_voice.contains(&user_id) { ctx.lavalink() - .dispatch(guild_id, Event::AlternateVoteCastDenied); + .connection_from(in_voice) + .dispatch(Event::AlternateVoteCastDenied); continue; } match votes.entry(user_id) { @@ -591,7 +596,8 @@ async fn wait_for_votes( } Entry::Occupied(e) => { ctx.lavalink() - .dispatch(guild_id, Event::AlternateVoteCastedAlready(*e.get())); + .connection_from(in_voice) + .dispatch(Event::AlternateVoteCastedAlready(*e.get())); continue; } } diff --git a/lyra/src/bot/command/require.rs b/lyra/src/bot/command/require.rs new file mode 100644 index 0000000..cbcd534 --- /dev/null +++ b/lyra/src/bot/command/require.rs @@ -0,0 +1,203 @@ +use lavalink_rs::{ + error::LavalinkResult, model::player::Player as PlayerInfo, player_context::PlayerContext, +}; +use twilight_cache_inmemory::{model::CachedVoiceState, InMemoryCache, Reference}; +use twilight_model::{ + channel::ChannelType, + guild::Permissions, + id::{ + marker::{ChannelMarker, GuildMarker, UserMarker}, + Id, + }, +}; + +use crate::bot::{ + core::model::{AuthorIdAware, AuthorPermissionsAware, CacheAware}, + error::{ + command::check, lavalink::NoPlayerError, Cache, CacheResult, InVoiceWithoutSomeoneElse, + NotInGuild, NotInVoice, QueueEmpty, Suppressed, + }, + gateway::GuildIdAware, + lavalink::{PlayerAware, PlayerDataRwLockArc, UnwrappedPlayerData}, +}; + +use super::model::{Ctx, CtxKind, GuildCtx, WeakGuildCtx}; + +pub fn guild(ctx: Ctx) -> Result, NotInGuild> { + GuildCtx::try_from(ctx) +} + +pub fn guild_weak(ctx: &Ctx) -> Result, NotInGuild> { + WeakGuildCtx::try_from(ctx) +} + +pub struct Player { + pub context: PlayerContext, +} + +impl Player { + pub async fn info(&self) -> LavalinkResult { + self.context.get_player().await + } + + pub fn data(&self) -> PlayerDataRwLockArc { + self.context.data_unwrapped() + } + + pub async fn and_queue_not_empty(self) -> Result { + if self.data().read().await.queue().is_empty() { + return Err(QueueEmpty); + } + + Ok(self) + } +} + +pub fn player(ctx: &impl PlayerAware) -> Result { + let context = ctx.get_player().ok_or(NoPlayerError)?; + Ok(Player { context }) +} + +pub type CachedVoiceStateRef<'a> = + Reference<'a, (Id, Id), CachedVoiceState>; + +#[derive(Clone)] +pub struct InVoiceCachedVoiceState { + guild_id: Id, + channel_id: Id, + mute: bool, + suppress: bool, +} + +impl From> for InVoiceCachedVoiceState { + fn from(value: CachedVoiceStateRef<'_>) -> Self { + Self { + guild_id: value.guild_id(), + channel_id: value.channel_id(), + mute: value.mute(), + suppress: value.suppress(), + } + } +} + +#[must_use] +pub struct InVoice<'a> { + state: InVoiceCachedVoiceState, + author_permissions: Permissions, + pub author_id: Id, + pub cache: &'a InMemoryCache, +} + +#[must_use] +pub struct CachelessInVoice { + state: InVoiceCachedVoiceState, + author_permissions: Permissions, + pub author_id: Id, +} + +impl From<&InVoice<'_>> for CachelessInVoice { + fn from(value: &InVoice<'_>) -> Self { + Self { + state: value.state.clone(), + author_permissions: value.author_permissions, + author_id: value.author_id, + } + } +} + +impl GuildIdAware for CachelessInVoice { + fn guild_id(&self) -> Id { + self.state.guild_id + } +} + +pub fn in_voice(ctx: &GuildCtx) -> Result { + let state = ctx.current_voice_state().ok_or(NotInVoice)?; + // SAFETY: it has been proven that there is a voice connection currently + Ok(unsafe { InVoice::new(state.into(), ctx) }) +} + +impl<'a> InVoice<'a> { + pub unsafe fn new( + state: InVoiceCachedVoiceState, + ctx: &'a (impl AuthorPermissionsAware + AuthorIdAware + CacheAware), + ) -> Self { + Self { + state, + author_permissions: ctx.author_permissions(), + author_id: ctx.author_id(), + cache: ctx.cache(), + } + } + + pub const fn channel_id(&self) -> Id { + self.state.channel_id + } + + pub fn and_unsuppressed(self) -> Result { + let state = &self.state; + let voice_state_channel = self.cache.channel(state.channel_id).ok_or(Cache)?; + + if state.mute { + Err(Suppressed::Muted)?; + } + let speaker_in_stage = + state.suppress && matches!(voice_state_channel.kind, ChannelType::GuildStageVoice); + + if speaker_in_stage { + Err(Suppressed::NotSpeaker)?; + } + Ok(self) + } + + pub fn and_with_someone_else(self) -> Result { + let channel_id = self.channel_id(); + + if !someone_else_in(channel_id, &self)? { + Err(InVoiceWithoutSomeoneElse(channel_id))?; + } + Ok(self) + } +} + +impl CacheAware for InVoice<'_> { + fn cache(&self) -> &InMemoryCache { + self.cache + } +} + +impl AuthorIdAware for InVoice<'_> { + fn author_id(&self) -> Id { + self.author_id + } +} + +impl AuthorPermissionsAware for InVoice<'_> { + fn author_permissions(&self) -> Permissions { + self.author_permissions + } +} + +impl GuildIdAware for InVoice<'_> { + fn guild_id(&self) -> Id { + self.state.guild_id + } +} + +pub fn someone_else_in( + channel_id: Id, + ctx: &(impl CacheAware + AuthorIdAware), +) -> CacheResult { + let cache = ctx.cache(); + cache + .voice_channel_states(channel_id) + .and_then(|states| { + for state in states { + if !cache.user(state.user_id())?.bot && state.user_id() != ctx.author_id() { + return Some(true); + } + } + Some(false) + }) + .ok_or(Cache) +} diff --git a/lyra/src/bot/command/util.rs b/lyra/src/bot/command/util.rs index b0969ca..a9c88b4 100644 --- a/lyra/src/bot/command/util.rs +++ b/lyra/src/bot/command/util.rs @@ -1,5 +1,5 @@ use chrono::Utc; -use lavalink_rs::error::LavalinkResult; +use lavalink_rs::{error::LavalinkResult, player_context::PlayerContext}; use rand::{distributions::Alphanumeric, Rng}; use twilight_gateway::Event; use twilight_model::{ @@ -20,13 +20,15 @@ use twilight_model::{ use super::{ check, macros::note_fol, - model::{CommandDataAware, Ctx, CtxKind, RespondViaMessage, RespondViaModal}, - ModalCtx, + model::{ + CommandDataAware, CtxKind, GuildCtx, GuildModalCtx, RespondViaMessage, RespondViaModal, + }, + require::{self, InVoice}, }; use crate::bot::{ component::connection::auto_join, core::{ - model::{BotStateAware, CacheAware, OwnedBotStateAware}, + model::{AuthorIdAware, BotStateAware, CacheAware, OwnedBotStateAware}, r#const::{ self, discord::{BASE_URL, CDN_URL}, @@ -42,7 +44,7 @@ use crate::bot::{ }, Suppressed as SuppressedError, }, - gateway::ExpectedGuildIdAware, + gateway::GuildIdAware, lavalink::{DelegateMethods, LavalinkAware}, }; @@ -53,7 +55,7 @@ pub trait MessageLinkAware { fn link(&self) -> String { let guild_id_str = self .guild_id() - .map_or_else(|| String::from("@me"), |g| g.to_string()); + .map_or_else(|| String::from("@me"), |i| i.to_string()); format!( "{}/channels/{}/{}/{}", BASE_URL, @@ -164,7 +166,10 @@ pub trait GuildAvatarUrlAware { impl GuildAvatarUrlAware for PartialMember { fn id(&self) -> Id { - self.user.as_ref().expect("member is not partial").id + self.user + .as_ref() + .unwrap_or_else(|| panic!("user field is missing")) + .id } fn avatar(&self) -> Option { self.avatar @@ -198,28 +203,34 @@ impl DefaultAvatarUrlAware for User { } pub async fn auto_join_or_check_in_voice_with_user_and_check_not_suppressed( - ctx: &mut Ctx, + ctx: &mut GuildCtx, ) -> Result<(), AutoJoinOrCheckInVoiceWithUserError> { - if let Some(voice_state) = ctx.current_voice_state() { - check::user_in(voice_state.channel_id(), ctx)?; - check::not_suppressed(ctx)?; + if let Ok(in_voice) = require::in_voice(ctx) { + let in_voice = in_voice.and_unsuppressed()?; + check::in_voice_with_user(in_voice)?; return Ok(()); } - let Err(e) = auto_join(ctx).await else { - let Err(NotSuppressedError::Suppressed(suppressed)) = check::not_suppressed(ctx) else { - return Ok(()); - }; - handle_suppressed_auto_join(suppressed, ctx).await?; - return Ok(()); - }; - - Err(e.unflatten_into_auto_join_attempt())? + match auto_join(ctx).await { + Err(e) => Err(e.unflatten_into_auto_join_attempt())?, + Ok(state) => { + let Err(NotSuppressedError::Suppressed(suppressed)) = { + // SAFETY: as `auto_join` was called and ran successfully, + // there must now be an active voice connection. + unsafe { InVoice::new(state, ctx) } + } + .and_unsuppressed() else { + return Ok(()); + }; + handle_suppressed_auto_join(suppressed, ctx).await?; + Ok(()) + } + } } async fn handle_suppressed_auto_join( error: SuppressedError, - ctx: &Ctx, + ctx: &GuildCtx, ) -> Result<(), HandleSuppressedAutoJoinError> { let bot_user_id = ctx.bot().user_id(); match error { @@ -252,7 +263,7 @@ async fn handle_suppressed_auto_join( ); let requested_to_speak_message = requested_to_speak.model().await?; let wait_for_speaker = tokio::time::timeout( - *r#const::misc::WAIT_FOR_BOT_EVENTS_TIMEOUT, + *r#const::misc::wait_for_bot_events_timeout(), wait_for_speaker, ); @@ -267,15 +278,15 @@ async fn handle_suppressed_auto_join( } pub async fn prompt_for_confirmation( - mut ctx: Ctx, -) -> Result { + mut ctx: GuildCtx, +) -> Result { let text_input = TextInput { custom_id: String::new(), - label: "This is a destructive command. Are you sure?".into(), + label: String::from("This is a destructive command. Are you sure?"), max_length: None, min_length: None, - required: true.into(), - placeholder: Some(r#"Type "YES" (All Caps) to confirm..."#.into()), + required: Some(true), + placeholder: Some(String::from(r#"Type "YES" (All Caps) to confirm..."#)), style: TextInputStyle::Short, value: None, }; @@ -309,7 +320,7 @@ pub async fn prompt_for_confirmation( }); let wait_for_modal_submit = tokio::time::timeout( - *r#const::misc::DESTRUCTIVE_COMMAND_CONFIRMATION_TIMEOUT, + *r#const::misc::destructive_command_confirmation_timeout(), wait_for_modal_submit, ) .await; @@ -326,7 +337,9 @@ pub async fn prompt_for_confirmation( } ctx } - Ok(Ok(_)) => unreachable!(), + // SAFETY: the future has been filtered to only match modal submit interaction + // so this branch is unreachable + Ok(Ok(_)) => unsafe { std::hint::unreachable_unchecked() }, Ok(Err(e)) => Err(e)?, Err(_) => Err(ConfirmationError::TimedOut)?, }; @@ -334,12 +347,14 @@ pub async fn prompt_for_confirmation( Ok(modal_ctx) } -pub async fn auto_new_player_data(ctx: &Ctx) -> LavalinkResult<()> { +pub async fn auto_new_player(ctx: &GuildCtx) -> LavalinkResult { let guild_id = ctx.guild_id(); let lavalink = ctx.lavalink(); - if lavalink.get_player_data(guild_id).is_none() { - lavalink.new_player_data(guild_id).await?; - } - Ok(()) + let player = match lavalink.get_player_context(guild_id) { + Some(player) => player, + None => lavalink.new_player(guild_id).await?, + }; + + Ok(player) } diff --git a/lyra/src/bot/component/config/access.rs b/lyra/src/bot/component/config/access.rs index f15589c..544223a 100644 --- a/lyra/src/bot/component/config/access.rs +++ b/lyra/src/bot/component/config/access.rs @@ -4,6 +4,7 @@ mod mode; mod view; use bitflags::bitflags; +use const_str::concat as const_str_concat; use itertools::Itertools; use sqlx::{Pool, Postgres}; use tokio::task::JoinSet; @@ -63,25 +64,24 @@ impl CalculatorBuilder { } } - fn query(mut self, column: &'static str, id: i64) -> Self { + fn query(mut self, category: &AccessCategoryFlag, id: i64) -> Self { + let column = category.ident(); let db = self.db.clone(); self.set.spawn(async move { let in_access_controls = sqlx::query_as::<_, (Option,)>(&format!( - "--sql - SELECT EXISTS (SELECT 1 FROM {column} WHERE guild = $1 AND id = $2) - " + "SELECT EXISTS (SELECT 1 FROM {column} WHERE guild = $1 AND id = $2)" )) .bind(self.guild_id) .bind(id) .fetch_one(&db) .await? - .0 - .expect("SELECT EXISTS is non-null"); + .0; + + // SAFETY: `SELECT EXISTS ...` is always non-null + let in_access_controls = unsafe { in_access_controls.unwrap_unchecked() }; let (access_mode,) = sqlx::query_as::<_, (Option,)>(&format!( - "--sql - SELECT {column} FROM guild_configs WHERE id = $1 - " + "SELECT {column} FROM guild_configs WHERE id = $1" )) .bind(self.guild_id) .fetch_one(&db) @@ -95,19 +95,13 @@ impl CalculatorBuilder { self } - pub fn user(self, user_id: Id) -> Self { - let id = user_id.get() as i64; - self.query("usr_access", id) - } - pub fn roles<'a>(mut self, role_ids: impl Iterator>) -> Self { + let column = AccessCategoryFlag::Roles.ident(); let db = self.db.clone(); let where_clause = role_ids.map(|id| format!("id = {id}")).join(" OR "); self.set.spawn(async move { let (Some(in_access_controls),) = sqlx::query_as::<_, (Option,)>(&format!( - "--sql - SELECT EXISTS (SELECT 1 FROM rol_access WHERE guild = $1 AND ({})) - ", + "SELECT EXISTS (SELECT 1 FROM {column} WHERE guild = $1 AND ({}))", where_clause.or("true") )) .bind(self.guild_id) @@ -118,9 +112,7 @@ impl CalculatorBuilder { }; let access_mode = sqlx::query!( - r"--sql - SELECT rol_access FROM guild_configs WHERE id = $1 - ", + "SELECT rol_access FROM guild_configs WHERE id = $1", self.guild_id ) .fetch_one(&db) @@ -135,24 +127,29 @@ impl CalculatorBuilder { self } + pub fn user(self, user_id: Id) -> Self { + let id = user_id.get() as i64; + self.query(&AccessCategoryFlag::Users, id) + } + pub fn thread(self, thread_id: Id) -> Self { let id = thread_id.get() as i64; - self.query("xch_access", id) + self.query(&AccessCategoryFlag::Threads, id) } pub fn text_channel(self, text_channel_id: Id) -> Self { let id = text_channel_id.get() as i64; - self.query("tch_access", id) + self.query(&AccessCategoryFlag::TextChannels, id) } pub fn voice_channel(self, voice_channel_id: Id) -> Self { let id = voice_channel_id.get() as i64; - self.query("vch_access", id) + self.query(&AccessCategoryFlag::VoiceChannels, id) } pub fn category_channel(self, category_channel_id: Id) -> Self { let id = category_channel_id.get() as i64; - self.query("cch_access", id) + self.query(&AccessCategoryFlag::CategoryChannels, id) } pub async fn build(mut self) -> Result { @@ -165,6 +162,57 @@ impl CalculatorBuilder { } } +#[repr(u8)] +#[derive(PartialEq, Eq, Hash)] +enum AccessCategoryFlag { + Users = 0b0000_0001, + Roles = 0b0000_0010, + Threads = 0b0000_0100, + TextChannels = 0b0000_1000, + VoiceChannels = 0b0001_0000, + CategoryChannels = 0b0010_0000, +} + +impl From for AccessCategoryFlags { + fn from(value: AccessCategoryFlag) -> Self { + Self::from_bits_retain(value as u8) + } +} + +impl TryFrom for AccessCategoryFlag { + type Error = AccessCategoryFlags; + + fn try_from(value: AccessCategoryFlags) -> Result { + if value.iter().count() != 1 { + return Err(value); + } + + // SAFETY: `value` is guruanteed to only have one flag, + // so this transmute is safe + Ok(unsafe { std::mem::transmute(value.bits()) }) + } +} + +impl AccessCategoryFlag { + const fn ident(&self) -> &'static str { + const POSTFIX: &str = "_access"; + macro_rules! concat_postfix { + ($postfix: expr) => { + const_str_concat!($postfix, POSTFIX) + }; + } + + match self { + Self::Users => concat_postfix!("usr"), + Self::Roles => concat_postfix!("rol"), + Self::Threads => concat_postfix!("xch"), + Self::TextChannels => concat_postfix!("tch"), + Self::VoiceChannels => concat_postfix!("vch"), + Self::CategoryChannels => concat_postfix!("cch"), + } + } +} + bitflags! { struct AccessCategoryFlags: u8 { const USERS = 0b0000_0001; @@ -189,23 +237,17 @@ impl FlagsPrettify for AccessCategoryFlags {} impl From for AccessCategoryFlags { fn from(category: AccessCategory) -> Self { - Self::from_bits_truncate(category.value() as u8) + Self::from_bits_retain(category.value() as u8) } } impl AccessCategoryFlags { - pub fn iter_names_as_column(&self) -> impl Iterator { - self.iter_names() - .map(|(n, _)| match n { - "USERS" => "usr", - "ROLES" => "rol", - "THREADS" => "xch", - "TEXT_CHANNELS" => "tch", - "VOICE_CHANNELS" => "vch", - "CATEGORY_CHANNELS" => "cch", - _ => unreachable!(), - }) - .map(|n| format!("{n}_access")) + pub fn iter_each(&self) -> impl Iterator { + self.iter().flat_map(Self::try_into) + } + + pub fn iter_as_columns(&self) -> impl Iterator { + self.iter_each().map(|f| f.ident()) } } diff --git a/lyra/src/bot/component/config/access/clear.rs b/lyra/src/bot/component/config/access/clear.rs index 8cb2250..3b217c6 100644 --- a/lyra/src/bot/component/config/access/clear.rs +++ b/lyra/src/bot/component/config/access/clear.rs @@ -7,6 +7,7 @@ use crate::bot::{ check, macros::{out, sus}, model::BotSlashCommand, + require, util::prompt_for_confirmation, SlashCtx, }, @@ -14,7 +15,7 @@ use crate::bot::{ core::r#const::text::NO_ROWS_AFFECTED_MESSAGE, error::CommandResult, ext::util::FlagsPrettify, - gateway::ExpectedGuildIdAware, + gateway::GuildIdAware, }; /// Clears all currently configured access controls for channels, roles or members @@ -27,12 +28,13 @@ pub struct Clear { impl BotSlashCommand for Clear { async fn run(self, ctx: SlashCtx) -> CommandResult { + let ctx = require::guild(ctx)?; check::user_is_access_manager(&ctx)?; let category_flags = AccessCategoryFlags::from(self.category); let mut set = JoinSet::new(); - category_flags.iter_names_as_column().for_each(|c| { + category_flags.iter_as_columns().for_each(|c| { let db = ctx.db().clone(); let g = ctx.guild_id().get() as i64; diff --git a/lyra/src/bot/component/config/access/edit.rs b/lyra/src/bot/component/config/access/edit.rs index 98e1b5e..28db80f 100644 --- a/lyra/src/bot/component/config/access/edit.rs +++ b/lyra/src/bot/component/config/access/edit.rs @@ -1,3 +1,5 @@ +use std::collections::{HashMap, HashSet}; + use itertools::Itertools; use sqlx::{postgres::PgQueryResult, Pool, Postgres}; use tokio::task::JoinSet; @@ -13,17 +15,17 @@ use twilight_model::{ }, }; -use super::AccessCategoryFlags; +use super::AccessCategoryFlag; use crate::bot::{ command::{ check, macros::{out, sus}, model::BotSlashCommand, - SlashCtx, + require, SlashCtx, }, core::r#const::text::NO_ROWS_AFFECTED_MESSAGE, error::CommandResult, - gateway::ExpectedGuildIdAware, + gateway::GuildIdAware, }; type SqlxResultJoinSet = JoinSet>; @@ -34,16 +36,16 @@ impl AccessCategoryMarker for GenericMarker {} impl AccessCategoryMarker for ChannelMarker {} fn add_access( - set: &mut SqlxResultJoinSet, - db: Pool, - cat: &AccessCategoryFlags, - g: i64, + join_set: &mut SqlxResultJoinSet, + database: Pool, + category: &AccessCategoryFlag, + guild_id: i64, ids: impl IntoIterator>, ) { - let column = cat.iter_names_as_column().next().expect("cat is non-empty"); + let column = category.ident(); let values_clause = ids.into_iter().map(|id| format!("($1,{id})")).join(","); - set.spawn(async move { + join_set.spawn(async move { sqlx::query(&format!( "--sql INSERT INTO {column} @@ -56,31 +58,31 @@ fn add_access( ); " )) - .bind(g) - .execute(&db) + .bind(guild_id) + .execute(&database) .await }); } fn remove_access( - set: &mut SqlxResultJoinSet, - db: Pool, - cat: &AccessCategoryFlags, - g: i64, + join_set: &mut SqlxResultJoinSet, + database: Pool, + category: &AccessCategoryFlag, + guild_id: i64, ids: impl IntoIterator>, ) { - let column = cat.iter_names_as_column().next().expect("cat is non-empty"); + let column = category.ident(); let where_clause = ids.into_iter().map(|c| format!("id = {c}")).join(" OR "); - set.spawn(async move { + join_set.spawn(async move { sqlx::query(&format!( "--sql DELETE FROM {column} WHERE guild = $1 AND ({where_clause}); ", )) - .bind(g) - .execute(&db) + .bind(guild_id) + .execute(&database) .await }); } @@ -152,10 +154,11 @@ pub struct MemberRole { } impl BotSlashCommand for MemberRole { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; check::user_is_access_manager(&ctx)?; - let inputted_mentionables = [ + let input_mentionables: HashMap<_, HashSet<_>> = [ Some(self.member_or_role), self.member_or_role_2, self.member_or_role_3, @@ -164,41 +167,46 @@ impl BotSlashCommand for MemberRole { ] .into_iter() .flatten() - .unique_by(twilight_interactions::command::ResolvedMentionable::id) - .collect::>(); - - let members = ( - AccessCategoryFlags::USERS, - inputted_mentionables - .iter() - .filter(|m| matches!(m, ResolvedMentionable::User(_))) - .map(ResolvedMentionable::id) - .collect::>(), - ); - let roles = ( - AccessCategoryFlags::ROLES, - inputted_mentionables - .iter() - .filter(|m| matches!(m, ResolvedMentionable::Role(_))) - .map(ResolvedMentionable::id) - .collect::>(), - ); - + .map(|v| { + let flag = match v { + ResolvedMentionable::User(_) => AccessCategoryFlag::Users, + ResolvedMentionable::Role(_) => AccessCategoryFlag::Roles, + }; + (flag, v.id()) + }) + .fold(HashMap::new(), |mut acc, (k, v)| { + acc.entry(k).or_default().insert(v); + acc + }); + + let input_mentionables_len = input_mentionables.values().fold(0, |acc, v| acc + v.len()); + + let database = ctx.db(); + let guild_id = ctx.guild_id().get() as i64; let mut set = JoinSet::new(); - - let categorized_mentionables = [members, roles] - .into_iter() - .filter(|(_, mentionables)| !mentionables.is_empty()); - - let db = ctx.db(); - let g = ctx.guild_id().get() as i64; match self.action { - EditAction::Add => categorized_mentionables.for_each(|(cat, mentionables)| { - add_access(&mut set, db.clone(), &cat, g, mentionables); - }), - EditAction::Remove => categorized_mentionables.for_each(|(cat, mentionables)| { - remove_access(&mut set, db.clone(), &cat, g, mentionables); - }), + EditAction::Add => { + for (category, mentionables) in input_mentionables { + add_access( + &mut set, + database.clone(), + &category, + guild_id, + mentionables, + ); + } + } + EditAction::Remove => { + for (category, mentionables) in input_mentionables { + remove_access( + &mut set, + database.clone(), + &category, + guild_id, + mentionables, + ); + } + } } let mut rows_affected = 0; @@ -211,7 +219,7 @@ impl BotSlashCommand for MemberRole { sus!(NO_ROWS_AFFECTED_MESSAGE, ctx); } - let ignored_changes = inputted_mentionables.len() as u64 - rows_affected; + let ignored_changes = input_mentionables_len as u64 - rows_affected; let ignored_changes_notice = match ignored_changes { 1.. => { format!( @@ -255,11 +263,13 @@ pub struct Channel { target_5: Option, } +#[allow(clippy::too_many_lines)] impl BotSlashCommand for Channel { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; check::user_is_access_manager(&ctx)?; - let inputted_channels = [ + let input_channels: HashMap<_, HashSet<_>> = [ Some(self.target), self.target_2, self.target_3, @@ -268,67 +278,40 @@ impl BotSlashCommand for Channel { ] .into_iter() .flatten() - .unique_by(|c| c.id) - .collect::>(); - - let threads = ( - AccessCategoryFlags::THREADS, - inputted_channels - .iter() - .filter(|&c| { - matches!( - c.kind, - ChannelType::PublicThread - | ChannelType::PrivateThread - | ChannelType::AnnouncementThread - ) - }) - .map(|c| c.id) - .collect::>(), - ); - let text_channels = ( - AccessCategoryFlags::TEXT_CHANNELS, - inputted_channels - .iter() - .filter(|c| matches!(c.kind, ChannelType::GuildText)) - .map(|c| c.id) - .collect::>(), - ); - let voice_channels = ( - AccessCategoryFlags::VOICE_CHANNELS, - inputted_channels - .iter() - .filter(|c| { - matches!( - c.kind, - ChannelType::GuildVoice | ChannelType::GuildStageVoice - ) - }) - .map(|c| c.id) - .collect::>(), - ); - let category_channels = ( - AccessCategoryFlags::CATEGORY_CHANNELS, - inputted_channels - .iter() - .filter(|c| matches!(c.kind, ChannelType::GuildCategory)) - .map(|c| c.id) - .collect::>(), - ); - + .map(|v| { + let flag = match v.kind { + ChannelType::PublicThread + | ChannelType::PrivateThread + | ChannelType::AnnouncementThread => AccessCategoryFlag::Threads, + ChannelType::GuildVoice | ChannelType::GuildStageVoice => { + AccessCategoryFlag::VoiceChannels + } + ChannelType::GuildCategory => AccessCategoryFlag::CategoryChannels, + _ => AccessCategoryFlag::TextChannels, + }; + (flag, v.id) + }) + .fold(HashMap::new(), |mut acc, (k, v)| { + acc.entry(k).or_default().insert(v); + acc + }); + + let input_channels_len = input_channels.values().fold(0, |acc, v| acc + v.len()); + + let database = ctx.db(); + let guild_id = ctx.guild_id().get() as i64; let mut set = JoinSet::new(); - - let categorized_channels = [threads, text_channels, voice_channels, category_channels] - .into_iter() - .filter(|(_, channels)| !channels.is_empty()); - - let db = ctx.db(); - let g = ctx.guild_id().get() as i64; match self.action { - EditAction::Add => categorized_channels - .for_each(|(cat, channels)| add_access(&mut set, db.clone(), &cat, g, channels)), - EditAction::Remove => categorized_channels - .for_each(|(cat, channels)| remove_access(&mut set, db.clone(), &cat, g, channels)), + EditAction::Add => { + for (category, channels) in input_channels { + add_access(&mut set, database.clone(), &category, guild_id, channels); + } + } + EditAction::Remove => { + for (category, channels) in input_channels { + remove_access(&mut set, database.clone(), &category, guild_id, channels); + } + } } let mut rows_affected = 0; @@ -341,7 +324,7 @@ impl BotSlashCommand for Channel { sus!(NO_ROWS_AFFECTED_MESSAGE, ctx); } - let ignored_changes = inputted_channels.len() as u64 - rows_affected; + let ignored_changes = input_channels_len as u64 - rows_affected; let ignored_changes_notice = match ignored_changes { 1.. => { format!( diff --git a/lyra/src/bot/component/config/access/mode.rs b/lyra/src/bot/component/config/access/mode.rs index ed3d71c..6481c11 100644 --- a/lyra/src/bot/component/config/access/mode.rs +++ b/lyra/src/bot/component/config/access/mode.rs @@ -7,13 +7,13 @@ use crate::bot::{ check, macros::{out, sus}, model::BotSlashCommand, - SlashCtx, + require, SlashCtx, }, component::config::access::AccessCategoryFlags, core::r#const::text::NO_ROWS_AFFECTED_MESSAGE, error::CommandResult, ext::util::FlagsPrettify, - gateway::ExpectedGuildIdAware, + gateway::GuildIdAware, }; pub(super) trait AccessModePrettify { @@ -71,7 +71,8 @@ pub struct Mode { } impl BotSlashCommand for Mode { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; check::user_is_access_manager(&ctx)?; let access_mode = >::from(self.mode); @@ -79,11 +80,11 @@ impl BotSlashCommand for Mode { let category_flags = AccessCategoryFlags::from(self.category); let set_statements = category_flags - .iter_names_as_column() + .iter_as_columns() .map(|c| format!("{c} = $2")) .join(","); let where_clause = category_flags - .iter_names_as_column() + .iter_as_columns() .map(|c| format!("{c} IS NOT {sql_access_mode}")) .join(" OR "); diff --git a/lyra/src/bot/component/config/access/view.rs b/lyra/src/bot/component/config/access/view.rs index a66d58d..8b1662d 100644 --- a/lyra/src/bot/component/config/access/view.rs +++ b/lyra/src/bot/component/config/access/view.rs @@ -9,12 +9,12 @@ use twilight_model::id::{ use twilight_util::builder::embed::{EmbedBuilder, EmbedFieldBuilder}; use crate::bot::{ - command::{model::BotSlashCommand, SlashCtx}, + command::{model::BotSlashCommand, require, SlashCtx}, component::config::access::mode::AccessModePrettify, core::r#const::{colours::EMBED_DEFAULT, text::EMPTY_EMBED_FIELD}, error::CommandResult, ext::util::OptionMap, - gateway::ExpectedGuildIdAware, + gateway::GuildIdAware, }; /// Views the currently configured access controls for channels, roles and members @@ -23,7 +23,8 @@ use crate::bot::{ pub struct View; impl BotSlashCommand for View { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; let guild_id = ctx.guild_id().get() as i64; let db = ctx.db(); diff --git a/lyra/src/bot/component/config/now_playing.rs b/lyra/src/bot/component/config/now_playing.rs index ffa3bc2..900d9d3 100644 --- a/lyra/src/bot/component/config/now_playing.rs +++ b/lyra/src/bot/component/config/now_playing.rs @@ -1,9 +1,9 @@ use twilight_interactions::command::{CommandModel, CreateCommand}; use crate::bot::{ - command::{macros::out, model::BotSlashCommand, SlashCtx}, + command::{macros::out, model::BotSlashCommand, require, SlashCtx}, error::CommandResult, - gateway::ExpectedGuildIdAware, + gateway::GuildIdAware, }; use lyra_proc::BotCommandGroup; @@ -20,11 +20,10 @@ pub enum NowPlaying { pub struct Toggle; impl BotSlashCommand for Toggle { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; let new_now_playing = sqlx::query!( - r"--sql - UPDATE guild_configs SET now_playing = NOT now_playing WHERE id = $1 RETURNING now_playing; - ", + "UPDATE guild_configs SET now_playing = NOT now_playing WHERE id = $1 RETURNING now_playing;", ctx.guild_id().get() as i64, ) .fetch_one(ctx.db()) diff --git a/lyra/src/bot/component/connection.rs b/lyra/src/bot/component/connection.rs index 6ac06fd..ae85faa 100644 --- a/lyra/src/bot/component/connection.rs +++ b/lyra/src/bot/component/connection.rs @@ -33,7 +33,7 @@ use crate::bot::{ HandleVoiceStateUpdateError, MatchStateChannelIdError, StartInactivityTimeoutError, }, }, - gateway::{voice, ExpectedGuildIdAware, SenderAware}, + gateway::{voice, GuildIdAware, SenderAware}, lavalink::{self, LavalinkAware}, }; @@ -56,7 +56,7 @@ struct InactivityTimeoutContext { } impl InactivityTimeoutContext { - fn new_via(ctx: &(impl OwnedBotStateAware + SenderAware + ExpectedGuildIdAware)) -> Self { + fn new_via(ctx: &(impl OwnedBotStateAware + SenderAware + GuildIdAware)) -> Self { Self { inner: ctx.bot_owned(), sender: ctx.sender().clone(), @@ -89,7 +89,7 @@ impl HttpAware for InactivityTimeoutContext { } } -impl ExpectedGuildIdAware for InactivityTimeoutContext { +impl GuildIdAware for InactivityTimeoutContext { fn guild_id(&self) -> Id { self.guild_id } @@ -108,13 +108,16 @@ async fn start_inactivity_timeout( ); for _ in 0..const_connection::INACTIVITY_TIMEOUT_POLL_N { - tokio::time::sleep(*const_connection::INACTIVITY_TIMEOUT_POLL_INTERVAL).await; + tokio::time::sleep(*const_connection::inactivity_timeout_poll_interval()).await; if users_in_voice(&ctx, channel_id).is_some_and(|n| n >= 1) { return Ok(()); } } - ctx.lavalink().notify_connection_change(guild_id); + let Some(connection) = ctx.lavalink().get_connection(guild_id) else { + return Ok(()); + }; + connection.notify_change(); pre_disconnect_cleanup(&ctx).await?; disconnect(&ctx)?; diff --git a/lyra/src/bot/component/connection/join.rs b/lyra/src/bot/component/connection/join.rs index 45af064..af45ace 100644 --- a/lyra/src/bot/component/connection/join.rs +++ b/lyra/src/bot/component/connection/join.rs @@ -19,12 +19,15 @@ use crate::bot::{ command::{ check, macros::{bad, cant, nope, note, note_fol, out, sus_fol}, - model::{BotSlashCommand, Ctx, CtxKind, RespondViaMessage}, + model::{BotSlashCommand, CtxKind, GuildCtx, RespondViaMessage}, + require::{self, InVoiceCachedVoiceState}, SlashCtx, }, component::connection::{start_inactivity_timeout, users_in_voice}, core::{ - model::{BotState, BotStateAware, CacheAware, HttpAware, OwnedBotStateAware}, + model::{ + AuthorIdAware, BotState, BotStateAware, CacheAware, HttpAware, OwnedBotStateAware, + }, r#const::connection::INACTIVITY_TIMEOUT_SECS, traced, }, @@ -37,8 +40,8 @@ use crate::bot::{ }, Cache as CacheError, CommandResult, UserNotInVoice as UserNotInVoiceError, }, - gateway::{ExpectedGuildIdAware, SenderAware}, - lavalink::LavalinkAware, + gateway::{GuildIdAware, SenderAware}, + lavalink::{Connection, LavalinkAware}, }; pub(super) enum Response { @@ -79,7 +82,7 @@ impl JoinedChannel { let kind = match kind { ChannelType::GuildVoice => JoinedChannelType::Voice, ChannelType::GuildStageVoice => JoinedChannelType::Stage, - _ => unreachable!(), + _ => panic!("unknown channel type: {kind:?}"), }; Self { id, kind } } @@ -97,7 +100,7 @@ impl Display for JoinedChannel { type GetUsersVoiceChannelResult = Result<(Id, ChannelType, Option>), GetUsersVoiceChannelError>; -fn get_users_voice_channel(ctx: &Ctx) -> GetUsersVoiceChannelResult { +fn get_users_voice_channel(ctx: &GuildCtx) -> GetUsersVoiceChannelResult { let voice_state = ctx .cache() .voice_state(ctx.author_id(), ctx.guild_id()) @@ -112,7 +115,7 @@ fn get_users_voice_channel(ctx: &Ctx) -> GetUsersVoiceChannelResul } async fn impl_join( - ctx: &Ctx, + ctx: &GuildCtx, channel: Option, ) -> Result { let (channel_id, channel_type, channel_parent_id) = match channel { @@ -123,7 +126,7 @@ async fn impl_join( Ok(connect_to(channel_id, channel_type, channel_parent_id, ctx).await?) } -async fn impl_auto_join(ctx: &Ctx) -> Result { +async fn impl_auto_join(ctx: &GuildCtx) -> Result { let (channel_id, channel_type, channel_parent_id) = get_users_voice_channel(ctx)?; Ok(connect_to_new(channel_id, channel_type, channel_parent_id, ctx).await?) @@ -131,7 +134,7 @@ async fn impl_auto_join(ctx: &Ctx) -> Result, + ctx: &GuildCtx, ) -> Result<(), error::UserNotStageManager> { if channel_type == ChannelType::GuildStageVoice { check::user_is_stage_manager(ctx)?; @@ -143,7 +146,7 @@ async fn connect_to_new( channel_id: Id, channel_type: ChannelType, channel_parent_id: Option>, - ctx: &Ctx, + ctx: &GuildCtx, ) -> Result { check_user_is_stage_manager(channel_type, ctx)?; @@ -162,7 +165,7 @@ async fn connect_to( channel_id: Id, channel_type: ChannelType, channel_parent_id: Option>, - ctx: &Ctx, + ctx: &GuildCtx, ) -> Result { check_user_is_stage_manager(channel_type, ctx)?; @@ -197,10 +200,10 @@ async fn impl_connect_to( channel_type: ChannelType, old_channel_id: Option>, guild_id: Id, - ctx: &Ctx, + ctx: &GuildCtx, ) -> Result { if !ctx - .bot_permissions_for(channel_id) + .bot_permissions_for(channel_id)? .contains(Permissions::CONNECT) { Err(error::ConnectionForbidden(channel_id))?; @@ -214,15 +217,25 @@ async fn impl_connect_to( let response = old_channel_id.map_or_else( || { - ctx.lavalink() - .new_connection(guild_id, channel_id, ctx.channel_id()); + let connection = Connection::new(channel_id, ctx.channel_id()); + connection.notify_change(); + ctx.lavalink().new_connection_with(guild_id, connection); Response::Joined { voice: joined, empty: voice_is_empty, } }, |from| { - ctx.lavalink().connection_mut(guild_id).channel_id = channel_id; + let mut connection = + // SAFETY: `old_channel_id` is of variant `Some`, meaning another connection exists, + // so `ctx.lavalink().get_connection_mut(guild_id).unwrap_unchecked()` is safe + unsafe { + ctx.lavalink() + .get_connection_mut(guild_id) + .unwrap_unchecked() + }; + connection.channel_id = channel_id; + connection.notify_change(); Response::Moved { from, to: joined, @@ -231,7 +244,6 @@ async fn impl_connect_to( }, ); - ctx.lavalink().notify_connection_change(guild_id); ctx.sender() .command(&UpdateVoiceState::new(guild_id, channel_id, true, false))?; @@ -258,7 +270,7 @@ struct DeleteEmptyVoiceNotice { impl DeleteEmptyVoiceNotice { fn new( - ctx: &Ctx, + ctx: &GuildCtx, message_id: Id, channel_id: Id, ) -> Self { @@ -306,8 +318,8 @@ fn stage_fmt(txt: &str, stage: bool) -> Cow<'_, str> { async fn handle_response( response: Response, - ctx: &mut Ctx, -) -> Result<(), HandleResponseError> { + ctx: &mut GuildCtx, +) -> Result { let (joined, empty) = match response { Response::Joined { voice, empty } => { let stage = matches!(voice.kind, JoinedChannelType::Stage); @@ -349,24 +361,27 @@ async fn handle_response( ))); } - let muted = ctx.current_voice_state().ok_or(CacheError)?.mute(); + let state = ctx.current_voice_state().ok_or(CacheError)?; + let muted = state.mute(); if muted { sus_fol!( "Currently server muted; Some features will be limited.", ?ctx ); } - Ok(()) + Ok(state.into()) } -pub async fn auto(ctx: &mut Ctx) -> Result<(), AutoJoinError> { +pub async fn auto( + ctx: &mut GuildCtx, +) -> Result { Ok(handle_response(impl_auto_join(ctx).await?, ctx).await?) } pub async fn join( - ctx: &mut Ctx, + ctx: &mut GuildCtx, channel: Option, -) -> Result<(), JoinError> { +) -> Result { Ok(handle_response(impl_join(ctx, channel).await?, ctx).await?) } @@ -380,7 +395,8 @@ pub struct Join { } impl BotSlashCommand for Join { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; let Err(e) = join(&mut ctx, self.channel).await else { return Ok(()); }; diff --git a/lyra/src/bot/component/connection/leave.rs b/lyra/src/bot/component/connection/leave.rs index fa22670..b354a87 100644 --- a/lyra/src/bot/component/connection/leave.rs +++ b/lyra/src/bot/component/connection/leave.rs @@ -12,15 +12,15 @@ use crate::bot::{ command::{ check, macros::{caut, out}, - model::{BotSlashCommand, Ctx, CtxKind}, - SlashCtx, + model::{BotSlashCommand, CtxKind, GuildCtx}, + require, SlashCtx, }, error::{ component::connection::leave::{self, PreDisconnectCleanupError}, CommandResult, }, - gateway::{ExpectedGuildIdAware, SenderAware}, - lavalink::{self, LavalinkAware}, + gateway::{GuildIdAware, SenderAware}, + lavalink::{self, Event, LavalinkAware}, }; pub(super) struct LeaveResponse(pub(super) Id); @@ -31,9 +31,7 @@ impl Display for LeaveResponse { } } -pub(super) fn disconnect( - ctx: &(impl SenderAware + ExpectedGuildIdAware), -) -> Result<(), ChannelError> { +pub(super) fn disconnect(ctx: &(impl SenderAware + GuildIdAware)) -> Result<(), ChannelError> { ctx.sender() .command(&UpdateVoiceState::new(ctx.guild_id(), None, false, false))?; @@ -41,26 +39,29 @@ pub(super) fn disconnect( } pub(super) async fn pre_disconnect_cleanup( - ctx: &(impl ExpectedGuildIdAware + lavalink::LavalinkAware + Sync), + ctx: &(impl GuildIdAware + lavalink::LavalinkAware + Sync), ) -> Result<(), PreDisconnectCleanupError> { let guild_id = ctx.guild_id(); let lavalink = ctx.lavalink(); - lavalink.dispatch_queue_clear(guild_id); + if let Some(connection) = lavalink.get_connection(guild_id) { + connection.dispatch(Event::QueueClear); + }; lavalink.drop_connection(guild_id); lavalink.delete_player(guild_id).await?; Ok(()) } -async fn leave(ctx: &Ctx) -> Result { +async fn leave(ctx: &GuildCtx) -> Result { let guild_id = ctx.guild_id(); - let in_voice = check::in_voice(ctx)?; + let in_voice = require::in_voice(ctx)?; + let connection = ctx.lavalink().connection_from(&in_voice); let channel_id = in_voice.channel_id(); - in_voice.with_user()?.only()?; + check::in_voice_with_user(in_voice)?.only()?; - ctx.lavalink().notify_connection_change(guild_id); + connection.notify_change(); pre_disconnect_cleanup(ctx).await?; disconnect(ctx)?; @@ -75,7 +76,8 @@ async fn leave(ctx: &Ctx) -> Result { pub struct Leave; impl BotSlashCommand for Leave { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; match leave(&ctx).await { Ok(LeaveResponse(voice)) => { out!(format!("📎 ~~{}~~", voice.mention()), ctx); diff --git a/lyra/src/bot/component/queue.rs b/lyra/src/bot/component/queue.rs index bfd2914..4275c3a 100644 --- a/lyra/src/bot/component/queue.rs +++ b/lyra/src/bot/component/queue.rs @@ -26,24 +26,24 @@ use twilight_model::application::command::{CommandOptionChoice, CommandOptionCho use crate::bot::{ command::{ macros::{note_fol, out}, - model::{Ctx, CtxKind, RespondViaMessage}, + model::{GuildCtx, RespondViaMessage}, + require::Player, }, core::{ model::{CacheAware, InteractionClient}, r#const::{ - discord::COMMAND_CHOICES_LIMIT, misc::ADD_TRACKS_WRAP_LIMIT, text::FUZZY_MATCHER, + discord::COMMAND_CHOICES_LIMIT, misc::ADD_TRACKS_WRAP_LIMIT, text::fuzzy_matcher, }, }, error::{component::queue::RemoveTracksError, PositionOutOfRange as PositionOutOfRangeError}, ext::util::{PrettifiedTimestamp, PrettyJoiner, PrettyTruncator}, - gateway::ExpectedGuildIdAware, - lavalink::{CorrectTrackInfo, ExpectedPlayerDataAware, LavalinkAware, QueueItem}, + lavalink::{CorrectTrackInfo, QueueItem}, }; fn generate_position_choice( position: NonZeroUsize, track: &QueueItem, - ctx: &Ctx, + ctx: &impl CacheAware, ) -> CommandOptionChoice { let track_info = &track.track().info; let track_length = PrettifiedTimestamp::from(Duration::milliseconds(track_info.length as i64)); @@ -76,7 +76,7 @@ fn generate_position_choices<'a>( queue_len: NonZeroUsize, queue_iter: impl Iterator + Clone, excluded: &HashSet, - ctx: &Ctx, + ctx: &impl CacheAware, ) -> Vec { impl_generate_position_choices( queue_iter @@ -93,7 +93,7 @@ fn generate_position_choices_reversed<'a>( queue_len: NonZeroUsize, queue_iter: impl Clone + DoubleEndedIterator, excluded: &HashSet, - ctx: &Ctx, + ctx: &impl CacheAware, ) -> Vec { impl_generate_position_choices( queue_iter @@ -109,7 +109,7 @@ fn generate_position_choices_reversed<'a>( fn impl_generate_position_choices<'a>( queue_iter: impl Iterator + Clone, excluded: &HashSet, - ctx: &Ctx, + ctx: &impl CacheAware, ) -> Vec { queue_iter .filter(|(p, _)| !excluded.contains(p)) @@ -123,7 +123,7 @@ fn generate_position_choices_from_input<'a>( queue_len: NonZeroUsize, queue_iter: impl Clone + DoubleEndedIterator, excluded: &HashSet, - ctx: &Ctx, + ctx: &impl CacheAware, ) -> Vec { normalize_queue_position(input, queue_len) .filter(|p| !excluded.contains(p)) @@ -139,7 +139,7 @@ fn generate_position_choices_from_fuzzy_match<'a>( focused: &str, queue_iter: impl Iterator, excluded: &HashSet, - ctx: &Ctx, + ctx: &impl CacheAware, ) -> Vec { let queue_iter = queue_iter .filter_map(|(p, t)| { @@ -150,7 +150,7 @@ fn generate_position_choices_from_fuzzy_match<'a>( Some(( p, t, - FUZZY_MATCHER.fuzzy_match(&format!("{requester} {author} {title}",), focused)?, + fuzzy_matcher().fuzzy_match(&format!("{requester} {author} {title}",), focused)?, )) }) .sorted_by_key(|(_, _, s)| -s) @@ -192,9 +192,10 @@ fn validate_input_positions( async fn remove_range( start: i64, end: i64, - ctx: &mut Ctx, + ctx: &mut GuildCtx, + player: &Player, ) -> Result<(), RemoveTracksError> { - let data = ctx.player_data(); + let data = player.data(); let mut data_w = data.write().await; let queue = data_w.queue_mut(); @@ -213,14 +214,15 @@ async fn remove_range( .collect(); drop(data_w); - impl_remove(positions, removed, queue_cleared, ctx).await + impl_remove(positions, removed, queue_cleared, ctx, player).await } async fn remove( positions: Box<[NonZeroUsize]>, - ctx: &mut Ctx, + ctx: &mut GuildCtx, + player: &Player, ) -> Result<(), RemoveTracksError> { - let data = ctx.player_data(); + let data = player.data(); let mut data_w = data.write().await; let queue = data_w.queue_mut(); @@ -234,16 +236,17 @@ async fn remove( }; drop(data_w); - impl_remove(positions, removed, queue_cleared, ctx).await + impl_remove(positions, removed, queue_cleared, ctx, player).await } async fn impl_remove( positions: Box<[NonZeroUsize]>, removed: Vec, queue_cleared: bool, - ctx: &mut Ctx, + ctx: &mut GuildCtx, + player: &Player, ) -> Result<(), RemoveTracksError> { - let data = ctx.player_data(); + let data = player.data(); let mut data_w = data.write().await; let queue = data_w.queue_mut(); @@ -258,7 +261,9 @@ async fn impl_remove( _ => format!("`{removed_len} tracks`"), }; let minus = match removed_len { - 0 => unreachable!(), + // SAFETY: `/remove` always remove at least one track after input positions have been validated, + // so this branch is unreachable + 0 => unsafe { std::hint::unreachable_unchecked() }, 1 => "**`ー`**", _ => "**`≡-`**", }; @@ -270,12 +275,11 @@ async fn impl_remove( if positions.binary_search(¤t).is_ok() { queue.adjust_repeat_mode(); let next = queue.current().map(|t| t.track().clone()); - let guild_id = ctx.guild_id(); queue - .with_advance_lock_and_stopped(guild_id, ctx.lavalink(), |player| async move { + .with_advance_lock_and_stopped(&player.context, |p| async move { if let Some(ref next) = next { - player.play(next).await?; + p.play(next).await?; } Ok(()) }) diff --git a/lyra/src/bot/component/queue/clear.rs b/lyra/src/bot/component/queue/clear.rs index d360326..98b7ce2 100644 --- a/lyra/src/bot/component/queue/clear.rs +++ b/lyra/src/bot/component/queue/clear.rs @@ -7,10 +7,10 @@ use crate::bot::{ check, macros::out, model::{BotSlashCommand, SlashCtx}, + require, }, error::CommandResult, - gateway::ExpectedGuildIdAware, - lavalink::{DelegateMethods, Event, LavalinkAware}, + lavalink::{Event, LavalinkAware}, }; /// Clears the queue @@ -19,15 +19,14 @@ use crate::bot::{ pub struct Clear; impl BotSlashCommand for Clear { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - let in_voice_with_user = check::in_voice(&ctx)?.with_user()?; - check::queue_not_empty(&ctx).await?; - check::not_suppressed(&ctx)?; - - let guild_id = ctx.guild_id(); - let lavalink = ctx.lavalink(); - - let data = lavalink.player_data(guild_id); + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let in_voice = require::in_voice(&ctx)?.and_unsuppressed()?; + let connection = ctx.lavalink().connection_from(&in_voice); + let in_voice_with_user = check::in_voice_with_user(in_voice)?; + let player = require::player(&ctx)?.and_queue_not_empty().await?; + + let data = player.data(); { let data_r = data.read().await; let queue = data_r.queue(); @@ -35,8 +34,9 @@ impl BotSlashCommand for Clear { let positions = (1..=queue.len()).filter_map(NonZeroUsize::new); check::all_users_track(positions, in_voice_with_user, queue, &ctx)?; - queue.stop_with_advance_lock(guild_id, lavalink).await?; - lavalink.dispatch(guild_id, Event::QueueClear); + queue.stop_with_advance_lock(&player.context).await?; + connection.dispatch(Event::QueueClear); + drop(connection); } { diff --git a/lyra/src/bot/component/queue/fair_queue.rs b/lyra/src/bot/component/queue/fair_queue.rs index 6f504cf..9f1aa7d 100644 --- a/lyra/src/bot/component/queue/fair_queue.rs +++ b/lyra/src/bot/component/queue/fair_queue.rs @@ -5,11 +5,10 @@ use crate::bot::{ check, macros::{bad, out}, model::BotSlashCommand, - SlashCtx, + require, SlashCtx, }, error::CommandResult, - gateway::ExpectedGuildIdAware, - lavalink::{DelegateMethods, IndexerType, LavalinkAware}, + lavalink::IndexerType, }; /// Toggles fair queuing @@ -18,13 +17,13 @@ use crate::bot::{ pub struct FairQueue; impl BotSlashCommand for FairQueue { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; check::user_is_dj(&ctx)?; - check::in_voice(&ctx)?.with_someone_else()?; - check::queue_not_empty(&ctx).await?; + let _ = require::in_voice(&ctx)?.and_with_someone_else()?; + let player = require::player(&ctx)?.and_queue_not_empty().await?; - let guild_id = ctx.guild_id(); - let data = ctx.lavalink().player_data(guild_id); + let data = player.data(); let indexer_type = data.read().await.queue().indexer_type(); match indexer_type { diff --git a/lyra/src/bot/component/queue/move.rs b/lyra/src/bot/component/queue/move.rs index 69f6fa0..abfa347 100644 --- a/lyra/src/bot/component/queue/move.rs +++ b/lyra/src/bot/component/queue/move.rs @@ -8,11 +8,12 @@ use crate::bot::{ check, macros::{bad, out, sus}, model::{BotAutocomplete, BotSlashCommand}, - AutocompleteCtx, SlashCtx, + require, AutocompleteCtx, SlashCtx, }, component::queue::normalize_queue_position, + core::model::CacheAware, error::{command::AutocompleteResult, CommandResult}, - lavalink::{CorrectTrackInfo, ExpectedPlayerDataAware, PlayerDataAware}, + lavalink::{CorrectTrackInfo, PlayerAware}, }; enum MoveAutocompleteOptionType { @@ -29,11 +30,12 @@ struct MoveAutocompleteOptions { async fn generate_move_autocomplete_choices( options: &MoveAutocompleteOptions, - ctx: &AutocompleteCtx, + ctx: &(impl PlayerAware + CacheAware + Sync), ) -> Vec { - let Some(data) = ctx.get_player_data() else { + let Ok(player) = require::player(ctx) else { return Vec::new(); }; + let data = player.data(); let data_r = data.read().await; let (queue, Some(queue_len)) = (data_r.queue(), NonZeroUsize::new(data_r.queue().len())) else { return Vec::new(); @@ -103,7 +105,8 @@ pub struct Autocomplete { } impl BotAutocomplete for Autocomplete { - async fn execute(self, mut ctx: AutocompleteCtx) -> AutocompleteResult { + async fn execute(self, ctx: AutocompleteCtx) -> AutocompleteResult { + let mut ctx = require::guild(ctx)?; let (focused, kind) = match (self.track, self.position) { (AutocompleteValue::Focused(focused), AutocompleteValue::None) => { (focused, MoveAutocompleteOptionType::TrackFocused) @@ -119,7 +122,9 @@ impl BotAutocomplete for Autocomplete { focused, MoveAutocompleteOptionType::PositionFocusedTrackCompleted(i), ), - _ => unreachable!(), + // SAFETY: only one autocomplete options can be focused at a time, + // so this branch is unreachable + _ => unsafe { std::hint::unreachable_unchecked() }, }; let options = MoveAutocompleteOptions { @@ -144,18 +149,18 @@ pub struct Move { } impl BotSlashCommand for Move { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - let in_voice_with_user = check::in_voice(&ctx)?.with_user()?; - check::queue_not_empty(&ctx).await?; - check::not_suppressed(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let in_voice_with_user = + check::in_voice_with_user(require::in_voice(&ctx)?.and_unsuppressed()?)?; + let player = require::player(&ctx)?.and_queue_not_empty().await?; - let data = ctx.player_data(); + let data = player.data(); let mut data_w = data.write().await; let queue = data_w.queue_mut(); let queue_len = queue.len(); if queue_len == 1 { - drop(in_voice_with_user); sus!( "Nowhere to move the track as it is the only track in the queue.", ctx @@ -165,24 +170,22 @@ impl BotSlashCommand for Move { super::validate_input_positions(&[self.track, self.position], queue_len)?; if self.track == self.position { - drop(in_voice_with_user); bad!( format!("Invalid new position: {}; New position must be different from the old position", self.position), ctx ); } - let position = - NonZeroUsize::new(self.position as usize).expect("self.position is non-zero"); + // SAFETY: `self.track as usize` is in range [1, +inf), so it is non-zero + let position = unsafe { NonZeroUsize::new_unchecked(self.position as usize) }; check::users_track(position, in_voice_with_user, queue, &ctx)?; - let track_position = - NonZeroUsize::new(self.track as usize).expect("self.track is non-zero"); + // SAFETY: `self.track as usize` is in range [1, +inf), so it is non-zero + let track_position = unsafe { NonZeroUsize::new_unchecked(self.track as usize) }; let queue_position = queue.position(); - let track = queue - .remove(track_position.get() - 1) - .expect("self.track is in bounds"); + // SAFETY: `track_position.get() - 1` has been validated to be in-bounds, so this unwrap is safe + let track = unsafe { queue.remove(track_position.get() - 1).unwrap_unchecked() }; let track_title = track.track().info.corrected_title(); let message = format!("⤴️ Moved `{track_title}` to position **`{position}`**"); diff --git a/lyra/src/bot/component/queue/play.rs b/lyra/src/bot/component/queue/play.rs index 849b26e..71d543d 100644 --- a/lyra/src/bot/component/queue/play.rs +++ b/lyra/src/bot/component/queue/play.rs @@ -1,3 +1,5 @@ +use std::hint::unreachable_unchecked; + use chrono::Duration; use futures::future; use itertools::{Either, Itertools}; @@ -22,18 +24,24 @@ use twilight_util::builder::command::CommandBuilder; use crate::bot::{ command::{ macros::{bad, crit, out_or_fol, what}, - model::{BotAutocomplete, BotMessageCommand, BotSlashCommand, Ctx, RespondViaMessage}, - util, AutocompleteCtx, MessageCtx, SlashCtx, + model::{BotAutocomplete, BotMessageCommand, BotSlashCommand, GuildCtx, RespondViaMessage}, + require, util, AutocompleteCtx, MessageCtx, SlashCtx, + }, + core::{ + model::AuthorIdAware, + r#const::{discord::COMMAND_CHOICES_LIMIT, misc::ADD_TRACKS_WRAP_LIMIT, regex}, }, - core::r#const::{discord::COMMAND_CHOICES_LIMIT, misc::ADD_TRACKS_WRAP_LIMIT, regex}, error::{ command::AutocompleteResult, component::queue::play::{self, LoadTrackProcessManyError, QueryError}, CommandResult, LoadFailed as LoadFailedError, }, ext::util::{PrettifiedTimestamp, PrettyJoiner, PrettyTruncator, ViaGrapheme}, - gateway::ExpectedGuildIdAware, - lavalink::{CorrectPlaylistInfo, CorrectTrackInfo, DelegateMethods, LavalinkAware}, + gateway::GuildIdAware, + lavalink::{ + CorrectPlaylistInfo, CorrectTrackInfo, LavalinkAware, UnwrappedPlayerData, + UnwrappedPlayerInfoUri, + }, }; struct LoadTrackContext { @@ -42,7 +50,7 @@ struct LoadTrackContext { } impl LoadTrackContext { - fn new_via(ctx: &(impl ExpectedGuildIdAware + LavalinkAware)) -> Self { + fn new_via(ctx: &(impl GuildIdAware + LavalinkAware)) -> Self { Self { guild_id: ctx.guild_id(), lavalink: ctx.lavalink().clone_inner(), @@ -64,7 +72,9 @@ impl LoadTrackContext { match loaded.load_type { TrackLoadType::Track => { let Some(TrackLoadData::Track(t)) = loaded.data else { - unreachable!() + // SAFETY: `loaded.load_type` is `Track`, + // so `loaded.data` must be `TrackLoadData::Track(_)` + unsafe { unreachable_unchecked() } }; Ok(LoadTrackResult::Track(t)) } @@ -99,7 +109,9 @@ impl Playlist { match loaded.load_type { TrackLoadType::Playlist => { let Some(TrackLoadData::Playlist(data)) = loaded.data else { - unreachable!() + // SAFETY: `loaded.load_type` is `Playlist`, + // so `loaded.data` must be `TrackLoadData::Playlist(_)` + unsafe { unreachable_unchecked() } }; Self { @@ -163,6 +175,10 @@ trait AutocompleteResultPrettify { fn prettify(&mut self) -> String; } +trait UnsafeAutocompleteResultPrettify { + unsafe fn prettify(&mut self) -> String; +} + impl AutocompleteResultPrettify for TrackData { fn prettify(&mut self) -> String { let track_info = &mut self.info; @@ -181,10 +197,12 @@ impl AutocompleteResultPrettify for TrackData { } } -impl AutocompleteResultPrettify for LoadedTracks { - fn prettify(&mut self) -> String { +impl UnsafeAutocompleteResultPrettify for LoadedTracks { + unsafe fn prettify(&mut self) -> String { let Some(TrackLoadData::Playlist(ref mut data)) = self.data else { - unreachable!() + // SAFETY: `loaded.load_type` is `Search`, + // so `loaded.data` must be `TrackLoadData::Search(_)` + unsafe { unreachable_unchecked() } }; let name = data.info.take_and_correct_name(); @@ -203,26 +221,30 @@ impl AutocompleteResultPrettify for LoadedTracks { } impl BotAutocomplete for Autocomplete { - async fn execute(self, mut ctx: AutocompleteCtx) -> AutocompleteResult { - let query = [ - self.query, - self.query_2, - self.query_3, - self.query_4, - self.query_5, - ] - .into_iter() - .find_map(|q| match q { - AutocompleteValue::Focused(q) => Some(q), - _ => None, - }) - .map(|q| { - let source = self.source.unwrap_or_default(); - (!regex::URL.is_match(&q)) - .then(|| format!("{}{}", source.value(), q).into_boxed_str()) - .unwrap_or_else(|| q.into_boxed_str()) - }) - .expect("exactly one option is focused"); + async fn execute(self, ctx: AutocompleteCtx) -> AutocompleteResult { + let mut ctx = require::guild(ctx)?; + // SAFETY: exactly one autocomplete option is focused, so finding will always be successful + let query = unsafe { + [ + self.query, + self.query_2, + self.query_3, + self.query_4, + self.query_5, + ] + .into_iter() + .find_map(|q| match q { + AutocompleteValue::Focused(q) => Some(q), + _ => None, + }) + .map(|q| { + let source = self.source.unwrap_or_default(); + (!regex::url().is_match(&q)) + .then(|| format!("{}{}", source.value(), q).into_boxed_str()) + .unwrap_or_else(|| q.into_boxed_str()) + }) + .unwrap_unchecked() + }; let guild_id = ctx.guild_id(); let load_ctx = LoadTrackContext { @@ -234,7 +256,9 @@ impl BotAutocomplete for Autocomplete { let choices = match loaded.load_type { TrackLoadType::Search => { let Some(TrackLoadData::Search(tracks)) = loaded.data else { - unreachable!() + // SAFETY: `loaded.load_type` is `Search`, + // so `loaded.data` must be `TrackLoadData::Search(_)` + unsafe { unreachable_unchecked() } }; tracks @@ -242,29 +266,28 @@ impl BotAutocomplete for Autocomplete { .map(|mut t| CommandOptionChoice { name: t.prettify(), name_localizations: None, - value: CommandOptionChoiceValue::String( - t.info.uri.expect("track is nonlocal"), - ), + value: CommandOptionChoiceValue::String(t.info.into_uri_unwrapped()), }) .take(COMMAND_CHOICES_LIMIT) .collect() } TrackLoadType::Track => { let Some(TrackLoadData::Track(mut track)) = loaded.data else { - unreachable!() + // SAFETY: `loaded.load_type` is `Track`, + // so `loaded.data` must be `TrackLoadData::Track(_)` + unsafe { unreachable_unchecked() } }; vec![CommandOptionChoice { name: track.prettify(), name_localizations: None, - value: CommandOptionChoiceValue::String( - track.info.uri.expect("track is nonlocal"), - ), + value: CommandOptionChoiceValue::String(track.info.into_uri_unwrapped()), }] } TrackLoadType::Playlist => { let mut choices = vec![CommandOptionChoice { - name: loaded.prettify(), + // SAFETY: `loaded.load_type` is `Playlist`, so this is safe + name: unsafe { loaded.prettify() }, name_localizations: None, value: CommandOptionChoiceValue::String( query.grapheme_truncate(100).to_string(), @@ -285,9 +308,7 @@ impl BotAutocomplete for Autocomplete { choices.push(CommandOptionChoice { name: track.prettify(), name_localizations: None, - value: CommandOptionChoiceValue::String( - track.info.uri.expect("track is nonlocal"), - ), + value: CommandOptionChoiceValue::String(track.info.into_uri_unwrapped()), }); } @@ -302,11 +323,9 @@ impl BotAutocomplete for Autocomplete { } async fn play( - ctx: &mut Ctx, + ctx: &mut GuildCtx, queries: impl IntoIterator> + Send, ) -> Result<(), play::Error> { - let guild_id = ctx.guild_id(); - let load_ctx = LoadTrackContext::new_via(ctx); match load_ctx.process_many(queries).await { Ok(results) => { @@ -321,7 +340,7 @@ async fn play( format!( "[`{}`](<{}>)", t.info.corrected_title(), - t.info.uri.as_ref().expect("track is nonlocal") + t.info.uri_unwrapped() ) }) .collect::>() @@ -357,7 +376,9 @@ async fn play( .collect::>() .pretty_join_with_and(); let plus = match tracks_len + playlists_len { - 0 => unreachable!(), + // SAFETY: at least one tracks or playlists must be loaded, + // so this should never happen + 0 => unsafe { std::hint::unreachable_unchecked() }, 1 => "**`+`**", _ => "**`≡+`**", }; @@ -365,18 +386,19 @@ async fn play( util::auto_join_or_check_in_voice_with_user_and_check_not_suppressed(ctx).await?; let total_tracks = Vec::from(results); - let first_track = total_tracks.first().expect("results is non-empty").clone(); + // SAFETY: at least one tracks must be loaded, so this unwrap is safe + let first_track = unsafe { total_tracks.first().cloned().unwrap_unchecked() }; - util::auto_new_player_data(ctx).await?; + let player = util::auto_new_player(ctx).await?; - ctx.lavalink() - .player_data(guild_id) + player + .data_unwrapped() .write() .await .queue_mut() .enqueue(total_tracks, ctx.author_id()); - ctx.lavalink().player(guild_id).play(&first_track).await?; + player.play(&first_track).await?; out_or_fol!(format!("{} Added {}", plus, enqueued_text), ctx); } @@ -445,7 +467,8 @@ pub struct Play { } impl BotSlashCommand for Play { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; let queries = [ Some(self.query), self.query_2, @@ -478,7 +501,8 @@ pub struct File { } impl BotSlashCommand for File { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; let files = [ Some(self.track), self.track_2, @@ -527,12 +551,13 @@ pub struct AddToQueue; impl AddToQueue { pub fn create_command() -> Command { - CommandBuilder::new("➕ Add to queue", "", CommandType::Message).build() + CommandBuilder::new("➕ Add to queue", String::new(), CommandType::Message).build() } } impl BotMessageCommand for AddToQueue { - async fn run(mut ctx: MessageCtx) -> CommandResult { + async fn run(ctx: MessageCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; let message = ctx.target_message(); let queries = extract_queries(message); diff --git a/lyra/src/bot/component/queue/remove.rs b/lyra/src/bot/component/queue/remove.rs index c714720..5c62e88 100644 --- a/lyra/src/bot/component/queue/remove.rs +++ b/lyra/src/bot/component/queue/remove.rs @@ -11,20 +11,22 @@ use crate::bot::{ command::{ check, model::{BotAutocomplete, BotSlashCommand}, - AutocompleteCtx, SlashCtx, + require, AutocompleteCtx, SlashCtx, }, + core::model::CacheAware, error::{command::AutocompleteResult, CommandResult}, - lavalink::{ExpectedPlayerDataAware, PlayerDataAware}, + lavalink::PlayerAware, }; async fn generate_remove_choices( focused: &str, finished: Vec, - ctx: &AutocompleteCtx, + ctx: &(impl CacheAware + PlayerAware + Sync), ) -> Vec { - let Some(data) = ctx.get_player_data() else { + let Ok(player) = require::player(ctx) else { return Vec::new(); }; + let data = player.data(); let data_r = data.read().await; let (queue, Some(queue_len)) = (data_r.queue(), NonZeroUsize::new(data_r.queue().len())) else { return Vec::new(); @@ -68,7 +70,8 @@ pub struct Autocomplete { } impl BotAutocomplete for Autocomplete { - async fn execute(self, mut ctx: AutocompleteCtx) -> AutocompleteResult { + async fn execute(self, ctx: AutocompleteCtx) -> AutocompleteResult { + let mut ctx = require::guild(ctx)?; let tracks = [ self.track, self.track_2, @@ -85,13 +88,16 @@ impl BotAutocomplete for Autocomplete { }) .copied() .collect::>(); - let focused = tracks - .into_iter() - .find_map(|a| match a { - AutocompleteValue::Focused(i) => Some(i), - _ => None, - }) - .expect("exactly one option is focused"); + // SAFETY: exactly one autocomplete option is focused, so finding will always be successful + let focused = unsafe { + tracks + .into_iter() + .find_map(|a| match a { + AutocompleteValue::Focused(i) => Some(i), + _ => None, + }) + .unwrap_unchecked() + }; let choices = generate_remove_choices(&focused, finished, &ctx).await; Ok(ctx.autocomplete(choices).await?) @@ -120,12 +126,13 @@ pub struct Remove { } impl BotSlashCommand for Remove { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - let in_voice_with_user = check::in_voice(&ctx)?.with_user()?; - check::queue_not_empty(&ctx).await?; - check::not_suppressed(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let in_voice_with_user = + check::in_voice_with_user(require::in_voice(&ctx)?.and_unsuppressed()?)?; + let player = require::player(&ctx)?.and_queue_not_empty().await?; - let data = ctx.player_data(); + let data = player.data(); let data_r = data.read().await; let queue = data_r.queue(); let queue_len = queue.len(); @@ -154,6 +161,6 @@ impl BotSlashCommand for Remove { positions.sort_unstable(); drop(data_r); - Ok(super::remove(positions.into(), &mut ctx).await?) + Ok(super::remove(positions.into(), &mut ctx, &player).await?) } } diff --git a/lyra/src/bot/component/queue/remove_range.rs b/lyra/src/bot/component/queue/remove_range.rs index c75348a..0cbf118 100644 --- a/lyra/src/bot/component/queue/remove_range.rs +++ b/lyra/src/bot/component/queue/remove_range.rs @@ -11,12 +11,12 @@ use crate::bot::{ check, macros::{bad, sus}, model::{BotAutocomplete, BotSlashCommand}, - AutocompleteCtx, SlashCtx, + require, AutocompleteCtx, SlashCtx, }, component::queue::Remove, - core::model::InteractionClient, + core::model::{CacheAware, InteractionClient}, error::{command::AutocompleteResult, CommandResult}, - lavalink::{ExpectedPlayerDataAware, PlayerDataAware}, + lavalink::PlayerAware, }; enum RemoveRangeAutocompleteOptionsType { @@ -33,11 +33,12 @@ struct RemoveRangeAutocompleteOptions { async fn generate_remove_range_autocomplete_choices( options: &RemoveRangeAutocompleteOptions, - ctx: &AutocompleteCtx, + ctx: &(impl CacheAware + PlayerAware + Sync), ) -> Vec { - let Some(data) = ctx.get_player_data() else { + let Ok(player) = require::player(ctx) else { return Vec::new(); }; + let data = player.data(); let data_r = data.read().await; let (queue, Some(queue_len)) = (data_r.queue(), NonZeroUsize::new(data_r.queue().len())) else { return Vec::new(); @@ -108,7 +109,8 @@ pub struct Autocomplete { } impl BotAutocomplete for Autocomplete { - async fn execute(self, mut ctx: AutocompleteCtx) -> AutocompleteResult { + async fn execute(self, ctx: AutocompleteCtx) -> AutocompleteResult { + let mut ctx = require::guild(ctx)?; let (focused, kind) = match (self.start, self.end) { (AutocompleteValue::Focused(focused), AutocompleteValue::None) => { (focused, RemoveRangeAutocompleteOptionsType::StartFocused) @@ -124,7 +126,9 @@ impl BotAutocomplete for Autocomplete { focused, RemoveRangeAutocompleteOptionsType::EndFocusedStartCompleted(i), ), - _ => unreachable!(), + // SAFETY: only one autocomplete options can be focused at a time, + // so this branch is unreachable + _ => unsafe { std::hint::unreachable_unchecked() }, }; let options = RemoveRangeAutocompleteOptions { @@ -149,12 +153,13 @@ pub struct RemoveRange { } impl BotSlashCommand for RemoveRange { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - let in_voice_with_user = check::in_voice(&ctx)?.with_user()?; - check::queue_not_empty(&ctx).await?; - check::not_suppressed(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let in_voice_with_user = + check::in_voice_with_user(require::in_voice(&ctx)?.and_unsuppressed()?)?; + let player = require::player(&ctx)?.and_queue_not_empty().await?; - let data = ctx.player_data(); + let data = player.data(); let data_r = data.read().await; let queue = data_r.queue(); let queue_len = queue.len(); @@ -162,7 +167,6 @@ impl BotSlashCommand for RemoveRange { if queue_len == 1 { let remove = InteractionClient::mention_command::(); - drop(in_voice_with_user); sus!( format!("The queue only has one track; Use {remove} instead."), ctx @@ -187,7 +191,6 @@ impl BotSlashCommand for RemoveRange { ) }; - drop(in_voice_with_user); bad!(message, ctx); } @@ -195,6 +198,6 @@ impl BotSlashCommand for RemoveRange { check::all_users_track(positions, in_voice_with_user, queue, &ctx)?; drop(data_r); - Ok(super::remove_range(self.start, self.end, &mut ctx).await?) + Ok(super::remove_range(self.start, self.end, &mut ctx, &player).await?) } } diff --git a/lyra/src/bot/component/queue/repeat.rs b/lyra/src/bot/component/queue/repeat.rs index 47befee..9ae3274 100644 --- a/lyra/src/bot/component/queue/repeat.rs +++ b/lyra/src/bot/component/queue/repeat.rs @@ -2,10 +2,15 @@ use twilight_interactions::command::{CommandModel, CommandOption, CreateCommand, use crate::bot::{ command::{ - check::CheckerBuilder, macros::out_or_upd, model::BotSlashCommand, poll::Topic, SlashCtx, + check, + macros::out_or_upd, + model::BotSlashCommand, + poll::Topic, + require::{self, CachelessInVoice}, + SlashCtx, }, error::CommandResult, - gateway::ExpectedGuildIdAware, + gateway::GuildIdAware, lavalink::{self, DelegateMethods, LavalinkAware}, }; @@ -38,7 +43,8 @@ pub struct Repeat { } impl BotSlashCommand for Repeat { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; let guild_id = ctx.guild_id(); let mode = { if let Some(mode) = self.mode { @@ -52,17 +58,19 @@ impl BotSlashCommand for Repeat { } }; - CheckerBuilder::new() - .in_voice_with_user_only_with_poll(Topic::Repeat(mode)) - .queue_not_empty() - .build() - .run(&mut ctx) + let in_voice = require::in_voice(&ctx)?; + let in_voice_cacheless = CachelessInVoice::from(&in_voice); + let player = require::player(&ctx)?.and_queue_not_empty().await?; + check::in_voice_with_user(in_voice)? + .only_else_poll(Topic::Repeat(mode))? + .start(&mut ctx) .await?; - let lavalink = ctx.lavalink(); - lavalink.dispatch(guild_id, lavalink::Event::QueueRepeat); - lavalink - .player_data(guild_id) + ctx.lavalink() + .connection_from(&in_voice_cacheless) + .dispatch(lavalink::Event::QueueRepeat); + player + .data() .write() .await .queue_mut() diff --git a/lyra/src/bot/component/queue/shuffle.rs b/lyra/src/bot/component/queue/shuffle.rs index a051230..384542b 100644 --- a/lyra/src/bot/component/queue/shuffle.rs +++ b/lyra/src/bot/component/queue/shuffle.rs @@ -2,14 +2,13 @@ use twilight_interactions::command::{CommandModel, CreateCommand}; use crate::bot::{ command::{ - check::CheckerBuilder, + check, macros::{bad, out}, model::BotSlashCommand, - SlashCtx, + require, SlashCtx, }, error::CommandResult, - gateway::ExpectedGuildIdAware, - lavalink::{DelegateMethods, IndexerType, LavalinkAware}, + lavalink::IndexerType, }; /// Toggles queue shuffling @@ -18,16 +17,12 @@ use crate::bot::{ pub struct Shuffle; impl BotSlashCommand for Shuffle { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - CheckerBuilder::new() - .in_voice_with_user_only() - .queue_not_empty() - .build() - .run(&mut ctx) - .await?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + check::in_voice_with_user(require::in_voice(&ctx)?)?.only()?; + let player = require::player(&ctx)?.and_queue_not_empty().await?; - let guild_id = ctx.guild_id(); - let data = ctx.lavalink().player_data(guild_id); + let data = player.data(); let data_r = data.read().await; let indexer_type = data_r.queue().indexer_type(); diff --git a/lyra/src/bot/component/tuning.rs b/lyra/src/bot/component/tuning.rs index f21d500..d1ac255 100644 --- a/lyra/src/bot/component/tuning.rs +++ b/lyra/src/bot/component/tuning.rs @@ -14,54 +14,62 @@ pub use volume::Volume; use crate::bot::{ command::{ check, - model::{Ctx, CtxKind}, + model::{CtxKind, GuildCtx}, + require::{self, InVoice, Player}, }, core::model::{BotStateAware, HttpAware}, - error::CommandResult, - gateway::{voice, ExpectedGuildIdAware}, - lavalink::{DelegateMethods, ExpectedPlayerAware, LavalinkAware}, + error::CommandError, + gateway::{voice, GuildIdAware}, + lavalink::{DelegateMethods, LavalinkAware}, }; #[inline] -fn common_checks(ctx: &Ctx) -> CommandResult { +fn check_user_is_dj_and_require_unsuppressed_player( + ctx: &GuildCtx, +) -> Result<(InVoice, Player), CommandError> { check::user_is_dj(ctx)?; - check::in_voice(ctx)?; - check::not_suppressed(ctx)?; - check::player_exist(ctx)?; + let in_voice = require::in_voice(ctx)?.and_unsuppressed()?; + let player = require::player(ctx)?; - Ok(()) + Ok((in_voice, player)) } #[inline] -fn unmuting_checks(ctx: &Ctx) -> CommandResult { +fn unmuting_checks(ctx: &GuildCtx) -> Result { check::user_is_dj(ctx)?; - check::in_voice(ctx)?; + let in_voice = require::in_voice(ctx)?; - Ok(()) + Ok(in_voice) } #[inline] -fn unmuting_player_checks(ctx: &Ctx) -> CommandResult { +fn check_user_is_dj_and_require_player( + ctx: &GuildCtx, +) -> Result<(InVoice, Player), CommandError> { check::user_is_dj(ctx)?; - check::in_voice(ctx)?; - check::player_exist(ctx)?; + let in_voice = require::in_voice(ctx)?; + let player = require::player(ctx)?; - Ok(()) + Ok((in_voice, player)) +} + +trait ApplyFilter { + fn apply_to(self, filter: Filters) -> Filters; } trait UpdateFilter { - fn apply(self, filter: Filters) -> Filters; + async fn update_filter(&self, update: impl ApplyFilter + Send + Sync) -> LavalinkResult<()>; } -async fn set_filter( - ctx: &(impl ExpectedPlayerAware + Sync), - update: impl UpdateFilter + Send + Sync, -) -> LavalinkResult<()> { - let player = ctx.player(); - let old_filter = player.get_player().await?.filters.unwrap_or_default(); +impl UpdateFilter for Player { + async fn update_filter(&self, update: impl ApplyFilter + Send + Sync) -> LavalinkResult<()> { + let old_filter = self.info().await?.filters.unwrap_or_default(); - player.set_filters(update.apply(old_filter)).await?; - Ok(()) + self.context + .set_filters(update.apply_to(old_filter)) + .await?; + Ok(()) + } } #[tracing::instrument(skip_all, name = "voice_state_update")] @@ -82,7 +90,8 @@ pub async fn handle_voice_state_update(ctx: &voice::Context) -> Result<(), twili } else if let Some(d) = lavalink.get_player_data(guild_id) { Some(d.read().await.volume()) } else { - Some(NonZeroU16::new(100).expect("volume is non-zero")) + // SAFETY: `100` is non-zero + Some(unsafe { NonZeroU16::new_unchecked(100) }) }); let describe = if state_mute { "muted" } else { "unmuted" }; diff --git a/lyra/src/bot/component/tuning/equaliser.rs b/lyra/src/bot/component/tuning/equaliser.rs index 618a7ab..5a0f4a4 100644 --- a/lyra/src/bot/component/tuning/equaliser.rs +++ b/lyra/src/bot/component/tuning/equaliser.rs @@ -27,8 +27,8 @@ impl SetEqualiser { } } -impl super::UpdateFilter for Option { - fn apply(self, filter: Filters) -> Filters { +impl super::ApplyFilter for Option { + fn apply_to(self, filter: Filters) -> Filters { Filters { equalizer: self.map(|f| f.0.into()), ..filter diff --git a/lyra/src/bot/component/tuning/equaliser/custom.rs b/lyra/src/bot/component/tuning/equaliser/custom.rs index 1a6a59e..a6eddf6 100644 --- a/lyra/src/bot/component/tuning/equaliser/custom.rs +++ b/lyra/src/bot/component/tuning/equaliser/custom.rs @@ -1,8 +1,13 @@ use twilight_interactions::command::{CommandModel, CreateCommand}; use crate::bot::{ - command::macros::{bad, out}, - component::tuning::{common_checks, equaliser::SetEqualiser, set_filter}, + command::{ + macros::{bad, out}, + require, + }, + component::tuning::{ + check_user_is_dj_and_require_unsuppressed_player, equaliser::SetEqualiser, UpdateFilter, + }, }; /// Enable the player equaliser with custom settings. @@ -58,8 +63,9 @@ pub struct Custom { } impl crate::bot::command::model::BotSlashCommand for Custom { - async fn run(self, mut ctx: crate::bot::command::SlashCtx) -> crate::bot::error::CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: crate::bot::command::SlashCtx) -> crate::bot::error::CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; let equaliser = [ self.band_1, @@ -89,7 +95,7 @@ impl crate::bot::command::model::BotSlashCommand for Custom { ); }; - set_filter(&ctx, Some(filter)).await?; + player.update_filter(Some(filter)).await?; out!("🎛️🟢 Enabled player equaliser (**`Custom Settings`**)", ctx); } } diff --git a/lyra/src/bot/component/tuning/equaliser/off.rs b/lyra/src/bot/component/tuning/equaliser/off.rs index d2cef84..52e797b 100644 --- a/lyra/src/bot/component/tuning/equaliser/off.rs +++ b/lyra/src/bot/component/tuning/equaliser/off.rs @@ -1,8 +1,8 @@ use twilight_interactions::command::{CommandModel, CreateCommand}; use crate::bot::{ - command::macros::out, - component::tuning::{common_checks, set_filter}, + command::{macros::out, require}, + component::tuning::{check_user_is_dj_and_require_unsuppressed_player, UpdateFilter}, }; /// Disable the player equaliser @@ -11,10 +11,11 @@ use crate::bot::{ pub struct Off; impl crate::bot::command::model::BotSlashCommand for Off { - async fn run(self, mut ctx: crate::bot::command::SlashCtx) -> crate::bot::error::CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: crate::bot::command::SlashCtx) -> crate::bot::error::CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; - set_filter(&ctx, None::).await?; + player.update_filter(None::).await?; out!("🎛️🔴 Disabled equaliser", ctx); } } diff --git a/lyra/src/bot/component/tuning/equaliser/preset.rs b/lyra/src/bot/component/tuning/equaliser/preset.rs index 4301ad9..bec0d8f 100644 --- a/lyra/src/bot/component/tuning/equaliser/preset.rs +++ b/lyra/src/bot/component/tuning/equaliser/preset.rs @@ -1,6 +1,11 @@ use twilight_interactions::command::{CommandModel, CreateCommand}; -use crate::bot::{command::macros::out, component::tuning::equaliser::SetEqualiser}; +use crate::bot::{ + command::{macros::out, require}, + component::tuning::{ + check_user_is_dj_and_require_unsuppressed_player, equaliser::SetEqualiser, UpdateFilter, + }, +}; lyra_proc::read_equaliser_presets_as!(EqualiserPreset); @@ -25,13 +30,14 @@ pub struct Preset { } impl crate::bot::command::model::BotSlashCommand for Preset { - async fn run(self, mut ctx: crate::bot::command::SlashCtx) -> crate::bot::error::CommandResult { - super::super::common_checks(&ctx)?; + async fn run(self, ctx: crate::bot::command::SlashCtx) -> crate::bot::error::CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; let preset_name = self.preset.value(); let update = Some(SetEqualiser::from(self.preset)); - super::super::set_filter(&ctx, update).await?; + player.update_filter(update).await?; out!( format!( "🎛️🟢 Enabled player equaliser (Preset: **`{}`**)", diff --git a/lyra/src/bot/component/tuning/filter.rs b/lyra/src/bot/component/tuning/filter.rs index 6e5b30d..fb400b8 100644 --- a/lyra/src/bot/component/tuning/filter.rs +++ b/lyra/src/bot/component/tuning/filter.rs @@ -13,7 +13,7 @@ use lavalink_rs::model::player::{Filters, TremoloVibrato}; use lyra_proc::BotCommandGroup; use twilight_interactions::command::{CommandModel, CreateCommand}; -use super::UpdateFilter; +use super::ApplyFilter; trait TremoloVibratoMarker {} struct TremoloMarker; @@ -75,25 +75,22 @@ enum TremoloVibratoSettings { impl std::fmt::Display for TremoloVibratoSettings { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let settings = match self { - Self::Default => String::from("**`Default Settings`**"), - Self::Depth(d) => format!("Depth: `{d}`"), - Self::Frequency(f) => format!("Frequency: `{f} Hz.`"), - Self::Custom { - frequency: f, - depth: d, - } => format!("Frequency: `{f} Hz.`, Depth: `{d}`"), - }; - - write!(f, "{settings}") + match self { + Self::Default => f.write_str("**`Default Settings`**"), + Self::Depth(d) => write!(f, "Depth: `{d}`"), + Self::Frequency(frequency) => write!(f, "Frequency: `{frequency} Hz.`"), + Self::Custom { frequency, depth } => { + write!(f, "Frequency: `{frequency} Hz.`, Depth: `{depth}`") + } + } } } type SetTremolo = SetTremoloVibrato; type SetVibrato = SetTremoloVibrato; -impl UpdateFilter for Option> { - fn apply(self, filter: Filters) -> Filters { +impl ApplyFilter for Option> { + fn apply_to(self, filter: Filters) -> Filters { Filters { tremolo: self.map(|f| f.inner), ..filter @@ -101,8 +98,8 @@ impl UpdateFilter for Option> { } } -impl UpdateFilter for Option> { - fn apply(self, filter: Filters) -> Filters { +impl ApplyFilter for Option> { + fn apply_to(self, filter: Filters) -> Filters { Filters { vibrato: self.map(|f| f.inner), ..filter diff --git a/lyra/src/bot/component/tuning/filter/all_off.rs b/lyra/src/bot/component/tuning/filter/all_off.rs index 0225b03..feda6cd 100644 --- a/lyra/src/bot/component/tuning/filter/all_off.rs +++ b/lyra/src/bot/component/tuning/filter/all_off.rs @@ -1,7 +1,10 @@ use lavalink_rs::model::player::{Filters, Timescale}; use twilight_interactions::command::{CommandModel, CreateCommand}; -use crate::bot::{command::macros::out, lavalink::ExpectedPlayerDataAware}; +use crate::bot::{ + command::{macros::out, require}, + component::tuning::UpdateFilter, +}; struct ResetAllExceptSpeed; @@ -14,8 +17,8 @@ impl ResetAllExceptSpeed { } } -impl super::UpdateFilter for ResetAllExceptSpeed { - fn apply(self, filter: Filters) -> Filters { +impl super::ApplyFilter for ResetAllExceptSpeed { + fn apply_to(self, filter: Filters) -> Filters { let timescale = Some(Self::into_timescale_via( &filter.timescale.unwrap_or_default(), )); @@ -33,14 +36,12 @@ impl super::UpdateFilter for ResetAllExceptSpeed { pub struct AllOff; impl crate::bot::command::model::BotSlashCommand for AllOff { - async fn run( - self, - mut ctx: crate::bot::command::SlashCtx, - ) -> crate::bot::error::command::Result { - super::super::common_checks(&ctx)?; - - super::super::set_filter(&ctx, ResetAllExceptSpeed).await?; - ctx.player_data().write().await.pitch_mut().reset(); + async fn run(self, ctx: crate::bot::command::SlashCtx) -> crate::bot::error::command::Result { + let mut ctx = require::guild(ctx)?; + let player = require::player(&ctx)?; + + player.update_filter(ResetAllExceptSpeed).await?; + player.data().write().await.pitch_mut().reset(); out!("🪄🔴 Disabled all filters", ctx); } diff --git a/lyra/src/bot/component/tuning/filter/channel_mix.rs b/lyra/src/bot/component/tuning/filter/channel_mix.rs index 67cdad1..6a7b728 100644 --- a/lyra/src/bot/component/tuning/filter/channel_mix.rs +++ b/lyra/src/bot/component/tuning/filter/channel_mix.rs @@ -6,9 +6,9 @@ use crate::bot::{ command::{ macros::{bad, out}, model::BotSlashCommand, - SlashCtx, + require, SlashCtx, }, - component::tuning::{common_checks, set_filter}, + component::tuning::{check_user_is_dj_and_require_unsuppressed_player, UpdateFilter}, error::CommandResult, }; @@ -46,8 +46,8 @@ impl SetChannelMix { } } -impl crate::bot::component::tuning::UpdateFilter for Option { - fn apply(self, filter: Filters) -> Filters { +impl crate::bot::component::tuning::ApplyFilter for Option { + fn apply_to(self, filter: Filters) -> Filters { Filters { channel_mix: self.map(|c| c.0), ..filter @@ -83,8 +83,9 @@ pub struct On { } impl BotSlashCommand for On { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; let Some(update) = SetChannelMix::new( self.left_to_left, @@ -102,7 +103,7 @@ impl BotSlashCommand for On { ); }; - set_filter(&ctx, Some(update)).await?; + player.update_filter(Some(update)).await?; out!("⚗️🟢 Enabled channel mix)", ctx); } } @@ -113,10 +114,11 @@ impl BotSlashCommand for On { pub struct Off; impl BotSlashCommand for Off { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; - set_filter(&ctx, None::).await?; + player.update_filter(None::).await?; out!("⚗️🔴 Disabled channel mix", ctx); } } diff --git a/lyra/src/bot/component/tuning/filter/distortion.rs b/lyra/src/bot/component/tuning/filter/distortion.rs index 30c786f..f2870d6 100644 --- a/lyra/src/bot/component/tuning/filter/distortion.rs +++ b/lyra/src/bot/component/tuning/filter/distortion.rs @@ -6,9 +6,9 @@ use crate::bot::{ command::{ macros::{bad, out}, model::BotSlashCommand, - SlashCtx, + require, SlashCtx, }, - component::tuning::{common_checks, set_filter}, + component::tuning::{check_user_is_dj_and_require_unsuppressed_player, UpdateFilter}, error::CommandResult, }; @@ -43,8 +43,8 @@ impl SetDistortion { } } -impl crate::bot::component::tuning::UpdateFilter for Option { - fn apply(self, filter: Filters) -> Filters { +impl crate::bot::component::tuning::ApplyFilter for Option { + fn apply_to(self, filter: Filters) -> Filters { Filters { distortion: self.map(|d| d.0), ..filter @@ -84,8 +84,9 @@ pub struct On { } impl BotSlashCommand for On { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; let distortion = LavalinkDistortion { sin_offset: self.sin_offset, @@ -108,7 +109,7 @@ impl BotSlashCommand for On { ); }; - set_filter(&ctx, Some(update)).await?; + player.update_filter(Some(update)).await?; out!(format!("🍭🟢 Enabled distortion"), ctx); } } @@ -119,10 +120,11 @@ impl BotSlashCommand for On { pub struct Off; impl BotSlashCommand for Off { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; - set_filter(&ctx, None::).await?; + player.update_filter(None::).await?; out!("🍭🔴 Disabled distortion", ctx); } } diff --git a/lyra/src/bot/component/tuning/filter/low_pass.rs b/lyra/src/bot/component/tuning/filter/low_pass.rs index 7d07aca..3519de7 100644 --- a/lyra/src/bot/component/tuning/filter/low_pass.rs +++ b/lyra/src/bot/component/tuning/filter/low_pass.rs @@ -6,9 +6,9 @@ use crate::bot::{ command::{ macros::{bad, out}, model::BotSlashCommand, - SlashCtx, + require, SlashCtx, }, - component::tuning::{common_checks, set_filter}, + component::tuning::{check_user_is_dj_and_require_unsuppressed_player, UpdateFilter}, error::CommandResult, }; @@ -41,17 +41,15 @@ enum LowPassSettings { impl std::fmt::Display for LowPassSettings { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let settings = match self { - Self::Default => String::from("**`Default Settings`**"), - Self::Custom(s) => format!("Smoothing: `{s:.1}`"), - }; - - write!(f, "{settings}") + match self { + Self::Default => f.write_str("**`Default Settings`**"), + Self::Custom(s) => write!(f, "Smoothing: `{s:.1}`"), + } } } -impl crate::bot::component::tuning::UpdateFilter for Option { - fn apply(self, filter: Filters) -> Filters { +impl crate::bot::component::tuning::ApplyFilter for Option { + fn apply_to(self, filter: Filters) -> Filters { Filters { low_pass: self.map(|l| l.0), ..filter @@ -78,8 +76,9 @@ pub struct On { } impl BotSlashCommand for On { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; let Some(update) = SetLowPass::new(self.smoothing) else { bad!( @@ -89,7 +88,7 @@ impl BotSlashCommand for On { }; let settings = update.settings(); - set_filter(&ctx, Some(update)).await?; + player.update_filter(Some(update)).await?; out!(format!("😶‍🌫️🟢 Enabled low pass ({settings})"), ctx); } } @@ -100,10 +99,11 @@ impl BotSlashCommand for On { pub struct Off; impl BotSlashCommand for Off { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; - set_filter(&ctx, None::).await?; + player.update_filter(None::).await?; out!("😶‍🌫️🔴 Disabled low pass", ctx); } } diff --git a/lyra/src/bot/component/tuning/filter/pitch.rs b/lyra/src/bot/component/tuning/filter/pitch.rs index 52a48ac..439e336 100644 --- a/lyra/src/bot/component/tuning/filter/pitch.rs +++ b/lyra/src/bot/component/tuning/filter/pitch.rs @@ -11,10 +11,7 @@ use lavalink_rs::{ use lyra_proc::BotCommandGroup; use twilight_interactions::command::{CommandModel, CreateCommand}; -use crate::bot::{ - gateway::ExpectedGuildIdAware, - lavalink::{DelegateMethods, LavalinkAware, Pitch as PitchModel}, -}; +use crate::bot::{command::require::Player, lavalink::Pitch as PitchModel}; enum Tier { Default, @@ -43,16 +40,13 @@ impl PitchModel { } async fn shift_pitch( - ctx: &(impl LavalinkAware + ExpectedGuildIdAware + Sync), + player: &Player, half_tones: NonZeroI64, ) -> LavalinkResult<(PitchModel, PitchModel)> { - let guild_id = ctx.guild_id(); - let lavalink = ctx.lavalink(); - let player = lavalink.player(guild_id); - let old_filter = player.get_player().await?.filters.unwrap_or_default(); + let old_filter = player.info().await?.filters.unwrap_or_default(); - let (old_pitch, new_pitch) = lavalink - .player_data(guild_id) + let (old_pitch, new_pitch) = player + .data() .write() .await .pitch_mut() @@ -65,6 +59,7 @@ async fn shift_pitch( }); player + .context .set_filters(Filters { timescale, ..old_filter diff --git a/lyra/src/bot/component/tuning/filter/pitch/down.rs b/lyra/src/bot/component/tuning/filter/pitch/down.rs index 4c3c7e8..30cc648 100644 --- a/lyra/src/bot/component/tuning/filter/pitch/down.rs +++ b/lyra/src/bot/component/tuning/filter/pitch/down.rs @@ -3,8 +3,10 @@ use std::num::NonZeroI64; use twilight_interactions::command::{CommandModel, CreateCommand}; use crate::bot::{ - command::{macros::out, model::BotSlashCommand, SlashCtx}, - component::tuning::{common_checks, filter::pitch::shift_pitch}, + command::{macros::out, model::BotSlashCommand, require, SlashCtx}, + component::tuning::{ + check_user_is_dj_and_require_unsuppressed_player, filter::pitch::shift_pitch, + }, error::CommandResult, }; @@ -18,12 +20,13 @@ pub struct Down { } impl BotSlashCommand for Down { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; - let half_tones = - NonZeroI64::new(self.half_tones.unwrap_or(2)).expect("self.half_tones is non-zero"); - let (old, new) = shift_pitch(&ctx, -half_tones).await?; + // SAFETY: `self.half_tones.unwrap_or(2)` is non-empty + let half_tones = unsafe { NonZeroI64::new_unchecked(self.half_tones.unwrap_or(2)) }; + let (old, new) = shift_pitch(&player, -half_tones).await?; let emoji = new.tier().emoji(); out!(format!("{emoji}**`ー`** ~~`{old}`~~ ➜ **`{new}`**"), ctx); diff --git a/lyra/src/bot/component/tuning/filter/pitch/set.rs b/lyra/src/bot/component/tuning/filter/pitch/set.rs index e0aab5b..4aaeb89 100644 --- a/lyra/src/bot/component/tuning/filter/pitch/set.rs +++ b/lyra/src/bot/component/tuning/filter/pitch/set.rs @@ -5,11 +5,12 @@ use crate::bot::{ command::{ macros::{bad, out}, model::BotSlashCommand, - SlashCtx, + require, SlashCtx, + }, + component::tuning::{ + check_user_is_dj_and_require_unsuppressed_player, ApplyFilter, UpdateFilter, }, - component::tuning::{common_checks, set_filter}, error::CommandResult, - lavalink::ExpectedPlayerDataAware, }; use super::Tier; @@ -48,8 +49,8 @@ impl SetPitch { } } -impl super::super::UpdateFilter for SetPitch { - fn apply(self, filter: Filters) -> Filters { +impl ApplyFilter for SetPitch { + fn apply_to(self, filter: Filters) -> Filters { let timescale = Some(self.into_timescale_via(&filter.timescale.unwrap_or_default())); Filters { @@ -69,8 +70,9 @@ pub struct Set { } impl BotSlashCommand for Set { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; let Some(update) = SetPitch::new(self.multiplier) else { bad!("Multiplier must not be 0", ctx); @@ -78,8 +80,8 @@ impl BotSlashCommand for Set { let multiplier = update.multiplier(); let emoji = update.tier().emoji(); - set_filter(&ctx, update).await?; - ctx.player_data().write().await.pitch_mut().set(multiplier); + player.update_filter(update).await?; + player.data().write().await.pitch_mut().set(multiplier); out!( format!("{emoji} Set the playback pitch to `{multiplier}`×."), diff --git a/lyra/src/bot/component/tuning/filter/pitch/up.rs b/lyra/src/bot/component/tuning/filter/pitch/up.rs index 372e151..0884e64 100644 --- a/lyra/src/bot/component/tuning/filter/pitch/up.rs +++ b/lyra/src/bot/component/tuning/filter/pitch/up.rs @@ -3,8 +3,10 @@ use std::num::NonZeroI64; use twilight_interactions::command::{CommandModel, CreateCommand}; use crate::bot::{ - command::{macros::out, model::BotSlashCommand, SlashCtx}, - component::tuning::{common_checks, filter::pitch::shift_pitch}, + command::{macros::out, model::BotSlashCommand, require, SlashCtx}, + component::tuning::{ + check_user_is_dj_and_require_unsuppressed_player, filter::pitch::shift_pitch, + }, error::CommandResult, }; @@ -18,12 +20,13 @@ pub struct Up { } impl BotSlashCommand for Up { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; - let half_tones = - NonZeroI64::new(self.half_tones.unwrap_or(2)).expect("self.half_tones is non-zero"); - let (old, new) = shift_pitch(&ctx, half_tones).await?; + // SAFETY: `self.half_tones.unwrap_or(2)` is non-zero + let half_tones = unsafe { NonZeroI64::new_unchecked(self.half_tones.unwrap_or(2)) }; + let (old, new) = shift_pitch(&player, half_tones).await?; let emoji = new.tier().emoji(); out!(format!("{emoji}**`+`** ~~`{old}`~~ ➜ **`{new}`**"), ctx); diff --git a/lyra/src/bot/component/tuning/filter/rotation.rs b/lyra/src/bot/component/tuning/filter/rotation.rs index 7410ec2..6b933cc 100644 --- a/lyra/src/bot/component/tuning/filter/rotation.rs +++ b/lyra/src/bot/component/tuning/filter/rotation.rs @@ -6,9 +6,9 @@ use crate::bot::{ command::{ macros::{bad, out}, model::BotSlashCommand, - SlashCtx, + require, SlashCtx, }, - component::tuning::{common_checks, set_filter}, + component::tuning::{check_user_is_dj_and_require_unsuppressed_player, UpdateFilter}, error::CommandResult, }; @@ -26,8 +26,8 @@ impl SetRotation { } } -impl super::UpdateFilter for Option { - fn apply(self, filter: Filters) -> Filters { +impl super::ApplyFilter for Option { + fn apply_to(self, filter: Filters) -> Filters { Filters { rotation: self.map(|r| r.0), ..filter @@ -53,15 +53,16 @@ pub struct On { } impl BotSlashCommand for On { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; let Some(update) = SetRotation::new(self.frequency) else { bad!("Frequency must not be zero.", ctx); }; let frequency = update.frequency(); - set_filter(&ctx, Some(update)).await?; + player.update_filter(Some(update)).await?; out!( format!("🍳🟢 Enabled rotation (Frequency: `{frequency} Hz.`)"), ctx @@ -75,10 +76,11 @@ impl BotSlashCommand for On { pub struct Off; impl BotSlashCommand for Off { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; - set_filter(&ctx, None::).await?; + player.update_filter(None::).await?; out!("🍳🔴 Disabled rotation", ctx); } } diff --git a/lyra/src/bot/component/tuning/filter/tremolo.rs b/lyra/src/bot/component/tuning/filter/tremolo.rs index f9ab7aa..cbaf8bb 100644 --- a/lyra/src/bot/component/tuning/filter/tremolo.rs +++ b/lyra/src/bot/component/tuning/filter/tremolo.rs @@ -5,9 +5,11 @@ use crate::bot::{ command::{ macros::{bad, out}, model::BotSlashCommand, - SlashCtx, + require, SlashCtx, + }, + component::tuning::{ + check_user_is_dj_and_require_unsuppressed_player, filter::SetTremolo, UpdateFilter, }, - component::tuning::{common_checks, filter::SetTremolo, set_filter}, error::CommandResult, }; @@ -33,15 +35,16 @@ pub struct On { } impl BotSlashCommand for On { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; let Some(update) = SetTremolo::new(self.frequency, self.depth) else { bad!("Both frequency and depth must not be zero.", ctx); }; let settings = update.settings(); - set_filter(&ctx, Some(update)).await?; + player.update_filter(Some(update)).await?; out!(format!("🎸🟢 Enabled tremolo ({settings})"), ctx); } } @@ -52,10 +55,11 @@ impl BotSlashCommand for On { pub struct Off; impl BotSlashCommand for Off { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; - set_filter(&ctx, None::).await?; + player.update_filter(None::).await?; out!("🎸🔴 Disabled tremolo", ctx); } } diff --git a/lyra/src/bot/component/tuning/filter/vibrato.rs b/lyra/src/bot/component/tuning/filter/vibrato.rs index 17b4877..c7c776e 100644 --- a/lyra/src/bot/component/tuning/filter/vibrato.rs +++ b/lyra/src/bot/component/tuning/filter/vibrato.rs @@ -5,9 +5,11 @@ use crate::bot::{ command::{ macros::{bad, out}, model::BotSlashCommand, - SlashCtx, + require, SlashCtx, + }, + component::tuning::{ + check_user_is_dj_and_require_unsuppressed_player, filter::SetVibrato, UpdateFilter, }, - component::tuning::{common_checks, filter::SetVibrato, set_filter}, error::CommandResult, }; @@ -33,15 +35,16 @@ pub struct On { } impl BotSlashCommand for On { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; let Some(update) = SetVibrato::new(self.frequency, self.depth) else { bad!("Both frequency and depth must not be zero.", ctx); }; let settings = update.settings(); - set_filter(&ctx, Some(update)).await?; + player.update_filter(Some(update)).await?; out!(format!("🎻🟢 Enabled vibrato ({settings})"), ctx); } } @@ -52,10 +55,11 @@ impl BotSlashCommand for On { pub struct Off; impl BotSlashCommand for Off { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; - set_filter(&ctx, None::).await?; + player.update_filter(None::).await?; out!("🎻🔴 Disabled vibrato", ctx); } } diff --git a/lyra/src/bot/component/tuning/speed.rs b/lyra/src/bot/component/tuning/speed.rs index d951692..341efb1 100644 --- a/lyra/src/bot/component/tuning/speed.rs +++ b/lyra/src/bot/component/tuning/speed.rs @@ -5,13 +5,13 @@ use crate::bot::{ command::{ macros::{bad, out}, model::BotSlashCommand, - SlashCtx, + require, SlashCtx, }, - component::tuning::common_checks, + component::tuning::{check_user_is_dj_and_require_unsuppressed_player, UpdateFilter}, error::CommandResult, }; -use super::UpdateFilter; +use super::ApplyFilter; enum Tier { Default, Fast, @@ -78,8 +78,8 @@ impl SpeedFilter { } } -impl UpdateFilter for SpeedFilter { - fn apply(self, filter: Filters) -> Filters { +impl ApplyFilter for SpeedFilter { + fn apply_to(self, filter: Filters) -> Filters { let timescale = Some(self.into_timescale_via(&filter.timescale.unwrap_or_default())); Filters { @@ -101,17 +101,18 @@ pub struct Speed { } impl BotSlashCommand for Speed { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; - let Some(filter) = SpeedFilter::new(self.multiplier, self.pitch_shift.unwrap_or_default()) + let Some(update) = SpeedFilter::new(self.multiplier, self.pitch_shift.unwrap_or_default()) else { bad!("Multiplier must not be 0", ctx); }; - let multiplier = filter.multiplier(); - let emoji = filter.tier().emoji(); - super::set_filter(&ctx, filter).await?; + let multiplier = update.multiplier(); + let emoji = update.tier().emoji(); + player.update_filter(update).await?; out!( format!("{emoji} Set the playback speed to `{multiplier}`×."), diff --git a/lyra/src/bot/component/tuning/volume.rs b/lyra/src/bot/component/tuning/volume.rs index f3d1074..9f58ea4 100644 --- a/lyra/src/bot/component/tuning/volume.rs +++ b/lyra/src/bot/component/tuning/volume.rs @@ -13,7 +13,8 @@ pub(super) const fn volume_emoji(percent: Option) -> &'static str { return "🔇"; }; match percent.get() { - 0 => unreachable!(), + // SAFETY: `percent` is `NonZeroU16`, so this branch is unreachable + 0 => unsafe { std::hint::unreachable_unchecked() }, 1..=33 => "🔈", 34..=66 => "🔉", 67..=100 => "🔊", diff --git a/lyra/src/bot/component/tuning/volume/down.rs b/lyra/src/bot/component/tuning/volume/down.rs index 090622b..dfc5729 100644 --- a/lyra/src/bot/component/tuning/volume/down.rs +++ b/lyra/src/bot/component/tuning/volume/down.rs @@ -3,12 +3,12 @@ use std::num::NonZeroU16; use twilight_interactions::command::{CommandModel, CreateCommand}; use crate::bot::{ - command::{macros::out, model::BotSlashCommand, SlashCtx}, - component::tuning::common_checks, + command::{macros::out, model::BotSlashCommand, require, SlashCtx}, + component::tuning::check_user_is_dj_and_require_unsuppressed_player, core::model::{BotStateAware, HttpAware}, error::CommandResult, - gateway::ExpectedGuildIdAware, - lavalink::{DelegateMethods, LavalinkAware}, + gateway::GuildIdAware, + lavalink::LavalinkAware, }; /// Decrease the playback volume @@ -21,12 +21,12 @@ pub struct Down { } impl BotSlashCommand for Down { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let (in_voice, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; - let lavalink = ctx.lavalink(); let guild_id = ctx.guild_id(); - let data = lavalink.player_data(guild_id); + let data = player.data(); let old_percent = data.read().await.volume(); let maybe_new_percent = old_percent @@ -36,10 +36,7 @@ impl BotSlashCommand for Down { let emoji = super::volume_emoji(maybe_new_percent); let (new_percent_str, warning) = if let Some(new_percent) = maybe_new_percent { - lavalink - .player(guild_id) - .set_volume(new_percent.get()) - .await?; + player.context.set_volume(new_percent.get()).await?; data.write().await.set_volume(new_percent); ( @@ -47,7 +44,7 @@ impl BotSlashCommand for Down { super::clipping_warning(new_percent), ) } else { - lavalink.connection_mut(guild_id).mute = true; + ctx.lavalink().connection_mut_from(&in_voice).mute = true; ctx.http() .update_guild_member(guild_id, ctx.bot().user_id()) .mute(true) diff --git a/lyra/src/bot/component/tuning/volume/set.rs b/lyra/src/bot/component/tuning/volume/set.rs index 09ea2ad..28225f7 100644 --- a/lyra/src/bot/component/tuning/volume/set.rs +++ b/lyra/src/bot/component/tuning/volume/set.rs @@ -3,11 +3,9 @@ use std::num::NonZeroU16; use twilight_interactions::command::{CommandModel, CreateCommand}; use crate::bot::{ - command::{macros::out, model::BotSlashCommand, SlashCtx}, - component::tuning::common_checks, + command::{macros::out, model::BotSlashCommand, require, SlashCtx}, + component::tuning::check_user_is_dj_and_require_unsuppressed_player, error::CommandResult, - gateway::ExpectedGuildIdAware, - lavalink::{DelegateMethods, LavalinkAware}, }; /// Set the playback volume @@ -20,18 +18,14 @@ pub struct Set { } impl BotSlashCommand for Set { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - common_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let (_, player) = check_user_is_dj_and_require_unsuppressed_player(&ctx)?; - let percent = NonZeroU16::new(self.percent as u16).expect("self.percent is non-zero"); - let lavalink = ctx.lavalink(); - let guild_id = ctx.guild_id(); - lavalink.player(guild_id).set_volume(percent.get()).await?; - lavalink - .player_data(guild_id) - .write() - .await - .set_volume(percent); + // SAFETY: `self.percent as u16` is in range [1, 1_000], so it is non-zero + let percent = unsafe { NonZeroU16::new_unchecked(self.percent as u16) }; + player.context.set_volume(percent.get()).await?; + player.data().write().await.set_volume(percent); let emoji = super::volume_emoji(Some(percent)); let warning = super::clipping_warning(percent); diff --git a/lyra/src/bot/component/tuning/volume/toggle_mute.rs b/lyra/src/bot/component/tuning/volume/toggle_mute.rs index 3119d43..5e0fc00 100644 --- a/lyra/src/bot/component/tuning/volume/toggle_mute.rs +++ b/lyra/src/bot/component/tuning/volume/toggle_mute.rs @@ -1,11 +1,11 @@ use twilight_interactions::command::{CommandModel, CreateCommand}; use crate::bot::{ - command::{macros::out, model::BotSlashCommand, SlashCtx}, + command::{macros::out, model::BotSlashCommand, require, SlashCtx}, component::tuning::unmuting_checks, core::model::{BotStateAware, HttpAware}, error::CommandResult, - gateway::ExpectedGuildIdAware, + gateway::GuildIdAware, lavalink::LavalinkAware, }; @@ -15,11 +15,12 @@ use crate::bot::{ pub struct ToggleMute; impl BotSlashCommand for ToggleMute { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - unmuting_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let in_voice = unmuting_checks(&ctx)?; let guild_id = ctx.guild_id(); - let mut connection = ctx.lavalink().connection_mut(guild_id); + let mut connection = ctx.lavalink().connection_mut_from(&in_voice); let mute = !connection.mute; ctx.http() diff --git a/lyra/src/bot/component/tuning/volume/up.rs b/lyra/src/bot/component/tuning/volume/up.rs index 19c0a4f..72db9fe 100644 --- a/lyra/src/bot/component/tuning/volume/up.rs +++ b/lyra/src/bot/component/tuning/volume/up.rs @@ -6,13 +6,13 @@ use crate::bot::{ command::{ macros::{note, out}, model::BotSlashCommand, - SlashCtx, + require, SlashCtx, }, - component::tuning::unmuting_player_checks, + component::tuning::check_user_is_dj_and_require_player, core::model::{BotStateAware, HttpAware}, error::CommandResult, - gateway::ExpectedGuildIdAware, - lavalink::{DelegateMethods, LavalinkAware}, + gateway::GuildIdAware, + lavalink::LavalinkAware, }; /// Increase the playback volume @@ -25,17 +25,19 @@ pub struct Up { } impl BotSlashCommand for Up { - async fn run(self, mut ctx: SlashCtx) -> CommandResult { - unmuting_player_checks(&ctx)?; + async fn run(self, ctx: SlashCtx) -> CommandResult { + let mut ctx = require::guild(ctx)?; + let (in_voice, player) = check_user_is_dj_and_require_player(&ctx)?; let lavalink = ctx.lavalink(); let guild_id = ctx.guild_id(); - let data = &lavalink.player_data(guild_id); + let data = player.data(); let percent_u16 = self.percent.unwrap_or(10) as u16; - let max_percent = NonZeroU16::new(1_000).expect("1_000 is non-zero"); - let (old_percent_str, new_percent) = if lavalink.connection(guild_id).mute { - lavalink.connection_mut(guild_id).mute = false; + // SAFETY: `1_000` is non-zero + let max_percent = unsafe { NonZeroU16::new_unchecked(1_000) }; + let (old_percent_str, new_percent) = if lavalink.connection_from(&in_voice).mute { + lavalink.connection_mut_from(&in_voice).mute = false; ctx.http() .update_guild_member(guild_id, ctx.bot().user_id()) .mute(false) @@ -43,7 +45,8 @@ impl BotSlashCommand for Up { ( String::from("Muted"), - NonZeroU16::new(percent_u16).expect("self.percent is non-zero"), + // SAFETY: `percent_u16` is in range [1, 1_000], so it is non-zero + unsafe { NonZeroU16::new_unchecked(percent_u16) }, ) } else { let old_percent = data.read().await.volume(); @@ -65,10 +68,7 @@ impl BotSlashCommand for Up { .then_some(" (`Max`)") .unwrap_or_default(); - lavalink - .player(guild_id) - .set_volume(new_percent.get()) - .await?; + player.context.set_volume(new_percent.get()).await?; data.write().await.set_volume(new_percent); out!( diff --git a/lyra/src/bot/core/const.rs b/lyra/src/bot/core/const.rs index 5f3d4fb..350d45d 100644 --- a/lyra/src/bot/core/const.rs +++ b/lyra/src/bot/core/const.rs @@ -1,4 +1,6 @@ pub mod metadata { + use std::sync::OnceLock; + const VERSION: &str = env!("CARGO_PKG_VERSION"); const COPYRIGHT: &str = env!("CARGO_PKG_LICENSE"); const AUTHORS: &str = env!("CARGO_PKG_AUTHORS"); @@ -52,48 +54,69 @@ pub mod metadata { "%cargo_opt_level", ]; - lazy_static::lazy_static! { - pub static ref BANNER: Box = { + pub fn banner() -> &'static str { + static BANNER: OnceLock<&'static str> = OnceLock::new(); + BANNER.get_or_init(|| { use aho_corasick::AhoCorasick; let rdr = include_str!("../../../../assets/lyra2-ascii.ans"); let mut wtr = Vec::new(); let ac = AhoCorasick::new(METADATA_PATTERNS).expect("METADATA_PATTERNS is valid"); - ac.try_stream_replace_all(rdr.as_bytes(), &mut wtr, &METADATA_REPLACEMENTS).expect("searching is infallible"); - String::from_utf8(wtr).expect("slice is UTF-8").into() - }; + ac.try_stream_replace_all(rdr.as_bytes(), &mut wtr, &METADATA_REPLACEMENTS) + .expect("searching is infallible"); + // SAFETY: since `rdr` is utf-8, `wtr` must also be utf-8 + unsafe { String::from_utf8_unchecked(wtr).leak() } + }) } } pub mod connection { - use std::time::Duration; + use std::{sync::OnceLock, time::Duration}; pub const INACTIVITY_TIMEOUT_SECS: u16 = 600; pub const INACTIVITY_TIMEOUT_POLL_N: u8 = 10; - lazy_static::lazy_static! { - pub static ref CONNECTION_CHANGED_TIMEOUT: Duration = Duration::from_millis(500); - pub static ref GET_LAVALINK_CONNECTION_INFO_TIMEOUT: Duration = Duration::from_millis(2_000); - pub static ref INACTIVITY_TIMEOUT_POLL_INTERVAL: Duration = - Duration::from_secs(u64::from(INACTIVITY_TIMEOUT_SECS) / u64::from(INACTIVITY_TIMEOUT_POLL_N)); + pub fn connection_changed_timeout() -> &'static Duration { + static CONNECTION_CHANGED_TIMEOUT: OnceLock = OnceLock::new(); + CONNECTION_CHANGED_TIMEOUT.get_or_init(|| Duration::from_millis(500)) + } + + pub fn get_lavalink_connection_info_timeout() -> &'static Duration { + static GET_LAVALINK_CONNECTION_INFO_TIMEOUT: OnceLock = OnceLock::new(); + GET_LAVALINK_CONNECTION_INFO_TIMEOUT.get_or_init(|| Duration::from_millis(2_000)) + } + + pub fn inactivity_timeout_poll_interval() -> &'static Duration { + static INACTIVITY_TIMEOUT_POLL_INTERVAL: OnceLock = OnceLock::new(); + INACTIVITY_TIMEOUT_POLL_INTERVAL.get_or_init(|| { + Duration::from_secs( + u64::from(INACTIVITY_TIMEOUT_SECS) / u64::from(INACTIVITY_TIMEOUT_POLL_N), + ) + }) } } pub mod misc { - use std::time::Duration; + use std::{sync::OnceLock, time::Duration}; pub const ADD_TRACKS_WRAP_LIMIT: usize = 3; pub const WAIT_FOR_NOT_SUPPRESSED_TIMEOUT_SECS: u8 = 30; - lazy_static::lazy_static! { - pub static ref WAIT_FOR_BOT_EVENTS_TIMEOUT: Duration = Duration::from_millis(1_000); - pub static ref WAIT_FOR_NOT_SUPPRESSED_TIMEOUT: Duration = Duration::from_secs(WAIT_FOR_NOT_SUPPRESSED_TIMEOUT_SECS.into()); - pub static ref DESTRUCTIVE_COMMAND_CONFIRMATION_TIMEOUT: Duration = Duration::from_secs(60); + pub fn wait_for_bot_events_timeout() -> &'static Duration { + static WAIT_FOR_BOT_EVENTS_TIMEOUT: OnceLock = OnceLock::new(); + WAIT_FOR_BOT_EVENTS_TIMEOUT.get_or_init(|| Duration::from_millis(1_000)) + } + + pub fn destructive_command_confirmation_timeout() -> &'static Duration { + static DESTRUCTIVE_COMMAND_CONFIRMATION_TIMEOUT: OnceLock = OnceLock::new(); + DESTRUCTIVE_COMMAND_CONFIRMATION_TIMEOUT.get_or_init(|| Duration::from_secs(60)) } } pub mod text { + use std::sync::OnceLock; + use fuzzy_matcher::skim::SkimMatcherV2; pub const UNTITLED_TRACK: &str = "(Untitled Track)"; @@ -102,24 +125,45 @@ pub mod text { pub const EMPTY_EMBED_FIELD: &str = "`-Empty-`"; pub const NO_ROWS_AFFECTED_MESSAGE: &str = "🔐 No changes were made."; - lazy_static::lazy_static! { - pub static ref FUZZY_MATCHER: SkimMatcherV2 = SkimMatcherV2::default(); + pub fn fuzzy_matcher() -> &'static SkimMatcherV2 { + static FUZZY_MATCHER: OnceLock = OnceLock::new(); + FUZZY_MATCHER.get_or_init(SkimMatcherV2::default) } } pub mod regex { + use std::sync::OnceLock; + use regex::Regex; - lazy_static::lazy_static! { - pub static ref URL: Regex = - Regex::new(r"(https://www\.|http://www\.|https://|http://)?[a-zA-Z]{2,}(\.[a-zA-Z]{2,})(\.[a-zA-Z]{2,})?/[a-zA-Z0-9]{2,}|((https://www\.|http://www\.|https://|http://)?[a-zA-Z]{2,}(\.[a-zA-Z]{2,})(\.[a-zA-Z]{2,})?)|(https://www\.|http://www\.|https://|http://)?[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}(\.[a-zA-Z0-9]{2,})?") - .expect("regex is valid"); - pub static ref TIMESTAMP: Regex = - Regex::new(r"^(((?[1-9]\d*):(?[0-5]\d))|(?[0-5]?\d)):(?[0-5]\d)(\.(?\d{3}))?$") - .expect("regex is valild"); - pub static ref TIMESTAMP_2: Regex = - Regex::new(r"^((?[1-9]\d*)\s?hr?)?\s*((?[1-9]|[1-5]\d)\s?m(in)?)?\s*((?[1-9]|[1-5]\d)\s?s(ec)?)?\s*((?[1-9]\d{0,2})\s?ms(ec)?)?$") - .expect("regex is valid"); + pub fn url() -> &'static Regex { + static URL: OnceLock = OnceLock::new(); + URL.get_or_init(|| { + Regex::new( + r"(https://www\.|http://www\.|https://|http://)?[a-zA-Z]{2,}(\.[a-zA-Z]{2,})(\.[a-zA-Z]{2,})?/[a-zA-Z0-9]{2,}|((https://www\.|http://www\.|https://|http://)?[a-zA-Z]{2,}(\.[a-zA-Z]{2,})(\.[a-zA-Z]{2,})?)|(https://www\.|http://www\.|https://|http://)?[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}(\.[a-zA-Z0-9]{2,})?" + ) + .expect("regex is valid") + }) + } + + pub fn timestamp() -> &'static Regex { + static TIMESTAMP: OnceLock = OnceLock::new(); + TIMESTAMP.get_or_init(|| { + Regex::new( + r"^(((?[1-9]\d*):(?[0-5]\d))|(?[0-5]?\d)):(?[0-5]\d)(\.(?\d{3}))?$", + ) + .expect("regex is valid") + }) + } + + pub fn timestamp_2() -> &'static Regex { + static TIMESTAMP_2: OnceLock = OnceLock::new(); + TIMESTAMP_2.get_or_init(|| { + Regex::new( + r"^((?[1-9]\d*)\s?hr?)?\s*((?[1-9]|[1-5]\d)\s?m(in)?)?\s*((?[1-9]|[1-5]\d)\s?s(ec)?)?\s*((?[1-9]\d{0,2})\s?ms(ec)?)?$" + ) + .expect("regex is valid") + }) } } diff --git a/lyra/src/bot/core/model.rs b/lyra/src/bot/core/model.rs index 469cd62..02f11d5 100644 --- a/lyra/src/bot/core/model.rs +++ b/lyra/src/bot/core/model.rs @@ -102,6 +102,10 @@ impl BotInfo { pub type BotStateRef<'a> = &'a BotState; pub type OwnedBotState = Arc; +pub trait AuthorIdAware { + fn author_id(&self) -> Id; +} + pub trait AuthorPermissionsAware { fn author_permissions(&self) -> Permissions; } @@ -173,7 +177,7 @@ impl BotState { pub fn user(&self) -> CurrentUser { self.cache .current_user() - .expect("current user should be in cache") + .unwrap_or_else(|| panic!("current user isn't in cache")) } #[inline] diff --git a/lyra/src/bot/core/model/interaction.rs b/lyra/src/bot/core/model/interaction.rs index 2b44856..8640ee9 100644 --- a/lyra/src/bot/core/model/interaction.rs +++ b/lyra/src/bot/core/model/interaction.rs @@ -15,7 +15,7 @@ use twilight_util::builder::InteractionResponseDataBuilder; use crate::bot::{ command::{ - declare::{MESSAGE_COMMANDS, POPULATED_COMMANDS_MAP, SLASH_COMMANDS}, + declare::{message_commands, slash_commands, POPULATED_COMMANDS_MAP}, model::CommandInfoAware, }, error::core::{FollowupResult, RegisterGlobalCommandsError, RespondResult}, @@ -44,6 +44,7 @@ impl Interface<'_> { ) -> MessageRespondResult { let interaction_token = self.interaction_token(); self.inner + .0 .create_response( self.interaction_id, interaction_token, @@ -54,7 +55,7 @@ impl Interface<'_> { ) .await?; - self.inner.response(interaction_token).await + self.inner.0.response(interaction_token).await } pub async fn update_message_with( @@ -63,6 +64,7 @@ impl Interface<'_> { ) -> MessageRespondResult { let interaction_token = self.interaction_token(); self.inner + .0 .create_response( self.interaction_id, interaction_token, @@ -73,11 +75,11 @@ impl Interface<'_> { ) .await?; - self.inner.response(interaction_token).await + self.inner.0.response(interaction_token).await } fn update(&self) -> UpdateResponse<'_> { - self.inner.update_response(self.interaction_token()) + self.inner.0.update_response(self.interaction_token()) } pub async fn update_no_components_embeds(&self, content: &str) -> MessageFollowupResult { @@ -108,6 +110,7 @@ impl Interface<'_> { pub async fn followup(&self, content: &str) -> MessageFollowupResult { Ok(self .inner + .0 .create_followup(self.interaction_token()) .content(content) .await?) @@ -116,6 +119,7 @@ impl Interface<'_> { pub async fn followup_ephem(&self, content: &str) -> MessageFollowupResult { Ok(self .inner + .0 .create_followup(self.interaction_token()) .flags(MessageFlags::EPHEMERAL) .content(content) @@ -142,6 +146,7 @@ impl Interface<'_> { .into(); self.inner + .0 .create_response( self.interaction_id, self.interaction_token(), @@ -164,6 +169,7 @@ impl Interface<'_> { .into(); self.inner + .0 .create_response( self.interaction_id, self.interaction_token(), @@ -182,6 +188,7 @@ impl Interface<'_> { content: &str, ) -> UnitFollowupResult { self.inner + .0 .update_followup(self.interaction_token(), message_id) .content(Some(content)) .await?; @@ -190,6 +197,7 @@ impl Interface<'_> { pub async fn delete_followup(&self, message_id: Id) -> UnitRespondResult { self.inner + .0 .delete_followup(self.interaction_token(), message_id) .await?; Ok(()) @@ -211,7 +219,10 @@ impl<'a> Client<'a> { pub async fn register_global_commands(&self) -> Result<(), RegisterGlobalCommandsError> { let commands = self - .set_global_commands(&[SLASH_COMMANDS.as_ref(), MESSAGE_COMMANDS.as_ref()].concat()) + .0 + .set_global_commands( + &[slash_commands().as_slice(), message_commands().as_slice()].concat(), + ) .await? .models() .await?; @@ -230,7 +241,7 @@ impl<'a> Client<'a> { ) -> &'static twilight_model::application::command::Command { POPULATED_COMMANDS_MAP .get() - .expect("POPULATED_COMMANDS_MAP is populated") + .unwrap_or_else(|| panic!("`POPULATED_COMMANDS_MAP` is not yet populated")) .get(T::name()) .unwrap_or_else(|| panic!("command not found: {}", T::name())) } @@ -239,16 +250,27 @@ impl<'a> Client<'a> { let cmd = Self::populated_command::(); let name = &cmd.name; - let id = cmd.id.expect("id exists"); + let id = cmd + .id + .unwrap_or_else(|| panic!("`POPULATED_COMMANDS_MAP` is not yet populated")); format!("").into_boxed_str() } -} -impl<'a> std::ops::Deref for Client<'a> { - type Target = twilight_http::client::InteractionClient<'a>; + #[inline] + pub const fn create_followup( + &'a self, + interaction_token: &'a str, + ) -> twilight_http::request::application::interaction::CreateFollowup<'a> { + self.0.create_followup(interaction_token) + } - fn deref(&self) -> &Self::Target { - &self.0 + #[inline] + pub const fn delete_followup( + &'a self, + interaction_token: &'a str, + message_id: Id, + ) -> twilight_http::request::application::interaction::DeleteFollowup<'a> { + self.0.delete_followup(interaction_token, message_id) } } diff --git a/lyra/src/bot/error.rs b/lyra/src/bot/error.rs index 198a94b..1db7468 100644 --- a/lyra/src/bot/error.rs +++ b/lyra/src/bot/error.rs @@ -5,6 +5,7 @@ pub mod gateway; pub mod lavalink; pub mod runner; +pub use command::Error as CommandError; pub use command::Result as CommandResult; use thiserror::Error; @@ -22,6 +23,8 @@ pub trait EPrint: std::error::Error + std::fmt::Debug { #[error("missing from cache")] pub struct Cache; +pub type CacheResult = Result; + #[derive(Debug, Error)] #[error("user is not a DJ")] pub struct UserNotDj; @@ -166,3 +169,7 @@ pub enum RunError { Dotenvy(#[from] dotenvy::Error), StartError(#[from] runner::StartError), } + +#[derive(Error, Debug)] +#[error("not in a guild")] +pub struct NotInGuild; diff --git a/lyra/src/bot/error/command.rs b/lyra/src/bot/error/command.rs index 707a42e..4aca3fa 100644 --- a/lyra/src/bot/error/command.rs +++ b/lyra/src/bot/error/command.rs @@ -47,6 +47,10 @@ pub enum Error { TwilightHttp(#[from] twilight_http::Error), Lavalink(#[from] lavalink_rs::error::LavalinkError), NoPlayer(#[from] super::lavalink::NoPlayerError), + NotInGuild(#[from] super::NotInGuild), + CheckUserOnlyIn(#[from] check::UserOnlyInError), + Cache(#[from] super::Cache), + HandlePoll(#[from] check::HandlePollError), } pub enum FlattenedError<'a> { @@ -84,6 +88,7 @@ pub enum FlattenedError<'a> { AutoJoinAttemptFailed(&'a super::AutoJoinAttemptFailed), Lavalink(&'a lavalink_rs::error::LavalinkError), NoPlayer(&'a super::lavalink::NoPlayerError), + NotInGuild(&'a super::NotInGuild), } pub use FlattenedError as Fe; @@ -216,9 +221,7 @@ impl<'a> Fe<'a> { check::HandleInVoiceWithSomeoneElseError::PollResolvable(e) => { Self::from_vote_resolvable(e) } - check::HandleInVoiceWithSomeoneElseError::HandlePollError(e) => { - Self::from_handle_poll(e) - } + check::HandleInVoiceWithSomeoneElseError::HandlePoll(e) => Self::from_handle_poll(e), } } @@ -531,6 +534,8 @@ impl Error { Self::TwilightHttp(e) => Fe::TwilightHttp(e), Self::Lavalink(e) => Fe::Lavalink(e), Self::NoPlayer(e) => Fe::NoPlayer(e), + Self::NotInGuild(e) => Fe::NotInGuild(e), + Self::Cache(e) => Fe::Cache(e), Self::CheckNotSuppressed(e) => Fe::from_check_not_suppressed_error(e), Self::CheckUsersTrack(e) => Fe::from_users_track_error(e), Self::InVoiceWithSomeoneElse(e) => Fe::from_in_voice_with_someone_else_error(e), @@ -544,6 +549,8 @@ impl Error { Self::Play(e) => Fe::from_play(e), Self::DeserializeBodyFromHttp(e) => Fe::from_deserialize_body_from_http_error(e), Self::RemoveTracks(e) => Fe::from_remove_tracks(e), + Self::CheckUserOnlyIn(e) => Fe::from_check_user_only_in(e), + Self::HandlePoll(e) => Fe::from_handle_poll(e), } } } @@ -556,6 +563,7 @@ pub enum AutocompleteError { LoadFailed(#[from] super::LoadFailed), Respond(#[from] RespondError), Lavalink(#[from] lavalink_rs::error::LavalinkError), + NotInGuild(#[from] super::NotInGuild), } pub type AutocompleteResult = core::result::Result<(), AutocompleteError>; diff --git a/lyra/src/bot/error/command/check.rs b/lyra/src/bot/error/command/check.rs index 8204fab..33cc353 100644 --- a/lyra/src/bot/error/command/check.rs +++ b/lyra/src/bot/error/command/check.rs @@ -173,7 +173,7 @@ pub enum PollLossErrorKind { #[error(transparent)] pub enum HandleInVoiceWithSomeoneElseError { PollResolvable(#[from] PollResolvableError), - HandlePollError(#[from] HandlePollError), + HandlePoll(#[from] HandlePollError), } #[derive(Error, Debug)] @@ -189,3 +189,10 @@ pub enum RunError { Paused(#[from] error::Paused), Stopped(#[from] error::Stopped), } + +#[derive(Error, Debug)] +#[error(transparent)] +pub enum OnlyElsePoll { + Cache(#[from] CacheError), + HandlePoll(#[from] HandlePollError), +} diff --git a/lyra/src/bot/ext/image.rs b/lyra/src/bot/ext/image.rs index 7c5a941..9c4ae6c 100644 --- a/lyra/src/bot/ext/image.rs +++ b/lyra/src/bot/ext/image.rs @@ -1,5 +1,3 @@ -use std::ops::Deref; - use image::{self, imageops::FilterType, DynamicImage, GenericImageView}; use kmeans_colors::Sort; use palette::{cast::from_component_slice, FromColor, IntoColor, Lab, Srgb, Srgba}; @@ -28,19 +26,23 @@ impl DominantPalette for DynamicImage { .map(|x| x.into_format::<_, f32>().into_color()) .collect::>(); - let result = (0..RUNS) - .map(|i| { - kmeans_colors::get_kmeans_hamerly( - palette_size, - MAX_ITERATIONS, - COVERAGE, - false, - &lab, - RANDOM_SEED + u64::from(i), - ) - }) - .max_by(|k1, k2| k1.score.total_cmp(&k2.score)) - .expect("RUNS is non-zero"); + // SAFETY: `0..RUNS` is a non-empty iterator, + // so unwrapping `.max_by(...)` is safe + let result = unsafe { + (0..RUNS) + .map(|i| { + kmeans_colors::get_kmeans_hamerly( + palette_size, + MAX_ITERATIONS, + COVERAGE, + false, + &lab, + RANDOM_SEED + u64::from(i), + ) + }) + .max_by(|k1, k2| k1.score.total_cmp(&k2.score)) + .unwrap_unchecked() + }; let mut res = Lab::sort_indexed_colors(&result.centroids, &result.indices); res.sort_unstable_by(|a, b| (b.percentage).total_cmp(&a.percentage)); @@ -63,14 +65,6 @@ impl LimitImageFileSizeResponse { } } -impl Deref for LimitImageFileSizeResponse { - type Target = DynamicImage; - - fn deref(&self) -> &Self::Target { - &self.image - } -} - #[derive(Debug, PartialEq, Eq)] pub enum LimitImageFileSizeResponseKind { Noop, diff --git a/lyra/src/bot/ext/util.rs b/lyra/src/bot/ext/util.rs index fcf3e2c..eee749c 100644 --- a/lyra/src/bot/ext/util.rs +++ b/lyra/src/bot/ext/util.rs @@ -1,6 +1,7 @@ use std::{ borrow::{Borrow, Cow}, fmt::{Debug, Display}, + ops::Add, str::FromStr, }; @@ -134,21 +135,14 @@ pub trait ViaGrapheme: UnicodeSegmentation { impl ViaGrapheme for str {} -pub trait PrettyTruncator: ViaGrapheme { +pub trait PrettyTruncator: ViaGrapheme + ToOwned + 'static +where + for<'a> Cow<'a, Self>: Add<&'a Self, Output = Cow<'a, Self>>, +{ fn trail() -> &'static Self; fn pretty_truncate(&self, new_len: usize) -> Cow where - Self: ToOwned; -} - -impl PrettyTruncator for str { - fn trail() -> &'static Self { - "…" - } - - fn pretty_truncate(&self, new_len: usize) -> Cow - where - Self: ToOwned, + for<'a> ::Owned: FromIterator<&'a str>, { let trail = Self::trail(); @@ -158,6 +152,12 @@ impl PrettyTruncator for str { } } +impl PrettyTruncator for str { + fn trail() -> &'static Self { + "…" + } +} + pub trait FlagsPrettify: Flags { fn prettify(&self) -> String { self.iter_names() @@ -177,21 +177,13 @@ pub trait FlagsPrettify: Flags { #[derive(PartialEq, Eq, Debug)] pub struct PrettifiedTimestamp(Duration); -impl std::ops::Deref for PrettifiedTimestamp { - type Target = Duration; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - impl FromStr for PrettifiedTimestamp { type Err = PrettifiedTimestampParseError; fn from_str(value: &str) -> Result { - let captures = if let Some(captures) = const_regex::TIMESTAMP.captures(value) { + let captures = if let Some(captures) = const_regex::timestamp().captures(value) { captures - } else if let Some(captures) = const_regex::TIMESTAMP_2.captures(value) { + } else if let Some(captures) = const_regex::timestamp_2().captures(value) { captures } else { return Err(PrettifiedTimestampParseError); diff --git a/lyra/src/bot/gateway.rs b/lyra/src/bot/gateway.rs index b3fe2b8..7457140 100644 --- a/lyra/src/bot/gateway.rs +++ b/lyra/src/bot/gateway.rs @@ -6,6 +6,6 @@ mod shard; pub mod voice; pub use self::{ - model::{ExpectedGuildIdAware, GuildIdAware, LastCachedStates, Process, SenderAware}, + model::{GuildIdAware, LastCachedStates, OptionallyGuildIdAware, Process, SenderAware}, process::process, }; diff --git a/lyra/src/bot/gateway/guild.rs b/lyra/src/bot/gateway/guild.rs index 3b72eca..184c22a 100644 --- a/lyra/src/bot/gateway/guild.rs +++ b/lyra/src/bot/gateway/guild.rs @@ -23,8 +23,7 @@ impl CreateContext<'_> { } sqlx::query!( - r"--sql - INSERT INTO guild_configs + "INSERT INTO guild_configs (id) SELECT $1 WHERE diff --git a/lyra/src/bot/gateway/interaction.rs b/lyra/src/bot/gateway/interaction.rs index 9039bef..e9495a3 100644 --- a/lyra/src/bot/gateway/interaction.rs +++ b/lyra/src/bot/gateway/interaction.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{hint::unreachable_unchecked, sync::Arc}; use twilight_gateway::{Latency, MessageSender}; use twilight_mention::Mention; @@ -14,6 +14,7 @@ use super::model::Process; use crate::bot::{ command::{ macros::{bad, cant, caut, crit, err, hid, nope, note, out_upd, sus, sus_fol}, + model::NonPingInteraction, util::MessageLinkAware, AutocompleteCtx, MessageCtx, SlashCtx, }, @@ -67,32 +68,35 @@ impl BotState { impl Process for Context { async fn process(self) -> ProcessResult { match self.inner.kind { - InteractionType::ApplicationCommand => self.process_as_app_command().await, - InteractionType::ApplicationCommandAutocomplete => self.process_as_autocomplete().await, - InteractionType::MessageComponent => self.process_as_component().await, - InteractionType::ModalSubmit | InteractionType::Ping => Ok(()), + // SAFETY: `self.inner.kind` is `ApplicationCommand`, so this is safe + InteractionType::ApplicationCommand => unsafe { self.process_as_app_command() }.await, + InteractionType::ApplicationCommandAutocomplete => { + // SAFETY: `self.inner.kind` is `ApplicationCommandAutocomplete`, so this is safe + unsafe { self.process_as_autocomplete() }.await + } + // SAFETY: `self.inner.kind` is `MessageComponent`, so this is safe + InteractionType::MessageComponent => unsafe { self.process_as_component() }.await, + InteractionType::ModalSubmit | InteractionType::Ping => Ok(()), // ignored _ => unimplemented!(), } } } impl Context { - async fn process_as_app_command(mut self) -> ProcessResult { + async unsafe fn process_as_app_command(mut self) -> ProcessResult { let bot = self.bot; let i = bot.interaction().await?.interfaces(&self.inner); let Some(InteractionData::ApplicationCommand(data)) = self.inner.data.take() else { - unreachable!() + // SAFETY: interaction is of type `ApplicationCommand`, + // so `self.inner.data.take()` will always be `InteractionData::ApplicationCommand(_)` + unsafe { std::hint::unreachable_unchecked() } }; let name = data.name.clone().into(); let inner_guild_id = self.inner.guild_id; - let channel_id = self - .inner - .channel - .as_ref() - .map(|c| c.id) - .expect("interaction type is not ping"); + // SAFETY: interaction type is not `Ping`, so `channel` is present + let channel_id = unsafe { self.inner.channel_id_unchecked() }; let result = match data.kind { CommandType::ChatInput => { @@ -122,13 +126,10 @@ impl Context { }; if let Some(guild_id) = inner_guild_id { - let lavalink = bot.lavalink(); - - if lavalink - .get_connection(guild_id) - .is_some_and(|c| c.text_channel_id != channel_id) - { - lavalink.connection_mut(guild_id).text_channel_id = channel_id; + if let Some(mut connection) = bot.lavalink().get_connection_mut(guild_id) { + if connection.text_channel_id != channel_id { + connection.text_channel_id = channel_id; + } } } @@ -142,7 +143,9 @@ impl Context { } Fuunacee::Command(_) => { let CommandExecuteError::Command(error) = source else { - unreachable!() + // SAFETY: `source.flatten_until_user_not_allowed_as()` is `Fuunacee::Command(_)`, + // so the unflattened source error must be `CommandExecuteError::Command(_)` + unsafe { unreachable_unchecked() } }; match_error(error, name, i).await } @@ -155,9 +158,10 @@ impl Context { } } - async fn process_as_autocomplete(mut self) -> ProcessResult { + async unsafe fn process_as_autocomplete(mut self) -> ProcessResult { let Some(InteractionData::ApplicationCommand(data)) = self.inner.data.take() else { - unreachable!() + // SAFETY: + unsafe { unreachable_unchecked() } }; let name = data.name.clone().into(); @@ -178,7 +182,7 @@ impl Context { } #[allow(clippy::unused_async)] - async fn process_as_component(self) -> ProcessResult { + async unsafe fn process_as_component(self) -> ProcessResult { // TODO: implement controller Ok(()) } diff --git a/lyra/src/bot/gateway/model.rs b/lyra/src/bot/gateway/model.rs index 56ed0e7..38d8d5b 100644 --- a/lyra/src/bot/gateway/model.rs +++ b/lyra/src/bot/gateway/model.rs @@ -13,11 +13,11 @@ pub trait SenderAware { fn sender(&self) -> &MessageSender; } -pub trait GuildIdAware { +pub trait OptionallyGuildIdAware { fn get_guild_id(&self) -> Option>; } -pub trait ExpectedGuildIdAware { +pub trait GuildIdAware { fn guild_id(&self) -> Id; } @@ -32,7 +32,10 @@ impl LastCachedStates { Event::VoiceStateUpdate(event) => cache .voice_state( event.user_id, - event.guild_id.expect("event received in a guild"), + // SAFETY: this bot cannot join DM voice calls, + // meaning all voice states will be from a guild voice channel, + // so `e.guild_id` is present + unsafe { event.guild_id.unwrap_unchecked() }, ) .as_deref() .cloned(), diff --git a/lyra/src/bot/gateway/shard.rs b/lyra/src/bot/gateway/shard.rs index e91e379..54a5616 100644 --- a/lyra/src/bot/gateway/shard.rs +++ b/lyra/src/bot/gateway/shard.rs @@ -41,18 +41,17 @@ impl Process for ReadyContext<'_> { self.inner.guilds.iter().for_each(|g| { let db = self.bot.db().clone(); - let g = g.id.get() as i64; + let guild_id = g.id.get() as i64; set.spawn(async move { sqlx::query!( - r"--sql - INSERT INTO guild_configs + "INSERT INTO guild_configs (id) SELECT $1 WHERE NOT EXISTS ( SELECT 1 FROM guild_configs WHERE id = $1 );", - g + guild_id ) .execute(&db) .await?; diff --git a/lyra/src/bot/gateway/voice.rs b/lyra/src/bot/gateway/voice.rs index 6befd41..6b6203b 100644 --- a/lyra/src/bot/gateway/voice.rs +++ b/lyra/src/bot/gateway/voice.rs @@ -12,7 +12,7 @@ use crate::bot::component::{connection, tuning}; use crate::bot::core::model::{BotState, BotStateAware, CacheAware, HttpAware, OwnedBotStateAware}; use crate::bot::error::gateway::ProcessResult; use crate::bot::{ - gateway::{ExpectedGuildIdAware, SenderAware}, + gateway::{GuildIdAware, SenderAware}, lavalink::{Lavalink, LavalinkAware}, }; @@ -83,9 +83,12 @@ impl SenderAware for Context { } } -impl ExpectedGuildIdAware for Context { +impl GuildIdAware for Context { fn guild_id(&self) -> Id { - self.inner.guild_id.expect("event received in a guild") + // SAFETY: this bot cannot join DM voice calls, + // meaning all voice states will be from a guild voice channel, + // so `e.guild_id` is present + unsafe { self.inner.guild_id.unwrap_unchecked() } } } diff --git a/lyra/src/bot/lavalink.rs b/lyra/src/bot/lavalink.rs index 6c3900e..4a1c06a 100644 --- a/lyra/src/bot/lavalink.rs +++ b/lyra/src/bot/lavalink.rs @@ -6,10 +6,10 @@ mod track; pub use self::{ model::{ - wait_for_with, ClientAware as LavalinkAware, CorrectPlaylistInfo, CorrectTrackInfo, - DelegateMethods, Event, EventRecvResult, ExpectedPlayerAware, ExpectedPlayerDataAware, - IndexerType, Lavalink, Pitch, PlayerAware, PlayerDataAware, Queue, QueueItem, RepeatMode, + wait_for_with, ClientAware as LavalinkAware, Connection, CorrectPlaylistInfo, + CorrectTrackInfo, DelegateMethods, Event, EventRecvResult, IndexerType, Lavalink, Pitch, + PlayerAware, PlayerDataRwLockArc, Queue, QueueItem, RepeatMode, UnwrappedPlayerData, + UnwrappedPlayerInfoUri, }, - plugin::PluginInfo, process::handlers, }; diff --git a/lyra/src/bot/lavalink/model.rs b/lyra/src/bot/lavalink/model.rs index fc977df..b6b6e9c 100644 --- a/lyra/src/bot/lavalink/model.rs +++ b/lyra/src/bot/lavalink/model.rs @@ -4,10 +4,12 @@ mod pitch; mod queue; mod queue_indexer; -use std::{num::NonZeroU16, ops::Deref, sync::Arc}; +use std::{num::NonZeroU16, sync::Arc}; use lavalink_rs::{ - client::LavalinkClient, error::LavalinkResult, model::player::ConnectionInfo, + client::LavalinkClient, + error::LavalinkResult, + model::{player::ConnectionInfo, track::TrackInfo}, player_context::PlayerContext, }; use tokio::sync::RwLock; @@ -17,46 +19,30 @@ use twilight_model::id::{ }; use crate::bot::{ + command::require::{CachelessInVoice, InVoice}, core::r#const, - gateway::{ExpectedGuildIdAware, GuildIdAware}, + gateway::GuildIdAware, }; -use self::connection::{Connection, ConnectionRef, ConnectionRefMut}; +use self::connection::{ConnectionRef, ConnectionRefMut}; pub use self::{ - connection::{wait_for_with, Event, EventRecvResult}, + connection::{wait_for_with, Connection, Event, EventRecvResult}, correct_info::{CorrectPlaylistInfo, CorrectTrackInfo}, pitch::Pitch, queue::{Item as QueueItem, Queue, RepeatMode}, queue_indexer::IndexerType, }; -type PlayerDataRwLockArc = Arc>; +pub type PlayerDataRwLockArc = Arc>; pub trait ClientAware { fn lavalink(&self) -> &Lavalink; } -pub trait PlayerDataAware: ClientAware + GuildIdAware { - fn get_player_data(&self) -> Option { - self.lavalink().get_player_data(self.get_guild_id()?) - } -} -pub trait ExpectedPlayerDataAware: ClientAware + ExpectedGuildIdAware { - fn player_data(&self) -> PlayerDataRwLockArc { - self.lavalink().player_data(self.guild_id()) - } -} - pub trait PlayerAware: ClientAware + GuildIdAware { fn get_player(&self) -> Option { - self.lavalink().get_player_context(self.get_guild_id()?) - } -} - -pub trait ExpectedPlayerAware: ClientAware + ExpectedGuildIdAware { - fn player(&self) -> PlayerContext { - self.lavalink().player(self.guild_id()) + self.lavalink().get_player_context(self.guild_id()) } } @@ -68,9 +54,10 @@ pub struct PlayerData { } impl PlayerData { - pub fn new() -> Self { + pub const fn new() -> Self { Self { - volume: NonZeroU16::new(100).expect("volume is non-zero"), + // SAFETY: `100` is non-zero + volume: unsafe { NonZeroU16::new_unchecked(100) }, pitch: Pitch::new(), queue: Queue::new(), now_playing_message_id: None, @@ -103,6 +90,71 @@ pub struct Lavalink { connections: dashmap::DashMap, Connection>, } +impl DelegateMethods for Lavalink { + #[inline] + fn handle_voice_server_update( + &self, + guild_id: impl Into, + token: String, + endpoint: Option, + ) { + ::handle_voice_server_update( + &self.inner, + guild_id, + token, + endpoint, + ); + } + + #[inline] + fn handle_voice_state_update( + &self, + guild_id: impl Into, + channel_id: Option>, + user_id: impl Into, + session_id: String, + ) { + ::handle_voice_state_update( + &self.inner, + guild_id, + channel_id, + user_id, + session_id, + ); + } + + #[inline] + async fn get_connection_info( + &self, + guild_id: impl Into + Send, + timeout: std::time::Duration, + ) -> LavalinkResult { + ::get_connection_info(&self.inner, guild_id, timeout) + .await + } + + #[inline] + async fn create_player_context_with_data( + &self, + guild_id: impl Into + Send, + connection_info: impl Into + Send, + user_data: Arc, + ) -> LavalinkResult { + ::create_player_context_with_data( + &self.inner, + guild_id, + connection_info, + user_data, + ) + .await + } + + #[inline] + fn get_player_context(&self, guild_id: impl Into) -> Option { + ::get_player_context(&self.inner, guild_id) + } +} + impl From for Lavalink { fn from(value: LavalinkClient) -> Self { Self { @@ -115,13 +167,13 @@ impl From for Lavalink { type LavalinkGuildId = lavalink_rs::model::GuildId; pub trait DelegateMethods { - fn _handle_voice_server_update( + fn handle_voice_server_update( &self, guild_id: impl Into, token: String, endpoint: Option, ); - fn _handle_voice_state_update( + fn handle_voice_state_update( &self, guild_id: impl Into, channel_id: Option>, @@ -131,11 +183,14 @@ pub trait DelegateMethods { fn process(&self, event: &twilight_gateway::Event) { match event { twilight_gateway::Event::VoiceServerUpdate(e) => { - self._handle_voice_server_update(e.guild_id, e.token.clone(), e.endpoint.clone()); + self.handle_voice_server_update(e.guild_id, e.token.clone(), e.endpoint.clone()); } twilight_gateway::Event::VoiceStateUpdate(e) => { - self._handle_voice_state_update( - e.guild_id.expect("event received in a guild"), + self.handle_voice_state_update( + // SAFETY: this bot cannot join DM voice calls, + // meaning all voice states will be from a guild voice channel, + // so `e.guild_id` is present + unsafe { e.guild_id.unwrap_unchecked() }, e.channel_id, e.user_id, e.session_id.clone(), @@ -145,52 +200,46 @@ pub trait DelegateMethods { } } - async fn _get_connection_info( + async fn get_connection_info( &self, guild_id: impl Into + Send, timeout: std::time::Duration, ) -> LavalinkResult; - async fn _create_player_context_with_data( + async fn create_player_context_with_data( &self, guild_id: impl Into + Send, connection_info: impl Into + Send, user_data: Arc, ) -> LavalinkResult; - async fn new_player_data( + async fn new_player( &self, guild_id: impl Into + Send + Copy, - ) -> LavalinkResult<()> { + ) -> LavalinkResult { let now = tokio::time::Instant::now(); let info = self - ._get_connection_info( + .get_connection_info( guild_id, - *r#const::connection::GET_LAVALINK_CONNECTION_INFO_TIMEOUT, + *r#const::connection::get_lavalink_connection_info_timeout(), ) .await?; tracing::trace!("getting lavalink connection info took {:?}", now.elapsed()); let data = Arc::new(RwLock::new(PlayerData::new())); - self._create_player_context_with_data(guild_id, info, data) + let player = self + .create_player_context_with_data(guild_id, info, data) .await?; - Ok(()) + Ok(player) } - fn _get_player_context(&self, guild_id: impl Into) -> Option; + fn get_player_context(&self, guild_id: impl Into) -> Option; fn get_player_data( &self, guild_id: impl Into + Send, ) -> Option { - self._get_player_context(guild_id) - .map(|c| c.data().expect("data type is valid")) - } - fn player(&self, guild_id: impl Into + Send) -> PlayerContext { - self._get_player_context(guild_id) - .expect("player context exists") - } - fn player_data(&self, guild_id: impl Into + Send) -> PlayerDataRwLockArc { - self.player(guild_id).data().expect("data type is valid") + self.get_player_context(guild_id) + .map(|c| c.data_unwrapped()) } } @@ -199,14 +248,18 @@ impl Lavalink { self.inner.clone() } + pub fn new_connection_with(&self, guild_id: Id, connection: Connection) { + self.connections.insert(guild_id, connection); + } + pub fn new_connection( &self, guild_id: Id, channel_id: Id, text_channel_id: Id, ) { - self.connections - .insert(guild_id, Connection::new(channel_id, text_channel_id)); + let connection = Connection::new(channel_id, text_channel_id); + self.new_connection_with(guild_id, connection); } pub fn drop_connection(&self, guild_id: Id) { @@ -217,37 +270,38 @@ impl Lavalink { self.connections.get(&guild_id) } - pub fn get_connection_mut(&self, guild_id: Id) -> Option { - self.connections.get_mut(&guild_id) - } - - pub fn connection(&self, guild_id: Id) -> ConnectionRef { - self.get_connection(guild_id).expect("connection exists") + pub fn connection_from(&self, from: &impl GetConnection) -> ConnectionRef { + // SAFETY: because the caller has an instance of `InVoice`, + // this proves that there is a voice connection currently. + unsafe { self.connections.get(&from.guild_id()).unwrap_unchecked() } } - pub fn connection_mut(&self, guild_id: Id) -> ConnectionRefMut { - self.get_connection_mut(guild_id) - .expect("connection exists") - } - - pub fn notify_connection_change(&self, guild_id: Id) { - self.connection(guild_id).notify_change(); + pub fn connection_mut_from(&self, from: &impl GetConnection) -> ConnectionRefMut { + // SAFETY: because the caller has an instance of `InVoice`, + // this proves that there is a voice connection currently. + unsafe { + self.connections + .get_mut(&from.guild_id()) + .unwrap_unchecked() + } } - #[inline] - pub fn dispatch(&self, guild_id: Id, event: Event) { - self.connection(guild_id).dispatch(event); + pub fn get_connection_mut(&self, guild_id: Id) -> Option { + self.connections.get_mut(&guild_id) } #[inline] - pub fn dispatch_queue_clear(&self, guild_id: Id) { - self.dispatch(guild_id, Event::QueueClear); + pub async fn delete_player( + &self, + guild_id: impl Into + Send, + ) -> LavalinkResult<()> { + self.inner.delete_player(guild_id).await } } impl DelegateMethods for LavalinkClient { #[inline] - fn _handle_voice_server_update( + fn handle_voice_server_update( &self, guild_id: impl Into, token: String, @@ -257,7 +311,7 @@ impl DelegateMethods for LavalinkClient { } #[inline] - fn _handle_voice_state_update( + fn handle_voice_state_update( &self, guild_id: impl Into, channel_id: Option>, @@ -268,7 +322,7 @@ impl DelegateMethods for LavalinkClient { } #[inline] - async fn _get_connection_info( + async fn get_connection_info( &self, guild_id: impl Into + Send, timeout: std::time::Duration, @@ -277,7 +331,7 @@ impl DelegateMethods for LavalinkClient { } #[inline] - async fn _create_player_context_with_data( + async fn create_player_context_with_data( &self, guild_id: impl Into + Send, connection_info: impl Into + Send, @@ -288,15 +342,41 @@ impl DelegateMethods for LavalinkClient { } #[inline] - fn _get_player_context(&self, guild_id: impl Into) -> Option { + fn get_player_context(&self, guild_id: impl Into) -> Option { self.get_player_context(guild_id) } } -impl Deref for Lavalink { - type Target = LavalinkClient; +pub trait UnwrappedPlayerData { + fn data_unwrapped(&self) -> PlayerDataRwLockArc; +} + +impl UnwrappedPlayerData for PlayerContext { + fn data_unwrapped(&self) -> PlayerDataRwLockArc { + // SAFETY: Player data exists of type `Arc>` + unsafe { self.data().unwrap_unchecked() } + } +} + +pub trait UnwrappedPlayerInfoUri { + fn into_uri_unwrapped(self) -> String; + fn uri_unwrapped(&self) -> &str; +} - fn deref(&self) -> &Self::Target { - &self.inner +impl UnwrappedPlayerInfoUri for TrackInfo { + fn uri_unwrapped(&self) -> &str { + self.uri + .as_ref() + .unwrap_or_else(|| panic!("local tracks are unsupported")) + } + + fn into_uri_unwrapped(self) -> String { + self.uri + .unwrap_or_else(|| panic!("local tracks are unsupported")) } } + +pub trait GetConnection: GuildIdAware {} + +impl GetConnection for InVoice<'_> {} +impl GetConnection for CachelessInVoice {} diff --git a/lyra/src/bot/lavalink/model/connection.rs b/lyra/src/bot/lavalink/model/connection.rs index 24b5ddc..8bc64dd 100644 --- a/lyra/src/bot/lavalink/model/connection.rs +++ b/lyra/src/bot/lavalink/model/connection.rs @@ -21,7 +21,7 @@ pub(super) type ConnectionRefMut<'a> = dashmap::mapref::one::RefMut<'a, Id, Connection>; impl Connection { - pub(super) fn new(channel_id: Id, text_channel_id: Id) -> Self { + pub fn new(channel_id: Id, text_channel_id: Id) -> Self { Self { channel_id, text_channel_id, @@ -34,7 +34,7 @@ impl Connection { pub async fn changed(&self) -> bool { tokio::time::timeout( - *r#const::connection::CONNECTION_CHANGED_TIMEOUT, + *r#const::connection::connection_changed_timeout(), self.change.notified(), ) .await @@ -57,7 +57,7 @@ impl Connection { let _ = self.event_sender.send(event); } - pub(super) fn notify_change(&self) { + pub fn notify_change(&self) { tracing::trace!("notified connection change"); self.change.notify_one(); } @@ -99,7 +99,7 @@ pub async fn wait_for_with( rx: &mut broadcast::Receiver, predicate: impl Fn(&Event) -> bool + Send + Sync, ) -> EventRecvResult> { - let event = tokio::time::timeout(*r#const::misc::WAIT_FOR_BOT_EVENTS_TIMEOUT, async { + let event = tokio::time::timeout(*r#const::misc::wait_for_bot_events_timeout(), async { loop { let event = rx.recv().await?; if predicate(&event) { @@ -107,5 +107,6 @@ pub async fn wait_for_with( } } }); + Ok(event.await.transpose()?.ok()) } diff --git a/lyra/src/bot/lavalink/model/queue.rs b/lyra/src/bot/lavalink/model/queue.rs index 9ee60ee..d638a2a 100644 --- a/lyra/src/bot/lavalink/model/queue.rs +++ b/lyra/src/bot/lavalink/model/queue.rs @@ -7,17 +7,11 @@ use std::{ use futures::Future; use lavalink_rs::{model::track::TrackData, player_context::PlayerContext}; use rayon::iter::{IntoParallelIterator, ParallelExtend, ParallelIterator}; -use twilight_model::id::{ - marker::{GuildMarker, UserMarker}, - Id, -}; +use twilight_model::id::{marker::UserMarker, Id}; use crate::bot::error::component::queue::remove::WithAdvanceLockAndStoppedError; -use super::{ - queue_indexer::{IndexerType, QueueIndexer}, - DelegateMethods, Lavalink, -}; +use super::queue_indexer::{IndexerType, QueueIndexer}; #[derive(Hash, Copy, Clone)] pub enum RepeatMode { @@ -53,7 +47,7 @@ impl RepeatMode { impl std::fmt::Display for RepeatMode { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.description()) + f.write_str(self.description()) } } @@ -90,20 +84,6 @@ pub struct Queue { current_track_started: u64, } -impl std::ops::Deref for Queue { - type Target = VecDeque; - - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl std::ops::DerefMut for Queue { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.inner - } -} - impl Queue { pub(super) const fn new() -> Self { Self { @@ -118,7 +98,8 @@ impl Queue { pub fn position(&self) -> NonZeroUsize { let d = usize::from(self.current().is_some() || self.index == 0); - NonZeroUsize::new(self.index + d).expect("self.index + d is non-zero") + // SAFETY: `self.index + d` is non-zero + unsafe { NonZeroUsize::new_unchecked(self.index + d) } } pub const fn index(&self) -> &usize { @@ -258,26 +239,58 @@ impl Queue { pub async fn stop_with_advance_lock( &self, - guild_id: Id, - lavalink: &Lavalink, + player: &PlayerContext, ) -> Result<(), WithAdvanceLockAndStoppedError> { - self.with_advance_lock_and_stopped(guild_id, lavalink, |_| async { Ok(()) }) + self.with_advance_lock_and_stopped(player, |_| async { Ok(()) }) .await } - pub async fn with_advance_lock_and_stopped< - F: Future> + Send, - >( + pub async fn with_advance_lock_and_stopped<'a, 'b, F>( &self, - guild_id: Id, - lavalink: &Lavalink, - f: impl FnOnce(PlayerContext) -> F + Send, - ) -> Result<(), WithAdvanceLockAndStoppedError> { + player: &'a PlayerContext, + f: impl FnOnce(&'b PlayerContext) -> F + Send, + ) -> Result<(), WithAdvanceLockAndStoppedError> + where + F: Future> + Send, + 'a: 'b, + { self.advance_lock(); - let player = lavalink.player(guild_id); player.stop_now().await?; f(player).await?; Ok(()) } + + #[inline] + pub fn is_empty(&self) -> bool { + self.inner.is_empty() + } + + #[inline] + pub fn len(&self) -> usize { + self.inner.len() + } + + #[inline] + pub fn remove(&mut self, index: usize) -> Option { + self.inner.remove(index) + } + + #[inline] + pub fn iter(&self) -> std::collections::vec_deque::Iter<'_, Item> { + self.inner.iter() + } + + #[inline] + pub fn insert(&mut self, index: usize, value: Item) { + self.inner.insert(index, value); + } +} + +impl std::ops::Index for Queue { + type Output = Item; + + fn index(&self, index: usize) -> &Self::Output { + &self.inner[index] + } } diff --git a/lyra/src/bot/lavalink/plugin.rs b/lyra/src/bot/lavalink/plugin.rs index e8656f1..36c260a 100644 --- a/lyra/src/bot/lavalink/plugin.rs +++ b/lyra/src/bot/lavalink/plugin.rs @@ -1,4 +1,2 @@ mod lava_search; mod lava_src; - -pub use lava_src::PluginInfo; diff --git a/lyra/src/bot/lavalink/track.rs b/lyra/src/bot/lavalink/track.rs index 94f4885..a785a49 100644 --- a/lyra/src/bot/lavalink/track.rs +++ b/lyra/src/bot/lavalink/track.rs @@ -6,7 +6,7 @@ use lavalink_rs::{ use crate::bot::{ error::lavalink::ProcessResult, - lavalink::{model::CorrectTrackInfo, DelegateMethods}, + lavalink::{model::CorrectTrackInfo, UnwrappedPlayerData}, }; // FIXME: don't debug `LavalinkClient` until `lavalink_rs` stops stack overflowing @@ -31,11 +31,12 @@ async fn impl_end(lavalink: LavalinkClient, event: &TrackEnd) -> ProcessResult { event.track.info.checked_title() ); - let Some(data) = lavalink.get_player_data(guild_id) else { + let Some(player) = lavalink.get_player_context(guild_id) else { tracing::trace!(?guild_id, "track ended via forced disconnection"); return Ok(()); }; + let data = player.data_unwrapped(); let data_r = data.read().await; let queue = data_r.queue(); @@ -44,13 +45,12 @@ async fn impl_end(lavalink: LavalinkClient, event: &TrackEnd) -> ProcessResult { queue.advance_unlock(); } else { drop(data_r); - let data = lavalink.player_data(guild_id); let mut data_w = data.write().await; let queue = data_w.queue_mut(); queue.advance(); if let Some(item) = queue.current() { - lavalink.player(guild_id).play_now(item.track()).await?; + player.play_now(item.track()).await?; } } diff --git a/lyra/src/bot/runner.rs b/lyra/src/bot/runner.rs index fd64ab1..15f4c79 100644 --- a/lyra/src/bot/runner.rs +++ b/lyra/src/bot/runner.rs @@ -29,7 +29,7 @@ use twilight_model::{ id::{marker::UserMarker, Id}, }; -use crate::bot::core::r#const::metadata::BANNER; +use crate::bot::core::r#const::metadata::banner; use super::{ core::{ @@ -62,17 +62,20 @@ fn build_http_client() -> Client { fn build_shard_config() -> ShardConfig { ConfigBuilder::new(CONFIG.token.to_owned(), INTENTS) .presence( - UpdatePresencePayload::new( - [Activity::from(MinimalActivity { - kind: ActivityType::Listening, - name: "/play".into(), - url: None, - })], - false, - None, - Status::Online, - ) - .expect("activities is non-empty"), + // SAFETY: provided non-empty set of activities + unsafe { + UpdatePresencePayload::new( + [Activity::from(MinimalActivity { + kind: ActivityType::Listening, + name: "/play".into(), + url: None, + })], + false, + None, + Status::Online, + ) + .unwrap_unchecked() + }, ) .build() } @@ -104,7 +107,7 @@ pub(super) async fn start() -> Result<(), StartError> { tasks.push(tokio::spawn(handle_gateway_events(shard, bot.clone()))); } - println!("{}", *BANNER); + println!("{}", banner()); Ok(wait_until_shutdown(senders, tasks).await?) } diff --git a/lyra_proc/Cargo.toml b/lyra_proc/Cargo.toml index 7cc3806..65d82a2 100644 --- a/lyra_proc/Cargo.toml +++ b/lyra_proc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lyra_proc" -version = "0.6.0" +version = "0.7.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/lyra_proc/src/config_access.rs b/lyra_proc/src/config_access.rs index 1aaad26..bc19cfe 100644 --- a/lyra_proc/src/config_access.rs +++ b/lyra_proc/src/config_access.rs @@ -6,7 +6,7 @@ use syn::Ident; use crate::model::Args; -pub fn impl_view_access_ids(categories: &Args) -> TokenStream { +pub fn impl_view_access_ids(Args(categories): &Args) -> TokenStream { let column_names = categories .iter() .map(|c| match c.to_string().as_str() { diff --git a/lyra_proc/src/model.rs b/lyra_proc/src/model.rs index e00d39b..df4e729 100644 --- a/lyra_proc/src/model.rs +++ b/lyra_proc/src/model.rs @@ -1,5 +1,3 @@ -use std::ops::Deref; - use syn::{ parse::{Parse, ParseStream}, punctuated::Punctuated, @@ -14,10 +12,3 @@ impl Parse for Args { Ok(Self(vars.into_iter().collect())) } } - -impl Deref for Args { - type Target = Vec; - fn deref(&self) -> &Self::Target { - &self.0 - } -}