use std::str::FromStr;
use poise::AutocompleteChoice;
use crate::errors::Error;
/**
* Describes a Reaction Role as it appears in SQL
*/
#[derive(Debug, Clone)]
pub struct ReactionRole {
/// The primary key
pub id: i32,
/// The ID of the channel where the menu is kept, turned into a String for ease of storage
pub channel_id: String,
/// The ID of the message within the channel containing the reaction menu
pub message_id: String,
/// The ID of the guild containing the channel
pub guild_id: String,
/// The String representation of the reaction, either as a unicode Emoji or a discord custom
/// emoji ID
pub reaction: String,
/// The ID of the role to be toggled by the menu option
pub role_id: String,
}
#[derive(Debug, Clone, sqlx::Type)]
#[sqlx(type_name="filter_action", rename_all="lowercase")]
pub enum FilterAction {
Review,
Delete
}
/**
* Describes a message filter as it appears in SQL
*/
#[derive(Debug, Clone, sqlx::FromRow)]
pub struct MessageFilter {
/// Primary Key
pub id: i32,
/// Pattern
pub pattern: String,
pub action: FilterAction,
pub guild_id: String,
}
#[derive(Debug, Clone)]
pub struct ConfigChannel {
pub id: i32,
pub channel_id: String,
pub guild_id: String,
pub purpose: String
}
impl FromStr for FilterAction {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"review" => Ok(FilterAction::Review),
"delete" => Ok(FilterAction::Delete),
_ => {
return Err(Error::Unknown("invalid option".to_string()));
}
}
}
}
impl ToString for FilterAction {
fn to_string(&self) -> String {
match self {
FilterAction::Review => "Review".to_string(),
FilterAction::Delete => "Delete".to_string(),
}
}
}
impl ToString for MessageFilter {
fn to_string(&self) -> String {
format!("`{}`: {} ({})", self.pattern, self.action.to_string(), self.id)
}
}
impl From<FilterAction> for AutocompleteChoice<String> {
fn from(m: FilterAction) -> Self {
match m {
FilterAction::Review => AutocompleteChoice {
name: "Flag the message for review and send it to a channel for moderators".to_string(),
value: "review".to_string()
},
FilterAction::Delete => AutocompleteChoice {
name: "Deletes the message and logs the deletion in a channel for moderators".to_string(),
value: "delete".to_string()
}
}
}
}