Add basic moderator commands
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
use time::UtcDateTime;
|
||||
use twilight_model::channel::message::Embed;
|
||||
use twilight_util::builder::embed::{
|
||||
EmbedAuthorBuilder, EmbedBuilder, EmbedFieldBuilder, ImageSource,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
constants::{COLOR_RED, COLOR_YELLOW},
|
||||
database::models::{UserIncident, UserIncidentType},
|
||||
utils::ellipse,
|
||||
};
|
||||
|
||||
fn format_timestamp(timestamp: UtcDateTime) -> String {
|
||||
format!(
|
||||
"<t:{}> (<t:{}:R>)",
|
||||
timestamp.unix_timestamp(),
|
||||
timestamp.unix_timestamp()
|
||||
)
|
||||
}
|
||||
|
||||
pub fn incident_embed(incident: &UserIncident) -> Embed {
|
||||
if let Some(message) = &incident.message {
|
||||
let mut builder = EmbedBuilder::new()
|
||||
.color(match incident.r#type {
|
||||
UserIncidentType::Ban => COLOR_RED,
|
||||
UserIncidentType::Warning => COLOR_YELLOW,
|
||||
})
|
||||
.author(
|
||||
EmbedAuthorBuilder::new(&message.author_name)
|
||||
.icon_url(ImageSource::url(&message.author_avatar_url).unwrap()),
|
||||
)
|
||||
.title("Message Incident")
|
||||
.thumbnail(ImageSource::url(message.author_avatar_url.clone()).unwrap())
|
||||
.field(EmbedFieldBuilder::new("Message", ellipse(message.content.clone(), 100)).build())
|
||||
.field(EmbedFieldBuilder::new("Author Name", message.author_name.clone()).build())
|
||||
.field(
|
||||
EmbedFieldBuilder::new(
|
||||
"Author Avatar",
|
||||
format!("[Click to open avatar](<{}>)", &message.author_avatar_url),
|
||||
)
|
||||
.build(),
|
||||
)
|
||||
.field(
|
||||
EmbedFieldBuilder::new("Created At", format_timestamp(incident.created_at)).build(),
|
||||
)
|
||||
.field(EmbedFieldBuilder::new(
|
||||
"Created By",
|
||||
incident
|
||||
.created_by_id
|
||||
.map(|id| format!("<@{id}>"))
|
||||
.unwrap_or("Automod".into()),
|
||||
));
|
||||
|
||||
if incident.r#type == UserIncidentType::Ban {
|
||||
builder = builder.field(
|
||||
EmbedFieldBuilder::new(
|
||||
"Expires At",
|
||||
incident
|
||||
.expires_at
|
||||
.map(format_timestamp)
|
||||
.unwrap_or("*Never*".into()),
|
||||
)
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
builder.build()
|
||||
} else {
|
||||
let mut builder = EmbedBuilder::new()
|
||||
.color(match incident.r#type {
|
||||
UserIncidentType::Ban => COLOR_RED,
|
||||
UserIncidentType::Warning => COLOR_YELLOW,
|
||||
})
|
||||
.title("Manual Incident")
|
||||
.field(EmbedFieldBuilder::new("Reason", incident.reason.clone()))
|
||||
.field(
|
||||
EmbedFieldBuilder::new("Created At", format_timestamp(incident.created_at)).build(),
|
||||
)
|
||||
.field(EmbedFieldBuilder::new(
|
||||
"Created By",
|
||||
incident
|
||||
.created_by_id
|
||||
.map(|id| format!("<@{id}>"))
|
||||
.unwrap_or("Automod".into()),
|
||||
));
|
||||
|
||||
if incident.r#type == UserIncidentType::Ban {
|
||||
builder = builder.field(
|
||||
EmbedFieldBuilder::new(
|
||||
"Expires At",
|
||||
incident
|
||||
.expires_at
|
||||
.map(format_timestamp)
|
||||
.unwrap_or("*Never*".into()),
|
||||
)
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
builder.build()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user