git ssb

0+

Dominic / ssb-irc



Tree: 84264ad623514504ac769c561b7e7b10a163e69a

Files: 84264ad623514504ac769c561b7e7b10a163e69a / index.js

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

Built with git-ssb-web