diff --git a/Cargo.lock b/Cargo.lock index 12ec226..0591b56 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -164,9 +164,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.6" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c79fed4cdb43e993fcdadc7e58a09fd0e3e649c4436fa11da71c9f1f3ee7feb9" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "bitflags" @@ -551,7 +551,6 @@ dependencies = [ "linkify", "num-format", "parking_lot", - "paste", "poise", "rand", "regex", @@ -1186,9 +1185,9 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "js-sys" -version = "0.3.66" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" +checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" dependencies = [ "wasm-bindgen", ] @@ -1802,7 +1801,7 @@ version = "0.11.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b1ae8d9ac08420c66222fb9096fc5de435c3c48542bc5336c51892cffafb41" dependencies = [ - "base64 0.21.6", + "base64 0.21.7", "bytes", "encoding_rs", "futures-core", @@ -1912,9 +1911,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.28" +version = "0.38.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" +checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" dependencies = [ "bitflags 2.4.1", "errno", @@ -1965,7 +1964,7 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "base64 0.21.6", + "base64 0.21.7", ] [[package]] @@ -2105,9 +2104,9 @@ dependencies = [ [[package]] name = "serde-aux" -version = "4.3.1" +version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "184eba62ebddb71658697c8b08822edee89970bf318c5362189f0de27f85b498" +checksum = "a86348501c129f3ad50c2f4635a01971f76974cd8a3f335988a0f1581c082765" dependencies = [ "chrono", "serde", @@ -2181,11 +2180,11 @@ dependencies = [ [[package]] name = "serenity" version = "0.12.0" -source = "git+https://github.com/serenity-rs/serenity?branch=next#4df87e16c513d1b94dccd0be5786744df5889dc5" +source = "git+https://github.com/serenity-rs/serenity?branch=next#c9b6766941c8acc8c06c9451e3f4ca46db5d84d4" dependencies = [ "arrayvec", "async-trait", - "base64 0.21.6", + "base64 0.21.7", "bitflags 2.4.1", "bool_to_bitflags", "bytes", @@ -2291,20 +2290,20 @@ dependencies = [ [[package]] name = "small-fixed-array" -version = "0.1.2" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe8b47b4046c1a383f46cb1d783b8afaabf36cea0833d739ac1c6c4a94f57d15" +checksum = "b35c6fe7591431a7c7383d683c2e202de0217187e397e4ca2a197b5ae991098d" dependencies = [ + "nonmax", "serde", - "tracing", "typesize", ] [[package]] name = "smallvec" -version = "1.11.2" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "2593d31f82ead8df961d8bd23a64c2ccf2eb5dd34b0a34bfb4dd54011c72009e" [[package]] name = "socket2" @@ -2483,7 +2482,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6ac0ac3b7ccd10cc96c7ab29791a7dd236bd94021f31eec7ba3d46a74aa1c24" dependencies = [ "atoi", - "base64 0.21.6", + "base64 0.21.7", "bitflags 2.4.1", "byteorder", "crc", @@ -3326,9 +3325,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" +checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -3336,9 +3335,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" +checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" dependencies = [ "bumpalo", "log", @@ -3351,9 +3350,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.39" +version = "0.4.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac36a15a220124ac510204aec1c3e5db8a22ab06fd6706d881dc6149f8ed9a12" +checksum = "bde2032aeb86bdfaecc8b261eef3cba735cc426c1f3a3416d1e0791be95fc461" dependencies = [ "cfg-if", "js-sys", @@ -3363,9 +3362,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" +checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3373,9 +3372,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" +checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" dependencies = [ "proc-macro2", "quote", @@ -3386,9 +3385,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" +checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" [[package]] name = "wasm-streams" @@ -3405,9 +3404,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.66" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50c24a44ec86bb68fbecd1b3efed7e85ea5621b39b35ef2766b66cd984f8010f" +checksum = "58cd2333b6e0be7a39605f0e255892fd7418a682d8da8fe042fe25128794d2ed" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index 2596df3..71c5251 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,6 @@ const_format = "0.2" strum_macros = "0.25" arrayvec = "0.7.4" bitflags = "2.4.1" -paste = "1.0.14" typesize = { version = "0.1.2", features = ["arrayvec"] } bool_to_bitflags = { version = "0.1", features = ["typesize"] } diff --git a/src/commands/settings.rs b/src/commands/settings.rs index 9604213..3c85b56 100644 --- a/src/commands/settings.rs +++ b/src/commands/settings.rs @@ -16,14 +16,17 @@ use std::{borrow::Cow, collections::HashMap, fmt::Write}; -use self::serenity::{builder::*, ChannelId, ComponentInteractionDataKind, Mentionable}; use anyhow::bail; -use database::Compact; + +use self::serenity::{ + builder::*, small_fixed_array::FixedString, ChannelId, ComponentInteractionDataKind, + Mentionable, +}; use poise::serenity_prelude as serenity; use crate::{ constants::{OPTION_SEPERATORS, PREMIUM_NEUTRAL_COLOUR}, - database, + database::{self, Compact}, funcs::{confirm_dialog, random_footer}, opt_ext::OptionGettext, require, require_guild, @@ -265,7 +268,9 @@ impl<'a> MenuPaginator<'a> { .map(|emoji| { CreateButton::new(emoji) .style(serenity::ButtonStyle::Primary) - .emoji(serenity::ReactionType::Unicode(String::from(emoji).into())) + .emoji(serenity::ReactionType::Unicode( + FixedString::from_str_trunc(emoji), + )) .disabled( disabled || (["⏮️", "◀"].contains(&emoji) && self.index == 0) diff --git a/src/errors.rs b/src/errors.rs index abe12cc..4899e3d 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -4,11 +4,12 @@ use anyhow::{Error, Result}; use sha2::Digest; use tracing::error; -use poise::serenity_prelude as serenity; - use self::serenity::{ - CreateActionRow, CreateButton, CreateInteractionResponse, FullEvent as Event, + small_fixed_array::TruncatingInto, CreateActionRow, CreateButton, CreateInteractionResponse, + FullEvent as Event, }; +use poise::serenity_prelude as serenity; + use crate::{ constants, require, structs::{Data, FrameworkContext}, @@ -89,7 +90,7 @@ async fn fetch_update_occurrences( let mut embed = message.embeds.into_vec().remove(0); embed.footer.as_mut().try_unwrap()?.text = - format!("This error has occurred {occurrences} times!").into(); + format!("This error has occurred {occurrences} times!").trunc_into(); let builder = serenity::EditWebhookMessage::default().embeds(vec![embed.into()]); error_webhook.edit_message(ctx, message_id, builder).await?; diff --git a/src/events/message.rs b/src/events/message.rs index 382d6ab..b323665 100644 --- a/src/events/message.rs +++ b/src/events/message.rs @@ -227,16 +227,15 @@ async fn process_mention_msg( message: &serenity::Message, data: &Data, ) -> Result<()> { - let bot_user = ctx.cache.current_user().id; - if ![ - format!("<@{bot_user}>").into(), - format!("<@!{bot_user}>").into(), - ] - .contains(&message.content) - { + let Some(bot_mention_regex) = data.regex_cache.bot_mention.get() else { + return Ok(()); + }; + + if !bot_mention_regex.is_match(&message.content) { return Ok(()); }; + let bot_user = ctx.cache.current_user().id; let guild_id = require!(message.guild_id, Ok(())); let channel = message.channel(ctx).await?.guild().unwrap(); let permissions = channel.permissions_for_user(ctx, bot_user)?; diff --git a/src/main.rs b/src/main.rs index 928ef37..08ee09e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,7 +42,7 @@ use std::{ collections::BTreeMap, num::NonZeroU16, str::FromStr, - sync::{atomic::AtomicBool, Arc}, + sync::{atomic::AtomicBool, Arc, OnceLock}, }; use anyhow::Ok; @@ -259,13 +259,10 @@ async fn _main(start_time: std::time::SystemTime) -> Result<()> { let analytics = Arc::new(analytics::Handler::new(pool.clone())); tokio::spawn(analytics.clone().start()); + let startup_builder = ExecuteWebhook::default().content("**TTS Bot is starting up**"); let startup_message = webhooks .logs - .execute( - &http, - true, - ExecuteWebhook::default().content("**TTS Bot is starting up**"), - ) + .execute(&http, true, startup_builder) .await? .unwrap() .id; @@ -294,6 +291,7 @@ async fn _main(start_time: std::time::SystemTime) -> Result<()> { ], id_in_brackets: regex::Regex::new(r"\((\d+)\)")?, emoji: regex::Regex::new(r"<(a?):([^<>]+):\d+>")?, + bot_mention: OnceLock::new(), }; let data = Data(Arc::new(DataInner { @@ -431,8 +429,15 @@ async fn _main(start_time: std::time::SystemTime) -> Result<()> { let mut client = serenity::Client::builder(&token, intents) .voice_manager::(songbird) - .framework(poise::Framework::new(framework_options, |_, _, _| { - Box::pin(async { Ok(data) }) + .framework(poise::Framework::new(framework_options, |_, ready, _| { + Box::pin(async { + data.regex_cache + .bot_mention + .set(regex::Regex::new(&format!("<@!{}>", ready.user.id))?) + .unwrap(); + + Ok(data) + }) })) .await?; diff --git a/src/structs.rs b/src/structs.rs index 186e766..4237148 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -1,7 +1,7 @@ use std::{ borrow::Cow, collections::{BTreeMap, HashMap}, - sync::Arc, + sync::{Arc, OnceLock}, }; pub use anyhow::{Error, Result}; @@ -108,6 +108,7 @@ pub struct PatreonInfo { pub struct RegexCache { pub replacements: [(regex::Regex, &'static str); 3], + pub bot_mention: OnceLock, pub id_in_brackets: regex::Regex, pub emoji: regex::Regex, }