Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Replace moderation project queue with moderation action log (#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
triphora authored Sep 24, 2023
1 parent 3767e9f commit 51777c3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 98 deletions.
72 changes: 0 additions & 72 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::ratelimit::middleware::RateLimiter;
use crate::util::cors::default_cors;
use crate::util::env::{parse_strings_from_var, parse_var};
use actix_web::{web, App, HttpServer};
use chrono::{DateTime, Utc};
use deadpool_redis::{Config, Runtime};
use env_logger::Env;
use log::{error, info, warn};
Expand Down Expand Up @@ -181,77 +180,6 @@ async fn main() -> std::io::Result<()> {
}
});

// Reminding moderators to review projects which have been in the queue longer than 40hr
let pool_ref = pool.clone();
let redis_ref = redis_pool.clone();
let webhook_message_sent = Arc::new(Mutex::new(Vec::<(
database::models::ProjectId,
DateTime<Utc>,
)>::new()));

scheduler.run(std::time::Duration::from_secs(10 * 60), move || {
let pool_ref = pool_ref.clone();
let redis_ref = redis_ref.clone();
let webhook_message_sent_ref = webhook_message_sent.clone();
info!("Checking reviewed projects submitted more than 40hrs ago");

async move {
let do_steps = async {
use futures::TryStreamExt;

let project_ids = sqlx::query!(
"
SELECT id FROM mods
WHERE status = $1 AND queued < NOW() - INTERVAL '40 hours'
ORDER BY updated ASC
",
crate::models::projects::ProjectStatus::Processing.as_str(),
)
.fetch_many(&pool_ref)
.try_filter_map(|e| async {
Ok(e.right().map(|m| database::models::ProjectId(m.id)))
})
.try_collect::<Vec<database::models::ProjectId>>()
.await?;

let mut webhook_message_sent_ref = webhook_message_sent_ref.lock().await;

webhook_message_sent_ref.retain(|x| Utc::now() - x.1 < chrono::Duration::hours(12));

for project in project_ids {
if webhook_message_sent_ref.iter().any(|x| x.0 == project) { continue; }

if let Ok(webhook_url) =
dotenvy::var("MODERATION_DISCORD_WEBHOOK")
{
util::webhook::send_discord_webhook(
project.into(),
&pool_ref,
&redis_ref,
webhook_url,
Some("<@&783155186491195394> This project has been in the queue for over 40 hours!".to_string()),
)
.await
.ok();

webhook_message_sent_ref.push((project, Utc::now()));
}
}

Ok::<(), routes::ApiError>(())
};

if let Err(e) = do_steps.await {
warn!(
"Checking reviewed projects submitted more than 40hrs ago failed: {:?}",
e
);
}

info!("Finished checking reviewed projects submitted more than 40hrs ago");
}
});

scheduler::schedule_versions(&mut scheduler, pool.clone());

let download_queue = web::Data::new(DownloadQueue::new());
Expand Down
14 changes: 0 additions & 14 deletions src/routes/v2/project_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,20 +875,6 @@ async fn project_create_inner(
monetization_status: MonetizationStatus::Monetized,
};

if status == ProjectStatus::Processing {
if let Ok(webhook_url) = dotenvy::var("MODERATION_DISCORD_WEBHOOK") {
crate::util::webhook::send_discord_webhook(
response.id,
pool,
redis,
webhook_url,
None,
)
.await
.ok();
}
}

Ok(HttpResponse::Ok().json(response))
}
}
Expand Down
32 changes: 20 additions & 12 deletions src/routes/v2/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,18 +493,6 @@ pub async fn project_edit(
)
.execute(&mut *transaction)
.await?;

if let Ok(webhook_url) = dotenvy::var("MODERATION_DISCORD_WEBHOOK") {
crate::util::webhook::send_discord_webhook(
project_item.inner.id.into(),
&pool,
&redis,
webhook_url,
None,
)
.await
.ok();
}
}

if status.is_approved() && !project_item.inner.status.is_approved() {
Expand Down Expand Up @@ -545,6 +533,26 @@ pub async fn project_edit(
}
}

if user.role.is_mod() {
if let Ok(webhook_url) = dotenvy::var("MODERATION_DISCORD_WEBHOOK") {
crate::util::webhook::send_discord_webhook(
project_item.inner.id.into(),
&pool,
&redis,
webhook_url,
Some(
format!(
"**[{}]({}/user/{})** changed project status from **{}** to **{}**",
user.username, dotenvy::var("SITE_URL")?, user.username, &project_item.inner.status, status
)
.to_string(),
),
)
.await
.ok();
}
}

if team_member.map(|x| !x.accepted).unwrap_or(true) {
let notified_members = sqlx::query!(
"
Expand Down

0 comments on commit 51777c3

Please sign in to comment.