nmp (nomorepasting) — File Browser

nmpnomorepastingv1.9 / nmpnomorepastingv1.9 / nmp_1.9 / nmp.mrc

nmp.mrc — 11.14 KB — Download this file

/*
**
** Created by: Rand (@DALnet)
**             Altaren (www.mirc.net), Justarius (www.mircscripts.org)
**
** Script name: nmp v1.9 (nomorepasting)
** 
**
** Useage:
**
**    * /nmp [-sc] [channel|nick]
**             -- The switches are optional.
**
**             -- 's' messages your active window.
**                    This will not trigger if it's your status window,
**                    or an @window. You can specify a channel or nick.
**
**             -- 'd' opens the nmp dialog.
**
**             -- 'c' will force a close on the nmp socket.
**                    note that this should not be needed.
**
**    * /getnmp [-dc] <ID>
**             -- The switches are optional, but <ID> is a must.
**
**             --  'd' Is meant to be used alone, it opens the getnmp dialog.
**
**             --  'c' If there is a "getnmp" being processed, it will close it,
**                     and start a new one.
**
**    * /getnmpcatcher [on|off]
**             This just turns the "catcher" off or on. [on|off] is optional,
**             will toggle between on and off if neither is specified.
**             Default setting is "on"
**
*/

alias nmp {
  ;---
  ;  Displaying the link and using switches.

  var %display = echo -a NMP:
  if (-*d* iswm $1) { dialog -md nmp nmp | return }
  if (-*c* iswm $1) { sockclose _nmp }
  if (-*b* iswm $1) { var %dialog = 1 }
  if (-*s* iswm $1) {
    if ($2) { var %display = msg $2 }
    elseif (@* !iswm $active || Status Window != $active) {
      var %display = msg $active
    }
  }


  if ($sock(_nmp)) { echo -a *** NMP: Currently pasting. Please wait. | return }

  ;---
  ; Parsing the clipboard (with POST info for nmp.com)
  ; if the paste bvar has not already been made through the dialog.
  if (!%dialog) {
    bset -t &paste 1 action=addpaste&q=·¸§½±&verifier=HGXBN&lang=mirc&body=
    var %i = 1, %pos 
    while (%i <= $cb(0)) {
      %pos = $bvar(&paste, 0) + 1
      bset -t &paste %pos $urlencode($cb(%i)) $+ $crlf
      inc %i
    }
    hadd -mb _nmp paste &paste
  }

  ;---
  ;  Opening the sock, and marking it.
  sockopen _nmp www.nomorepasting.com 80
  sockmark _nmp %display
}

on *:sockopen:_nmp:{
  if ($sock($sockname).status != active) {
    echo -a NMP: Error (Socket was unable to connect. Try again in a few?)
    return
  }
  var %% = sockwrite -n $sockname

  %% POST /paste.php HTTP/1.0
  %% Host: www.nomorepasting.com
  %% User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6)
  %% Content-Length: $hget(_nmp,paste,&clip)
  %% Content-Type: application/x-www-form-urlencoded
  %% Connection: close
  %%
}
on *:sockwrite:_nmp:{
  if ($sock($sockname).sq) { return }
  var %n = $hget(_nmp,paste,&clip)
  if (!%n) { return }
  elseif (%n <= 8000) { 
    sockwrite -n $sockname &clip
    hfree _nmp
  }
  else {
    bcopy -c &send 1 &clip 1 8000
    bcopy -c &clip 1 &clip 8001 -1
    hadd -mb _nmp paste &clip
    sockwrite $sockname &send
  }
}
on *:sockread:_nmp:{
  var %s | sockread %s
  while ($sockbr) {
    if ($regex(%s,/<a href="(.*?)">view your paste now<\/a>/i)) {
      var %link = $regml(1)
      $sock($sockname).mark %link
      if ($dialog(nmp)) {
        noop $regex(%link,/(?<=pasteid=)(\d+)/i)
        did -ra nmp 12 %link
        did -a nmp 7 NMP#: $regml(1) -- Pasted successfully.
        did -e nmp 8
      }
      sockclose _nmp | return
    }
    sockread %s
  }
}
on *:sockclose:_nmp:{
  if ($hget(_nmp)) { hfree _nmp }
  if ($dialog(nmp)) { did -e nmp 8 }
}




/*
** url encoding.
** We want to encode our paste of course!
*/
alias -l urlencode {
  returnex $regsubex($1-,/([^\w])/g,$utype(\t))
}
alias -l utype {
  if ($asc($1) == 32) { return + }
  else { return $chr(37) $+ $base($v1,10,16,2) }
}



/*
** nmp dialog goodness
*/

dialog nmp {
  title "nmp"
  size -1 -1 260 177
  option dbu
  text "To:", 2, 2 2 9 8
  combo 3, 12 1 60 100, size drop
  text "HL:", 4, 76 2 10 8
  combo 5, 87 1 60 100, size drop
  button "Paste!", 6, 148 1 30 10
  box "NMP#:", 7, 1 13 258 152
  edit "", 8, 3 23 254 140, multi return hsbar vsbar
  button "Fetch:", 9, 188 1 30 10
  edit "", 10, 219 1 40 10, autohs
  text "Link:", 11, 2 167 12 8
  edit "", 12, 15 166 165 10, read autohs
  button "Load?", 13, 196 166 30 10
  button "Close", 14, 228 166 30 10, ok
}



on *:dialog:nmp:init:*:{
  didtok $dname 5 44 No Hightlighting,mIRC,C#,C++,C,ASP, $+ $&
    Assembler,ColdFusion,Delphi,HTML,Inno,Java,Javascript, $+ $&
    Lisp,MySQL,Pascal,Perl,PHP,Python,Ruby,SQL,TCL,VB.NET, $+ $&
    VB6,XML
  var %ci = 1 , %qi = 1 , %ch = 1
  didtok $dname 3 44 Active (say),Active (echo)
  while ($chan(%ci)) { did -a $dname 3 $chan(%ci) | inc %ci }
  while ($query(%qi)) { did -a $dname 3 $query(%qi) | inc %qi }
  while ($chat(%ch)) { did -a $dname 3 = $+ $chat(%ch) | inc %ch }
  did -c $dname 5 2 | did -c $dname 3 1
}
alias nmphl {
  var %hl = -,mirc,csharp,cpp,c,asp,asm,cfm,delphi,html4strict, $+ $&
    inno,java,javascript,lisp,mysql,pascal,perl,php,python,ruby, $+ $&
    sql,tcl,vbnet,vb,xml
  return $gettok(%hl,$1,44)
}

