All pastes #1097233 Raw Edit

Something

public text v1 · immutable
#1097233 ·published 2008-08-09 19:40 UTC
rendered paste body
3B Pastebin Clipboard Uploader v0.1 created by Chessnut
; Type /pastebin or right-click and select "Pastebin Clipboard"
; to upload the entire contents of the clipboard to pastebin.ca
; and return the submission URL.

alias urlencode { var %a = $regsubex($$1,/([^\w\s])/Sg,$+(%,$base($asc(\t),10,16,2))) | return $replace(%a,$chr(32),$chr(43)) }
alias pastebin { if ($sock(pastebin)) .sockclose pastebin | sockopen pastebin pastebin.ca 80 }
menu status,query,nicklist,channel {
  Pastebin Clipboard:/pastebin
}

on *:sockopen:pastebin: {
  var %y = 1
  $iif($exists(pbindata),btrunc pbindata 1,bwrite pbindata -1 -1 X)
  set %pbfirst $left($cb(1),30) $+ ...
  while (%y <= $cb(0)) {
    if ($cb(%y) != $null) {
      bwrite pbindata -1 -1 $+($iif($left($urlencode($cb(%y)),1) == %,$right($urlencode($cb(%y)),-1),$urlencode($cb(%y))),$iif(%y != $cb(0),$+($chr(37),0D))) $+ $iif($regex($cb($calc(%y + 1)),/^[^A-Za-z ]/) || $cb($calc(%y + 1)) == $null && $cb(0) != %y,$chr(37))
    }
    else bwrite pbindata -1 -1 $+(0D,$chr(37),0A) $+ $iif($regex($cb($calc(%y + 1)),/^[^A-Za-z ]/) || $cb($calc(%y + 1)) == $null && $cb(0) != %y,$chr(37))
    inc %y
  }
  sockwrite -nt $sockname POST /index.php? HTTP/1.1
  sockwrite -nt $sockname Host: pastebin.ca
  sockwrite -nt $sockname Content-Type: application/x-www-form-urlencoded
  bread pbindata 1 $file(pbindata).size &appstring
  sockwrite -nt $sockname Content-Length: $calc($len(content=&s=Submit+Post&description=&type=1&expiry=&name=) + $file(pbindata).size)
  sockwrite -t $sockname $crlf content=
  var %x = 1
  while (%x <= $calc($file(pbindata).size + 900)) {
    if ($bvar(&appstring, %x, 900).text) sockwrite $sockname $bvar(&appstring, %x, 900).text
    inc %x 900
  }
  sockwrite -nt $sockname &s=Submit+Post&description=&type=1&expiry=&name=
}

on *:sockread:pastebin: {
  if ($sockerr) halt
  else {
    var %sockreader
    sockread %sockreader
    if ($regex(%sockreader,/<meta http-equiv="refresh" content="7;(.*?)"/)) {
      echo -a Pastebin URL for $+($chr(3),04) $+ $qt(%pbfirst) $+ : $+($chr(3),12,$chr(31)) $+ $regml(1)
      clipboard $regml(1)
      unset %pbfirst
      sockclose $sockname
    }
  }
}