Skip to content

Commit

Permalink
Slack webhooks (#959)
Browse files Browse the repository at this point in the history
* Slack webhooks

* Fix automod rejecting audio and locale packs

* Run prepare
  • Loading branch information
Geometrically authored Sep 7, 2024
1 parent 2e35f36 commit cb0f03c
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 283 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ REDIS_MAX_CONNECTIONS=10000
BIND_ADDR=127.0.0.1:8000
SELF_ADDR=http://127.0.0.1:8000

MODERATION_DISCORD_WEBHOOK=
MODERATION_SLACK_WEBHOOK=
PUBLIC_DISCORD_WEBHOOK=
CLOUDFLARE_INTEGRATION=false

Expand Down

This file was deleted.

12 changes: 8 additions & 4 deletions src/queue/moderation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,11 @@ impl AutomatedModerationQueue {
mod_messages.messages.push(ModerationMessage::MissingCustomLicenseUrl { license: project.inner.license.clone() });
}

if (project.project_types.contains(&"resourcepack".to_string()) || project.project_types.contains(&"shader".to_string())) && project.gallery_items.is_empty() {
if (project.project_types.contains(&"resourcepack".to_string()) || project.project_types.contains(&"shader".to_string())) &&
project.gallery_items.is_empty() &&
!project.categories.contains(&"audio".to_string()) &&
!project.categories.contains(&"locale".to_string())
{
mod_messages.messages.push(ModerationMessage::MissingGalleryImage);
}

Expand Down Expand Up @@ -660,15 +664,15 @@ impl AutomatedModerationQueue {
.insert_many(members.into_iter().map(|x| x.user_id).collect(), &mut transaction, &redis)
.await?;

if let Ok(webhook_url) = dotenvy::var("MODERATION_DISCORD_WEBHOOK") {
crate::util::webhook::send_discord_webhook(
if let Ok(webhook_url) = dotenvy::var("MODERATION_SLACK_WEBHOOK") {
crate::util::webhook::send_slack_webhook(
project.inner.id.into(),
&pool,
&redis,
webhook_url,
Some(
format!(
"**[AutoMod]({}/user/AutoMod)** changed project status from **{}** to **Rejected**",
"*<{}/user/AutoMod|AutoMod>* changed project status from *{}* to *Rejected*",
dotenvy::var("SITE_URL")?,
&project.inner.status.as_friendly_str(),
)
Expand Down
1 change: 1 addition & 0 deletions src/routes/v3/oauth_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ pub struct OAuthClientEdit {
)]
pub name: Option<String>,

#[validate(custom(function = "crate::util::validate::validate_no_restricted_scopes"))]
pub max_scopes: Option<Scopes>,

#[validate(length(min = 1))]
Expand Down
8 changes: 4 additions & 4 deletions src/routes/v3/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,18 +398,18 @@ 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(
if let Ok(webhook_url) = dotenvy::var("MODERATION_SLACK_WEBHOOK") {
crate::util::webhook::send_slack_webhook(
project_item.inner.id.into(),
&pool,
&redis,
webhook_url,
Some(
format!(
"**[{}]({}/user/{})** changed project status from **{}** to **{}**",
user.username,
"*<{}/user/{}|{}>* changed project status from *{}* to *{}*",
dotenvy::var("SITE_URL")?,
user.username,
user.username,
&project_item.inner.status.as_friendly_str(),
status.as_friendly_str(),
)
Expand Down
Loading

0 comments on commit cb0f03c

Please sign in to comment.