Files: f48fb1aaaee24b2d0214b1f4aa1f66f3dec41972 / index.js
1219 bytesRaw
1 | var ssb = require('./ssb') |
2 | var IRC = require('./irc') |
3 | //this should just wrap the stuff in util.js |
4 | |
5 | exports.name = 'irc' |
6 | exports.version = '1.0.0' |
7 | exports.manifest = {} |
8 | |
9 | exports.init = function (sbot, config) { |
10 | // |
11 | var n = 2 |
12 | //load current state |
13 | var state = ssb.init(sbot, process.argv[2] || sbot.id, next) |
14 | var irc = IRC(config, next) |
15 | |
16 | |
17 | function notify (note) { |
18 | irc.say( |
19 | note.type == 'channel' |
20 | ? IRC.toChannel(note.target) |
21 | : note.target |
22 | , |
23 | ssb.render(note, ssb.link(note.id, config)) |
24 | ) |
25 | } |
26 | |
27 | function next (err, state) { |
28 | if(--n) return |
29 | //XXX: properly persist state with a flumeview? |
30 | |
31 | //make sure we have joined every channel |
32 | for(var k in state.channels) { |
33 | var channel = state.channels[k] |
34 | IRC.join(irc, channel) |
35 | } |
36 | |
37 | //only notify about live posts. |
38 | //this may cut out if the connection to IRC drops |
39 | //though, since |
40 | |
41 | pull( |
42 | sbot.createLogStream({live: true}), |
43 | pull.drain(function (msg) { |
44 | if(msg.sync) return |
45 | var a = tests.reduce(function (found, test) { |
46 | return found.concat(exports.match(state, msg) || []) |
47 | }, []) |
48 | |
49 | if(a.length) |
50 | a.forEach(notify) |
51 | }) |
52 | ) |
53 | } |
54 | } |
55 | |
56 | |
57 |
Built with git-ssb-web