mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
move wolframalpha code to internal/commands
This commit is contained in:
parent
64fb0255f1
commit
15956b235b
|
@ -200,14 +200,16 @@ func (app *application) handleCommand(message twitch.PrivateMessage) {
|
|||
case "location":
|
||||
app.SetUserLocation(message)
|
||||
}
|
||||
case "wa":
|
||||
reply = app.WolframAlphaQuery(message.Message[5:len(message.Message)])
|
||||
|
||||
// --------------------------------
|
||||
// 100 user level
|
||||
// trusted
|
||||
// vip
|
||||
// --------------------------------
|
||||
case "wa":
|
||||
if userLevel >= 100 {
|
||||
reply = commands.WolframAlphaQuery(message.Message[5:len(message.Message)], app.Config.wolframAlphaAppID)
|
||||
}
|
||||
case "debug":
|
||||
switch cmdParams[1] {
|
||||
case "user":
|
||||
|
|
29
internal/commands/wolframalpha.go
Normal file
29
internal/commands/wolframalpha.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
}
|
Loading…
Reference in a new issue