2023-12-17 17:23:42 +01:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
2024-02-28 11:53:39 +01:00
|
|
|
// WolframAlphaQuery queries the WolframAlpha api with the supplied query and replies
|
|
|
|
// with the result.
|
2023-12-17 17:23:42 +01:00
|
|
|
func WolframAlphaQuery(query, appid string) string {
|
|
|
|
escaped := url.QueryEscape(query)
|
|
|
|
url := fmt.Sprintf("http://api.wolframalpha.com/v1/result?appid=%s&i=%s", appid, escaped)
|
|
|
|
|
|
|
|
resp, err := http.Get(url)
|
|
|
|
if err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
body, err := io.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
reply := string(body)
|
|
|
|
return reply
|
|
|
|
|
|
|
|
}
|