Add expire ban button to incidents command
This commit is contained in:
@@ -78,6 +78,60 @@ impl Button<State, Extras> for CounterButton {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ExpireIncidentButton {
|
||||
pub user_id: u64,
|
||||
pub incident_id: u64,
|
||||
pub incident_index: usize,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Button<State, Extras> for ExpireIncidentButton {
|
||||
fn id(&self) -> Option<String> {
|
||||
Some(format!("incidents:expire:{}", get_random_u64()))
|
||||
}
|
||||
|
||||
fn label(&self) -> Option<String> {
|
||||
Some("Expire Incident".into())
|
||||
}
|
||||
|
||||
fn style(&self) -> ButtonStyle {
|
||||
ButtonStyle::Danger
|
||||
}
|
||||
|
||||
fn disabled(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
async fn on_press(
|
||||
&self,
|
||||
ctx: InteractionContext<State, Extras>,
|
||||
) -> Result<(), InteractionError> {
|
||||
if !ctx.extras.user.is_moderator {
|
||||
ctx.defer().await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
UserIncident::expire_by_user_and_incident_id(
|
||||
self.user_id,
|
||||
self.incident_id,
|
||||
&ctx.rt.state.db,
|
||||
)
|
||||
.await?;
|
||||
|
||||
ctx.edit_original_message(
|
||||
get_incident_page(self.user_id, &ctx.rt.state.db, self.incident_index)
|
||||
.await
|
||||
.inspect_err(|e| log::error!("Failed to get incident page: {e:?}"))?
|
||||
.into(),
|
||||
)
|
||||
.await
|
||||
.inspect_err(|e| log::error!("Failed to edit original message: {e:?}"))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DeleteIncidentButton {
|
||||
pub user_id: u64,
|
||||
|
||||
@@ -48,7 +48,7 @@ pub fn incident_embed(incident: &UserIncident) -> Embed {
|
||||
incident
|
||||
.created_by_id
|
||||
.map(|id| format!("<@{id}>"))
|
||||
.unwrap_or("Automod".into()),
|
||||
.unwrap_or("Automatic Moderator".into()),
|
||||
));
|
||||
|
||||
if incident.r#type == UserIncidentType::Ban {
|
||||
@@ -81,7 +81,7 @@ pub fn incident_embed(incident: &UserIncident) -> Embed {
|
||||
incident
|
||||
.created_by_id
|
||||
.map(|id| format!("<@{id}>"))
|
||||
.unwrap_or("Automod".into()),
|
||||
.unwrap_or("Automatic Moderator".into()),
|
||||
));
|
||||
|
||||
if incident.r#type == UserIncidentType::Ban {
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
use scylla::client::session::Session;
|
||||
|
||||
use crate::{
|
||||
database::models::{DatabaseError, UserIncident},
|
||||
database::models::{DatabaseError, UserIncident, UserIncidentType},
|
||||
extras::Extras,
|
||||
framework::messages::MessageBuilder,
|
||||
groups::moderation::{
|
||||
components::{ArrowIncidentButton, CounterButton, DeleteIncidentButton},
|
||||
components::{
|
||||
ArrowIncidentButton, CounterButton, DeleteIncidentButton, ExpireIncidentButton,
|
||||
},
|
||||
embeds::incident_embed,
|
||||
},
|
||||
state::State,
|
||||
@@ -27,7 +29,7 @@ pub(super) async fn get_incident_page(
|
||||
incidents.sort_by(|a, b| b.created_at.cmp(&a.created_at));
|
||||
|
||||
if let Some(incident) = incidents.get(page_index) {
|
||||
Ok(MessageBuilder::new()
|
||||
let mut builder = MessageBuilder::new()
|
||||
.embed(incident_embed(incident))
|
||||
.component(
|
||||
ArrowIncidentButton {
|
||||
@@ -55,15 +57,29 @@ pub(super) async fn get_incident_page(
|
||||
go_to: incidents.get(page_index + 1).map(|_| page_index + 1),
|
||||
},
|
||||
1,
|
||||
)
|
||||
.component(
|
||||
DeleteIncidentButton {
|
||||
);
|
||||
|
||||
if incident.r#type == UserIncidentType::Ban {
|
||||
builder = builder.component(
|
||||
ExpireIncidentButton {
|
||||
incident_id: incident.incident_id,
|
||||
incident_index: page_index,
|
||||
user_id,
|
||||
},
|
||||
1,
|
||||
))
|
||||
2,
|
||||
);
|
||||
}
|
||||
|
||||
builder = builder.component(
|
||||
DeleteIncidentButton {
|
||||
incident_id: incident.incident_id,
|
||||
incident_index: page_index,
|
||||
user_id,
|
||||
},
|
||||
2,
|
||||
);
|
||||
|
||||
Ok(builder)
|
||||
} else {
|
||||
Ok(MessageBuilder::new().content("No incidents found for this user."))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user