diff --git a/CHANGELOG.md b/CHANGELOG.md index 11e4ad5ad..e510752f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,13 +20,17 @@ ## Discord Frontend +- **Added:** `plugin` attribute macro and `Plugin` traits +- **Added:** plugin-related functions to `CommandMetadata` trait +- **Added:** checks for whether plugins are enabled before running one of their commands +- **Changed:** lookup tables are now used for command dispatch rather than `match` - **Changed:** extracted configuration models to its own crate (`serde` support included) - **Changed:** updated `rust-version` to 1.80 - **Changed:** `/info emoji` now sends embeds - **Changed:** more information has been added to `/info emoji` +- **Changed:** `/info emoji` now handles the error of an emoji not being found from database - **Changed:** removed previously deprecated functions from `CommandMetadata` - **Changed:** deprecated `command_type` and `interaction_only` in `CommandMetadata` -- **Changed:** `/info` check on whether `Utilities` plugin has been enabled before running - **Removed:** `redis` dependency removed ## Localization Infrastructure diff --git a/discord-frontend/hartex-discord-commands/src/lib.rs b/discord-frontend/hartex-discord-commands/src/lib.rs index 7272265a2..5714c7d5a 100644 --- a/discord-frontend/hartex-discord-commands/src/lib.rs +++ b/discord-frontend/hartex-discord-commands/src/lib.rs @@ -30,6 +30,8 @@ #![deny(clippy::pedantic)] #![deny(unsafe_code)] #![deny(warnings)] +#![feature(if_let_guard)] +#![feature(let_chains)] pub mod general; pub mod utilities; diff --git a/discord-frontend/hartex-discord-commands/src/utilities/info/info_emoji.rs b/discord-frontend/hartex-discord-commands/src/utilities/info/info_emoji.rs index d9f06eb1f..321a46eb4 100644 --- a/discord-frontend/hartex-discord-commands/src/utilities/info/info_emoji.rs +++ b/discord-frontend/hartex-discord-commands/src/utilities/info/info_emoji.rs @@ -35,6 +35,7 @@ use hartex_discord_core::discord::model::id::marker::EmojiMarker; use hartex_discord_core::discord::model::id::Id; use hartex_discord_core::discord::util::builder::embed::{EmbedBuilder, EmbedFieldBuilder}; use hartex_discord_core::discord::util::builder::InteractionResponseDataBuilder; +use hartex_discord_entitycache_core::error::CacheError; use hartex_discord_entitycache_core::traits::Repository; use hartex_discord_entitycache_repositories::emoji::CachedEmojiRepository; use hartex_discord_utils::commands::CommandDataOptionExt; @@ -44,6 +45,7 @@ use hartex_discord_utils::markdown::MarkdownStyle; use hartex_localization_core::Localizer; use miette::IntoDiagnostic; use regex::Regex; +use tokio_postgres::error::SqlState; lazy_static::lazy_static! { /// The regex for looking for a Discord emoji in the command input. @@ -71,6 +73,8 @@ pub async fn execute( localizer.utilities_plugin_emojiinfo_error_only_custom_emojis()?; let emojiinfo_error_only_one_emoji = localizer.utilities_plugin_emojiinfo_error_only_one_emoji()?; + let emojiinfo_error_unknown_emoji = + localizer.utilities_plugin_emojiinfo_error_unknown_emoji()?; let Some(captures) = EMOJI_REGEX.captures(&emoji) else { interaction_client @@ -115,10 +119,33 @@ pub async fn execute( let id = captures.get(1).unwrap().as_str(); let emoji_id = Id::::from_str(id).unwrap(); - let emoji = CachedEmojiRepository - .get(emoji_id) - .await - .into_diagnostic()?; + let result = CachedEmojiRepository.get(emoji_id).await; + let emoji = match result { + Ok(emoji) => emoji, + Err(CacheError::Postgres(postgres_error)) + if let Some(code) = postgres_error.code() + && *code == SqlState::NO_DATA => + { + interaction_client + .create_response( + interaction.id, + &interaction.token, + &InteractionResponse { + kind: InteractionResponseType::ChannelMessageWithSource, + data: Some( + InteractionResponseDataBuilder::new() + .content(emojiinfo_error_unknown_emoji) + .build(), + ), + }, + ) + .await + .into_diagnostic()?; + + return Ok(()); + } + error => error.into_diagnostic()?, + }; let emojiinfo_embed_generalinfo_field_name = localizer.utilities_plugin_emojiinfo_embed_generalinfo_field_name()?; diff --git a/discord-frontend/hartex-discord-configuration-models/src/lib.rs b/discord-frontend/hartex-discord-configuration-models/src/lib.rs index 3c48262c6..4c4eb49d2 100644 --- a/discord-frontend/hartex-discord-configuration-models/src/lib.rs +++ b/discord-frontend/hartex-discord-configuration-models/src/lib.rs @@ -25,6 +25,9 @@ //! This crate contains models that are returned by evaluating Lua configuration and can be //! serialized via `serde`. +#![deny(clippy::pedantic)] +#![deny(unsafe_code)] +#![deny(warnings)] #![feature(result_flattening)] use mlua::Error; diff --git a/discord-frontend/hartex-discord-configuration-models/src/permissions.rs b/discord-frontend/hartex-discord-configuration-models/src/permissions.rs index 97c597d66..846efad31 100644 --- a/discord-frontend/hartex-discord-configuration-models/src/permissions.rs +++ b/discord-frontend/hartex-discord-configuration-models/src/permissions.rs @@ -71,18 +71,18 @@ impl<'lua> FromLua<'lua> for Permissions { .map_ok(|(key, value)| { Id::from_str(key.as_str()) .map(|id| (id, value)) - .map_err(|error| Error::runtime("invalid id")) + .map_err(|_| Error::runtime("invalid id")) }) - .map(|result| result.flatten()) + .map(Result::flatten) .collect::, _>>()?, users: users .pairs::() .map_ok(|(key, value)| { Id::from_str(key.as_str()) .map(|id| (id, value)) - .map_err(|error| Error::runtime("invalid id")) + .map_err(|_| Error::runtime("invalid id")) }) - .map(|result| result.flatten()) + .map(Result::flatten) .collect::, _>>()?, }) } diff --git a/localization/locales/en-GB/discord-frontend/commands/utilities-plugin.ftl b/localization/locales/en-GB/discord-frontend/commands/utilities-plugin.ftl index 6f599a99a..c1249106b 100644 --- a/localization/locales/en-GB/discord-frontend/commands/utilities-plugin.ftl +++ b/localization/locales/en-GB/discord-frontend/commands/utilities-plugin.ftl @@ -31,6 +31,7 @@ emojiinfo-embed-generalinfo-managed-subfield-name=Managed: emojiinfo-embed-generalinfo-name-subfield-name=Name: emojiinfo-error-only-custom-emojis=Sorry! Only custom emojis are supported at this stage. emojiinfo-error-only-one-emoji=Querying multiple emojis is not supported. +emojiinfo-error-unknown-emoji=Unknown emoji. Perhaps the bot is not in a server that has this emoji? roleinfo-embed-description=Information of {$roleMention} roleinfo-embed-generalinfo-field-name=General Information roleinfo-embed-generalinfo-id-subfield-name=ID: