use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct HttpIdentity {
pub intents: u32,
pub shards: [u32; 2],
pub callback_url: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct HttpBot {
pub id: String,
pub username: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct HttpReady {
pub version: i32,
pub session_id: String,
pub bot: HttpBot,
pub shard: [u32; 2],
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct HttpSession {
pub app_id: i64,
pub session_id: String,
pub callback_url: String,
pub env: String,
pub intents: i64,
pub last_heartbeat_time: String,
pub state: String,
pub shards: [i64; 2],
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct WebhookValidationRequest {
pub plain_token: String,
pub event_ts: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct WebhookValidationResponse {
pub plain_token: String,
pub signature: String,
pub data_version: String,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn http_identity_keeps_official_json_shape() {
let identity = HttpIdentity {
intents: 1 << 25,
shards: [0, 2],
callback_url: "https://example.com/callback".to_string(),
};
let value = serde_json::to_value(&identity).unwrap();
assert_eq!(value["intents"], 1 << 25);
assert_eq!(value["shards"], serde_json::json!([0, 2]));
assert_eq!(value["callback_url"], "https://example.com/callback");
}
#[test]
fn http_ready_bot_uses_embedded_shape() {
let ready: HttpReady = serde_json::from_value(serde_json::json!({
"version": 1,
"session_id": "session-1",
"bot": {
"id": "bot-1",
"username": "bot"
},
"shard": [0, 1]
}))
.unwrap();
assert_eq!(ready.version, 1);
assert_eq!(ready.session_id, "session-1");
assert_eq!(ready.bot.id, "bot-1");
assert_eq!(ready.bot.username, "bot");
assert_eq!(ready.shard, [0, 1]);
let value = serde_json::to_value(&ready).unwrap();
assert_eq!(value["bot"]["id"], "bot-1");
assert_eq!(value["bot"]["username"], "bot");
assert!(value["bot"].get("avatar").is_none());
assert!(value["bot"].get("bot").is_none());
}
}