Add autodelete setting and sticky np embed
Signed-off-by: trivernis <trivernis@protonmail.com>pull/2/head
parent
f36cf5a477
commit
69e7a2a18f
@ -0,0 +1,19 @@
|
||||
use crate::providers::settings::{get_setting, Setting};
|
||||
use crate::utils::error::BotResult;
|
||||
use serenity::model::channel::Message;
|
||||
use serenity::prelude::*;
|
||||
|
||||
/// Deletes a message automatically if configured that way
|
||||
pub async fn handle_autodelete(ctx: &Context, msg: &Message) -> BotResult<()> {
|
||||
if let Some(guild_id) = msg.guild_id {
|
||||
let autodelete = get_setting(ctx, guild_id, Setting::BotAutoDelete)
|
||||
.await?
|
||||
.unwrap_or(true);
|
||||
|
||||
if autodelete {
|
||||
let _ = msg.delete(ctx).await;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
@ -1 +1,2 @@
|
||||
pub(crate) mod music;
|
||||
pub(crate) mod settings;
|
||||
|
@ -0,0 +1,35 @@
|
||||
use crate::utils::context_data::DatabaseContainer;
|
||||
use crate::utils::error::{BotError, BotResult};
|
||||
use serenity::client::Context;
|
||||
use serenity::model::prelude::GuildId;
|
||||
use std::str::FromStr;
|
||||
|
||||
pub static ALL_SETTINGS: &[Setting] = &[Setting::MusicAutoShuffle, Setting::BotAutoDelete];
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Setting {
|
||||
MusicAutoShuffle,
|
||||
BotAutoDelete,
|
||||
}
|
||||
|
||||
impl ToString for Setting {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
Self::MusicAutoShuffle => "music.autoshuffle".to_string(),
|
||||
Self::BotAutoDelete => "bot.autodelete".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a specific guild setting
|
||||
pub async fn get_setting<T: 'static + FromStr>(
|
||||
ctx: &Context,
|
||||
guild_id: GuildId,
|
||||
setting: Setting,
|
||||
) -> BotResult<Option<T>> {
|
||||
let data = ctx.data.read().await;
|
||||
let database = data.get::<DatabaseContainer>().unwrap();
|
||||
database
|
||||
.get_guild_setting::<T>(guild_id.0, &setting.to_string())
|
||||
.map_err(BotError::from)
|
||||
}
|
Loading…
Reference in New Issue