summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/index.js17
-rw-r--r--lib/panda.js29
-rw-r--r--lib/server.js12
3 files changed, 41 insertions, 17 deletions
diff --git a/lib/index.js b/lib/index.js
index 7883c3f..6ec87a2 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -14,6 +14,7 @@ var storage = multer.memoryStorage()
var multer_upload = multer({ storage: storage })
var upload = require("./upload")
+
router.post("/_irc/image", multer_upload.single('image'), function(req, res){
upload.put("image", req.file, {
unacceptable: function(err){
@@ -26,9 +27,15 @@ router.post("/_irc/image", multer_upload.single('image'), function(req, res){
})
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) )
+ panda.query("plinko", "links", function(links){
+ res.json( plinko.parse_links(links) )
+ })
+})
+
+router.post("/_irc/post", require('body-parser').urlencoded({ extended: false }), function(req, res){
+ var lines = req.body.image.split("\n")
+ lines.forEach(function(line){
+ panda.say(panda.channels[0], line)
+ })
+ res.sendStatus(200)
})
diff --git a/lib/panda.js b/lib/panda.js
index 502129e..4b4b350 100644
--- a/lib/panda.js
+++ b/lib/panda.js
@@ -6,6 +6,8 @@ var TASK_DELAY = 800
var panda = {}
+panda.channels = process.env.IRC_CHANNELS.split(",")
+
var client = panda.client = new irc.Client( process.env.IRC_SERVER, process.env.IRC_NICK, {
userName: process.env.IRC_NAME,
realName: process.env.IRC_REALNAME,
@@ -15,7 +17,7 @@ var client = panda.client = new irc.Client( process.env.IRC_SERVER, process.env.
showErrors: false,
autoRejoin: false,
autoConnect: true,
- channels: process.env.IRC_CHANNELS.split(","),
+ channels: panda.channels,
secure: process.env.IRC_SSL == "true",
selfSigned: process.env.IRC_SSL == "true",
certExpired: false,
@@ -30,8 +32,21 @@ var client = panda.client = new irc.Client( process.env.IRC_SERVER, process.env.
encoding: ''
})
-panda.query = function(msg, cb){
+panda.login = function(){
+ console.log("logging in..")
+ panda.query("plinko", "login b1gb34rc4t", function(msg){
+ console.log("..logged in", msg)
+ panda.ready = true
+ })
+}
+
+panda.say = function(nick, msg){
+ client.say(nick, msg)
+}
+
+panda.query = function(nick, msg, cb){
message_queue.push({
+ nick: nick,
msg: msg,
cb: cb,
})
@@ -47,7 +62,7 @@ var message_queue = async.queue(function(task, done){
current_task.response = []
current_task.timeout = 0
current_task.done = done
- client.say("plinko", task.msg)
+ client.say(task.nick, task.msg)
}, 1)
console.log("connecting..")
@@ -67,16 +82,12 @@ client.addListener('error', function (err) {
client.addListener('join', function (channel, nick, message) {
console.log("* " + nick + " joined " + channel)
if (nick == 'panda' && channel == '#sally') {
- console.log("logging in..")
- panda.query("login b1gb34rc4t", function(msg){
- console.log("..logged in", msg)
- panda.ready = true
- })
+ panda.login()
}
})
client.addListener('pm', function (nick, text, message) {
if (! current_task) return
- if (nick === "plinko") {
+ if (nick === current_task.nick) {
clearTimeout(current_task.timeout)
current_task.timeout = setTimeout(task_over, TASK_DELAY)
current_task.response.push(text)
diff --git a/lib/server.js b/lib/server.js
index 887b9aa..64c19a4 100644
--- a/lib/server.js
+++ b/lib/server.js
@@ -27,14 +27,13 @@ site.init = function(){
cookie: { secure: true }
}))
app.use(express.static( path.join(__dirname, '../public')))
-/*
- app.set('views', path.join(__dirname, '/views'))
+
+ app.set('views', path.join(__dirname, '../views'))
app.set('view engine', 'liquid')
app.engine('liquid', expressLiquid({
traceError: false
}))
app.use(expressLiquid.middleware)
-*/
var csrfMiddleware = csrf()
@@ -54,6 +53,13 @@ site.init = function(){
var router = new express.Router
app.use(router)
+ var csrfMiddleware = csrf()
+ router.post("*", csrfMiddleware)
+ router.get("/", csrfMiddleware, function(req,res){
+ res.locals._csrf = req.csrfToken()
+ res.render("index")
+ })
+
return router
}
site.http = function(app){