Skip to content

Commit

Permalink
New feedback Discord notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Celeo committed Oct 22, 2024
1 parent 3931d5a commit 3de14ae
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
47 changes: 41 additions & 6 deletions vzdv-site/src/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ use axum::{
routing::{get, post},
Form, Router,
};
use log::info;
use log::{error, info};
use minijinja::{context, Environment};
use serde::Deserialize;
use serde_json::json;
use std::sync::Arc;
use tower_http::services::ServeDir;
use tower_sessions::Session;
use vzdv::sql::{self, Controller};
use vzdv::{
sql::{self, Controller},
GENERAL_HTTP_CLIENT,
};

pub mod admin;
pub mod airspace;
Expand Down Expand Up @@ -88,16 +92,47 @@ async fn page_feedback_form_post(
.bind(user_info.cid)
.execute(&state.db)
.await?;
info!(
"{} submitted feedback for {}",
user_info.cid, feedback.controller
);
flashed_messages::push_flashed_message(
session,
flashed_messages::MessageLevel::Success,
"Feedback submitted, thank you!",
)
.await?;
info!(
"{} submitted feedback for {}",
user_info.cid, feedback.controller
);
let notification_webhook = state.config.discord.webhooks.new_feedback.clone();
let for_controller: Controller = sqlx::query_as(sql::GET_CONTROLLER_BY_CID)
.bind(feedback.controller)
.fetch_one(&state.db)
.await?;
let message = format!(
"New {} feedback posted for {} {} ({}) on **{}** by {}:\n\t{}",
feedback.rating,
for_controller.first_name,
for_controller.last_name,
for_controller
.operating_initials
.unwrap_or_else(|| String::from("??")),
feedback.position,
user_info.cid,
if feedback.comments.len() >= 100 {
format!("{} ...", &feedback.comments[0..100])
} else {
feedback.comments
}
);
tokio::spawn(async move {
let res = GENERAL_HTTP_CLIENT
.post(&notification_webhook)
.json(&json!({ "content": message }))
.send()
.await;
if let Err(e) = res {
error!("Could not send info to new feedback webhook: {e}");
}
});
} else {
flashed_messages::push_flashed_message(
session,
Expand Down
1 change: 1 addition & 0 deletions vzdv-site/templates/changelog.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<li>Audit reporting for some events to another Discord webhook.</li>
<li>Approved feedback from the ADH site imported here.</li>
<li>Controllers can see their own feedback on their controller page.</li>
<li>Sr Staff notifications of new controller feedback.</li>
</ul>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions vzdv.empty.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ redirect_uri = ""

[discord.webhooks]
staffing_request = ""
new_feedback = ""
feedback = ""
new_visitor_app = ""
errors = ""
Expand Down
1 change: 1 addition & 0 deletions vzdv.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ redirect_uri = ""

[discord.webhooks]
staffing_request = ""
new_feedback = ""
feedback = ""
new_visitor_app = ""
errors = ""
Expand Down
1 change: 1 addition & 0 deletions vzdv/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub struct ConfigDiscordAuth {
#[derive(Debug, Clone, Deserialize, Default)]
pub struct ConfigDiscordWebhooks {
pub staffing_request: String,
pub new_feedback: String,
pub feedback: String,
pub new_visitor_app: String,
pub errors: String,
Expand Down

0 comments on commit 3de14ae

Please sign in to comment.