diff --git a/.gitignore b/.gitignore index 7787d68..e0aea96 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,5 @@ target/ /target .cargo/ -.DS_STORE \ No newline at end of file +.DS_STORE +.env \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 1cfc8d0..2ca6b2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,7 +32,7 @@ dependencies = [ "ahash 0.8.11", "base64 0.22.1", "bitflags 2.5.0", - "brotli 6.0.0", + "brotli", "bytes", "bytestring", "derive_more", @@ -343,12 +343,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base64" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" - [[package]] name = "base64" version = "0.21.7" @@ -427,17 +421,6 @@ dependencies = [ "syn_derive", ] -[[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 2.5.1", -] - [[package]] name = "brotli" version = "6.0.0" @@ -446,17 +429,7 @@ checksum = "74f7971dbd9326d58187408ab83117d8ac1bb9c17b085fdacd1cf2f598719b6b" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", - "brotli-decompressor 4.0.0", -] - -[[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", + "brotli-decompressor", ] [[package]] @@ -1221,17 +1194,6 @@ dependencies = [ "itoa", ] -[[package]] -name = "http-body" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" -dependencies = [ - "bytes", - "http 0.2.12", - "pin-project-lite", -] - [[package]] name = "http-body" version = "1.0.0" @@ -1251,7 +1213,7 @@ dependencies = [ "bytes", "futures-core", "http 1.1.0", - "http-body 1.0.0", + "http-body", "pin-project-lite", ] @@ -1267,30 +1229,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" -[[package]] -name = "hyper" -version = "0.14.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2 0.3.26", - "http 0.2.12", - "http-body 0.4.6", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - [[package]] name = "hyper" version = "1.3.1" @@ -1302,7 +1240,7 @@ dependencies = [ "futures-util", "h2 0.4.5", "http 1.1.0", - "http-body 1.0.0", + "http-body", "httparse", "itoa", "pin-project-lite", @@ -1313,16 +1251,20 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.23.2" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c" +checksum = "a0bea761b46ae2b24eb4aef630d8d1c398157b6fc29e6350ecf090a0b70c952c" dependencies = [ - "http 0.2.12", - "hyper 0.14.28", - "rustls 0.20.9", + "futures-util", + "http 1.1.0", + "hyper", + "hyper-util", + "rustls 0.22.4", "rustls-native-certs", + "rustls-pki-types", "tokio", - "tokio-rustls 0.23.4", + "tokio-rustls 0.25.0", + "tower-service", ] [[package]] @@ -1333,7 +1275,7 @@ checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" dependencies = [ "futures-util", "http 1.1.0", - "hyper 1.3.1", + "hyper", "hyper-util", "rustls 0.23.10", "rustls-pki-types", @@ -1350,7 +1292,7 @@ checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" dependencies = [ "bytes", "http-body-util", - "hyper 1.3.1", + "hyper", "hyper-util", "native-tls", "tokio", @@ -1368,8 +1310,8 @@ dependencies = [ "futures-channel", "futures-util", "http 1.1.0", - "http-body 1.0.0", - "hyper 1.3.1", + "http-body", + "hyper", "pin-project-lite", "socket2", "tokio", @@ -1776,7 +1718,6 @@ dependencies = [ "serde_json", "serde_repr", "sha2", - "signal-hook", "simd-json 0.13.10", "sqlx", "thiserror", @@ -1788,9 +1729,9 @@ dependencies = [ "tracing-subscriber", "twilight-gateway", "twilight-http", - "twilight-model", + "twilight-model 0.16.0-rc.1", "twilight-util", - "twilight-validate", + "twilight-validate 0.15.3", "url", "url-escape", "uuid", @@ -2408,9 +2349,9 @@ dependencies = [ "futures-util", "h2 0.4.5", "http 1.1.0", - "http-body 1.0.0", + "http-body", "http-body-util", - "hyper 1.3.1", + "hyper", "hyper-rustls 0.27.2", "hyper-tls", "hyper-util", @@ -2422,7 +2363,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls-pemfile 2.1.2", + "rustls-pemfile", "serde", "serde_json", "serde_urlencoded", @@ -2438,21 +2379,6 @@ dependencies = [ "winreg", ] -[[package]] -name = "ring" -version = "0.16.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" -dependencies = [ - "cc", - "libc", - "once_cell", - "spin 0.5.2", - "untrusted 0.7.1", - "web-sys", - "winapi", -] - [[package]] name = "ring" version = "0.17.8" @@ -2464,7 +2390,7 @@ dependencies = [ "getrandom", "libc", "spin 0.9.8", - "untrusted 0.9.0", + "untrusted", "windows-sys 0.52.0", ] @@ -2563,14 +2489,15 @@ dependencies = [ [[package]] name = "rustls" -version = "0.20.9" +version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" +checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" dependencies = [ - "log", - "ring 0.16.20", - "sct", - "webpki", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", ] [[package]] @@ -2588,25 +2515,17 @@ dependencies = [ [[package]] name = "rustls-native-certs" -version = "0.6.3" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" +checksum = "8f1fb85efa936c42c6d5fc28d2629bb51e4b2f4b8a5211e297d599cc5a093792" dependencies = [ "openssl-probe", - "rustls-pemfile 1.0.4", + "rustls-pemfile", + "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" @@ -2629,9 +2548,9 @@ version = "0.102.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" dependencies = [ - "ring 0.17.8", + "ring", "rustls-pki-types", - "untrusted 0.9.0", + "untrusted", ] [[package]] @@ -2655,16 +2574,6 @@ 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 0.17.8", - "untrusted 0.9.0", -] - [[package]] name = "seahash" version = "4.1.0" @@ -2775,6 +2684,12 @@ dependencies = [ "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" @@ -2795,16 +2710,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" @@ -3387,13 +3292,13 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.23.4" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" dependencies = [ - "rustls 0.20.9", + "rustls 0.22.4", + "rustls-pki-types", "tokio", - "webpki", ] [[package]] @@ -3419,32 +3324,40 @@ dependencies = [ ] [[package]] -name = "tokio-tungstenite" -version = "0.18.0" +name = "tokio-util" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54319c93411147bced34cb5609a80e0a8e44c5999c93903a81cd866630ec0bfd" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" dependencies = [ - "futures-util", - "log", - "rustls 0.20.9", - "rustls-native-certs", + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", "tokio", - "tokio-rustls 0.23.4", - "tungstenite", - "webpki", ] [[package]] -name = "tokio-util" -version = "0.7.11" +name = "tokio-websockets" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" +checksum = "988c6e20955aa5043e0822cb27093ebaabb430a126cda0223824b6d65ea900c1" dependencies = [ + "base64 0.21.7", "bytes", + "fastrand", "futures-core", "futures-sink", - "pin-project-lite", + "http 1.1.0", + "httparse", + "ring", + "rustls-native-certs", + "rustls-pki-types", + "sha1_smol", + "simdutf8", "tokio", + "tokio-rustls 0.25.0", + "tokio-util", + "tracing", ] [[package]] @@ -3571,55 +3484,31 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" -[[package]] -name = "tungstenite" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30ee6ab729cd4cf0fd55218530c4522ed30b7b6081752839b68fcec8d0960788" -dependencies = [ - "base64 0.13.1", - "byteorder", - "bytes", - "http 0.2.12", - "httparse", - "log", - "rand", - "rustls 0.20.9", - "sha1", - "thiserror", - "url", - "utf-8", - "webpki", -] - [[package]] name = "twilight-gateway" -version = "0.15.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30be5c7e2b13b4a59e0f93344c070c23404279a318a324eece1f4384ead47d86" +version = "0.16.0-rc.1" +source = "git+https://github.com/twilight-rs/twilight.git?rev=6a44028#6a4402826ced167ed68d6c27d2216763d53ac7fb" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", + "fastrand", "flate2", - "futures-util", - "rand", - "rustls 0.20.9", - "rustls-native-certs", + "futures-core", + "futures-sink", "serde", "serde_json", "simd-json 0.10.7", "tokio", - "tokio-tungstenite", + "tokio-websockets", "tracing", "twilight-gateway-queue", "twilight-http", - "twilight-model", + "twilight-model 0.16.0-rc.1", ] [[package]] name = "twilight-gateway-queue" -version = "0.15.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3073747da8e1d09bc5383eed750451c9534021c8206a20092405b9855b3cb35a" +version = "0.16.0-rc.1" +source = "git+https://github.com/twilight-rs/twilight.git?rev=6a44028#6a4402826ced167ed68d6c27d2216763d53ac7fb" dependencies = [ "tokio", "tracing", @@ -3627,33 +3516,32 @@ dependencies = [ [[package]] name = "twilight-http" -version = "0.15.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c78b55d912a58814dbfc4dc3cfb9496c7e83eb6ec738b1cc4c359ba0d2ff2dd8" +version = "0.16.0-rc.1" +source = "git+https://github.com/twilight-rs/twilight.git?rev=6a44028#6a4402826ced167ed68d6c27d2216763d53ac7fb" dependencies = [ - "brotli 3.5.0", - "hyper 0.14.28", - "hyper-rustls 0.23.2", + "brotli-decompressor", + "fastrand", + "http 1.1.0", + "http-body-util", + "hyper", + "hyper-rustls 0.26.0", + "hyper-util", "percent-encoding", - "rand", "serde", "serde_json", "simd-json 0.10.7", "tokio", "tracing", "twilight-http-ratelimiting", - "twilight-model", - "twilight-validate", + "twilight-model 0.16.0-rc.1", + "twilight-validate 0.16.0-rc.1", ] [[package]] name = "twilight-http-ratelimiting" -version = "0.15.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa4a03343ff60a8d5b5b722ce4b0b7e266ace6cc3e9143544a840d3cc127f02b" +version = "0.16.0-rc.1" +source = "git+https://github.com/twilight-rs/twilight.git?rev=6a44028#6a4402826ced167ed68d6c27d2216763d53ac7fb" dependencies = [ - "futures-util", - "http 0.2.12", "tokio", "tracing", ] @@ -3671,14 +3559,25 @@ dependencies = [ "time", ] +[[package]] +name = "twilight-model" +version = "0.16.0-rc.1" +source = "git+https://github.com/twilight-rs/twilight.git?rev=6a44028#6a4402826ced167ed68d6c27d2216763d53ac7fb" +dependencies = [ + "bitflags 2.5.0", + "serde", + "serde-value", + "serde_repr", + "time", +] + [[package]] name = "twilight-util" -version = "0.15.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe3149347d8222e042a55deba80cd32f93f14770bbb845b8e4cfbd70a5062c56" +version = "0.16.0-rc.1" +source = "git+https://github.com/twilight-rs/twilight.git?rev=6a44028#6a4402826ced167ed68d6c27d2216763d53ac7fb" dependencies = [ - "twilight-model", - "twilight-validate", + "twilight-model 0.16.0-rc.1", + "twilight-validate 0.16.0-rc.1", ] [[package]] @@ -3687,7 +3586,15 @@ version = "0.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3595d5ad595d8d3a97096a01899b53d3a8117ab16deda27526b315a1db815da4" dependencies = [ - "twilight-model", + "twilight-model 0.15.4", +] + +[[package]] +name = "twilight-validate" +version = "0.16.0-rc.1" +source = "git+https://github.com/twilight-rs/twilight.git?rev=6a44028#6a4402826ced167ed68d6c27d2216763d53ac7fb" +dependencies = [ + "twilight-model 0.16.0-rc.1", ] [[package]] @@ -3735,12 +3642,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" -[[package]] -name = "untrusted" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" - [[package]] name = "untrusted" version = "0.9.0" @@ -3773,12 +3674,6 @@ 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 = "utf16_iter" version = "1.0.5" @@ -3940,16 +3835,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webpki" -version = "0.22.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" -dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", -] - [[package]] name = "whoami" version = "1.5.1" diff --git a/crates/mellow/Cargo.toml b/crates/mellow/Cargo.toml index ed11783..23d910f 100644 --- a/crates/mellow/Cargo.toml +++ b/crates/mellow/Cargo.toml @@ -37,15 +37,14 @@ tokio-util = "0.7.11" serde_repr = "0.1.19" serde_json = "1.0.117" tracing-log = "0.2.0" -signal-hook = "0.3.17" derive_more = "0.99.18" futures-util = "0.3.30" tracing-error = "0.2.0" mellow_macros = { path = "../mellow_macros" } -twilight-http = { version = "0.15.4", features = ["simd-json"] } -twilight-util = { version = "0.15.4", features = ["builder"] } -twilight-model = "0.15.4" +twilight-http = { git = "https://github.com/twilight-rs/twilight.git", rev = "6a44028", features = ["simd-json"] } +twilight-util = { git = "https://github.com/twilight-rs/twilight.git", rev = "6a44028", features = ["builder"] } +twilight-model = { git = "https://github.com/twilight-rs/twilight.git", rev = "6a44028" } async-recursion = "1.1.1" -twilight-gateway = { version = "0.15.4", features = ["simd-json"] } +twilight-gateway = { git = "https://github.com/twilight-rs/twilight.git", rev = "6a44028", features = ["simd-json"] } twilight-validate = "0.15.3" tracing-subscriber = "0.3.18" \ No newline at end of file diff --git a/crates/mellow/src/commands/server.rs b/crates/mellow/src/commands/server.rs index 98d3f36..26c19c4 100644 --- a/crates/mellow/src/commands/server.rs +++ b/crates/mellow/src/commands/server.rs @@ -34,7 +34,7 @@ pub async fn setup(_context: Context, interaction: Interaction) -> Result = vec![]; @@ -210,7 +210,7 @@ pub async fn forcesyncall(context: Context, interaction: Interaction) -> Result< } INTERACTION.update_response(&interaction.token) - .content(Some(&format!("## Successfully synced {total_synced} profiles\n{total_changed} profile(s) in total were updated.")))? + .content(Some(&format!("## Successfully synced {total_synced} profiles\n{total_changed} profile(s) in total were updated."))) .await?; server.send_logs(logs).await?; diff --git a/crates/mellow/src/discord/gateway/event/guild.rs b/crates/mellow/src/discord/gateway/event/guild.rs index 90dc1e8..a7d2242 100644 --- a/crates/mellow/src/discord/gateway/event/guild.rs +++ b/crates/mellow/src/discord/gateway/event/guild.rs @@ -6,13 +6,16 @@ use crate::{ }; pub fn guild_create(guild_create: GuildCreate) -> Result<()> { - let guild_id = guild_create.id; - tracing::info!("model.discord.guild.create (guild_id={guild_id})"); - - for role in &guild_create.roles { - DISCORD_MODELS.roles.insert((guild_id, role.id), role.clone().into()); + if let GuildCreate::Available(guild) = guild_create { + let guild_id = guild.id; + tracing::info!("model.discord.guild.create (guild_id={guild_id})"); + + for role in &guild.roles { + DISCORD_MODELS.roles.insert((guild_id, role.id), role.clone().into()); + } + DISCORD_MODELS.guilds.insert(guild_id, guild.into()); } - DISCORD_MODELS.guilds.insert(guild_id, guild_create.0.into()); + Ok(()) } diff --git a/crates/mellow/src/discord/gateway/event/member.rs b/crates/mellow/src/discord/gateway/event/member.rs index c7276b8..5d16d33 100644 --- a/crates/mellow/src/discord/gateway/event/member.rs +++ b/crates/mellow/src/discord/gateway/event/member.rs @@ -1,12 +1,10 @@ use std::time::SystemTime; use tokio::sync::RwLock; use twilight_model::{ - id::{ - marker::{ UserMarker, GuildMarker }, + gateway::payload::incoming::{ MemberAdd, MemberChunk, MemberRemove, MemberUpdate }, guild::VerificationLevel, id::{ + marker::{ GuildMarker, UserMarker }, Id - }, - guild::VerificationLevel, - gateway::payload::incoming::{ MemberAdd, MemberChunk, MemberUpdate, MemberRemove } + } }; use crate::{ @@ -20,18 +18,20 @@ static PENDING_MEMBERS: RwLock, Id)>> = RwLock: pub async fn member_add(member_add: MemberAdd) -> Result<()> { let user_id = member_add.user.id; let guild_id = member_add.guild_id; - DISCORD_MODELS.members.insert((guild_id, user_id), member_add.member.clone().into()); + let new_member = DISCORD_MODELS.members + .entry((guild_id, user_id)) + .insert(member_add.member.into()) + .downgrade(); tracing::info!("model.discord.member.create (guild_id={guild_id}) (user_id={user_id})"); - if member_add.member.pending { + if new_member.pending { PENDING_MEMBERS.write().await.push((guild_id, user_id)); } if let Some(document) = MELLOW_MODELS.event_document(guild_id, DocumentKind::MemberJoinEvent).await? { if document.is_ready_for_stream() { - let member = DISCORD_MODELS.member(guild_id, user_id).await?; let variables = Variable::create_map([ - ("member", Variable::from_member(member.value(), guild_id).await?) + ("member", Variable::from_member(new_member.value(), guild_id).await?) ], None); document .process(variables) diff --git a/crates/mellow/src/discord/gateway/mod.rs b/crates/mellow/src/discord/gateway/mod.rs index a7d2cb9..a42c7d4 100644 --- a/crates/mellow/src/discord/gateway/mod.rs +++ b/crates/mellow/src/discord/gateway/mod.rs @@ -1,12 +1,9 @@ -use std::sync::{ - atomic::{ Ordering, AtomicBool }, - Arc -}; +use std::sync::Arc; use twilight_model::gateway::{ payload::outgoing::update_presence::UpdatePresencePayload, presence::{ Status, Activity, ActivityType } }; -use twilight_gateway::{ Shard, Config, Intents, ShardId, CloseFrame }; +use twilight_gateway::{ Shard, Intents, ShardId, StreamExt, ConfigBuilder, EventTypeFlags }; pub use context::Context; @@ -16,7 +13,7 @@ pub mod event; pub async fn initialise() { tracing::info!("initialising discord gateway"); - let config = Config::builder( + let config = ConfigBuilder::new( env!("DISCORD_TOKEN").to_string(), Intents::GUILDS | Intents::GUILD_MEMBERS | Intents::GUILD_MESSAGES | Intents::MESSAGE_CONTENT @@ -43,29 +40,12 @@ pub async fn initialise() { let mut shard = Shard::with_config(ShardId::ONE, config); let context = Arc::new(Context::new(shard.sender())); - let term = Arc::new(AtomicBool::new(false)); - signal_hook::flag::register(signal_hook::consts::SIGINT, Arc::clone(&term)).unwrap(); - - loop { - if term.load(Ordering::Relaxed) { - tracing::info!("SIGINT received, shutting down gateway..."); - shard.close(CloseFrame::NORMAL).await.unwrap(); - break; - } - - let event = match shard.next_event().await { - Ok(event) => event, - Err(source) => { - tracing::warn!(?source, "error receiving event"); - if source.is_fatal() { - break; - } - - continue; - } + while let Some(item) = shard.next_event(EventTypeFlags::all()).await { + let Ok(event) = item else { + tracing::warn!(source = ?item.unwrap_err(), "error receiving event"); + continue; }; - let context = Arc::clone(&context); - context.handle_event(event); + Arc::clone(&context).handle_event(event); } } \ No newline at end of file diff --git a/crates/mellow/src/error.rs b/crates/mellow/src/error.rs index 6738504..d57ce4b 100644 --- a/crates/mellow/src/error.rs +++ b/crates/mellow/src/error.rs @@ -31,8 +31,8 @@ pub enum ErrorKind { #[error("Image Source Url Error: {0}")] TwilightImageUrlError(#[from] twilight_util::builder::embed::image_source::ImageSourceUrlError), - #[error("Gateway Send Error: {0}")] - TwilightSendError(#[from] twilight_gateway::error::SendError), + #[error("Twilight Channel Error: {0}")] + TwilightSendError(#[from] twilight_gateway::error::ChannelError), #[error("User Ids Error: {0}")] TwilightUserIdsError(#[from] twilight_model::gateway::payload::outgoing::request_guild_members::UserIdsError), diff --git a/crates/mellow/src/http/routes.rs b/crates/mellow/src/http/routes.rs index 85b2ae7..7fcd4d3 100644 --- a/crates/mellow/src/http/routes.rs +++ b/crates/mellow/src/http/routes.rs @@ -162,23 +162,25 @@ async fn model_update_webhook(_request: HttpRequest, payload: web::Json { let id = new_server.id; - if let Some(old_server) = MELLOW_MODELS.servers.get(&id) { + let new_logging_types = new_server.logging_types; + let new_logging_channel_id = new_server.logging_channel_id; + if let Some(old_server) = MELLOW_MODELS.servers.insert(id, new_server) { let mut logging_data_changes: Vec = vec![]; - if old_server.logging_types != new_server.logging_types { - logging_data_changes.push(DataChange::updated("Active Events", old_server.logging_types, new_server.logging_types)?); + if old_server.logging_types != new_logging_types { + logging_data_changes.push(DataChange::updated("Active Events", old_server.logging_types, new_logging_types)?); } - if old_server.logging_channel_id != new_server.logging_channel_id { + if old_server.logging_channel_id != new_logging_channel_id { if old_server.logging_channel_id.is_none() { - logging_data_changes.push(DataChange::created("Channel", new_server.logging_channel_id.unwrap())?); - } else if new_server.logging_channel_id.is_none() { + logging_data_changes.push(DataChange::created("Channel", new_logging_channel_id.unwrap())?); + } else if new_logging_channel_id.is_none() { logging_data_changes.push(DataChange::deleted("Channel", old_server.logging_channel_id.unwrap())?); } else { - logging_data_changes.push(DataChange::updated("Channel", old_server.logging_channel_id.unwrap(), new_server.logging_channel_id.unwrap())?); + logging_data_changes.push(DataChange::updated("Channel", old_server.logging_channel_id.unwrap(), new_logging_channel_id.unwrap())?); } } if !logging_data_changes.is_empty() { - if let Err(err) = new_server.send_logs(vec![ + if let Err(err) = old_server.send_logs(vec![ ServerLog::ActionLog(ActionLog { kind: "mellow.server.discord_logging.updated".into(), author: model_update.actionee, @@ -194,7 +196,6 @@ async fn model_update_webhook(_request: HttpRequest, payload: web::Json { diff --git a/crates/mellow/src/main.rs b/crates/mellow/src/main.rs index a4f7329..6254038 100644 --- a/crates/mellow/src/main.rs +++ b/crates/mellow/src/main.rs @@ -89,8 +89,9 @@ impl CommandResponse { _ => (", not sure what exactly though!", error.to_string()) }; INTERACTION.update_response(&interaction_token) - .content(Some(&format!("<:niko_look_left:1227198516590411826> something unexpected happened{text}\n```diff\n- {problem}\n--- {}```", error.context))).unwrap() - .await.unwrap(); + .content(Some(&format!("<:niko_look_left:1227198516590411826> something unexpected happened{text}\n```diff\n- {problem}\n--- {}```", error.context))) + .await + .unwrap(); } }); Self::Defer diff --git a/crates/mellow/src/model/discord/guild/member.rs b/crates/mellow/src/model/discord/guild/member.rs index d73449b..0b908a8 100644 --- a/crates/mellow/src/model/discord/guild/member.rs +++ b/crates/mellow/src/model/discord/guild/member.rs @@ -14,7 +14,7 @@ pub struct CachedMember { pub communication_disabled_until: Option, pub deaf: Option, pub flags: MemberFlags, - pub joined_at: Timestamp, + pub joined_at: Option, pub mute: Option, pub nick: Option, pub pending: bool, diff --git a/crates/mellow/src/server/logging.rs b/crates/mellow/src/server/logging.rs index 684c019..6a06d4c 100644 --- a/crates/mellow/src/server/logging.rs +++ b/crates/mellow/src/server/logging.rs @@ -198,7 +198,7 @@ impl Server { if !embeds.is_empty() { for chunk in embeds.chunks(EMBED_COUNT_LIMIT) { CLIENT.create_message(channel_id) - .embeds(chunk)? + .embeds(chunk) .await?; } } diff --git a/crates/mellow/src/syncing/mod.rs b/crates/mellow/src/syncing/mod.rs index 5d11018..76192d2 100644 --- a/crates/mellow/src/syncing/mod.rs +++ b/crates/mellow/src/syncing/mod.rs @@ -238,7 +238,7 @@ pub async fn sync_member(user: Option<&User>, member: &CachedMember, server: &Se // TODO: notify user via direct messages member_status = MemberStatus::Banned; CLIENT.create_ban(server.id, member.user_id) - .reason(&format!("Met criteria of {} — {}", action.display_name, reasoning.reason.as_ref().unwrap_or(&"No reason".into())))? + .reason(&format!("Met criteria of {} — {}", action.display_name, reasoning.reason.as_ref().unwrap_or(&"No reason".into()))) .await?; break; }, @@ -246,7 +246,7 @@ pub async fn sync_member(user: Option<&User>, member: &CachedMember, server: &Se // TODO: notify user via direct messages member_status = MemberStatus::Kicked; CLIENT.remove_guild_member(server.id, member.user_id) - .reason(&format!("Met criteria of {} — {}", action.display_name, reasoning.reason.as_ref().unwrap_or(&"No reason".into())))? + .reason(&format!("Met criteria of {} — {}", action.display_name, reasoning.reason.as_ref().unwrap_or(&"No reason".into()))) .await?; break; }, @@ -291,7 +291,7 @@ pub async fn sync_member(user: Option<&User>, member: &CachedMember, server: &Se request = request.roles(&roles); } if nickname_change.is_some() { - request = request.nick(target_nickname)?; + request = request.nick(target_nickname); } request.await?; } diff --git a/crates/mellow/src/visual_scripting/mod.rs b/crates/mellow/src/visual_scripting/mod.rs index df2a308..f7b4968 100644 --- a/crates/mellow/src/visual_scripting/mod.rs +++ b/crates/mellow/src/visual_scripting/mod.rs @@ -81,7 +81,7 @@ impl Document { if let Some(member) = reference.resolve(&*variables.read().await){ let user_id = member.get("id").cast_id(); CLIENT.create_ban(member.get("guild_id").cast_id(), user_id) - .reason("Triggered by a visual scripting element")? + .reason("Triggered by a visual scripting element") .await?; tracker.banned_member(user_id); break; @@ -91,7 +91,7 @@ impl Document { if let Some(member) = reference.resolve(&*variables.read().await) { let user_id = member.get("id").cast_id(); CLIENT.remove_guild_member(member.get("guild_id").cast_id(), user_id) - .reason("Triggered by a visual scripting element")? + .reason("Triggered by a visual scripting element") .await?; tracker.kicked_member(user_id); break; @@ -101,7 +101,7 @@ impl Document { if let Some(member) = data.reference.resolve(&*variables.read().await) { let user_id = member.get("id").cast_id(); CLIENT.add_guild_member_role(member.get("guild_id").cast_id(), user_id, Id::new(data.value.parse()?)) - .reason("Triggered by a visual scripting element")? + .reason("Triggered by a visual scripting element") .await?; tracker.assigned_member_role(user_id, &data.value); } @@ -110,7 +110,7 @@ impl Document { if let Some(member) = data.reference.resolve(&*variables.read().await) { let user_id = member.get("id").cast_id(); CLIENT.remove_guild_member_role(member.get("guild_id").cast_id(), user_id, Id::new(data.value.parse()?)) - .reason("Triggered by a visual scripting element")? + .reason("Triggered by a visual scripting element") .await?; tracker.removed_member_role(user_id, &data.value); } @@ -148,7 +148,7 @@ impl Document { if let Some(channel_id) = data.channel_id.resolve(variables) { let channel_id = channel_id.cast_id(); let message = CLIENT.create_message(channel_id) - .content(&data.content.clone().resolve(variables))? + .content(&data.content.clone().resolve(variables)) .await? .model() .await?; @@ -158,7 +158,7 @@ impl Document { ElementKind::Reply(data) => { if let Some(message) = data.reference.resolve(&*variables.read().await) { CLIENT.create_message(message.get("channel_id").cast_id()) - .content(&data.value)? + .content(&data.value) .reply(message.get("id").cast_id()) .await?; } @@ -175,7 +175,7 @@ impl Document { if let Some(message) = data.resolve(&*variables.read().await) { let channel_id = message.get("channel_id").cast_id(); CLIENT.delete_message(channel_id, message.get("id").cast_id()) - .reason("Triggered by a visual scripting element")? + .reason("Triggered by a visual scripting element") .await?; tracker.deleted_message(channel_id, message.get("author").get("id").cast_str()); } @@ -189,14 +189,14 @@ impl Document { let variables = &*variables.read().await; let token = variables.get("interaction_token").cast_str(); INTERACTION.update_response(token) - .content(Some(&data.resolve(variables)))? + .content(Some(&data.resolve(variables))) .await?; }, ElementKind::StartThreadFromMessage { name, message } => { let variables = &*variables.read().await; if let Some(message) = message.resolve(variables) { let channel_id = message.get("channel_id").cast_id(); - let new_thread = CLIENT.create_thread_from_message(channel_id, message.get("id").cast_id(), &name.resolve(variables))? + let new_thread = CLIENT.create_thread_from_message(channel_id, message.get("id").cast_id(), &name.resolve(variables)) .await? .model() .await?;