Skip to content

Commit

Permalink
beta2: implement connect and other events
Browse files Browse the repository at this point in the history
  • Loading branch information
omnidan committed May 7, 2016
1 parent ebd25bc commit 7ee10a4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ networks.send({
```


## Special events

You can find a list of all events in the [`node-irc` documentation](http://node-irc.readthedocs.io/en/latest/API.html#events).

All events listed there are forwarded to coffea, arguments to the function become part of the `evt` object, e.g.:

```js
networks.on('motd', (evt) => {
console.log('motd received: ', evt.motd)
})
```


## Colors / Formatting

Not supported by coffea yet, so use [irc-colors](https://www.npmjs.com/package/irc-colors) for now:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coffea-irc",
"version": "1.0.0-beta1",
"version": "1.0.0-beta2",
"main": "lib/index.js",
"devDependencies": {
"babel-core": "^6.5.1",
Expand Down
22 changes: 22 additions & 0 deletions src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@ const { log } = dude('coffea-irc:events')

import { message, command, error } from 'coffea'

const listenToEvent = (client, dispatch, name) =>
client.addListener(name, (...args) =>
dispatch({
...args,
type: name
})
)

const listenToEvents = (client, dispatch, names) => names.map(
(name) => listenToEvent(client, dispatch, name)
)

export default function events (client, config, dispatch) {
client.connect(() => dispatch({ type: 'connect' }))

client.addListener('message', (from, to, text) => dispatch(message(
to, // channel
text, // text
Expand All @@ -27,4 +41,12 @@ export default function events (client, config, dispatch) {
})

client.addListener('error', (err) => dispatch(error(err)))

listenToEvents(client, dispatch, [
'registered', 'motd', 'names', 'topic', 'join', 'part', 'quit', 'kick',
'kill', 'selfMessage', 'notice', 'ping', 'pm', 'ctcp', 'ctcp-notice',
'ctcp-privmsg', 'ctcp-version', 'nick', 'invite', '+mode', '-mode',
'whois', 'channellist_start', 'channellist_item', 'channellist', 'raw',
'action'
])
}
2 changes: 1 addition & 1 deletion src/init.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import irc from 'irc'

export default function init (host, nick, channels) {
return new irc.Client(host, nick, { channels })
return new irc.Client(host, nick, { channels, autoConnect: false })
}

0 comments on commit 7ee10a4

Please sign in to comment.