Open 4th page to interpretation
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
2a6d0974cb
commit
a2cc6b3a8b
1 changed files with 35 additions and 3 deletions
|
@ -10,7 +10,8 @@ use tracing_subscriber::{EnvFilter, layer::SubscriberExt, util::SubscriberInitEx
|
|||
|
||||
mod error;
|
||||
|
||||
const WEBHOOK: &'static str = dotenv!("WEBHOOK");
|
||||
const SPECULATION_WEBHOOK: &'static str = dotenv!("SPECULATION_WEBHOOK");
|
||||
const IDEA_WEBHOOK: &'static str = dotenv!("IDEA_WEBHOOK");
|
||||
const LISTEN_ADDR: &'static str = dotenv!("LISTEN_ADDR");
|
||||
|
||||
#[tokio::main]
|
||||
|
@ -27,7 +28,9 @@ async fn main() -> eyre::Result<()> {
|
|||
.with(tracing_subscriber::fmt::layer())
|
||||
.init();
|
||||
|
||||
let app = Router::new().route("/api/speculate", post(speculate));
|
||||
let app = Router::new()
|
||||
.route("/api/speculate", post(speculate))
|
||||
.route("/api/page-idea", post(page_idea));
|
||||
|
||||
let listener = tokio::net::TcpListener::bind(LISTEN_ADDR)
|
||||
.await
|
||||
|
@ -47,7 +50,7 @@ struct Speculation {
|
|||
async fn speculate(Form(speculation): Form<Speculation>) -> Result<maud::Markup, error::Error> {
|
||||
let discord_http = Http::new("");
|
||||
|
||||
let webhook = Webhook::from_url(&discord_http, WEBHOOK)
|
||||
let webhook = Webhook::from_url(&discord_http, SPECULATION_WEBHOOK)
|
||||
.await
|
||||
.wrap_err("Failed to initialize webhook")
|
||||
.with_status_code(StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
|
@ -65,3 +68,32 @@ async fn speculate(Form(speculation): Form<Speculation>) -> Result<maud::Markup,
|
|||
p { "Speculation launched at high speed directly into our DMs" }
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct PageIdea {
|
||||
#[serde(rename = "page-idea")]
|
||||
page_idea: String,
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
async fn page_idea(Form(page_idea): Form<PageIdea>) -> Result<maud::Markup, error::Error> {
|
||||
let discord_http = Http::new("");
|
||||
|
||||
let webhook = Webhook::from_url(&discord_http, IDEA_WEBHOOK)
|
||||
.await
|
||||
.wrap_err("Failed to initialize webhook")
|
||||
.with_status_code(StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
|
||||
let builder = ExecuteWebhook::new()
|
||||
.content(page_idea.page_idea)
|
||||
.username("Anonymous ideator");
|
||||
webhook
|
||||
.execute(&discord_http, false, builder)
|
||||
.await
|
||||
.wrap_err("Could not execute webhook")
|
||||
.with_status_code(StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
|
||||
Ok(maud::html! {
|
||||
p { "Page idea launched at high speed directly into our DMs" }
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue