All pastes #596333 Raw Edit

Anonymous

public text v1 · immutable
#596333 ·published 2007-06-29 21:36 UTC
rendered paste body
/*
#################################################################################
#                                                                               #
#   mPRE v1.0.6                                                                 #
#                                                                               #
#   description:    monitor channels for PRE/NUKE/UNNUKE(s) based on your       #
#                   filters and display relevant information in an @window      #
#                                                                               #
#   syntax:                                                                     #
#       /pre add -t type filter           adds filter for type                  #
#       /pre add filter                   adds filter for all types             #
#       /pre chan add #channel            adds #channel to monitoring           #
#       /pre chan del #channel            removes #channel from monitoring      #
#       /pre del N                        removes filter N                      #
#       /pre list                         list filters + channels               #
#       /pre tip                          toggles tooltips on/off               #
#       /pre tip delay N                  sets tooltip delay to N secs          #
#       /pre tip fade                     toggles tooltip fade on/off           #
#                                                                               #
#   examples:                                                                   #
#       /pre add -t xvid *DiAMOND                                               #
#       /pre add *HR?HDTV*                                                      #
#       /pre add -t tv *                                                        #
#       /pre add -t tv Heroes?S0?E??HDTV?*                                      #
#       /pre add -t mp3 *RNS                                                    #
#       /pre del 5                                                              #
#       /pre del 1                                                              #
#                                                                               #
#   *** REGULAR EXPRESSIONS (ADVANCED) ***                                      #
#   if you want to use regular expression filters, use -r/-rt/-tr. here's a     #
#   few examples to get you started. if you don't know how to use these, it's   #
#   probably best to avoid them.                                                #
#       /pre add -r /(DiAMOND|DEiTY|DoNE|ESPiSE)$/                              #
#       /pre add -rt tv /(LOL|XOR|CRiMSON|CTU|NBS|DIMENSION|NoTV)$/             #
#       /pre add -r /^(The[ .]Simpsons|Family[ .]Guy|American[ .]Dad)/          #
#                                                                               #
#   *** CHANNELS CURRENTLY SUPPORTED ***                                        #
#       (FreeQuest) #pre                                                        #
#       (P2P-NET) #persian-pre, #pre, #pre-rts, #st.pre                         #
#       (SceneAccess) #scc-pre                                                  #
#      NOTE: i need more channels! find me (via contact info below) and give    #
#            me some examples of PRE/NUKE/UNNUKE output and the channel name    #
#            and i will add it into the script for the next update. it's not    #
#            recommended to code it yourself, unless you know how to do it..    #
#                                                                               #
#   *** CONTACT INFORMATION ***                                                 #
#       NETWORK: Cyanide-x (irc.cyanide-x.net)                                  #
#       CHANNEL: #TorrentHelp                                                   #
#       IRCNICK: mitch                                                          #
#                                                                               #
#################################################################################
*/


alias -l # return $+($iif(#* !iswm $1,$chr(35)),$1)
alias -l ' return $+(',$1,')
alias -l ; return $+($chr(40),$1,$chr(41))
alias -l [ return $+([,$1,])
alias -l _e echo -ac info $[(pre) $1-
alias -l _error _e syntax: | _e /pre add [-rt] [type] [filter] | _e /pre chan [add|del] #channel | _e /pre del N | _e /pre list | _e /pre tip [delay|fade] [N]
alias -l _filter var %i = $($1), %x = $hget(_mPRE,$+(filter_,%i)) | if (%i == 0) { return $($hfind(_mPRE,filter_*,0,w)) } | tokenize %x 1 | if ($prop == f) { %x = $2 } | if ($prop == t) { %x = $1 } | return %x
alias -l _h {
  var %x = _mPRE, %z = $+(%x,.db) | if (!$hget(%x)) { .hmake %x 10 }
  if ($1 == add) || ($1 == del) { if ($1 == add) { .hadd %x $2 $3- } | if ($1 == del) { .hdel %x $+(filter_,$$2) } | .hsave %x %z }
  if ($1 == init) { if ($isfile(%z)) { .hload %x %z } | else { .hadd %x tooltips 0 | .hsave %x %z } }
  if ($isid) { return $hget(%x,$$1) }
}
alias -l _scr return mPRE v1.0.6
alias -l _w {
  var %@ = @mPRE, %a = aline -phi10 %@, %tip = $_h(tooltips), %t = $1, %# = $2, %c, %m, %r, %i, %x, %y
  if (!$window(%@)) { window -n %@ }
  tokenize 32 $1-
  while ($($+($,%i),2)) {
    %x = $v1 | %y = $($+($,$calc(%i +1)),2)
    if (%x == -c) { if (%y != -n) && (%y != -r) { %c = %y } }
    if (%x == -n) { if (%y != -r) { %m = %y } }
    if (%x == -r) { %r = $($+($,$calc(%i +1),-),2) }
    inc %i
  }
  %a $+([,$time(mm/dd/yy HH:nn:ss),]) %#    $[(%t)    $iif(%c,$;(%c))   %r $iif(%m,[[ %m ]])
  if ($appactive) && (%tip == 1) {
    %r = $+(,%r,)
    if (%m) { %m = $+(,$iif(%t == U,UN),NUKE  ,%m) }
    ptip $+(%r,,%m)
  }
  halt
}
alias pre {
  var %c, %t, %f, %n, %r, %x, %l, %i, %ii, %h = _mPRE
  _h init
  if (!$1) { _error }
  if ($1 == add) {
    if (!$2) { _error }
    if ($2) {
      if ($2 == -r) { if (!$3) { _error } | if ($3) { %t = * | %f = $3- | %r = 1 } }
      if ($istok(-rt -tr,$2,32)) { if (!$4) { _error } | if ($4) { %t = $3 | %f = $4- | %r = 1 } }
      if ($2 == -t) { if (!$3) { _error } | if ($3) { %t = $3 | %f = $iif($4,$4-,*) } }
      if (!$istok(-r -rt -t -tr,$2,32)) { if ($#(*) iswm $2) { _error } | else { %t = * | %f = $2- } }
      _h add $+(filter_,$calc($_filter(0) +1)) $+(%t,,$iif(%r == 1,$+(%r,,%f),%f))
      _e added $'(%f) $iif(%t != *,$;(%t)) to filters $iif(%r == 1,$[(r))
    }
  }
  if ($1 == chan) {
    if ($2 == add) {
      if ($3) {
        if ($istok($_h(channels),$#($3),44)) { _e channel $'($#($3)) exists }
        else { _h add channels $addtok($_h(channels),$#($3),44) | _e added $'($#($3)) to channels }
      }
      else { _error }
    }
    if ($2 == del) {
      if ($3) {
        if ($istok($_h(channels),$#($3),44)) { _h add channels $deltok($_h(channels),$findtok($_h(channels),$#($3),1,44),44) | _e removed $'($#($3)) from channels }
        else { _e channel $'($#($3)) does not exist }
      }
      else { _error }
    }
  }
  if ($1 == del) {
    %x = $($2) | if ($_filter(%x)) { %t = $gettok($v1,1,1) | %f = $gettok($v1,2,1) | if ($numtok(%f,127) == 2) { %f = $gettok(%f,2,127) } }
    if ($_h($+(filter_,%x))) { _h del %x | _e removed $'(%f) $iif(%t != *,$;(%t)) from filters | %i = %x | while ($_filter($calc(%i +1))) { _h add $+(filter_,%i) $_filter($calc(%i +1)) | inc %i } | _h del %i }
    else { _e invalid filter }
  }
  if ($1 == list) {
    %x = 1
    while ($_filter(%x)) {
      %l = $_filter(%x) | %t = $gettok(%l,1,1) | %f = $gettok(%l,2,1) | if ($numtok(%f,127) == 2) { %r = $gettok(%f,1,127) | %f = $gettok(%f,2,127) }
      _e    $+($#(%x),:)    $;($iif(%t == *,---,%t)) %f $iif(%r == 1,$[(r)) | %r = "" | inc %x
    }
    _e    * channels: $numtok($_h(channels),44) $iif($_h(channels),$;($v1)) | _e    * filters: $_filter(0)
  }
  if ($1 == tip) {
    if ($2 == delay) {
      _h add delay $iif($3 isnum 1-30,$int($3),5)
      _e tooltip delay set to: $_h(delay) $+(sec,$iif($_h(delay) != 1,s))
    }
    if ($2 == fade) {
      _h add fade $iif($_h(fade) == 1,0,1)
      _e toggled tooltip fade: $iif($_h(fade) == 1,on,off)
    }
    if (!$2) {
      _h add tooltips $iif($_h(tooltips) == 1,0,1)
      _e toggled tooltips: $iif($_h(tooltips) == 1,on,off)
    }
  }
}


/*
#  tooltips section
#  mPRE Notifications v1
*/

/*
#  $trim(text,font,size,length)
#  returns 'text' trimmed to 'length' (pixels) for tooltip
*/
alias -l trim {
  var %c = 0, %x = $1, %z, %i = $len(%x), %trim
  if ($width(%x,$2,$3,0,1) > $$4) { while (%i) { %z = $left(%x,%i) | if ($width(%z,$2,$3,0,1) < $4) { %trim = $+(%z,...) | break } | dec %i } }
  if (!%trim) { %trim = %x }
  return %trim
}
/*
#  /ptip.close
#  closes currently open tooltip and opens the next in queue (if any)
#  queue idea was borrowed from gr33ny; he uses vars, i use hash tables
*/
alias ptip.close {
  var %h = @ptip, %i = 1, %m, %r, %v, %x | window -c %h
  if ($hget(%h,1)) { ptip $hget(%h,1) | while ($hget(%h,$calc(%i +1))) { .hadd %h %i $v1 | inc %i } | .hdel %h %i }
  if ($hget(%h)) && ($hget(%h,0).item == 0) { .hfree %h }
}
/*
#  /ptip releasemessage
#  opens tooltip (message is optional; meant for nuke/unnuke)
*/
alias ptip {
  tokenize 1 $1-
  var %@ = @ptip, %tm = $time(mm/dd/yy   HH:nn:ss), %rls = $trim($1,%font,%sz,620), %msg
  var %h = 0, %i, %x, %w = 0, %y
  var %font = Tahoma, %sz = 14, %bg = 14811135, %bt = 6381921, %tt = 16777215
  if ($width(%rls,%font,%sz,0,1) < 220) { %w = 250 }
  if (!%w) { %w = $calc(30 +$width(%rls,%font,%sz,0,1)) }
  %msg = $trim($2,%font,$calc(%sz -2),$calc(%w -35))
  %h = $calc(36 +$height(%rls,%font,%sz) +$height(%msg,%font,$calc(%sz -2)))
  %x = $calc((($window(-2).x +$window(-2).w) -%w) -10) | %y = $calc((($window(-2).y +$window(-2).h) -%h) -10)
  if ($window(%@)) {
    if (!$hget(%@)) { .hmake %@ }
    %i = $calc($hget(%@,0).item +1)
    .hadd %@ %i $+(%rls,,%msg)
    return
  }
  window -pBhdo +dL %@ %x %y %w %h
  drawrect -nrf %@ %bg 1 0 0 %w %h
  drawrect -nrf %@ 0 1 0 0 %w 20
  drawrect -nr %@ 0 0.5 0 0 %w %h
  drawpic -cntros %@ 16711935 5 2 16 16 4 $+(",$mircexe,")
  drawtext -npr %@ %tt %font $calc(%sz -2) 26 2 mPRE Notifications
  drawtext -npr %@ %tt %font $calc(%sz -4) $calc((%w -5) -$width(%tm,%font,$calc(%sz -4),0,1)) 3 %tm
  drawtext -npr %@ %bt %font %sz 10 26 %rls
  if ($0 == 2) && (%msg) { drawtext -npr %@ %bt %font $calc(%sz -2) 15 46 %msg }
  drawdot %@ | window -a %@ | showmirc -r | .timerptip.close 1 $_h(delay) ptip.close
}


/*
#  LOAD/UNLOAD scripts to successfully clean everything up
#  removes all necessary files after, you are just left with mPRE.mrc
*/
on *:LOAD:_e Loaded $_scr successfully. | _e To toggle tooltips on/off, type /pre tip | pre
on *:UNLOAD:var %x = mPRE | _e Unloaded $+($_scr,... goodbye!) | if ($window($+(@,%x))) { window -c $+(@,%x) } | .hfree $+($+(_,%x)) | .remove $+(_,%x,.db)


/*
#  THIS NEXT PART IS WHERE THE SCRIPT COLLECTS THE INFORMATION!
#  IF YOU WANT EVERYTHING TO BE ACCURATE, TEST IT FIRST!
#
#  NOTE: v1.1.0 will feature a rewrite + have more channels listed below
*/
on *:TEXT:*:# {
  var %f = goto _x, %i = 1, %st = $strip($1-), %x, %z, %cat, %rls, %rsn
  tokenize 32 %st | %x = $0
  if ($istok($_h(channels),#,44)) {
    if (# == #pre) {
      ; #pre @ FreeQuest
      if ($network == FreeQuest) {
        if ($1 == PRE) { %cat = $3 | %rls = $5 | %z = P | %f }
        if ($istok(NUKE UNNUKE,$1,32)) { %rls = $3 | %rsn = $5 | %z = $iif(U* iswm $1,U,N) | %f }
      }
      ; #pre @ P2P-NET
      if ($network == P2P-NET) {
        if ($1 == [PRE]) { %cat = $($+($,$calc(%x -3)),2) | %rls = $($+($,3-,$calc(%x -6)),2) | %z = P | %f }
        if ($istok([NUKE] [UNNUKE],$1,32)) { %cat = $($+($,$calc(%x -6)),2) | %rls = $($+($,3-,$calc(%x -9)),2) | %rsn = $($+($,$calc(%x -1)),2) | %z = $iif(?U* iswm $1,U,N) | %f }
      }
    }
    ; #sex0rs-relay @ P2P-NET
    if (# == #sex0rs-relay) && ($network == P2P-NET) {
      if ($1 == [PRE]) { %cat = $($+($,$calc(%x -3)),2) | %rls = $($+($,3-,$calc(%x -6)),2) | %z = P | %f }
      if ($istok([NUKE] [UNNUKE],$1,32)) { %cat = $($+($,$calc(%x -6)),2) | %rls = $($+($,3-,$calc(%x -9)),2) | %rsn = $($+($,$calc(%x -1)),2) | %z = $iif(?U* iswm $1,U,N) | %f }
    }
    ; #persian-pre @ P2P-NET
    if (# == #persian-pre) && ($network == P2P-NET) {
      if ($2 == PRE) { %rls = $4 | %cat = $6 | %z = P | %f }
      if ($istok(NUKE UNNUKE,$2,32)) { %rls = $4 | %rsn = $6 | %z = $iif(U* iswm $2,U,N) | %f }
    }
    ; #pre-rts @ P2P-NET
    if (# == #pre-rts) && ($network == P2P-NET) {
      if ($2 == PRE) { %cat = $6 | %rls = $10 | %z = P | %f }
      if ($istok(NUKE UNNUKE,$2,32)) { %rls = $6 | %rsn = $10 | %z = $iif(U* iswm $2,U,N) | %f }
    }
    ; #scc-pre @ SceneAccess
    if (# == #scc-pre) && ($network == SceneAccess) {
      if ($2 == PRE) { %cat = $4 | %rls = $($+($,6-,$calc(%x -1)),2) | %z = P | %f }
      if ($istok(NUKE UNNUKE,$2,32)) { %rls = $($+($,4-,$calc(%x -3)),2) | %rsn = $($+($,$calc(%x -1)),2) | %z = $iif(U* iswm $2,U,N) | %f }
    }
    ; #st.pre @ P2P-NET
    if (# == #st.pre) && ($network == P2P-NET) {
      if ($;(*) iswm $1) && ($2 == -) { %rls = $3 | %cat = $mid($1,2,-1) | %z = P | %f }
      if ($istok([NUKE] [UNNUKE],$1,32)) { %rls = $3 | %rsn = $mid($5,2,-1) | %z = $iif(?U* iswm $1,U,N) | %f }
    }
    ; #420-pre @ Cyanide-x (sandbox)
    if (# == #420-pre) && ($network == Cyanide-x) {
      if ($1 == [PRE]) { %cat = $($+($,$calc(%x -3)),2) | %rls = $($+($,3-,$calc(%x -6)),2) | %z = P | %f }
      if ($istok([NUKE] [UNNUKE],$1,32)) { %cat = $($+($,$calc(%x -6)),2) | %rls = $($+($,3-,$calc(%x -9)),2) | %rsn = $($+($,$calc(%x -1)),2) | %z = $iif(?U* iswm $1,U,N) | %f }
    }   
    :_x | var %_x = 1, %_c, %_f, %_r, %_t
    while ($_filter(%_x)) {
      %_t = $v1 | %_c = $gettok(%_t,1,1) | %_f = $gettok(%_t,2,1)
      if ($numtok(%_f,127) == 2) { %_r = $gettok(%_f,1,127) | %_f = $gettok(%_f,2,127) }
      if (%_f iswm %rls) || ((%_r == 1) && ($regex(%rls,%_f))) {
        if (%_c == *) { _w %z # -c %cat -n %rsn -r %rls }
        if (%_c != *) { if ((%cat) && (%cat == %_c)) || ((!%cat) && (%z == P)) { _w %z # -c %cat -n %rsn -r %rls } }
      }
      inc %_x
    }
  }
}


/*
#################################################################################
# changelog                                                                     #
#                                                                               #
# 1.0.6 (20070628)                                                              #
#   !   rewrote, redesigned, and renamed tooltip command                        #
#   +   added fade/delay to /pre tip [option]; /pre tip still toggles tips      #
#   +   added tooltip queue (tooltips will popup in succession)                 #
#   +   $trim(text,font,size,length) for tooltips; trims text to length         #
#                                                                               #
# 1.0.5 (20070614)                                                              #
#   !   redesigned filter check                                                 #
#   !   fixed regex/normal randomly missing some filters                        #
#   !   fixed tooltip timer issue                                               #
#   !   fixed #st.pre issues (haha i must have been stoned...)                  #
#                                                                               #
# 1.0.4 (20070612)                                                              #
#   !   modified /pre, /_w, and filter-check (now works for normal and regex)   #
#   !   modified window output slightly again... didnt like the last change     #
#   !   tweaked tooltips a little                                               #
#   +   added on UNLOAD cleanup routine                                         #
#                                                                               #
# 1.0.3 (20070611)                                                              #
#   !   modified window output slightly                                         #
#   +   added tooltips (toggle with /pre tip)                                   #
#                                                                               #
# 1.0.2 (20070608)                                                              #
#   !   renamed to mPRE                                                         #
#   !   updated everything in script                                            #
#   !   changed /_error output                                                  #
#   +   added contact info, regexp examples, channel info                       #
#                                                                               #
# 1.0.1 (20070603)                                                              #
#   !   updated /_w for adding info to @window                                  #
#   +   added probable matches (matches if no category, denotes probable match) #
#   +   -r now accepted for regexp filter match                                 #
#   +   listing of filters now possible with /pre list                          #
#   -   removed /_f (filter-check alias); now inside event                      #
#                                                                               #
# 1.0.0 (20070601)                                                              #
#   +   first (semi-)working version                                            #
#################################################################################
*/

suggestions;

1. treeview of the mPre window, for example:
  
- release1
  |______nuke
  |______unnuked
  |______nuked
+ release2
- release3
  |____nuke
  |____delpre

2. ability to work from addpre source,
   this would then allow the ability to add 
   more info into the tooltip such as file 
   info and genre. obviously with this it 
   would have to re-popup or refresh the
   data after ~2 seconds to ensure any file
   information or genre information was
   recieved.
   also, as shown above in the - release3
   treebar view, it would enable the ability
   for delpre and any other commands like
   that.

3. on-the-fly colour changing abilities to
   maximise potential and so that the user 
   can fully enjoy a this script.

4. perhaps a dialog window for editting all 
   of the settings and stuff like this also
   so that the naabs, or just people who
   prefer guis and such can do it this way,
   which would enable the on-the-fly colour
   change to take place also.