fix: log full bot tokens + write to data_dir/bot-tokens.txt

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Siavash Sameni
2026-03-29 15:05:11 +04:00
parent 1e47b888c8
commit 3489a7cf74
2 changed files with 27 additions and 7 deletions

10
warzone/Cargo.lock generated
View File

@@ -2956,7 +2956,7 @@ dependencies = [
[[package]] [[package]]
name = "warzone-client" name = "warzone-client"
version = "0.0.32" version = "0.0.33"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"argon2", "argon2",
@@ -2989,7 +2989,7 @@ dependencies = [
[[package]] [[package]]
name = "warzone-mule" name = "warzone-mule"
version = "0.0.32" version = "0.0.33"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",
@@ -2998,7 +2998,7 @@ dependencies = [
[[package]] [[package]]
name = "warzone-protocol" name = "warzone-protocol"
version = "0.0.32" version = "0.0.33"
dependencies = [ dependencies = [
"base64", "base64",
"bincode", "bincode",
@@ -3023,7 +3023,7 @@ dependencies = [
[[package]] [[package]]
name = "warzone-server" name = "warzone-server"
version = "0.0.32" version = "0.0.33"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"axum", "axum",
@@ -3053,7 +3053,7 @@ dependencies = [
[[package]] [[package]]
name = "warzone-wasm" name = "warzone-wasm"
version = "0.0.32" version = "0.0.33"
dependencies = [ dependencies = [
"base64", "base64",
"bincode", "bincode",

View File

@@ -82,7 +82,7 @@ async fn main() -> anyhow::Result<()> {
// Register alias // Register alias
let _ = state.db.aliases.insert(b"a:botfather", botfather_fp.as_bytes()); let _ = state.db.aliases.insert(b"a:botfather", botfather_fp.as_bytes());
let _ = state.db.aliases.insert(format!("fp:{}", botfather_fp).as_bytes(), b"botfather"); let _ = state.db.aliases.insert(format!("fp:{}", botfather_fp).as_bytes(), b"botfather");
tracing::info!("BotFather created: @botfather (token: {}...)", &token[..20]); tracing::info!("BotFather created: @botfather (token: {})", token);
} else { } else {
tracing::info!("BotFather already exists"); tracing::info!("BotFather already exists");
} }
@@ -141,7 +141,7 @@ async fn main() -> anyhow::Result<()> {
let _ = state.db.tokens.insert(format!("bot_fp:{}", fp).as_bytes(), token.as_bytes()); let _ = state.db.tokens.insert(format!("bot_fp:{}", fp).as_bytes(), token.as_bytes());
let _ = state.db.aliases.insert(alias_key.as_bytes(), fp.as_bytes()); let _ = state.db.aliases.insert(alias_key.as_bytes(), fp.as_bytes());
let _ = state.db.aliases.insert(format!("fp:{}", fp).as_bytes(), alias.as_bytes()); let _ = state.db.aliases.insert(format!("fp:{}", fp).as_bytes(), alias.as_bytes());
tracing::info!("System bot @{} created (token: {}...)", alias, &token[..20]); tracing::info!("System bot @{} created (token: {})", alias, token);
fp fp
}; };
@@ -157,6 +157,26 @@ async fn main() -> anyhow::Result<()> {
} }
tracing::info!("Loaded {} system bots from {}", bots.len(), bots_path); tracing::info!("Loaded {} system bots from {}", bots.len(), bots_path);
// Write tokens to file for easy access
let tokens_path = format!("{}/bot-tokens.txt", cli.data_dir);
let mut token_lines = Vec::new();
for bot in &bots {
let name = bot.get("name").and_then(|v| v.as_str()).unwrap_or("");
if name.is_empty() { continue; }
let alias = name.to_lowercase();
if let Some(fp_bytes) = state.db.aliases.get(format!("a:{}", alias).as_bytes()).ok().flatten() {
let fp = String::from_utf8_lossy(&fp_bytes).to_string();
if let Some(tok_bytes) = state.db.tokens.get(format!("bot_fp:{}", fp).as_bytes()).ok().flatten() {
let tok = String::from_utf8_lossy(&tok_bytes).to_string();
token_lines.push(format!("{}={}", alias.to_uppercase(), tok));
}
}
}
if !token_lines.is_empty() {
let _ = std::fs::write(&tokens_path, token_lines.join("\n") + "\n");
tracing::info!("Bot tokens written to {}", tokens_path);
}
// Store bot list in DB for welcome screen // Store bot list in DB for welcome screen
let bot_list: Vec<serde_json::Value> = bots.iter().map(|b| { let bot_list: Vec<serde_json::Value> = bots.iter().map(|b| {
serde_json::json!({ serde_json::json!({