1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
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()
}
}
}
}
|