Add expire ban button to incidents command

This commit is contained in:
2025-08-23 02:11:23 -03:00
parent 9b70714fe3
commit 679096a685
9 changed files with 138 additions and 15 deletions
+54
View File
@@ -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,