tinybot
Advanced tools
Comparing version 1.0.4 to 1.0.5
10
index.js
@@ -152,4 +152,4 @@ 'use strict'; | ||
* bot.hears('baz', function() {}) | ||
* bot.drop('cool*') // drops 'foo' and 'bar' listener | ||
* bot.drop('*') // drops all listeners | ||
* bot.drop(/cool/) // drops 'foo' and 'bar' listener | ||
* bot.drop(/^/) // drops all listeners | ||
* | ||
@@ -161,6 +161,8 @@ * @param {(RegExp|string)} functionPattern Pattern of listener function names to remove | ||
if( !functionPattern ) { return console.warn("Pass * to remove all listeners"); } | ||
if( !functionPattern ) { return console.warn("Pass /.*/ to remove all listeners"); } | ||
if( functionPattern == '*' ) { functionPattern = '.*' } | ||
self.listeners.filter(function(l) { | ||
return l.name.match(functionPattern); | ||
return typeof functionPattern === 'string' ? | ||
l.name === functionPattern : | ||
l.name.match(functionPattern) | ||
}).forEach(function(l) { | ||
@@ -167,0 +169,0 @@ self.removeListener('message', l.listener); |
{ | ||
"name": "tinybot", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "A tiny wrapper around the Slack RTM API that provides methods to listen for and send slack messages.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -69,3 +69,3 @@ # tinybot | ||
bot.drop('foo*'); // deregister functions named foo and fooBar | ||
bot.drop('*'); // deregister all listeners | ||
bot.drop(/foo.*/); // deregister functions named foo and fooBar | ||
bot.drop(/.*/); // deregister all listeners |
@@ -46,3 +46,3 @@ var expect = require('expect'); | ||
afterEach(function() { | ||
bot.drop('*'); | ||
bot.drop(/.*/); | ||
}) | ||
@@ -125,4 +125,2 @@ | ||
slackTest.socket.send({text: 'nice'}); | ||
// TODO: desired api | ||
// waitFor(function() { return true}, function done()) | ||
setTimeout(function wait() { | ||
@@ -155,8 +153,33 @@ if( counter < 1 ) { return setTimeout(wait, 10); } | ||
if( counter < 1 ) { return setTimeout(wait, 10); } | ||
bot.drop('cool*'); | ||
bot.drop(/cool.*/); | ||
slackTest.socket.send({text: 'nice'}); | ||
}, 10); | ||
}) | ||
it('drops exact string matches properly', function(cb) { | ||
var counter = 0, coolCounter = 0; | ||
bot.hears({text: 'nice'}, function cool(message) { | ||
coolCounter++; | ||
}) | ||
bot.hears({text: 'nice'}, function yepcoolgreat(message) { | ||
coolCounter++; | ||
}) | ||
bot.hears({text: 'nice'}, function (message) { | ||
if( ++counter == 2 ) { | ||
expect(coolCounter).toEqual(3); | ||
cb(); | ||
} | ||
}) | ||
slackTest.socket.send({text: 'nice'}); | ||
setTimeout(function wait() { | ||
if( counter < 1 ) { return setTimeout(wait, 10); } | ||
bot.drop('cool'); | ||
slackTest.socket.send({text: 'nice'}); | ||
}, 10); | ||
}) | ||
}) | ||
}) | ||
}) |
16747
379