diff --git a/ia-main.go b/ia-main.go index 0e90477..a4f7d3a 100644 --- a/ia-main.go +++ b/ia-main.go @@ -56,7 +56,7 @@ func detectInstantAnswer(query string) *InstantAnswer { } // Try Wikipedia search - if title, text, link, ok := getWikipediaSummary(query); ok { + if title, text, link, ok := getWikipediaSummary(query, settings.SiteLanguage); ok { return &InstantAnswer{ Type: "wiki", Title: title, @@ -71,29 +71,17 @@ func detectInstantAnswer(query string) *InstantAnswer { } func initExchangeRates() { - // Initial synchronous load + // Initial sync if err := UpdateExchangeRates(); err != nil { printErr("Initial exchange rate update failed: %v", err) - } else { - PrecacheAllCurrencyPairs() } - // Pre-cache common wiki terms in background - go func() { - commonTerms := []string{"United States", "Europe", "Technology", "Science", "Mathematics"} - for _, term := range commonTerms { - getWikipediaSummary(term) - } - }() - - // Periodically update cache + // Periodic update only ticker := time.NewTicker(30 * time.Minute) go func() { for range ticker.C { if err := UpdateExchangeRates(); err != nil { printWarn("Periodic exchange rate update failed: %v", err) - } else { - PrecacheAllCurrencyPairs() } } }() diff --git a/ia-wiki.go b/ia-wiki.go index 3e9fe3c..707c06b 100644 --- a/ia-wiki.go +++ b/ia-wiki.go @@ -21,17 +21,18 @@ type WikipediaResponse struct { } // Get Wikipedia summary -func getWikipediaSummary(query string) (title, text, link string, ok bool) { - // Clean and prepare query +func getWikipediaSummary(query, lang string) (title, text, link string, ok bool) { + // Clean inputs query = strings.TrimSpace(query) - if query == "" { + lang = strings.ToLower(strings.TrimSpace(lang)) + if query == "" || lang == "" { return "", "", "", false } - // API request + // Construct Wikipedia API URL with lang apiURL := fmt.Sprintf( - "https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&exintro&explaintext&redirects=1&titles=%s", - url.QueryEscape(query), + "https://%s.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&exintro&explaintext&redirects=1&titles=%s", + lang, url.QueryEscape(query), ) resp, err := http.Get(apiURL)