Files: 3cd5d5225307fd500aaea83a68cbed379ce6ac72 / index.js
1332 bytesRaw
1 | var client = require('ssb-client'); |
2 | var pull = require('pull-stream'); |
3 | var moment = require('moment'); |
4 | var app = require('koa')(); |
5 | var router = require('koa-router')(); |
6 | var views = require('co-views'); |
7 | |
8 | var port = 1337; |
9 | var me = '@8Qee0I/DwI5DHSCi3p5fsl6FyLGArrnDz3ox9qZr5Qc=.ed25519' |
10 | var message = 'I said nothing'; |
11 | |
12 | client(function (err, sbot) { |
13 | if (err) { |
14 | throw err; |
15 | } |
16 | pull(sbot.createUserStream({ |
17 | id: me, |
18 | limit: 1, |
19 | reverse: true |
20 | }), |
21 | pull.drain(function printMessage(msg) { |
22 | date = moment(msg.value.timestamp).fromNow() |
23 | if (msg.value.content.type === 'post') { |
24 | message = (msg.value.content.text) |
25 | } |
26 | else if (msg.value.content.type === 'vote') { |
27 | message = ('I dug ' + msg.value.content.vote.link) |
28 | } |
29 | else if (msg.value.content.type === 'about') { |
30 | message = ('I identified ' + msg.value.content.about + ' as ' + msg.value.content.name) |
31 | } |
32 | else if (msg.value.content.type === 'git-update') { |
33 | message = ('I pushed a commit ') |
34 | } |
35 | else { |
36 | message = ('I sent a private message ') |
37 | } |
38 | })); |
39 | app.use(router.routes()) |
40 | app.use(router.allowedMethods()) |
41 | |
42 | var render = views(__dirname, { ext: 'jade'}); |
43 | |
44 | router.get('/', function *(next) { |
45 | this.body = yield render('index', {title: 'sdash', message, date}); |
46 | }); |
47 | app.listen(port); |
48 | }); |
49 | |
50 |
Built with git-ssb-web