From 815cb0df3b3e3f9dd2078b00f85754da87b1d55e Mon Sep 17 00:00:00 2001 From: seth Date: Tue, 5 Dec 2023 05:17:49 -0500 Subject: refactor: centralize storage handlers --- src/storage/settings.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/storage/settings.rs (limited to 'src/storage/settings.rs') diff --git a/src/storage/settings.rs b/src/storage/settings.rs new file mode 100644 index 0000000..c8a663d --- /dev/null +++ b/src/storage/settings.rs @@ -0,0 +1,37 @@ +use poise::serenity_prelude::{ChannelId, GuildId, ReactionType}; +use redis_macros::{FromRedisValue, ToRedisArgs}; +use serde::{Deserialize, Serialize}; + +pub const SETTINGS_KEY: &str = "settings-v1"; + +#[derive(poise::ChoiceParameter)] +pub enum SettingsProperties { + GuildId, + PinBoardChannel, + PinBoardWatch, + ReactBoardChannel, + ReactBoardRequirement, + ReactBoardReactions, + OptionalCommandsEnabled, +} + +#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, FromRedisValue, ToRedisArgs)] +pub struct Settings { + pub guild_id: GuildId, + pub pinboard_channel: Option, + pub pinboard_watch: Option>, + pub reactboard_channel: Option, + pub reactboard_requirement: Option, + pub reactboard_reactions: Option>, + pub optional_commands_enabled: bool, +} + +impl Settings { + pub fn can_use_reaction(&self, reaction: &ReactionType) -> bool { + if let Some(reactions) = &self.reactboard_reactions { + reactions.iter().any(|r| r == reaction) + } else { + false + } + } +} -- cgit v1.2.3