Advertisement
illpastethat

Wolfram|Alpha Script v1.0

Jul 4th, 2012
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 10.03 KB | None | 0 0
  1. ;Wolfram|Alpha Script v1.0
  2. ;Made by nick1
  3. ;Last edit June 26 2012
  4. ;EDITS -- Initial version
  5. ;2DO -- Fix subpod titles, clean up text with colors, comparison queries, max length
  6. ;NOTE -- [[Unfinished Version]] I am aware this is a very rough script and needs a lot of work, but since it is working
  7. ;for the basic stuff I am just putting it up as is for now
  8.  
  9. alias APIKey {
  10.   ;Important you MUST put in your own API Key here, get one FREE from http://developer.wolframalpha.com/portal/apisignup.html
  11.   return CHANGE_THIS_OR_IT_WILL_NOT_WORK
  12. }
  13.  
  14. alias -l urlencode {
  15.   return $replacex($regsubex($$1-,/([^\w\s])/Sg,$+(%,$base($asc(\t),10,16,2))),$chr(32),+,$chr(43),%2B)
  16. }
  17.  
  18. ;raw 408:*: msg $2 $remove($strip($13-),$chr(9))
  19.  
  20. alias nohtml { return $regsubex($$1-,/^[^<]*>|<[^>]*>|<[^>]*$/g,) }
  21.  
  22. alias shorten {
  23.   inc %shortens
  24.   if ($1 isnum) {
  25.     set %_bq.ticks $1
  26.     set %_bq.wolfram $urlencode($2-)
  27.     sockopen bq ou.gs 80
  28.   }
  29.   elseif ($2) {
  30.     set %_bq.nick $1
  31.     set %_bq.msgtype $iif((!%_bq.msgtype),msg $active,%_bq.msgtype)
  32.     set %_bq.url $2-
  33.     sockopen bq ou.gs 80
  34.   }
  35.   elseif ($2 == $null) {
  36.     set %_bq.msgtype echo -ac info
  37.     set %_bq.url $1-
  38.     sockopen bq ou.gs 80
  39.   }
  40. }
  41.  
  42. on *:sockopen:bq: {
  43.   if (%_bq.lmgtfy) {
  44.     sockwrite -nt $sockname GET $+(/index.php?url=,%_bq.url,&alias=,%_bq.nick,-,G0,-,%shortens) HTTP/1.1
  45.   }
  46.   elseif (%_bq.wolfram) {
  47.     sockwrite -nt $sockname GET $+(/index.php?url=,%_bq.wolfram,&alias=,%_bq.ticks) HTTP/1.1
  48.   }
  49.   elseif (%_bq.url) {
  50.     sockwrite -nt $sockname GET $+(/index.php?url=,$urlencode(%_bq.url)) HTTP/1.1
  51.   }
  52.   sockwrite -nt $sockname Host: ou.gs
  53.   sockwrite -nt $sockname $crlf
  54. }
  55.  
  56. on *:SOCKREAD:bq: {
  57.   if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
  58.   else {
  59.     var %sockreader
  60.     sockread %sockreader
  61.     if (*Short URL:* iswm %sockreader) {
  62.       if (%_bq.lmgtfy) {
  63.         tokenize 32 $nohtml(%sockreader)
  64.         %_bq.msgtype %_bq.nick $+ : 12[4Helpful Link12] $3
  65.         unset %_bq.*
  66.         sockclose $sockname
  67.         halt
  68.       }
  69.       else {
  70.         if (!%_bq.wolfram) {
  71.           %_bq.msgtype 10 $+ Long URL: $iif($left(%_bq.url,7) == http://,%_bq.url,http:// $+ %_bq.url) ( $+ $len($iif($left(%_bq.url,7) == http://,%_bq.url,http:// $+ %_bq.url)) Characters) Is4 $nohtml(%sockreader)
  72.           if (%_bq.msgtype == echo -ac info) {
  73.             tokenize 32 $nohtml(%sockreader)
  74.             clipboard $3
  75.           }    
  76.         }
  77.       }
  78.       unset %_bq.*
  79.       sockclose $sockname
  80.     }
  81.   }
  82. }
  83.  
  84.  
  85. alias wolf {
  86.   if ($1 != $null) {
  87.     var %ticks $ticks
  88.     shorten %ticks $+(http://www.wolframalpha.com/input/?i=,$urlencode($1-))
  89.     set $+(%,wa.,%ticks,.msgtype) echo @wolfram
  90.     set $+(%,wa.,%ticks,.text) $1-
  91.     set $+(%,wa.,%ticks,.input) $urlencode($1-)
  92.     sockopen $+(wa.,%ticks) api.wolframalpha.com 80
  93.   }
  94.   else if ($1 == $null) {
  95.     echo -ac info Incorrect Syntax: /wolf <search query>
  96.   }
  97. }
  98.  
  99. on $*:text:/^[!@](wolfram|wra|wolframalpha|alpha|wa|wolf|wfa|calc)/Si:*: {
  100.   $iif($istok(%youtubefetch,$chan,44),halt,noop)
  101.   $iif($istok(%nolinks,$nick,44),halt,noop)
  102.   if ($($+(%,botflood.,$nick),2)) {
  103.     if ($($+(%,botflood.,$nick),2) >= 50) {
  104.       ignore -u60 $address($nick,0)
  105.       msg $chan $+($nick,$chr(44)) You Have Been Put On Ignore For 60secs For Abusing The Bot.
  106.       halt
  107.     }
  108.     elseif ($($+(%,botflood.,$nick),2) >= 40) {
  109.       msg $chan $+($nick,$chr(44)) Please Do Not Abuse The Bot.
  110.       inc -z $+(%,botflood.,$nick) 20
  111.       halt
  112.     }
  113.     else {
  114.       inc -z $+(%,botflood.,$nick) 25
  115.     }
  116.   }
  117.   else {
  118.     inc -z $+(%,botflood.,$nick) 25
  119.   }
  120.   var %ticks $ticks
  121.   if ($2) {
  122.     var %i $2-
  123.     shorten %ticks $+(http://www.wolframalpha.com/input/?i=,$urlencode(%i))
  124.     set $+(%,wa.,%ticks,.msgtype) $iif($left($strip($1),1) == @,msg $chan,notice $nick)
  125.     set $+(%,wa.,%ticks,.text) %i
  126.     set $+(%,wa.,%ticks,.input) $urlencode(%i)
  127.     sockopen $+(wa.,%ticks) api.wolframalpha.com 80
  128.   }
  129.   elseif ($2 == $null) {
  130.     $iif($left($strip($1),1) == @,msg $chan,notice $nick) $+(4,$nick,,$chr(44)) 10Incorrect Syntax: Try $+(4,$1,10) <search term>
  131.   }
  132. }
  133.  
  134. on *:input:*: {
  135.   if ($left($1,1) != /) {
  136.     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)) {
  137.       if ($2) {
  138.         var %ticks $ticks
  139.         var %i $2-
  140.         shorten %ticks $+(http://www.wolframalpha.com/input/?i=,$urlencode(%i))
  141.         set $+(%,wa.,%ticks,.msgtype) msg $active
  142.         set $+(%,wa.,%ticks,.text) %i
  143.         set $+(%,wa.,%ticks,.input) $urlencode(%i)
  144.         sockopen $+(wa.,%ticks) api.wolframalpha.com 80
  145.       }
  146.       elseif ($2 == $null) {
  147.         halt
  148.       }
  149.     }
  150.   }
  151. }
  152.  
  153. on *:SOCKOPEN:wa*: {  
  154.   $iif(!$window(@Wolfram),window -evn @Wolfram,noop)
  155.   sockwrite -nt $sockname GET $+(/v2/query?input=,$($+(%,wa.,$remove($sockname,wa.),.input),2),&appid=,$apikey,&format=plaintext) HTTP/1.1
  156.   sockwrite -nt $sockname Host: api.wolframalpha.com
  157.   sockwrite -nt $sockname $crlf
  158. }
  159.  
  160. alias NotTextValues {
  161.   return scanner,id,position,error,numsubpods,input,text,value,desc,current,valid,word,template,suggestion
  162. }
  163.  
  164. on *:SOCKREAD:wa*: {
  165.   if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
  166.   sockread %sockreader
  167.   if (*numpods='* iswm %sockreader) {
  168.     tokenize 39 %sockreader
  169.     set $+(%,wa.,$remove($sockname,wa.),.pods) $2
  170.   }
  171.   elseif (*<subpod title='* iswm %sockreader) {
  172.     tokenize 39 %sockreader
  173.     if (($2 != $null) && ($2 != $chr(62))) {
  174.       set $+(%,wa.,$remove($sockname,wa.),.title.,$($+(%,wa.,$remove($sockname,wa.),.titles),2)) 12 $+ $2
  175.     }
  176.   }
  177.   elseif (*<pod title='* iswm %sockreader) {
  178.     inc $+(%,wa.,$remove($sockname,wa.),.titles)
  179.     tokenize 39 %sockreader
  180.     set $+(%,wa.,$remove($sockname,wa.),.title.,$($+(%,wa.,$remove($sockname,wa.),.titles),2)) 4 $+ $2
  181.   }
  182.   elseif (*<plaintext>* iswm %sockreader) {
  183.     inc $+(%,wa.,$remove($sockname,wa.),.texts)
  184.     if ($nohtml(%sockreader) != $null) {
  185.       if ($($+(%,wa.,$remove($sockname,wa.),.titles),2) == $($+(%,wa.,$remove($sockname,wa.),.texts),2)) {
  186.         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),&apos;,'),58)
  187.         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)
  188.       }
  189.       elseif ($($+(%,wa.,$remove($sockname,wa.),.titles),2) != $($+(%,wa.,$remove($sockname,wa.),.texts),2)) {
  190.         set $+(%,wa.,$remove($sockname,wa.),.result) $addtok($($+(%,wa.,$remove($sockname,wa.),.result),2),$chr(32) $replace($nohtml(%sockreader),&apos;,'),124) $+ $chr(32)
  191.       }
  192.     }
  193.   }
  194.   elseif (($($+(%,wa.,$remove($sockname,wa.),.taxts),2) == $($+(%,wa.,$remove($sockname,wa.),.pods),2)) && ($($+(%,wa.,$remove($sockname,wa.),.pods),2) != $null)) {
  195.     set $+(%,wa.,$remove($sockname,wa.),.result) $replace($($+(%,wa.,$remove($sockname,wa.),.result),2),$chr(58),4 $+ $chr(58) $+ 10)
  196.     $($+(%,wa.,$remove($sockname,wa.),.msgtype),2) 4Wolfram5|7Alpha $($+(%,wa.,$remove($sockname,wa.),.result),2)
  197.     unset $+(%,wa.,$remove($sockname,wa.),*)
  198.     sockclose $sockname
  199.   }
  200.   elseif (($($+(%,wa.,$remove($sockname,wa.),.texts),2) >= 1) && ($mid(%sockreader,2,1) != $chr(60))) {
  201.     tokenize 61 %sockreader
  202.     if ((!$istok($NotTextValues,$1,44)) && ($left($1,1) != $chr(60))) {
  203.       set $+(%,wa.,$remove($sockname,wa.),.result) $addtok($($+(%,wa.,$remove($sockname,wa.),.result),2),$chr(32) $replace($nohtml(%sockreader),&apos;,') $+ $chr(32),124)
  204.     }
  205.   }
  206.   elseif (*<queryresult success='false'* iswm %sockreader) {
  207.     if ($($+(%,wa.,$remove($sockname,wa.),.msgtype),2) == echo @Wolfram) {
  208.       echo -a  4Wolfram5|7Alpha10 Could not find an answer to this query (please try again!) or 4View5|7It10 $+(http://ou.gs/,$remove($sockname,wa.))
  209.     }
  210.     else {
  211.       $($+(%,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.))
  212.     }
  213.     unset $+(%,wa.,$remove($sockname,wa.),*)
  214.     sockclose $sockname
  215.   }
  216. }
  217. on *:SOCKCLOSE:wa*: {
  218.   set $+(%,wa.,$remove($sockname,wa.),.result) $replace($($+(%,wa.,$remove($sockname,wa.),.result),2),$chr(58),$chr(58) $+ 10,$chr(124),3 $+ $chr(124) $+ 10,&quot;,",&lt;,<,&gt;,>,&amp;,&,^2,$chr(178),^3,$chr(179),theta,$chr(952),<=,≤,>=,≥,(script capital l),$chr(8467))
  219.   if ($($+(%,wa.,$remove($sockname,wa.),.result),2) != $null) {
  220.     if ($($+(%,wa.,$remove($sockname,wa.),.msgtype),2) == echo @Wolfram) {
  221.       echo -a  4Wolfram5|7Alpha $($+(%,wa.,$remove($sockname,wa.),.result),2) 4View5|7It10 $+(http://ou.gs/,$remove($sockname,wa.))
  222.     }
  223.     else {
  224.       $($+(%,wa.,$remove($sockname,wa.),.msgtype),2) 4Wolfram5|7Alpha $($+(%,wa.,$remove($sockname,wa.),.result),2) 4View5|7It10 $+(http://ou.gs/,$remove($sockname,wa.))
  225.     }
  226.   }
  227.   elseif ($($+(%,wa.,$remove($sockname,wa.),.result),2) == $null) {
  228.     if ($($+(%,wa.,$remove($sockname,wa.),.msgtype),2) == echo @Wolfram) {
  229.       echo -a  4Wolfram5|7Alpha10 Could not find an answer to this query (please try again!) or 4View5|7It10 $+(http://ou.gs/,$remove($sockname,wa.))
  230.     }
  231.     else {
  232.       $($+(%,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.))
  233.     }    
  234.   }
  235.   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.))
  236.   unset $+(%,wa.,$remove($sockname,wa.),*)
  237.   sockclose $sockname
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement