Skip to content

Commit 5509e84

Browse files
committed
add empty checks
1 parent cad7e3e commit 5509e84

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

src/endpoints/mod_versions.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,11 @@ pub async fn create_version(
326326

327327
if !dev.verified || accepted_count == 0 {
328328
tokio::spawn(async move {
329+
if data.guild_id == 0 || data.channel_id == 0 || data.bot_token.is_empty() {
330+
log::error!("Discord configuration is not set up. Not creating forum threads.");
331+
return;
332+
}
333+
329334
let m = fetched_mod.unwrap();
330335
let v_res = ModVersion::get_one(&path.id, &json.version, true, false, &mut pool).await;
331336
if v_res.is_err() {
@@ -432,6 +437,11 @@ pub async fn update_version(
432437

433438
if payload.status == ModVersionStatusEnum::Accepted || payload.status == ModVersionStatusEnum::Rejected {
434439
tokio::spawn(async move {
440+
if data.guild_id == 0 || data.channel_id == 0 || data.bot_token.is_empty() {
441+
log::error!("Discord configuration is not set up. Not creating forum threads.");
442+
return;
443+
}
444+
435445
let m_res = Mod::get_one(&path.id, false, &mut pool).await.ok().flatten();
436446
if m_res.is_none() {
437447
return;

src/endpoints/mods.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ pub async fn create(
136136
.or(Err(ApiError::TransactionError))?;
137137

138138
tokio::spawn(async move {
139+
if data.guild_id == 0 || data.channel_id == 0 || data.bot_token.is_empty() {
140+
log::error!("Discord configuration is not set up. Not creating forum threads.");
141+
return;
142+
}
143+
139144
let m_res = Mod::get_one(&json.id, false, &mut pool).await.ok().flatten();
140145
if m_res.is_none() {
141146
return;

src/forum.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ pub async fn create_or_update_thread(
218218
admin: Option<FetchedDeveloper>,
219219
base_url: String
220220
) {
221+
if guild_id == 0 || channel_id == 0 || token.is_empty() {
222+
log::error!("Discord configuration is not set up. Not creating forum threads.");
223+
return;
224+
}
225+
221226
let thread_vec = if threads.is_some() {
222227
threads.unwrap()
223228
} else {

src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ async fn main() -> anyhow::Result<()> {
150150
.bind((addr, port))?;
151151

152152
tokio::spawn(async move {
153+
if guild_id == 0 || channel_id == 0 || bot_token.is_empty() {
154+
log::error!("Discord configuration is not set up. Not creating forum threads.");
155+
return;
156+
}
157+
153158
log::info!("Starting forum thread creation job");
154159
let pool_res = pool.clone().acquire().await;
155160
if pool_res.is_err() {

0 commit comments

Comments
 (0)