summaryrefslogtreecommitdiff
path: root/src/storage
diff options
context:
space:
mode:
Diffstat (limited to 'src/storage')
-rw-r--r--src/storage/mod.rs44
1 files changed, 7 insertions, 37 deletions
diff --git a/src/storage/mod.rs b/src/storage/mod.rs
index 45c150a..b025de9 100644
--- a/src/storage/mod.rs
+++ b/src/storage/mod.rs
@@ -1,9 +1,9 @@
use std::{env, fmt::Debug, str::FromStr};
-use eyre::Result;
+use anyhow::Result;
use log::debug;
use poise::serenity_prelude::{GuildId, MessageId};
-use redis::{AsyncCommands, Client, ConnectionLike, RedisError};
+use redis::{AsyncCommands, Client, RedisError};
pub mod reactboard;
pub mod settings;
@@ -30,10 +30,6 @@ impl Storage {
Ok(Self::from_str(&redis_url)?)
}
- pub fn is_connected(&mut self) -> bool {
- self.client.check_connection()
- }
-
pub async fn create_guild_settings(&self, settings: Settings) -> Result<()> {
let guild_key = format!("{SETTINGS_KEY}:{}", settings.guild_id);
@@ -41,7 +37,7 @@ impl Storage {
redis::pipe()
.set(&guild_key, &settings)
.sadd(SETTINGS_KEY, u64::from(settings.guild_id))
- .query_async(&mut con)
+ .exec_async(&mut con)
.await?;
Ok(())
@@ -65,7 +61,7 @@ impl Storage {
redis::pipe()
.del(&guild_key)
.srem(SETTINGS_KEY, u64::from(*guild_id))
- .query_async(&mut con)
+ .exec_async(&mut con)
.await?;
Ok(())
@@ -81,34 +77,6 @@ impl Storage {
Ok(exists)
}
- pub async fn get_all_guild_settings(&self) -> Result<Vec<Settings>> {
- debug!("Fetching all guild settings");
-
- let mut con = self.client.get_multiplexed_async_connection().await?;
- let found: Vec<u64> = con.smembers(SETTINGS_KEY).await?;
-
- let mut guilds = vec![];
- for key in found {
- let settings = self.get_guild_settings(&key.into()).await?;
- guilds.push(settings);
- }
-
- Ok(guilds)
- }
-
- /// get guilds that have enabled optional commands
- pub async fn get_opted_guilds(&self) -> Result<Vec<GuildId>> {
- debug!("Fetching opted-in guilds");
-
- let guilds = self.get_all_guild_settings().await?;
- let opted: Vec<GuildId> = guilds
- .iter()
- .filter_map(|g| g.optional_commands_enabled.then_some(g.guild_id))
- .collect();
-
- Ok(opted)
- }
-
// reactboard
pub async fn create_reactboard_entry(
@@ -123,7 +91,9 @@ impl Storage {
let entry_key = format!("{REACTBOARD_KEY}:{guild_id}:{}", entry.original_message_id);
let mut con = self.client.get_multiplexed_async_connection().await?;
- con.set_ex(&entry_key, &entry, 30 * 24 * 60 * 60).await?; // 30 days
+ // https://github.com/redis-rs/redis-rs/issues/1228
+ con.set_ex::<_, _, ()>(&entry_key, &entry, 30 * 24 * 60 * 60)
+ .await?; // 30 days
Ok(())
}