aboutsummaryrefslogtreecommitdiff
path: root/src/models.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/models.rs')
-rw-r--r--src/models.rs73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/models.rs b/src/models.rs
index 09d5d7c..b8dd5b1 100644
--- a/src/models.rs
+++ b/src/models.rs
@@ -1,3 +1,9 @@
+use std::str::FromStr;
+
+use poise::AutocompleteChoice;
+
+use crate::errors::Error;
+
/**
* Describes a Reaction Role as it appears in SQL
*/
@@ -17,3 +23,70 @@ pub struct ReactionRole {
/// 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,
+}
+
+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())
+ }
+}
+
+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()
+ }
+ }
+ }
+}