Skip to content

Instantly share code, notes, and snippets.

@jwheare
Forked from jhs/irccloud_search.js
Last active December 29, 2015 18:59
Show Gist options
  • Save jwheare/7714469 to your computer and use it in GitHub Desktop.
Save jwheare/7714469 to your computer and use it in GitHub Desktop.
var request = require('request')
var COOKIE = 'session=2.blahblahblah' // copy your site cookie in here
var CID = 1234; // copy the connection id here
var BID = 1234; // copy the buffer id here
var SINCE = +process.env.since // optional: set an environment variable "since" to offset the log
get_lines(SINCE);
function get_lines(beforeid) {
var headers = { 'Cookie': COOKIE }
var url = "https://www.irccloud.com/chat/backlog?bid=" + BID + "&cid=" + CID + "&num=1000";
if (beforeid) {
url += "&beforeid=" + beforeid;
}
console.log('Fetching: %s', url)
request({'url':url, 'headers':headers, 'json':true}, function(er, res, body) {
if(er) throw er
if(!Array.isArray(body))
throw new Error('Bad body: ' + JSON.stringify(body))
var first_id = body[0].eid
console.log('Got %d up to %d', body.length, first_id)
var highlights = body.reverse().filter(function(M) { return M.highlight })
if(highlights.length) {
console.log('')
highlights.forEach(function(M) {
if(! process.env.dir)
console.log('>>> %d <<< %s', M.eid, M.msg || M.eid)
else
console.dir(M)
})
console.log('')
}
get_lines(first_id)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment