2
0

fix config

This commit is contained in:
2026-03-22 18:57:03 +09:00
parent 45a7c1b9ae
commit 2c867eaf5c
5 changed files with 52 additions and 59 deletions

View File

@@ -233,11 +233,9 @@ fn save_state(state: &BotState) -> Result<()> {
Ok(())
}
/// Load admin DID from config.json
fn load_admin_did(config_path: &str) -> Result<String> {
let content = fs::read_to_string(config_path)
.with_context(|| format!("Config file not found: {}", config_path))?;
let config: Value = serde_json::from_str(&content)?;
/// Load admin DID from config.json ($cfg first, then fallback)
fn load_admin_did() -> Result<String> {
let config = token::load_config()?;
config["did"]
.as_str()
.map(|s| s.to_string())
@@ -342,8 +340,8 @@ async fn post_reply(
}
/// Main bot entry point
pub async fn start(interval_secs: u64, config_path: &str) -> Result<()> {
let admin_did = load_admin_did(config_path)?;
pub async fn start(interval_secs: u64) -> Result<()> {
let admin_did = load_admin_did()?;
eprintln!("bot: admin DID = {}", admin_did);
eprintln!("bot: polling interval = {}s", interval_secs);
@@ -564,10 +562,8 @@ fn save_chat_state(state: &ChatBotState) -> Result<()> {
}
/// Load chat proxy from config.json network field
fn load_chat_proxy(config_path: &str) -> Result<String> {
let content = fs::read_to_string(config_path)
.with_context(|| format!("Config file not found: {}", config_path))?;
let config: Value = serde_json::from_str(&content)?;
fn load_chat_proxy() -> Result<String> {
let config = token::load_config()?;
if let Some(network) = config["network"].as_str() {
Ok(format!("did:web:bsky.{}#bsky_chat", network))
} else {
@@ -578,9 +574,9 @@ fn load_chat_proxy(config_path: &str) -> Result<String> {
// Chat API uses XrpcClient with atproto-proxy header via query_auth_proxy / call_proxy
/// Main chat bot entry point
pub async fn start_chat(interval_secs: u64, config_path: &str) -> Result<()> {
let admin_did = load_admin_did(config_path)?;
let proxy_did = load_chat_proxy(config_path)?;
pub async fn start_chat(interval_secs: u64) -> Result<()> {
let admin_did = load_admin_did()?;
let proxy_did = load_chat_proxy()?;
eprintln!("chat-bot: admin DID = {}", admin_did);
eprintln!("chat-bot: proxy = {}", proxy_did);
eprintln!("chat-bot: polling interval = {}s", interval_secs);