Created
July 20, 2014 05:59
-
-
Save chrisgward/740014438bb4b986ecaf to your computer and use it in GitHub Desktop.
WolframAlpha Nromal Script (Lain compatible)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package require tdom | |
proc wolframalpha {nick channel arg} { | |
if {$arg == ""} { | |
return "Please provide a search query." | |
} elseif {[string first "Necrodoom" $arg] != -1} { | |
return "Did you mean: stop spamming $::botnick?" | |
} | |
set xml [wget http://api.wolframalpha.com/v2/query?format=plaintext&appid=APPID&[::http::formatQuery input $arg]] | |
set document [dom parse $xml] | |
set result [$document selectNodes /queryresult] | |
set success [$result getAttribute success] | |
set error [$result getAttribute error] | |
if {$success == "true" && $error == "false"} { | |
set nodes [$result selectNode pod] | |
foreach node $nodes { | |
if {[$node hasAttribute primary] && [$node getAttribute primary] == "true"} { | |
set response "Result: [[lindex [$node selectNode subpod/plaintext] 0] text]" | |
$document delete | |
return $response | |
} | |
} | |
foreach node $nodes { | |
if {[$node hasAttribute id] && [$node getAttribute "id"] == "Value"} { | |
set response "Result: [[lindex [$node selectNodes subpod/plaintext] 0] text]" | |
$document delete | |
return $response | |
} | |
} | |
return "Result: [[lindex [[lindex $nodes 0] selectNodes subpod/plaintext] 0] text]" | |
} else { | |
set err [$result selectNode error] | |
if {$err == ""} { | |
set didyoumeans [$result selectNodes didyoumeans] | |
if {$didyoumeans == ""} { | |
set response "Unknown error." | |
$document delete | |
return $response | |
} else { | |
set response "Did you mean: [[lindex [$didyoumeans selectNodes didyoumean] 0] text]?" | |
$document delete | |
return $response | |
} | |
} else { | |
set code [[$err selectNodes code] text] | |
set msg [[$err selectNodes msg]] | |
set response "Error: $code: $msg" | |
$document delete | |
return $response | |
} | |
} | |
$document delete | |
return "No result" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment