From 1db2bc99e4d3352030fdb891631b0af4cc28ce8c Mon Sep 17 00:00:00 2001 From: Kishor Date: Sun, 4 Jan 2026 02:38:34 +0530 Subject: [PATCH] fix legacy code #2 --- src/api.rs | 33 ++++++++++++++++++++++++--------- web/lib/discord.ts | 6 ++---- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/api.rs b/src/api.rs index 9523bbd..6d3ee24 100644 --- a/src/api.rs +++ b/src/api.rs @@ -11,7 +11,7 @@ use chrono; #[derive(Deserialize)] pub struct IsBotThereRequest { - pub guild_ids: Vec, + pub guild_ids: Vec, } #[derive(Serialize)] @@ -45,7 +45,7 @@ pub struct Role { #[derive(Serialize, Clone, Debug)] pub struct TrackLevelRole { - pub role_id: u64, + pub role_id: String, pub level: u64, } @@ -68,7 +68,7 @@ impl<'de> Deserialize<'de> for TrackLevelRole { E: serde::de::Error, { Ok(TrackLevelRole { - role_id: value, + role_id: value.to_string(), level: 0, // Default level for legacy data }) } @@ -78,7 +78,7 @@ impl<'de> Deserialize<'de> for TrackLevelRole { E: serde::de::Error, { Ok(TrackLevelRole { - role_id: value as u64, + role_id: value.to_string(), // Convert to string level: 0, }) } @@ -96,7 +96,14 @@ impl<'de> Deserialize<'de> for TrackLevelRole { if role_id.is_some() { return Err(serde::de::Error::duplicate_field("role_id")); } - role_id = Some(map.next_value()?); + let v: serde_json::Value = map.next_value()?; + if let Some(s) = v.as_str() { + role_id = Some(s.to_string()); + } else if let Some(n) = v.as_u64() { + role_id = Some(n.to_string()); + } else { + return Err(serde::de::Error::custom("role_id must be string or number")); + } } "level" => { if level.is_some() { @@ -228,9 +235,17 @@ async fn is_bot_there( let results: Vec = request_body .guild_ids .iter() - .map(|guild_id| { - let guild_exists = data.cache.guild(*guild_id).is_some(); - guild_exists + .map(|guild_id_str| { + if let Ok(guild_id) = guild_id_str.parse::() { + let exists = data.cache.guild(guild_id).is_some(); + if !exists { + info!("Bot cache miss for guild {}", guild_id); + } + exists + } else { + warn!("Invalid guild ID string: {}", guild_id_str); + false + } }) .collect(); @@ -853,7 +868,7 @@ async fn delete_beta_server( #[derive(Deserialize)] pub struct IsBetaServerRequest { - pub guild_ids: Vec, + pub guild_ids: Vec, } #[derive(Serialize)] diff --git a/web/lib/discord.ts b/web/lib/discord.ts index 7b73b2f..96df24e 100644 --- a/web/lib/discord.ts +++ b/web/lib/discord.ts @@ -108,10 +108,8 @@ export async function checkBetaServer(guildIds: string[]): Promise { if (safeGuildIds.length === 0) return guildIds.map(() => false); - // Manually construct JSON to preserve u64 precision (native JS numbers lose precision > 2^53) - // We want: { "guild_ids": [123, 456] } - // checkBotMembership also does this manual construction for the same reason. - const body = `{"guild_ids": [${safeGuildIds.join(",")}]}`; + // Use JSON.stringify which matches the backend expectation of strings + const body = JSON.stringify({ guild_ids: guildIds }); const response = await fetch(`${process.env.BOT_API_URL}/api/is_beta_server`, { method: "POST",