Skip to content

Commit c3ca180

Browse files
committed
move discord webhook into env
1 parent 891963c commit c3ca180

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

crates/api/src/api/challenges.rs

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -173,37 +173,39 @@ pub async fn submit(
173173
if !claims.ethereal() {
174174
update_chall_cache(&state.db, answer_info.id).await?;
175175
if answer_info.solves == 0 {
176-
// TODO(aiden): make this hookable instead of just vomitting this code here
177-
let client = reqwest::Client::new();
178-
179-
#[derive(Serialize)]
180-
struct WebhookData {
181-
content: String,
182-
embeds: Option<()>,
183-
attachments: Vec<()>,
176+
if let Some(u) = state.config.bloodbot_discord_webhook_url.as_ref() {
177+
// TODO(aiden): make this hookable instead of just vomitting this code here
178+
let client = reqwest::Client::new();
179+
180+
#[derive(Serialize)]
181+
struct WebhookData {
182+
content: String,
183+
embeds: Option<()>,
184+
attachments: Vec<()>,
185+
}
186+
let msg = format!(
187+
"Congrats to `{}` for first blooding `{}`!",
188+
sqlx::query!(
189+
"SELECT name FROM teams WHERE public_id = $1",
190+
claims.team_id
191+
)
192+
.fetch_one(&state.db)
193+
.await?
194+
.name,
195+
sqlx::query!(
196+
"SELECT public_id FROM challenges WHERE id = $1",
197+
answer_info.id
198+
)
199+
.fetch_one(&state.db)
200+
.await?
201+
.public_id
202+
);
203+
client.post(u).json(&WebhookData {
204+
content: msg,
205+
embeds: None,
206+
attachments: Vec::new(),
207+
}).send().await?;
184208
}
185-
let msg = format!(
186-
"Congrats to `{}` for first blooding `{}`!",
187-
sqlx::query!(
188-
"SELECT name FROM teams WHERE public_id = $1",
189-
claims.team_id
190-
)
191-
.fetch_one(&state.db)
192-
.await?
193-
.name,
194-
sqlx::query!(
195-
"SELECT public_id FROM challenges WHERE id = $1",
196-
answer_info.id
197-
)
198-
.fetch_one(&state.db)
199-
.await?
200-
.public_id
201-
);
202-
client.post("https://discord.com/api/webhooks/1129589162115338270/X5hz8w9ajwWOkgor7f_5FDnEyahortUyXyDuNw9ca42FfAgog4dVuADHjx276qPnP1CW").json(&WebhookData {
203-
content: msg,
204-
embeds: None,
205-
attachments: Vec::new(),
206-
}).send().await?;
207209
}
208210
}
209211
Ok(())

crates/api/src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ pub struct Config {
4646

4747
#[envconfig(from = "DEPLOYER_BASE", default = "http://deployer:3001")]
4848
pub deployer_base: String,
49+
50+
#[envconfig(from = "BLOODBOT_DISCORD_WEBHOOK_URL")]
51+
pub bloodbot_discord_webhook_url: Option<String>,
4952
}
5053

5154
pub struct StateInner {

0 commit comments

Comments
 (0)