ageisp0lis

[bitcoin] bitcoinica live ticker for mIRC

Dec 5th, 2011
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 6.14 KB | None | 0 0
  1. /*
  2. bitcoinica live ticker for mIRC
  3. by ageis @ #bitcoin-otc on freenode
  4. http://ageispolis.net
  5. modified: 12/05/2011
  6. donations: 1AgeisUFv9NJ3AGGq7VPJWymGfFpCHDhCw
  7.  
  8. to load the script, type /load -rs btcticker.mrc
  9. !! you must allow initialization commands
  10. to set variables required by this script !!
  11. to show the ticker, type /btcticker
  12. to configure settings, type /btcsettings
  13. or right-click for the menu
  14.  
  15. options:
  16. - vertical or horizontal tickers    [default: horizontal]
  17. - adjustable refresh rate       [default: 30 seconds]
  18. - always on top         [default: on]
  19. - show on desktop           [default: off]
  20. - refresh while offline     [default: off]
  21. */
  22.  
  23. on *:LOAD:{
  24.   unset btc*
  25.   set %btcurl https://www.bitcoinica.com/api/quotes/BTCUSD.json
  26.   set %btcrefresh 30
  27.   set %btcoxaot 1
  28.   set %btcoxoffline 0
  29.   set %btcoxdesktop 0
  30.   set %btcoxvert 0
  31. }
  32.  
  33. menu * {
  34.   bitcoinica
  35.   ..ticker:btcticker
  36.   ..config:btcsettings
  37. }
  38.  
  39. dialog btcconfig {
  40.   title "settings"
  41.   size -1 -1 54 78
  42.   option dbu
  43.   check "always on top",1, 2 2 45 10,
  44.   check "show on desktop",2, 2 12 50 10,
  45.   check "refresh offline",3, 2 22 45 10,  
  46.   combo 9,2 33 50 9, drop
  47.   text "refresh rate:",4, 2 45 50 8, center
  48.   edit "",5, 2 52 30 11, limit 5
  49.   text "secs",6, 34 54 10 10
  50.   button "okay",99, 2 66 50 10, ok flat
  51. }
  52.  
  53. dialog btcticker_vt {
  54.   title "bitcoinica"
  55.   size -1 -1 48 20
  56.   option dbu
  57.   text "BUY:" ,1, 2   0 14 8
  58.   edit ""     ,2, 18  0 30 10,read
  59.   text "SELL:" ,3, 2  10 14 8
  60.   edit ""     ,4, 18 10 30 10,read
  61.   ;button "refresh", 99, 0 60 48 10, flat
  62. }
  63.  
  64. dialog btcticker_hz {
  65.   title "bitcoinica live ticker"
  66.   size -1 -1 94 10
  67.   option dbu
  68.   text "BUY:" ,1, 2   1 12 8
  69.   edit ""     ,2, 16  0 30 10,read
  70.   text "SELL:" ,3, 48  1 14 8
  71.   edit ""     ,4, 64  0 30 10,read  
  72.   ;button "refresh", 99,278  0 32 10, flat
  73. }
  74.  
  75. on *:dialog:btcticker_vt:init:0:{
  76.   btcupdate btcticker_vt
  77.   if (%btcoffline == 1) {
  78.     .timerbtcvt -o 0 %btcrefresh btcupdate btcticker_vt
  79.   }
  80.   else { .timerbtcvt 0 %btcrefresh btcupdate btcticker_vt }
  81. }
  82. ;on *:dialog:btcticker_vt:sclick:99:{ btcupdate btcticker_vt }
  83. on *:dialog:btcticker_vt:close:0:{ .timerbtcvt off }
  84.  
  85. on *:dialog:btcticker_hz:init:0:{
  86.   btcupdate btcticker_hz
  87.   if (%btcoffline == 1) {
  88.     .timerbtchz -o 0 %btcrefresh btcupdate btcticker_hz
  89.   }
  90.   else { .timerbtchz 0 %btcrefresh btcupdate btcticker_hz }
  91. }
  92.  
  93. ;on *:dialog:btcticker_hz:sclick:99:{ btcupdate btcticker_hz }
  94. on *:dialog:btcticker_hz:close:0:{ .timerbtchz off }
  95.  
  96. on *:dialog:btcconfig:init:0:{
  97.   did -arf btcconfig 5 %btcrefresh
  98.   did -ai btcconfig 9 vertical
  99.   did -ai btcconfig 9 horizontal
  100.  
  101.   if (%btcvert == 1) { did -c btcconfig 9 1 }
  102.   else { did -c btcconfig 9 2 }
  103.   if (%btcaot == 1) { did -c btcconfig 1 }
  104.   if (%btcoffline == 1) { did -c btcconfig 3 }
  105.   if (%btcdesktop == 1) { did -c btcconfig 2 }
  106. }
  107.  
  108. on *:dialog:btcconfig:sclick:1:{
  109.   if ($did(btcconfig,1).state == 1) { set %btcaot 1 }
  110.   else { set %btcaot 0 }
  111. }
  112.  
  113. on *:dialog:btcconfig:sclick:2:{
  114.   if ($did(btcconfig,2).state == 1) { set %btcdesktop 1 }
  115.   else { set %btcdesktop 0 }
  116. }
  117.  
  118. on *:dialog:btcconfig:sclick:3:{
  119.   if ($did(btcconfig,3).state == 1) { set %btcoffline 1 }
  120.   else { set %btcoffline 0 }
  121. }
  122.  
  123. on *:dialog:btcconfig:sclick:9:{
  124.   if ($did(btcconfig,9) == vertical) { set %btcvert 1 }
  125.   else { set %btcvert 0 }
  126. }
  127. on *:dialog:btcconfig:edit:5:{
  128.   set %btcrefresh $did(btcconfig,5)
  129. }
  130.  
  131. alias btcticker {
  132.   var %params -mv
  133.   if (%btcdesktop == 1) { %params = %params $+ d }
  134.   if (%btcaot == 1) { %params = %params $+ o }
  135.  
  136.   if (%btcvert == 1) {
  137.     dialog %params btcticker_vt btcticker_vt
  138.   }
  139.   else { dialog %params btcticker_hz btcticker_hz }
  140. }
  141.  
  142. alias btcupdate {
  143.   .jsonclearcache %btcurl
  144.   var %btcbuy $json(%btcurl,buying)
  145.   var %btcsell $json(%btcurl,selling)
  146.   did -ar $1 2 %btcbuy
  147.   did -ar $1 4 %btcsell
  148. }
  149.  
  150. alias btcsettings {
  151.   dialog -mov btcconfig btcconfig
  152. }
  153.  
  154. ;JSON implementation by Timi at http://timscripts.com/
  155.  
  156. alias json {
  157.   if ($isid) {
  158.     var %c = jsonidentifier,%x = 2,%str,%p,%v,%addr
  159.     if ($isfile($1)) { %addr = $qt($replace($1,\,\\,;,\u003b,",\u0022)) }
  160.     else { %addr = $qt($replace($1,;,\u003b,",\u0022)) }
  161.     json.comcheck
  162.     if (!$timer(jsonclearcache)) { .timerjsonclearcache -o 0 300 jsonclearcache }
  163.     while (%x <= $0) {
  164.       %p = $($+($,%x),2)
  165.       if (%p == $null) { noop }
  166.       elseif (%p isnum || $qt($noqt(%p)) == %p) { %str = $+(%str,[,%p,]) }
  167.       else { %str = $+(%str,[",%p,"]) }
  168.       inc %x
  169.     }
  170.     if ($prop == count) { %str = %str $+ .length }
  171.     if ($isfile($1)) {
  172.       if ($com(%c,eval,1,bstr,$+(str2json,$chr(40),filejson,$chr(40),%addr,$chr(41),$chr(41),%str))) { return $com(%c).result }
  173.     }
  174.     elseif (http://* iswm $1 || https://* iswm $1) {
  175.       if ($com(%c,eval,1,bstr,$+(str2json,$chr(40),urlcache[,%addr,],$chr(41),%str))) { return $com(%c).result }
  176.       elseif ($com(%c,eval,1,bstr,$+(urlcache[,%addr,]) = $+(httpjson,$chr(40),$qt($1),$chr(41)))) {
  177.         if ($com(%c,eval,1,bstr,$+(str2json,$chr(40),urlcache[,%addr,],$chr(41),%str))) { return $com(%c).result }
  178.       }
  179.     }
  180.     elseif ($com(%c,eval,1,bstr,$+(x=,%addr,;,x,%str,;))) { return $com(%c).result }
  181.   }
  182. }
  183.  
  184. alias jsonclearcache {
  185.   if ($com(jsonidentifier)) {
  186.     if (!$1) { noop $com(jsonidentifier,executestatement,1,bstr,urlcache = {}) }
  187.     else { echo -qg $com(jsonidentifier,executestatement,1,bstr,urlcache[" $+ $1 $+ "] = "") }
  188.   }
  189. }
  190.  
  191. alias -l json.comcheck {
  192.   var %c = jsonidentifier
  193.   if (!$com(%c)) {
  194.     .comopen %c MSScriptControl.ScriptControl
  195.     noop $com(%c,language,4,bstr,jscript) $com(%c,addcode,1,bstr,function httpjson(url) $({,0) y=new ActiveXObject("Microsoft.XMLHTTP");y.open("GET",url,false);y.send();return y.responseText; $(},0))
  196.     noop $com(%c,addcode,1,bstr,function filejson (file) $({,0) x = new ActiveXObject("Scripting.FileSystemObject"); txt1 = x.OpenTextFile(file,1); txt2 = txt1.ReadAll(); txt1.Close(); return txt2; $(},0))
  197.     noop $com(%c,addcode,1,bstr,function str2json (json) $({,0) return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(json.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + json + ')'); $(},0))
  198.     noop $com(%c,addcode,1,bstr,urlcache = {})
  199.   }
  200. }
Add Comment
Please, Sign In to add comment