From 3d07413690c551d9f034c93af85ae8da5a495e14 Mon Sep 17 00:00:00 2001 From: seth Date: Sat, 20 Apr 2024 02:31:40 +0000 Subject: spring cleaning (#165) * treewide: lightly refactor everything * once_cell -> std::sync * remove build.rs we can get our target at runtime * commands::copypasta: refactor selection * drop owo_colors * reactboard: always remove author from count * commands: better handle behavior outside of guilds * ci: garnix -> gha * nix: drop flake-parts & pre-commit-hooks * nix: fix rust flags in derivation * add gha badge to readme * ci: fail when format changes are made * ci: only run on push to main * nix: fix nil script * nix: add libiconv to darwin deps * ci: disable fail-fast * nix: fix actionlint & static checks * ci: add release gates * nix: fix nil check again * ci: give release gates unique names * ci: only build static packages in docker workflow * nix: move dev outputs to subflake * fix some typos * nix: cleanup checks & dev shell * add editorconfig --- src/handlers/event/message.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/handlers/event/message.rs') diff --git a/src/handlers/event/message.rs b/src/handlers/event/message.rs index 3054e27..67dbb21 100644 --- a/src/handlers/event/message.rs +++ b/src/handlers/event/message.rs @@ -1,16 +1,10 @@ use crate::{consts, Data}; -use eyre::{eyre, Report, Result}; -use log::debug; +use eyre::{eyre, Result}; +use log::{debug, warn}; use poise::serenity_prelude::{Context, Message}; -use poise::FrameworkContext; - -pub async fn handle( - ctx: &Context, - _framework: FrameworkContext<'_, Data, Report>, - msg: &Message, - data: &Data, -) -> Result<()> { + +pub async fn handle(ctx: &Context, msg: &Message, data: &Data) -> Result<()> { if should_echo(ctx, msg, data).await? { msg.reply(ctx, &msg.content).await?; } @@ -27,11 +21,16 @@ async fn should_echo(ctx: &Context, msg: &Message, data: &Data) -> Result let gid = msg .guild_id .ok_or_else(|| eyre!("Couldn't get GuildId from {}!", msg.id))?; - let settings = data.storage.get_guild_settings(&gid).await?; - if !settings.optional_commands_enabled { - debug!("Not echoing in guild {gid}"); - return Ok(false); + if let Some(storage) = &data.storage { + let settings = storage.get_guild_settings(&gid).await?; + + if !settings.optional_commands_enabled { + debug!("Not echoing in guild {gid}"); + return Ok(false); + } + } else { + warn!("Ignoring restrictions on echoing messages; no storage backend is attached!"); } let content = &msg.content; -- cgit v1.2.3