Something went wrong. Try again.
7 Days to Die Discord bot (old and ugly code)
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142use anyhow::{Result, anyhow};use bytes::Bytes;use fjall::{Keyspace, PartitionCreateOptions, PartitionHandle, UserKey};
pub struct AppData { pub keyspace: Keyspace,}
pub trait GuildPartition { fn get_guild_partition(&self) -> Result<PartitionHandle>;}
pub trait FetchSettings { fn get_from_partition(&self, key: UserKey) -> Result<String>;}
pub type Error = Box<dyn std::error::Error + Send + Sync>;pub type Context<'a> = poise::Context<'a, AppData, Error>;
impl GuildPartition for Context<'_> { fn get_guild_partition(&self) -> Result<PartitionHandle> { let id = self .guild_id() .ok_or(anyhow!("guild not found, user command not supported"))?;
Ok(self .data() .keyspace .open_partition(format!("{id}").as_str(), PartitionCreateOptions::default())?) }}
impl FetchSettings for PartitionHandle { fn get_from_partition<'str>(&self, key: UserKey) -> Result<String> { let channel = self .get(key)? .ok_or(anyhow!("Could not find setting from partition"))?; let bytes = Bytes::from(channel.to_vec()); Ok(std::str::from_utf8(&bytes)?.to_string()) }}