diff options
| author | Jules Laplace <jules@okfoc.us> | 2016-11-15 13:40:06 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2016-11-15 13:40:06 -0500 |
| commit | 94ade9321a971e81c383e14186bf4c776bd304fc (patch) | |
| tree | ad37ec8434e302388b8694035678930dcf58911b /lib | |
| parent | d2a3fd6856265751b499c5f8921f450501b879c5 (diff) | |
parse links
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/index.js | 13 | ||||
| -rw-r--r-- | lib/panda.js | 7 | ||||
| -rw-r--r-- | lib/plinko.js | 20 |
3 files changed, 34 insertions, 6 deletions
diff --git a/lib/index.js b/lib/index.js index 8770fe1..7883c3f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,6 +2,7 @@ require('dotenv').config() var panda = require('./panda') +var plinko = require('./plinko') var server = require('./server') var router = server.init() @@ -13,7 +14,7 @@ var storage = multer.memoryStorage() var multer_upload = multer({ storage: storage }) var upload = require("./upload") -router.post("/service/image", multer_upload.single('image'), function(req, res){ +router.post("/_irc/image", multer_upload.single('image'), function(req, res){ upload.put("image", req.file, { unacceptable: function(err){ res.json({ error: err }) @@ -24,8 +25,10 @@ router.post("/service/image", multer_upload.single('image'), function(req, res){ }) }) -router.get("/irc/links", function(req, res){ - panda.query("links", function(links){ - res.json(links) - }) +router.get("/_irc/links", function(req, res){ +// panda.query("links", function(links){ +// res.json( plinko.parse_links(links) ) +// }) + links = ["\u00033,1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx links for 11/15/2016","\u00033<\u00033noisia\u00033>\u000315 http://imgur.com/9uoPXyL","\u00033<\u00033noisia\u00033>\u000315 https://usercontent.irccloud-cdn.com/file/CY0a0Fmw/Screen%20Shot%202016-11-14%20at%206.33.29%20PM.png","\u00033<\u00037ffog\u00033>\u000315 http://www.cmgreport.com/breaking-news-george-soros-has-died-possible-heart-attack/","\u00033<\u000311noth\u00033>\u000315 https://www.youtube.com/watch?v=JJXspT2VtOE","\u00033<\u000311noth\u00033>\u000315 https://www.youtube.com/watch?v=Zj5v5bO0K4I","\u00033<\u00030fanfare\u00033>\u000315 https://twitter.com/kincannon_show/status/798264132055302144","\u00033<\u00030thorns\u00033>\u000315 http://jollo.org/LNT/public/cQcOoZqY.html","\u00033,1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx type: menu"] + res.json( plinko.parse_links(links) ) }) diff --git a/lib/panda.js b/lib/panda.js index 0a6b520..d7c2133 100644 --- a/lib/panda.js +++ b/lib/panda.js @@ -55,12 +55,15 @@ console.log("connecting..") client.addListener('registered', function (message) { console.log("..registered!") }) + client.addListener('motd', function (motd) { console.log("..got motd!") }) + client.addListener('error', function (err) { console.log("..error!", err) }) + client.addListener('join', function (channel, nick, message) { console.log("* " + nick + " joined " + channel) if (nick == 'panda' && channel == '#sally') { @@ -78,6 +81,9 @@ client.addListener('pm', function (nick, text, message) { current_task.timeout = setTimeout(task_over, TASK_DELAY) current_task.response.push(text) } + else { + console.log("*" + nick + "*", text) + } }) function task_over (){ @@ -90,5 +96,4 @@ function task_over (){ done() } - module.exports = panda diff --git a/lib/plinko.js b/lib/plinko.js new file mode 100644 index 0000000..f4c662f --- /dev/null +++ b/lib/plinko.js @@ -0,0 +1,20 @@ +var stripColorCodesRegexp = /\u00031?\d(,?1?\d)?/g +var stripHTMLRegexp = /[<>"]/g + +var plinko = module.exports = {} + +plinko.parse_links = function(links){ + var header = links.shift() + var footer = links.pop() + return links.map(function(link,i){ + var partz = link.split(" ").map(plinko.strip_color_codes) + return { + nick: partz[0].replace(stripHTMLRegexp, ""), + url: partz[1], + } + }) +} + +plinko.strip_color_codes = function(s){ + return (s || "").replace(stripColorCodesRegexp, "") +}
\ No newline at end of file |
