maria commented on a Page, Reddit Latest Post & Comment Watcher  -  Jul 04, 2012

too late. fixed everything. lol....

jethro, thank you for starting this project and creating something useful, without your help i wouldn't have been able to finish this off myself.

here's a Sub-Reddit Post .JSON Feed to Channel Script;

alias -l reddit {
  hadd -m reddit callback msg $1
  hadd reddit attr.count 0
  hdel reddit rcvd
  var %sockname = reddit2
  if ($sock(%sockname)) sockclose $v1
  sockopen %sockname www.reddit.com 80
}
alias -l trans {
  return $replace($1,&lt;,<,&gt;,>,&quot;,",&nbsp;,$chr(160),&amp;,&,&amp;#39;,')
}

on *:sockopen:reddit2:{
  if ($sockerr) { 
    echo 4 -ag $gettok($sock(reddit).mark,2,32) Error Connecting to $sock(reddit).addr
  }
  var %reddit2 = sockwrite -nt reddit2
  %reddit2 GET $+(/r/,%reddits,/new.json?sort=new&limit=1,$iif($hget(reddit,id),&after= $+ $v1)) HTTP/1.0-
  %reddit2 Cache-Control: max-age=0
  %reddit2 Connection: close
  %reddit2 User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
  %reddit2 Host: $+($sock($sockname).addr,$str($crlf,2))
}

on *:sockread:reddit2:{
  if ($sockerr) { 
    echo 4 $gettok($sock(reddit).mark,2,32) Error Reading $sock(reddit).addr
    return
  }
  sockread &reddit2
  noop $hget(reddit,rcvd,&rcvd)
  bcopy &rcvd $calc($bvar(&rcvd,0) + 1) &reddit2 1 -1
  hadd -b reddit rcvd &rcvd
}

on *:sockclose:reddit2:{
  reddit.finished
}

alias reddit.finished {
  noop $hget(reddit,rcvd,&rcvd)

  var %g2 = $bvar(&rcvd,1-).text
  if ($regex(%g2,/"title"\: "(.*)"/)) {
    hadd -m reddit title $gettok($trans($regml(1)),1,34)
    hinc reddit attr.count
  }
  if ($regex(%g2,/"id"\: "(.*)"/)) {
    hadd -m reddit status old
    if ($hget(reddit,id) != $gettok($trans($regml(1)),1,34)) {
      hadd -m reddit id $v2
      hadd -m reddit status new
      hinc reddit attr.count
    }
  }
  if ($regex(%g2,/"author"\: "(.*)"/)) { 
    hadd -m reddit author $gettok($regml(1),1,34)
    hinc reddit attr.count
  }

  if ($hget(reddit,status) == new) && ($hget(reddit,attr.count) == 3) {
    $hget(reddit,callback) $&
      $chr(29) $+ $hget(reddit,title) $+ $chr(29) - $+(http://redd.it/,$hget(reddit,id)) by 12 $+ $hget(reddit,author)
  }
}

on me:*:join:#reddit:{
  if (%true) notice $me Reddit has been toggled off. Right-click on $&
    the nicklist or channel to toggle it on. | unset %true
}
on *:disconnect: if (%reddits) $+(.timer,#,$network) off | set -e %true 1
on me:*:part:#: if (%reddits) $+(.timer,#,$network) off | set -e %true 1
on *:kick:#:{
  if ($knick == $me) && (%reddits) $+(.timer,#,$network) off
  set -e %true 1
}
on *:quit:{
  if ($nick == $me) && (%reddits) {
    var %c = 1
    while ($comchan($me,%c)) {
      $+(.timer,$v1,$network) off
      set -e %true 1
      inc %c
    }
  }
}

menu channel,nicklist {
  Reddit
  .ON {
    if (!%reddits) {
      set -e %reddits $$?"Which Reddit to Watch?"
      set -e %reddittime $$?"How often do you want the latest post checked $&
        and sent to the channel in seconds?"
      $+(.timer,#,$network) 0 %reddittime reddit #
      echo 2 # * Reddit Set for: $+($chr(2),%reddits)
      echo 2 # * Time Interval in Seconds: $+($chr(2),%reddittime)
      if (%true) unset $v1
    }
    else echo 4 # * Reddit is Already Switched On!
  }
  .OFF { 
    if (%reddits) {
      $+(.timer,#,$network) off 
      echo 2 * Reddit Has Been Turned Off!
      unset %reddit* %true
    }
    else echo 4 # * Reddit is Already Switched Off!
  }
}
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.