Files: f48fb1aaaee24b2d0214b1f4aa1f66f3dec41972 / irc.js
1289 bytesRaw
1 | var 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 | irc.connect() |
10 | irc.on('ready', cb) |
11 | return irc |
12 | } |
13 | |
14 | IRC.toChannel = function (channel) { |
15 | return channel[0] == '#' ? channel : '#'+channel |
16 | } |
17 | |
18 | //join if not already joined... |
19 | IRC.join = function (irc, channel) { |
20 | if(!irc.channels) irc.channels = {} |
21 | if(!irc.channels[channel]) { |
22 | irc.channels[channel] = true |
23 | irc.join(IRC.toChannel(channel)) |
24 | } |
25 | } |
26 | |
27 | IRC.channel = function (irc, channel, message) { |
28 | IRC.join(irc, channel) |
29 | irc.say(IRC.toChannel(channel), message) |
30 | } |
31 | |
32 | IRC.private = function (irc, nick, message) { |
33 | irc.say(nick, message) |
34 | } |
35 | |
36 | |
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 = {} |
47 | |
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 | } |
57 | |
58 | notify(note) |
59 | }) |
60 | } |
61 | |
62 |
Built with git-ssb-web