Skip to content

Commit 5c19d59

Browse files
committed
fix(commands): limit forum repairs to 10 per invocation to avoid rate limits
1 parent 2b1df6a commit 5c19d59

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/discord/commands.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,17 @@ pub async fn do_repair(state: &AppState, guild_id: &Option<String>) -> Result<St
600600
};
601601
let project_list = projects::list_projects_by_guild(&state.db, guild_id_str).await?;
602602

603+
const MAX_FORUM_REPAIRS: usize = 10; // Prevent excessive API calls
604+
605+
let mut forum_repair_count = 0;
603606
for project in project_list.iter().filter(|p| p.is_approved) {
607+
if forum_repair_count >= MAX_FORUM_REPAIRS {
608+
repairs.push(format!(
609+
"⚠️ Stopped after {} forum repairs to avoid rate limits. Run /repair again.",
610+
MAX_FORUM_REPAIRS
611+
));
612+
break;
613+
}
604614
if !channel_exists(&channels, &project.forum_channel_id) {
605615
if let Some(cat_id) = github_cat {
606616
let name = project
@@ -619,6 +629,7 @@ pub async fn do_repair(state: &AppState, guild_id: &Option<String>) -> Result<St
619629
)
620630
.await?;
621631
repairs.push(format!("✅ Recreated forum for `{}`", project.github_repo));
632+
forum_repair_count += 1;
622633
}
623634
}
624635
}

0 commit comments

Comments
 (0)