;on *:dialog:nmp:sclick:15:{
;  if ($did(15).state) { did -n $dname 8 }
;  else { did -m $dname 8 }
;}
on *:dialog:nmp:sclick:13:{
  var %a = $$input(Loading a remote script could be dangerous. $crlf $+ Are you sure you want to do this?,ya,Warning)
  if (!%a) return

  ;------------
  ; The filename.
  ;   Make sure it's valid.
  var %t = $$input(What do you wish to name the file?,e,Name of file?)
  while ($validfname(%t) != 1) var %t = $$input($v1,e,Error)
  if ($nopath(%t) == %t) { var %t = $scriptdir $+ %t }
  var %t = $qt(%t)

  ;------------
  ; Load it from
  ;   The dialog, or the original source file.
  var %input = Do you want to load it from the dialog? $&
    $crlf $+ If you choose "No" it will load from the getnmp.txt instead.
  if ($input(%input,y,Load it from..)) { filter -if $dname 8 %t }
  else { filter -ff getnmp.txt %t }
  load -rs %t
  echo -a *** getnmp: Script ( $qt(%t) ) has been loaded. $&
    If you wish to unload it: /unload -rs %t
}
alias validfname {
  var %p = $nofile($1-) , var %f = $nopath($1-)
  if (%p && $isdir($qt(%p))) { return Error: Invalid path specified. $+ $crlf $+ If you wish to use this path, please make the folder first. }
  if ($isfile($+(%p,%f)) { return Error: That file already exists. }
  if ($count(%f,|,\,/,<,>,?,",*,:)) { return Error: Invalid file name, file names can not contain: $+ $crlf $+ |\/<>?"*: }
  return 1
}
on *:dialog:nmp:sclick:9:{
  if ($did(10) isnum) { var %d = $v1 }
  elseif ($regex($did(10),/pasteid=(\d+)/)) { var %d = $v1 }

  if (%d) { getnmp %d }
}
on *:dialog:nmp:sclick:6:{
  if ($sock(_nmp)) return
  if ($did(8)) {
    if ($did(nmp,3).sel != 2) {
      var %say = s , %w = $iif($v1 == 1,$active,$did(nmp,3))
      if (!$istok(channel chat query,$window(%w).type,32)) {
        noop $input(The output must be an open channel/chat/query.,o,Warning: Output.)
        return
      }
    }
    if ($did(nmp,5).sel) { var %lang = &lang= $+ $nmphl($v1) }
    bset -t &paste 1 action=addpaste&q=·¸§½±&verifier=HGXBN $+ %lang $+ &body=
    var %i = 1, %pos 
    while (%i <= $did(nmp,8).lines) {
      %pos = $bvar(&paste, 0) + 1
      bset -t &paste %pos $urlencode($did(nmp,8,%i)) $+ $crlf
      inc %i
    }
    did -b nmp 8
    hadd -mb _nmp paste &paste
    nmp -b $+ %say %w
  }
}

/*
**
** getnmp: Fetching the code, and sending it to the nmp dialog.
**
**
*/

alias getnmp {
  if ($regex($1,/^\-([dc]+)$/)) {
    var %s = $regml(1)
    if (d isin %s) { dialog -md nmp nmp | return }
    if (c isin %s) { sockclose getnmp }
    tokenize 32 $2
  }
  if ($1 !isnum) { echo -a *** GetNMP: Error, you must specify an ID. | return }
  if ($sock(getnmp)) { echo -a *** GetNMP: Error, sock is already open. | return }
  if ($isfile(getnmp-temp.txt)) { .remove getnmp-temp.txt }
  if ($dialog(nmp)) {
    did -b nmp 8
    did -r nmp 10
    did -a nmp 7 NMP#: ???? -- Fetching a paste...
  }
  sockopen getnmp www.nomorepasting.com 80
  sockmark getnmp $1
}
on *:sockopen:getnmp:{
  var %% = sockwrite -n $sockname
  %% GET /getpaste.php?pasteid= $+ $sock($sockname).mark $+ &seen=true&langoverride=- HTTP/1.0
  %% Host: www.nomorepasting.com
  %%
}

on *:sockread:getnmp:{
  if ($sockerr) return
  sockread &data
  while ($sockbr) {
    bwrite getnmp-temp.txt -1 -1 &data
    sockread &data
  }
}
on *:sockclose:getnmp:{
  var %s = $file(getnmp-temp.txt).size
  bread getnmp-temp.txt 0 %s &ifile
  var %begin = $bfind(&ifile,0,<pre>) , %end = $bfind(&ifile,1,</pre>)

  if (%begin && %end) {
    var %pos.a = %begin + 5 , %pos.b = %end - %pos.a
    bcopy &ofile 1 &ifile %pos.a %pos.b

    var %i = 1, %bin = $bvar(&ofile,0)

    while ($bfind(&ofile,%i,&)) { 
      var %a = $bfind(&ofile,%i,&) , %b = $bfind(&ofile,%a,;) + 1
      var %len = %b - %a , %otherlen = %a - %i
      if (%len > 10) { var %i = %b + 1 | continue }
      bcopy &file $blen &ofile %i %otherlen
      bset &file $blen $_rep(%a,%len)
      var %i = %b
    }
    if (%i < %bin) { bcopy &file $blen &ofile %i -1 }
    write -c getnmp.txt
    bwrite getnmp.txt 0 -1 &file
    .signal getnmp $sock($sockname).mark
  }
  else {
    if ($dialog(nmp)) { did -e nmp 8 }
    echo -a *** Error: Could not retrieve the paste.
  }
  .remove getnmp-temp.txt
}

alias -l blen { return $calc($bvar(&file,0) + 1) }
alias -l _rep { 
  var %t = $bvar(&ofile,$1,$2).text
  var %t = $replace(%t,&amp;,&,&nbsp;,$chr(32),&quot;,",&gt;,>,&lt;,<)
  var %t = $regsubex(%t,/(.)/g,$asc(\t) $+ $chr(32))
  returnex %t
}


on *:signal:getnmp:{
  var %size = $file(getnmp.txt)
  if (%size <= $calc(30*1024 - 50)) {
    if (!$dialog(nmp)) dialog -md nmp nmp
    if (!$dialog(nmp).active) dialog -v nmp
    filter -foc getnmp.txt nmp 8
    did -e nmp 8
    did -a nmp 7 NMP#: $1 -- Fetched successfully.
    did -ra nmp 12 http://www.nomorepasting.com/getpaste.php?pasteid= $+ $1
  }
  else {
    if (!$window(@getnmp)) { window -ae @getnmp }
    filter -fwpc getnmp.txt @getnmp
  }
}

/*
** This is where we'll catch incoming links, and echo another line
** to your window, which will contain a clickable "ID" so you can
** simply click it, and the script will automate fetching the paste.
*/

alias getnmpCatcher {
  var %g = #getnmpCatcher , %s = $group(%g)
  if ($1 == on) { .enable %g }
  elseif ($1 == off) { .disable %g }
  elseif (!$0) {
    var %e = echo -ag *** getnmpCatcher
    if (%s == on) { .disable %g | %e disabled. }
    else { .enable %g | %e enabled. }
  }
}

#getnmpCatcher on
on *:text:*http*nomorepasting.com*:*:{
  var %w = $iif($target == $me,$nick,$target)
  if ($regex($1-,/http:\/{2}(?:www\.)?nomorepasting\.com\/getpaste.php\?\S*pasteid=(\d+)/)) {
    echo -gtci3 normal %w *** NMP link posted by $nick $+ , fetch it? 4[ $+ $regml(1) $+ ]
  }
}
on ^$*:hotlink:/\[(\d+)\]/:*:{
  if ($regex($1,/NMP link posted by \S+ fetch it. .+/iS)) { return }
  if (* NMP link posted by * iswm $hotline) { return }
  halt
}
on $*:hotlink:/\[(\d+)\]/:*:{
  if (* NMP link posted by * iswm $hotline) { getnmp $regml(1) }
}
#getnmpCatcher end