mirror of https://github.com/fluffle/goirc
Fix error reporting in cmd-google.go:calc
This commit is contained in:
parent
7dc6308895
commit
56309794bd
|
@ -130,19 +130,41 @@ func calc(conn *irc.Conn, nick *irc.Nick, args, target string) {
|
||||||
|
|
||||||
re := regexp.MustCompile(`{lhs: "(.*)",rhs: "(.*)",error: "(.*)",icc: (true|false)}`)
|
re := regexp.MustCompile(`{lhs: "(.*)",rhs: "(.*)",error: "(.*)",icc: (true|false)}`)
|
||||||
result := re.FindSubmatch(b)
|
result := re.FindSubmatch(b)
|
||||||
if len(result) != 5 || len(result[3]) > 1 {
|
if len(result) != 5 {
|
||||||
say(conn, target, "%s: Error while calculating.", nick.Nick); return
|
say(conn, target, "%s: Error while parsing.", nick.Nick)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(result[3]) > 1 {
|
||||||
|
output := fmt.Sprintf(`"%s"`, result[3])
|
||||||
|
error := parseCalc(output)
|
||||||
|
if error != "" {
|
||||||
|
say(conn, target, "%s: Error: %s", nick.Nick, error)
|
||||||
|
} else {
|
||||||
|
say(conn, target, "%s: Error while calculating and error while decoding error.", nick.Nick)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(result[1]) == 0 || len(result[2]) == 0 {
|
||||||
|
say(conn, target, "%s: Error while calculating.", nick.Nick)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
output := fmt.Sprintf(`"%s = %s"`, result[1], result[2])
|
output := fmt.Sprintf(`"%s = %s"`, result[1], result[2])
|
||||||
output, err = strconv.Unquote(output)
|
output = parseCalc(output)
|
||||||
if err != nil {
|
if output == "" {
|
||||||
say(conn, target, "%s: Error while decoding.", nick.Nick); return
|
say(conn, target, "%s: Error while decoding.", nick.Nick); return
|
||||||
}
|
}
|
||||||
output = html.UnescapeString(output) // see go issue 1233
|
|
||||||
say(conn, target, output)
|
say(conn, target, output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseCalc(output string) string {
|
||||||
|
unquote, err := strconv.Unquote(output)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return html.UnescapeString(unquote)
|
||||||
|
}
|
||||||
|
|
||||||
// please disregard the reproduction of src/pkg/http/client.go:send below
|
// please disregard the reproduction of src/pkg/http/client.go:send below
|
||||||
// it's definitely not to send a User-Agent for undocumented Google APIs
|
// it's definitely not to send a User-Agent for undocumented Google APIs
|
||||||
func send(url string) ([]byte, os.Error) {
|
func send(url string) ([]byte, os.Error) {
|
||||||
|
|
Loading…
Reference in New Issue