-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First commit. Basic bot code with tests.
- Loading branch information
0 parents
commit 2d42be1
Showing
9 changed files
with
203 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,3 @@ | ||
.*.swp | ||
node_modules/ | ||
lib/ |
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,16 @@ | ||
{exec, spawn} = require 'child_process' | ||
fs = require 'fs' | ||
|
||
build = (callback) -> | ||
exec 'mkdir -p lib', (err, stdout, stderr) -> | ||
throw new Error(err) if err | ||
exec './node_modules/coffee-script/bin/coffee --compile --output lib/ src/', (err, stdout, stderr) -> | ||
throw new Error(err) if err | ||
callback() if callback | ||
|
||
test = -> | ||
build -> | ||
spawn './node_modules/mocha/bin/mocha', ['./test/'], stdio: 'inherit' | ||
|
||
task 'build', 'Build lib from src', -> build() | ||
task 'test', 'Test project', -> test() |
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,22 @@ | ||
Copyright (c) 2012, Peter-Paul van Gemerden <[email protected]> | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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,41 @@ | ||
_Boter_ is a simple library to build your own _smooth_ IRC bot using [node.js](http://nodejs.org). Boter is built on top of [node-irc](https://github.com/martynsmith/node-irc) and written in [CoffeeScript](http://coffeescript.org/). The name (_boter_) is obviously derived from the word "bot", and is Dutch for "butter". | ||
|
||
Installation | ||
------------ | ||
|
||
Clone the repository or copy the files to your path of choice, and then: | ||
|
||
$ cd path/to/boter/ | ||
$ npm install | ||
$ npm build | ||
|
||
This should also install the development dependencies (a necessary evil at this point), so you can check whether everything was installed correctly by running: | ||
|
||
$ npm test | ||
|
||
Usage | ||
----- | ||
|
||
You can create a _Boter_ bot like your would create a `node_irc` client: | ||
|
||
var boter = require('../path/to/boter/'); | ||
var bot = new boter.Boter('irc.server.foo', 'MyBoter', {channels: [#bar]}); | ||
|
||
More later on how to actually use the bot. | ||
|
||
Testing | ||
------- | ||
|
||
For testing, _Boter_ uses [Mocha](http://visionmedia.github.com/mocha/) and [should.js](https://github.com/visionmedia/should.js). In addition, [Mockery](https://github.com/mfncooper/mockery) and [Sinon.JS](http://sinonjs.org/) are used for mocking `node_irc`. | ||
|
||
To run the test: | ||
|
||
$ cd path/to/boter/ | ||
$ npm test | ||
|
||
Alternatively, you can use `cake test` or run `mocha ./test/` directly. | ||
|
||
License | ||
------- | ||
|
||
This software is licensed under the Simplified BSD License (see [LICENSE](./LICENSE)). |
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 @@ | ||
module.exports = require('./lib/boter'); |
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,31 @@ | ||
{ | ||
"name": "Boter", | ||
"version": "0.1.0", | ||
"description": "A simple library for writing smooth IRC bots.", | ||
"main": "index.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"dependencies": { | ||
"should": "~1.2.0", | ||
"irc": "~0.3.4" | ||
}, | ||
"devDependencies": { | ||
"coffee-script": "~1.3.3", | ||
"mocha": "~1.5.0", | ||
"mockery": "~1.2.0", | ||
"sinon": "~1.4.2" | ||
}, | ||
"scripts": { | ||
"prepublish": "cake build", | ||
"test": "cake test" | ||
}, | ||
"repository": "", | ||
"keywords": [ | ||
"irc", | ||
"bot", | ||
"coffee-script" | ||
], | ||
"author": "Peter-Paul van Gemerden <[email protected]>", | ||
"license": "BSD" | ||
} |
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 @@ | ||
#!/usr/bin/env coffee | ||
|
||
irc = require 'irc' | ||
show = console.log | ||
error = console.error | ||
|
||
class User | ||
constructor: (user, host) -> | ||
@user = user?.toLowerCase() | ||
@host = host?.toLowerCase() | ||
equals: (other) -> | ||
other.user.toLowerCase()==@user and other.host.toLowerCase()==@host | ||
|
||
class Message | ||
constructor: (@from, @context, text) -> | ||
this.original = text | ||
this.text = text.toLowerCase() | ||
|
||
class Boter | ||
constructor: (@server, @nickname, @config) -> | ||
@client = new irc.Client @server, @nickname, @config | ||
@handlers = [] | ||
|
||
exports.Boter = Boter | ||
exports.User = User | ||
exports.Message = Message |
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 @@ | ||
--compilers coffee:coffee-script | ||
--require should | ||
--reporter spec | ||
--colors |
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,59 @@ | ||
mockery = require 'mockery' | ||
sinon = require 'sinon' | ||
|
||
ircMock = { Client: sinon.spy() } | ||
boter = {} | ||
|
||
describe 'boter', -> | ||
|
||
before -> | ||
mockery.enable() | ||
mockery.registerMock 'irc', ircMock | ||
mockery.registerAllowable '../' | ||
mockery.registerAllowable './lib/boter' | ||
boter = require '../' | ||
|
||
after -> | ||
mockery.deregisterMock 'irc' | ||
mockery.disable() | ||
|
||
describe 'boter.User', -> | ||
describe '#equals()', -> | ||
it 'should return true if users have the name username and host', -> | ||
user1 = new boter.User 'user', 'some.host.foo' | ||
user2 = new boter.User 'user', 'some.host.foo' | ||
user1.equals(user2).should.be.true | ||
it 'should return false if usernames are different', -> | ||
user1 = new boter.User 'user', 'some.host.foo' | ||
user2 = new boter.User 'other', 'some.host.foo' | ||
user1.equals(user2).should.be.false | ||
it 'should return false if hostnames are different', -> | ||
user1 = new boter.User 'user', 'some.host.foo' | ||
user2 = new boter.User 'user', 'some.other.foo' | ||
user1.equals(user2).should.be.false | ||
|
||
describe 'boter.Message', -> | ||
describe 'Message()', -> | ||
text = "This is some Random Message with Important Capalization." | ||
message = {} | ||
beforeEach -> | ||
message = new boter.Message 'user', 'context', text | ||
it 'should save unmodified message in this.original', -> | ||
message.original.should.equal text | ||
it 'should make text lower case', -> | ||
message.text.should.equal text.toLowerCase() | ||
|
||
describe 'boter.Boter', -> | ||
args = | ||
server: 'irc.server.foo' | ||
name: 'MyBoter' | ||
opts: {'option': true} | ||
afterEach -> | ||
ircMock.Client.reset() | ||
describe 'Boter()', -> | ||
it 'should create irc client with same parameters', -> | ||
bot = new boter.Boter args.server, args.name, args.opts | ||
ircMock.Client.calledOnce.should.be.true | ||
ircMock.Client.calledWithNew().should.be.true | ||
ircMock.Client.calledWithExactly(args.server, args.name, args.opts).should.be.true | ||
|