Skip to content

Commit

Permalink
Report (and don't log) expired name requests
Browse files Browse the repository at this point in the history
  • Loading branch information
yungcomputerchair committed Jan 6, 2025
1 parent 9310407 commit 1f2485e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{env, sync::OnceLock, time::Duration};

use reqwest::Client;
use reqwest::{Client, StatusCode};
use serde::Serialize;

use crate::{Globals, NameRequest, Result};
Expand Down Expand Up @@ -46,7 +46,7 @@ pub(crate) async fn send_name_request_decision(
namereq: &NameRequest,
decision: &str,
by: &str,
) -> Result<()> {
) -> Result<bool> {
let endpoint = format!("https://{}/namereq", globals.ofapi_endpoint);
let req = NameRequestDecision {
player_uid: namereq.player_uid,
Expand All @@ -67,5 +67,7 @@ pub(crate) async fn send_name_request_decision(
if !status_code.is_success() {
return Err(format!("OFAPI error: {} {}", endpoint, status_code).into());
}
Ok(())

let updated = status_code != StatusCode::ALREADY_REPORTED;
Ok(updated)
}
21 changes: 19 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,31 @@ async fn handle_namereq_approve(
globals: &Globals,
interaction: &ComponentInteraction,
) -> Result<()> {
let http = &globals.context.http;

let msg = interaction.message.content.clone();
let user = interaction.member.as_ref().unwrap().distinct();

let namereq = NameRequest::parse_from_notification_message(&msg)?;
endpoint::send_name_request_decision(globals, &namereq, "approved", &user).await?;
let updated =
endpoint::send_name_request_decision(globals, &namereq, "approved", &user).await?;

// Try to delete the initial message
let _ = interaction.message.delete(&globals.context.http).await;
let _ = interaction.message.delete(http).await;

if !updated {
interaction
.create_response(
http,
CreateInteractionResponse::Message(
CreateInteractionResponseMessage::default()
.ephemeral(true)
.content("Request has already been processed"),
),
)
.await?;
return Ok(());
}

let Some(channel) = globals.log_channel else {
return Ok(());
Expand Down

0 comments on commit 1f2485e

Please sign in to comment.