;Wolfram|Alpha Script v1.1
;Made by nick1
;Last edit November 12 2013
;EDITS -- Changed the way the short links work. More reliable site
;2DO -- Fix subpod titles, clean up text with colors, comparison queries, max length
;NOTE -- [[Unfinished Version]] This works, but it's not the best. Comment with specific things you want fixed
Please pay attention to the APIKEY alias which you must put in your own.
Triggered using @wolf or @calc or @wa (the @ prefix is public, ! is private notice)
Also type /wolf to use on your own.
Please comment below if you find any bugs or would like any changes.
;Wolfram|Alpha Script v1.1
;Made by nick1
;Last edit November 12 2013
;EDITS -- Changed the way the short links work. More reliable site
;2DO -- Fix subpod titles, clean up text with colors, comparison queries, max length
;NOTE -- [[Unfinished Version]] This works, but it's not the best. Comment with specific things you want fixed
alias APIKey {
;Important you MUST put in your own API Key here, get one FREE from http://developer.wolframalpha.com/portal/apisignup.html
return CHANGE_THIS_OR_IT_WON'T_WORK
}
alias -l urlencode {
return $replacex($regsubex($$1-,/([^\w\s])/Sg,$+(%,$base($asc(\t),10,16,2))),$chr(32),+,$chr(43),%2B)
}
;raw 408:*: msg $2 $remove($strip($13-),$chr(9))
alias nohtml { return $regsubex($$1-,/^[^<]*>|<[^>]*>|<[^>]*$/g,) }
alias wshort {
sockopen $+(wshort.,$1) ou.gs 80
sockmark $+(wshort.,$1) $urlencode($2-)
}
on *:sockopen:wshort*: {
sockwrite -nt $sockname GET $+(/index.php?url=,$sock($sockname).mark,&alias=,$remove($sockname,wshort.)) HTTP/1.1
sockwrite -nt $sockname Host: ou.gs
sockwrite -nt $sockname $crlf
}
alias wolf {
if ($1 != $null) {
var %ticks $ticks
wshort %ticks $+(http://www.wolframalpha.com/input/?i=,$urlencode($1-))
set $+(%,wa.,%ticks,.msgtype) echo @wolfram
set $+(%,wa.,%ticks,.text) $1-
set $+(%,wa.,%ticks,.input) $urlencode($1-)
sockopen $+(wa.,%ticks) api.wolframalpha.com 80
}
else if ($1 == $null) {
echo -ac info Incorrect Syntax: /wolf <search query>
}
}
on $*:text:/^[!@](wolfram|wra|wolframalpha|alpha|wa|wolf|wfa|calc)(\s|$)/Si:*: {
$iif($istok(%nolinks,$nick,44),halt,noop)
$iif($istok(%youtubefetch,$chan,44),halt,noop)
if ($($+(%,botflood.,$nick),2)) {
if ($($+(%,botflood.,$nick),2) >= 50) {
ignore -u60 $address($nick,0)
msg $chan $+($nick,$chr(44)) You Have Been Put On Ignore For 60secs For Abusing The Bot.
halt
}
elseif ($($+(%,botflood.,$nick),2) >= 40) {
msg $chan $+($nick,$chr(44)) Please Do Not Abuse The Bot.
inc -z $+(%,botflood.,$nick) 20
halt
}
else {
inc -z $+(%,botflood.,$nick) 25
}
}
else {
inc -z $+(%,botflood.,$nick) 25
}
var %ticks $ticks
if ($2) {
var %i $2-
wshort %ticks $+(http://www.wolframalpha.com/input/?i=,$urlencode(%i))
set $+(%,wa.,%ticks,.msgtype) $iif($left($strip($1),1) == @,msg $chan,notice $nick)
set $+(%,wa.,%ticks,.text) %i
set $+(%,wa.,%ticks,.input) $urlencode(%i)
sockopen $+(wa.,%ticks) api.wolframalpha.com 80
}
elseif ($2 == $null) {
$iif($left($strip($1),1) == @,msg $chan,notice $nick) $+(4,$nick,,$chr(44)) 10Incorrect Syntax: Try $+(4,$1,10) <search term>
}
}
on *:input:*: {
if ($left($1,1) != /) {
if (($right($1,-1) == wolfram) || ($right($1,-1) == wa) || ($right($1,-1) == wra) || ($right($1,-1) == wolframalpha) || ($right($1,-1) == wolf) || ($right($1,-1) == wfa) || ($right($1,-1) == calc)) {
if ($2) {
if (($active == #homework) || ($active == #math)) {
msg $active $1-
halt
}
var %ticks $ticks
var %i $2-
wshort %ticks $+(http://www.wolframalpha.com/input/?i=,$urlencode(%i))
set $+(%,wa.,%ticks,.msgtype) msg $active
set $+(%,wa.,%ticks,.text) %i
set $+(%,wa.,%ticks,.input) $urlencode(%i)
sockopen $+(wa.,%ticks) api.wolframalpha.com 80
}
elseif ($2 == $null) {
echo -ac info Incorrect Syntax: $1 <input>
}
}
}
}
on *:SOCKOPEN:wa*: {
$iif(!$window(@Wolfram),window -evn @Wolfram,noop)
sockwrite -nt $sockname GET $+(/v2/query?input=,$($+(%,wa.,$remove($sockname,wa.),.input),2),&appid=,$apikey,&format=plaintext) HTTP/1.1
sockwrite -nt $sockname Host: api.wolframalpha.com
sockwrite -nt $sockname $crlf
}
alias NotTextValues {
return scanner,id,position,error,numsubpods,input,text,value,desc,current,valid,word,template,suggestion
}
on *:SOCKREAD:wa*: {
if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
sockread %sockreader
if (*numpods='* iswm %sockreader) {
tokenize 39 %sockreader
set $+(%,wa.,$remove($sockname,wa.),.pods) $2
}
elseif (*<subpod title='* iswm %sockreader) {
tokenize 39 %sockreader
if (($2 != $null) && ($2 != $chr(62))) {
set $+(%,wa.,$remove($sockname,wa.),.title.,$($+(%,wa.,$remove($sockname,wa.),.titles),2)) 12 $+ $2
}
}
elseif (*<pod title='* iswm %sockreader) {
inc $+(%,wa.,$remove($sockname,wa.),.titles)
tokenize 39 %sockreader
set $+(%,wa.,$remove($sockname,wa.),.title.,$($+(%,wa.,$remove($sockname,wa.),.titles),2)) 4 $+ $2
}
elseif (*<plaintext>* iswm %sockreader) {
inc $+(%,wa.,$remove($sockname,wa.),.texts)
if ($nohtml(%sockreader) != $null) {
if ($($+(%,wa.,$remove($sockname,wa.),.titles),2) == $($+(%,wa.,$remove($sockname,wa.),.texts),2)) {
set $+(%,wa.,$remove($sockname,wa.),.title.,$($+(%,wa.,$remove($sockname,wa.),.titles),2)) $addtok($($+(%,wa.,$remove($sockname,wa.),.title.,$($+(%,wa.,$remove($sockname,wa.),.titles),2)),2),$chr(32) $+ $replace($nohtml(%sockreader),','),58)
set $+(%,wa.,$remove($sockname,wa.),.result) $addtok($($+(%,wa.,$remove($sockname,wa.),.result),2),$($+(%,wa.,$remove($sockname,wa.),.title.,$($+(%,wa.,$remove($sockname,wa.),.titles),2)),2),32)
}
elseif ($($+(%,wa.,$remove($sockname,wa.),.titles),2) != $($+(%,wa.,$remove($sockname,wa.),.texts),2)) {
set $+(%,wa.,$remove($sockname,wa.),.result) $addtok($($+(%,wa.,$remove($sockname,wa.),.result),2),$chr(32) $replace($nohtml(%sockreader),','),124) $+ $chr(32)
}
}
}
elseif (($($+(%,wa.,$remove($sockname,wa.),.taxts),2) == $($+(%,wa.,$remove($sockname,wa.),.pods),2)) && ($($+(%,wa.,$remove($sockname,wa.),.pods),2) != $null)) {
set $+(%,wa.,$remove($sockname,wa.),.result) $replace($($+(%,wa.,$remove($sockname,wa.),.result),2),$chr(58),4 $+ $chr(58) $+ 10)
$($+(%,wa.,$remove($sockname,wa.),.msgtype),2) 4Wolfram5|7Alpha $($+(%,wa.,$remove($sockname,wa.),.result),2)
unset $+(%,wa.,$remove($sockname,wa.),*)
sockclose $sockname
}
elseif (($($+(%,wa.,$remove($sockname,wa.),.texts),2) >= 1) && ($mid(%sockreader,2,1) != $chr(60))) {
tokenize 61 %sockreader
if ((!$istok($NotTextValues,$1,44)) && ($left($1,1) != $chr(60))) {
set $+(%,wa.,$remove($sockname,wa.),.result) $addtok($($+(%,wa.,$remove($sockname,wa.),.result),2),$chr(32) $replace($nohtml(%sockreader),',') $+ $chr(32),124)
}
}
elseif (*<queryresult success='false'* iswm %sockreader) {
if ($($+(%,wa.,$remove($sockname,wa.),.msgtype),2) == echo @Wolfram) {
echo -a 4Wolfram5|7Alpha10 Could not find an answer to this query (please try again!) or 4View5|7It10 $+(http://ou.gs/,$remove($sockname,wa.))
}
else {
$($+(%,wa.,$remove($sockname,wa.),.msgtype),2) 4Wolfram5|7Alpha10 Could not find an answer to this query (please try again!) or 4View5|7It10 $+(http://ou.gs/,$remove($sockname,wa.))
}
unset $+(%,wa.,$remove($sockname,wa.),*)
sockclose $sockname
}
}
on *:SOCKCLOSE:wa*: {
set $+(%,wa.,$remove($sockname,wa.),.result) $replace($($+(%,wa.,$remove($sockname,wa.),.result),2),$chr(58),$chr(58) $+ 10,$chr(124),3 $+ $chr(124) $+ 10,",",<,<,>,>,&,&,^2,$chr(178),^3,$chr(179),theta,$chr(952),<=,≤,>=,≥,(script capital l),$chr(8467))
if ($($+(%,wa.,$remove($sockname,wa.),.result),2) != $null) {
if ($($+(%,wa.,$remove($sockname,wa.),.msgtype),2) == echo @Wolfram) {
echo -a 4Wolfram5|7Alpha $($+(%,wa.,$remove($sockname,wa.),.result),2) 4View5|7It10 $+(http://ou.gs/,$remove($sockname,wa.))
}
else {
$($+(%,wa.,$remove($sockname,wa.),.msgtype),2) 4Wolfram5|7Alpha $($+(%,wa.,$remove($sockname,wa.),.result),2) 4View5|7It10 $+(http://ou.gs/,$remove($sockname,wa.))
}
}
elseif ($($+(%,wa.,$remove($sockname,wa.),.result),2) == $null) {
if ($($+(%,wa.,$remove($sockname,wa.),.msgtype),2) == echo @Wolfram) {
echo -a 4Wolfram5|7Alpha10 Could not find an answer to this query (please try again!) or 4View5|7It10 $+(http://ou.gs/,$remove($sockname,wa.))
}
else {
$($+(%,wa.,$remove($sockname,wa.),.msgtype),2) 4Wolfram5|7Alpha10 Could not find an answer to this query (please try again!) or 4View5|7It10 $+(http://ou.gs/,$remove($sockname,wa.))
}
}
echo @Wolfram Query: $($+(%,wa.,$remove($sockname,wa.),.text),2) Request: $($+(%,wa.,$remove($sockname,wa.),.msgtype),2) 4Wolfram5|7Alpha $($+(%,wa.,$remove($sockname,wa.),.result),2) 4View5|7It10 $+(http://ou.gs/,$remove($sockname,wa.))
unset $+(%,wa.,$remove($sockname,wa.),*)
sockclose $sockname
}
Excellent. I made a few changes as I use my IRC bots to work inside of JTV.. so I always have to strip the color coding out and I changed the command ==@ and removed ,notice $nick -- as my only intentions are for people to type !wolfram (whatever) in the chat and get the results.
I got my API, made my small revisions and it works great. I'm really happy with it.
Thanks for help with the tweetcode.
Thanks again.
Glad you like it @Chromatic !
I just edited the script to provide a new website for link shortening. Please let me know if there is anything you want changed or added!