Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

FOSS node.js Shiichan post bot

Name: Anonymous 2013-08-16 23:31

var http = require('http')
var querystring = require('querystring')
function PostData(data, handler) {
  var string = ""
  http.request({
    host:    "dis.4chan.org",
    path:    "/post",
    method:  "POST",
    headers: {
      'content-type': "application/x-www-form-urlencoded",
      'content-length': data.length
    }
  }, function(res) {
    console.log('STATUS: ' + res.statusCode)
    console.log('HEADERS: ' + JSON.stringify(res.headers))
    res.setEncoding('utf8')
  }).on('response', function(response){
    response.on('data', function(chunk){ string += chunk })
    response.on('end', function(){ handler(string) })
  }).end(data)
}
function MakeMessage(data) {
  return querystring.stringify({
    bbs:      data.board,
    id:       data.thread,
    shiichan: "proper2",
    kotehan:  data.name,
    meiru:    data.email,
    com:      data.message,
    email:    "'"
  })
}
function PostMessage(data, handler) {
  PostData(MakeMessage(data), handler)
}
function TestMessage(data, handler) {
  console.log(MakeMessage(data))
  handler("")
}
function GetData(path, handler) {
  var string = ""
  http.get({host: "dis.4chan.org", path: path}, function(res) {
    console.log('STATUS: ' + res.statusCode)
    console.log('HEADERS: ' + JSON.stringify(res.headers))
    res.setEncoding('utf8')
  }).on('response', function(response){
    response.on('data', function(chunk){ string += chunk })
    response.on('end', function(){ handler(string) })
  })
}
function GetBoardData(board, handler) {
  GetData("/" + board + "/subject.txt", function(s){
    handler(function(){
      var o = s.split("\n").map(function(s){
      var a = s.split(/<>/)
      return {
        subject: a[0],
        op:      a[1],
        icon:    a[2],
        id:      a[3],
        last:    a[4],
        lp:      a[5],
        endtime: a[6],
      }})
      o.pop()
      return o
    }())
  })
}
function GetThreadData(board, thread, handler) {
  GetData("/json/" + board + "/" + thread, function(s){
    handler(JSON.parse(s))
  })
}
function ReadyForDubs(t) {
    var s = t.last.toString()
    var n = s.length
    if (n < 2) return false
    return ((s[n-1] == '9' && s[n-2] == '9') || +s[n-2] == s[n-1]+1)
}
function HasDubs(t) {
    var s = t.last.toString()
    var n = s.length
    if (n < 2) return false
    return (s[n-2] == s[n-1])
}
function MakePostWhere(poster, board, pred, datasrc) {
  GetBoardData(board, function(descr){
    function call(i){
      if (pred(descr[i])) {
        PostMessage(datasrc({
          board: board,
          thread: descr[i].id
        }, descr[i]), function(res){
          if (i + 1 < descr.length) setTimeout(call, 4700, i + 1)
        })
      } else if (i + 1 < descr.length) setImmediate(call, i + 1)
    }
    setImmediate(call, 0)
  })
}
MakePostWhere(PostMessage, "prog", HasDubs, function(p, t){
  p.message = ">>" + t.last + "\nNice dubs, bro!"
  return p
})

Name: Anonymous 2013-08-17 2:29

>>6
umena curl?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List