git ssb

0+

Dominic / ssb-irc



Commit 84264ad623514504ac769c561b7e7b10a163e69a

fix everything

Dominic Tarr committed on 7/20/2017, 10:47:23 AM
Parent: f48fb1aaaee24b2d0214b1f4aa1f66f3dec41972

Files changed

index.jschanged
irc.jschanged
ssb.jschanged
index.jsView
@@ -1,6 +1,7 @@
11 var ssb = require('./ssb')
22 var IRC = require('./irc')
3 +var pull = require('pull-stream')
34 //this should just wrap the stuff in util.js
45
56 exports.name = 'irc'
67 exports.version = '1.0.0'
@@ -9,12 +10,12 @@
910 exports.init = function (sbot, config) {
1011 //
1112 var n = 2
1213 //load current state
13- var state = ssb.init(sbot, process.argv[2] || sbot.id, next)
14 + var state = ssb.init(sbot, sbot.id, next)
1415 var irc = IRC(config, next)
1516
16-
17 + console.log("STATE", state)
1718 function notify (note) {
1819 irc.say(
1920 note.type == 'channel'
2021 ? IRC.toChannel(note.target)
@@ -23,15 +24,16 @@
2324 ssb.render(note, ssb.link(note.id, config))
2425 )
2526 }
2627
27- function next (err, state) {
28 + function next () {
2829 if(--n) return
2930 //XXX: properly persist state with a flumeview?
3031
3132 //make sure we have joined every channel
3233 for(var k in state.channels) {
33- var channel = state.channels[k]
34 + var channel = state.channels[k] === true ? k : state.channels[k]
35 + console.log("JOIN", channel)
3436 IRC.join(irc, channel)
3537 }
3638
3739 //only notify about live posts.
@@ -41,16 +43,14 @@
4143 pull(
4244 sbot.createLogStream({live: true}),
4345 pull.drain(function (msg) {
4446 if(msg.sync) return
45- var a = tests.reduce(function (found, test) {
46- return found.concat(exports.match(state, msg) || [])
47- }, [])
48-
47 + var a = ssb.match(state, msg)
4948 if(a.length)
5049 a.forEach(notify)
5150 })
5251 )
5352 }
5453 }
5554
5655
56 +
irc.jsView
@@ -5,10 +5,23 @@
55 conf.host || 'irc.freenode.net',
66 conf.port || 6667,
77 conf.name || 'ssbbot'
88 )
9- irc.connect()
9 + ;(function connect() {
10 + irc.connect()
11 + irc.client.on('error', reconnect)
12 + irc.client.on('close', reconnect)
13 + var retry = false
14 + function reconnect () {
15 + if(retry) return
16 + retry = true
17 + setTimeout(connect, 10e3)
18 + }
19 + })
1020 irc.on('ready', cb)
21 + irc.on('error', function () {
22 +
23 + })
1124 return irc
1225 }
1326
1427 IRC.toChannel = function (channel) {
@@ -33,29 +46,32 @@
3346 irc.say(nick, message)
3447 }
3548
3649
37-if(!module.parent) {
38- var ssb = require('./ssb')
39- var irc = IRC({}, function (err) {
40- var note = {
41- author: 'dominic',
42- target: 'domanic',
43- text: 'test 1 2 3, @domanic',
44- id: '%v6y1c1VYXthYbNYh0RqmXfC18HyhHnozDN3ZhrWLThU=.sha256'
45- }
46- var config = {}
50 +//if(!module.parent) {
51 +// var ssb = require('./ssb')
52 +// var irc = IRC({}, function (err) {
53 +// var note = {
54 +// author: 'dominic',
55 +// target: 'domanic',
56 +// text: 'test 1 2 3, @domanic',
57 +// id: '%v6y1c1VYXthYbNYh0RqmXfC18HyhHnozDN3ZhrWLThU=.sha256'
58 +// }
59 +// var config = {}
60 +//
61 +// function notify (note) {
62 +// irc.say(
63 +// note.type == 'channel'
64 +// ? IRC.toChannel(note.target)
65 +// : note.target
66 +// ,
67 +// ssb.render(note, ssb.link(note.id, config))
68 +// )
69 +// }
70 +//
71 +// notify(note)
72 +// })
73 +//}
74 +//
4775
48- function notify (note) {
49- irc.say(
50- note.type == 'channel'
51- ? IRC.toChannel(note.target)
52- : note.target
53- ,
54- ssb.render(note, ssb.link(note.id, config))
55- )
56- }
5776
58- notify(note)
59- })
60-}
6177
ssb.jsView
@@ -36,11 +36,14 @@
3636 })
3737 )
3838 })
3939 )
40 +
4041 return state
4142 }
4243
44 +exports.init = init
45 +
4346 function toKey(fn) {
4447 return function (state, msg) {
4548 var key
4649 if(msg.key) {
@@ -148,9 +151,9 @@
148151 exports.isUserMention,
149152 exports.isUserFollow
150153 ]
151154
152-exports.match = function (msg) {
155 +exports.match = function (state, msg) {
153156 return exports.tests.reduce(function (found, test) {
154157 return found.concat(test(state, msg) || [])
155158 }, [])
156159
@@ -172,29 +175,29 @@
172175 exports.link = function (id, config) {
173176 return ((config && config.irc && config.irc.domain) || "http://viewer.scuttlebot.io") + '/' + encodeURIComponent(id)
174177 }
175178
176-if(!module.parent) {
177- //this is just for testing...
178- require('ssb-client')(function (err, sbot) {
179- if(err) throw err
180- var state = init(sbot, process.argv[2] || sbot.id, function (err, state) {
181-
182- console.log(state)
183- //XXX: properly persist state with a flumeview?
184-
185- pull(
186- sbot.createLogStream({}),
187- pull.drain(function (msg) {
188- if(msg.sync) return
189- var a = tests.reduce(function (found, test) {
190- return found.concat(exports.match(state, msg) || [])
191- }, [])
192- if(a.length) {
193-
194- }
195- })
196- )
197- })
198- })
199-}
200-
179 +//if(!module.parent) {
180 +// //this is just for testing...
181 +// require('ssb-client')(function (err, sbot) {
182 +// if(err) throw err
183 +// var state = init(sbot, process.argv[2] || sbot.id, function (err, state) {
184 +//
185 +// console.log(state)
186 +// //XXX: properly persist state with a flumeview?
187 +//
188 +// pull(
189 +// sbot.createLogStream({}),
190 +// pull.drain(function (msg) {
191 +// if(msg.sync) return
192 +// var a = tests.reduce(function (found, test) {
193 +// return found.concat(exports.match(state, msg) || [])
194 +// }, [])
195 +// if(a.length) {
196 +//
197 +// }
198 +// })
199 +// )
200 +// })
201 +// })
202 +//}
203 +//

Built with git-ssb-web