Skip to content

Commit b9a3aac

Browse files
author
Stig Otnes Kolstad
committed
initial
0 parents  commit b9a3aac

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
*.swp

irc.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const Emitter = require('events')
2+
const Transform = require('stream').Transform
3+
4+
const patternMatch = (matchers) => {
5+
return es.map((data, cb) => {
6+
for ([pattern, fn] of matchers) {
7+
const result = pattern.exec(data)
8+
if (result) {
9+
fn(result)
10+
return
11+
}
12+
}
13+
})
14+
}
15+
16+
const emitter = new Emitter()
17+
const emit = emitter.emit
18+
19+
const matchers = [
20+
[ /PING (\S+)/, ([, hostname]) => emit('ping', {hostname}) ],
21+
[ /^(\S+) PRIVMSG (\S+) !(.+))/, (from, to, msg) => emit('msg', {from, to, msg}) ],
22+
]
23+
24+
module.exports = emitter
25+
26+
if (!module.parent) {
27+
//socket
28+
process.stdin
29+
.pipe(es.split())
30+
.pipe(patternMatch(matchers))
31+
.pipe(process.stdout)
32+
}
33+

0 commit comments

Comments
 (0)