-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5782fd3
Showing
11 changed files
with
217 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"presets": ["es2015"], | ||
"plugins": ["transform-object-rest-spread"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
extends: "standard" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
node_modules | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output from `webpack` | ||
lib | ||
|
||
# test file | ||
test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Caffeinery Team | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# coffea-irc | ||
|
||
_irc plugin for [coffea 1.0-beta](https://github.com/caffeinery/coffea/tree/1.0-beta)_ | ||
|
||
|
||
## Setup | ||
|
||
* Make sure to use the latest *beta* version of coffea by running: `npm install --save coffea@beta` | ||
* Install `coffea-irc`: `npm install coffea-irc` | ||
|
||
|
||
## Usage | ||
|
||
Specify the telegram protocol in your network config: | ||
|
||
```js | ||
{ | ||
"protocol": "irc", | ||
"network": "chat.freenode.net", | ||
"nick": "coffeabot1337", | ||
"channels": [ "#caffeinery" ] | ||
} | ||
``` | ||
|
||
coffea will automatically load `coffea-irc` when it's needed! Thus, using irc (or other protocols) this way should work on **any** coffea project, **without any tweaks** (other than installing `coffea-irc` and specifying the config). | ||
|
||
`coffea-irc` aims to be compatible with coffea. Of course, features that irc doesn't have (like audio messages) aren't available for irc protocols, they will just | ||
be ignored. | ||
|
||
|
||
## API | ||
|
||
Joining/parting channels: | ||
|
||
```js | ||
networks.send({ | ||
type: 'join', | ||
channel: '#caffeinery', | ||
password: 'optional password for the channel' | ||
}) | ||
|
||
networks.send({ | ||
type: 'part', | ||
channel: '#caffeinery' | ||
}) | ||
``` | ||
|
||
Sending irc commands: | ||
|
||
```js | ||
networks.send({ | ||
type: 'send', | ||
args: [ 'MODE', '#caffeinery', '+v', 'coffeabot1337' ] | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "coffea-irc", | ||
"version": "1.0.0-beta1", | ||
"main": "lib/index.js", | ||
"devDependencies": { | ||
"babel-core": "^6.5.1", | ||
"babel-plugin-transform-object-rest-spread": "^6.5.0", | ||
"babel-preset-es2015": "^6.5.0", | ||
"eslint": "^2.0.0-rc.1", | ||
"eslint-config-standard": "^5.1.0", | ||
"eslint-plugin-promise": "^1.0.8", | ||
"eslint-plugin-standard": "^1.3.2", | ||
"rimraf": "^2.5.2" | ||
}, | ||
"dependencies": { | ||
"coffea": "^1.0.0-beta14", | ||
"debug-dude": "^1.0.3", | ||
"irc": "^0.5.0" | ||
}, | ||
"scripts": { | ||
"lint": "./node_modules/.bin/eslint src test", | ||
"clean": "./node_modules/.bin/rimraf lib", | ||
"compile": "./node_modules/.bin/babel --presets es2015 -d lib/ src/", | ||
"prepublish": "npm run lint && npm run clean && npm run compile" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default function makeCommands (client) { | ||
return { | ||
// TODO: standardize these commands and document in coffea | ||
// e.g. message(...), me(), photo(...), ... | ||
'message': (event) => | ||
client.say(event.channel, event.text), | ||
'send': (event) => | ||
client.send(...event.args), | ||
'join': (event) => | ||
client.join(event.channel + (event.password ? ' ' + event.password : '')), | ||
'part': (event) => | ||
client.part(event.channel) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import dude from 'debug-dude' | ||
const { log } = dude('coffea-irc:events') | ||
|
||
import { message, command, error } from 'coffea' | ||
|
||
export default function events (client, config, dispatch) { | ||
client.addListener('message', (from, to, text) => dispatch(message( | ||
to, // channel | ||
text, // text | ||
{ from } // additional data | ||
))) | ||
|
||
client.addListener('message', (from, to, text) => { | ||
log('message event received: %o', { from, to, text }) | ||
if (text.charAt(0) === config.prefix) { // example: .nw name | ||
log(' `-> command detected') | ||
let args = text.substring(1).split(' ') // [ 'nw', 'name' ] | ||
let cmd = args.shift() // nw | ||
// args is now [ 'name' ] | ||
return dispatch(command( | ||
to, // channel | ||
cmd, // cmd | ||
args, // args | ||
{ from } // additional data | ||
)) | ||
} | ||
}) | ||
|
||
client.addListener('error', (err) => dispatch(error(err))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { forward } from 'coffea' | ||
|
||
import init from './init' | ||
import events from './events' | ||
import makeCommands from './commands' | ||
|
||
export default function irc (config, dispatch) { | ||
const client = init( | ||
config.network, | ||
config.nick, | ||
Array.isArray(config.channels) ? config.channels : [config.channels] | ||
) | ||
const commands = makeCommands(client) | ||
|
||
if (!config.prefix) config.prefix = '!' | ||
events(client, config, dispatch) | ||
|
||
return forward(commands) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import irc from 'irc' | ||
|
||
export default function init (host, nick, channels) { | ||
return new irc.Client(host, nick, { channels }) | ||
} |