git ssb

0+

Dominic / ssb-irc



Tree: 6c6b3aeb35148f475c0f590a5bcbe2288be61d5e

Files: 6c6b3aeb35148f475c0f590a5bcbe2288be61d5e / irc.js

1568 bytesRaw
1var IRC = module.exports = function (config, cb) {
2 var IRC = require('node-irc')
3 var conf = config.irc || {}
4 var irc = new IRC(
5 conf.host || 'irc.freenode.net',
6 conf.port || 6667,
7 conf.name || 'ssbbot'
8 )
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 })
20 irc.on('ready', cb)
21 irc.on('error', function () {
22
23 })
24 return irc
25}
26
27IRC.toChannel = function (channel) {
28 return channel[0] == '#' ? channel : '#'+channel
29}
30
31//join if not already joined...
32IRC.join = function (irc, channel) {
33 if(!irc.channels) irc.channels = {}
34 if(!irc.channels[channel]) {
35 irc.channels[channel] = true
36 irc.join(IRC.toChannel(channel))
37 }
38}
39
40IRC.channel = function (irc, channel, message) {
41 IRC.join(irc, channel)
42 irc.say(IRC.toChannel(channel), message)
43}
44
45IRC.private = function (irc, nick, message) {
46 irc.say(nick, message)
47}
48
49
50if(!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
75
76
77
78

Built with git-ssb-web