fix legacy code #2

This commit is contained in:
2026-01-04 02:38:34 +05:30
parent f7859d7e0a
commit 1db2bc99e4
2 changed files with 26 additions and 13 deletions

View File

@@ -11,7 +11,7 @@ use chrono;
#[derive(Deserialize)]
pub struct IsBotThereRequest {
pub guild_ids: Vec<u64>,
pub guild_ids: Vec<String>,
}
#[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<bool> = 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::<u64>() {
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<u64>,
pub guild_ids: Vec<String>,
}
#[derive(Serialize)]

View File

@@ -108,10 +108,8 @@ export async function checkBetaServer(guildIds: string[]): Promise<boolean[]> {
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",