add options to choose if quote should be sent via discord webhook
This commit is contained in:
@@ -53,6 +53,8 @@ pub struct QuoteCreateForm {
|
|||||||
pub context: Option<String>,
|
pub context: Option<String>,
|
||||||
pub location: Option<String>,
|
pub location: Option<String>,
|
||||||
pub public: bool,
|
pub public: bool,
|
||||||
|
#[serde(default)]
|
||||||
|
pub discord_webhook: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
@@ -85,5 +87,12 @@ pub async fn create(
|
|||||||
|
|
||||||
LogEntry::new(&mut tx, u, LogAction::CreateQuote { id: q.id }).await?;
|
LogEntry::new(&mut tx, u, LogAction::CreateQuote { id: q.id }).await?;
|
||||||
tx.commit().await?;
|
tx.commit().await?;
|
||||||
|
|
||||||
|
if form.discord_webhook {
|
||||||
|
if let Some(ref url) = state.conf.read().await.discord_webhook {
|
||||||
|
q.post_msg_webhook(url.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok((StatusCode::CREATED, Json(q)).into_response())
|
Ok((StatusCode::CREATED, Json(q)).into_response())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ pub async fn page(
|
|||||||
None => return Ok(Redirect::to(&format!("/login?r={}", req.uri().path())).into_response()),
|
None => return Ok(Redirect::to(&format!("/login?r={}", req.uri().path())).into_response()),
|
||||||
};
|
};
|
||||||
let names = Name::get_all(&mut *conn).await?;
|
let names = Name::get_all(&mut *conn).await?;
|
||||||
|
let feature_webhooks = state.conf.read().await.discord_webhook.is_some();
|
||||||
|
|
||||||
Ok(base(
|
Ok(base(
|
||||||
"Add Quote | Mnemosyne",
|
"Add Quote | Mnemosyne",
|
||||||
@@ -91,6 +92,15 @@ pub async fn page(
|
|||||||
class="px-2 py-1 w-full mb-2 bg-neutral-950/50 rounded border border-neutral-200/25";
|
class="px-2 py-1 w-full mb-2 bg-neutral-950/50 rounded border border-neutral-200/25";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@if feature_webhooks {
|
||||||
|
div class="flex flex-col justify-center mt-5" {
|
||||||
|
label class="flex items-center gap-2 cursor-pointer" {
|
||||||
|
input type="checkbox" name="discord_webhook" value="true" checked
|
||||||
|
class="w-4 h-4 cursor-pointer";
|
||||||
|
span {"Send to Discord"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
button type="submit" class="border mt-auto mb-2 cursor-pointer rounded h-fit px-2 py-1 bg-neutral-200/5 border-neutral-200/25 hover:border-neutral-200/45 hover:bg-neutral-200/15" {
|
button type="submit" class="border mt-auto mb-2 cursor-pointer rounded h-fit px-2 py-1 bg-neutral-200/5 border-neutral-200/25 hover:border-neutral-200/45 hover:bg-neutral-200/15" {
|
||||||
"Submit"
|
"Submit"
|
||||||
}
|
}
|
||||||
@@ -140,6 +150,7 @@ pub struct IncomingQuote {
|
|||||||
location: String,
|
location: String,
|
||||||
time: String,
|
time: String,
|
||||||
context: String,
|
context: String,
|
||||||
|
discord_webhook: Option<String>,
|
||||||
}
|
}
|
||||||
pub async fn form(
|
pub async fn form(
|
||||||
State(state): State<MnemoState>,
|
State(state): State<MnemoState>,
|
||||||
@@ -178,8 +189,11 @@ pub async fn form(
|
|||||||
LogEntry::new(&mut *tx, u, LogAction::CreateQuote { id: q.id }).await?;
|
LogEntry::new(&mut *tx, u, LogAction::CreateQuote { id: q.id }).await?;
|
||||||
tx.commit().await?;
|
tx.commit().await?;
|
||||||
|
|
||||||
if let Some(ref url) = state.conf.read().await.discord_webhook {
|
let should_send_webhook = form.discord_webhook.as_deref() == Some("true");
|
||||||
q.post_msg_webhook(url.clone());
|
if should_send_webhook {
|
||||||
|
if let Some(ref url) = state.conf.read().await.discord_webhook {
|
||||||
|
q.post_msg_webhook(url.clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Redirect::to("/dashboard").into_response())
|
Ok(Redirect::to("/dashboard").into_response())
|
||||||
|
|||||||
Reference in New Issue
Block a user