Skip to content

Commit

Permalink
Tennu 0.8.2: Response Object + disable-help + sjs tests + fez
Browse files Browse the repository at this point in the history
Fez and SJS tests are not working right now.
You can compile the SJS tests manually via:

```
sjs -m sweet-bdd -o test/filename.js test-src/filename.js
```

But only one test at a time.

Once I finish fez-sweet.js, you'll be able to `node fez.js` or
`npm build`.

The tests are just the first place macros are being used. I'll
use them in actual production code once I've got the build step
working correctly.

Anyways, this 0.8.2 release, what features does it have?

1. !help goes to query always.
2. You can disable the help module.
3. Responses can now be objects with {message, query, intent}.

But what about fixed bugs?

Well, I haven't noticed any bugs to fix.
  • Loading branch information
Havvy committed Jan 11, 2014
1 parent 7858633 commit b436cbc
Show file tree
Hide file tree
Showing 17 changed files with 350 additions and 335 deletions.
12 changes: 11 additions & 1 deletion doc/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,14 @@ Changelog
0.8.1:
* client.ctcp() and client.act() fixed.
* client.initialize() renamed to client.initializeModule()
* client.isInitializable() renamed to client.isModuleInitializable()
* client.isInitializable() renamed to client.isModuleInitializable()

0.8.2:
* config['disable-help'] set to true will disable the help module.
* Response can now be an object with the following fields:
* message (string) Required, message(s) to say.
* intent ('say' | 'act') Defaults to 'say'.
* query (boolean) Defaults to false. If true, responds in query.
* Added fez and sweet.js into the developer dependencies.
* Note that fez doesn't do anything yet. I (havvy) need to write fez-sweet.js first.
* Tests are now using sweet-bdd (also by havvy), but I haven't compiled them yet.
3 changes: 2 additions & 1 deletion examples/bare-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"realname": "tennu 0.8.0",
"trigger": "!",
"capab": false,
"secure": false
"secure": false,
"disable-help": false
}
10 changes: 10 additions & 0 deletions fez.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var fez = require('fez');
var sweetjs = require('fez-sweet.js');

exports.build = function(rule) {
rule.each("test-src/*.sjs", fez.mapFile("test/%f.js"), sweetjs({'modules': ['sweet-bdd']}));
};

exports.default = exports.build;

fez(module);
15 changes: 12 additions & 3 deletions lib/command-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function CommandParser (config, nickname, logger) {
parser.after(function (err, res, type, command) {
logger.debug(inspect(arguments));
// Response types allowed:
// string U [string] U Promise<string U [string]>
// string U [string] U {message: string, query: boolean?, intent: ('say' | 'act')?}

if (err) {
logger.error('Command Handler', 'Error thrown in command handler!');
Expand All @@ -80,9 +80,18 @@ function CommandParser (config, nickname, logger) {

if (Array.isArray(res) || typeof res === 'string') {
command.receiver.say(command.channel, res);
} else {
logger.error('Command Handler', format(badResponseFormat, command.command, String(res)));
return;
}

if (typeof res === 'object' && res.message) {
const channel = res.query ? command.nickname : command.channel;
const intent = res.intent === 'act' ? 'act' : 'say';

command.receiver[intent](channel, res.message);
return;
}

logger.error('Command Handler', format(badResponseFormat, command.command, inspect(res)));
});

return parser;
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tennu",
"version": "0.8.1",
"description": "Tennu Node.js IRC Framework",
"version": "0.8.2",
"description": "Tennu - Modular IRC Bot Framework for Node.js",
"maintainers": [
{
"name": "Ryan Scheel",
Expand Down Expand Up @@ -49,7 +49,10 @@
"devDependencies": {
"sinon": "~1.7.3",
"deep-eql": "~0.1.3",
"better-assert": "~1.0.0"
"better-assert": "~1.0.0",
"sweet-bdd": "~1.0.0",
"fez-sweet.js": "~0.1.0",
"fez": "0.0.3"
},
"scripts": {
"test": "mocha -R spec"
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ Sets the command `!help`.

See [Help Module Documentation](https://github.com/Havvy/tennu/blob/master/doc/module/help.md).

[0.8.2+]

If you don't want this functionality, set `disable-help` to `true` in your configuration object.

#### channels ####

Unimplemented.
Expand Down
23 changes: 16 additions & 7 deletions tennu_modules/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ const Set = require('simplesets').Set;

module.exports = {
init: function (client, imports) {
const enabled = !(client.config('disable-help'));

if (!enabled) {
// Empty module.
return {};
}

const registry = {};
const commandset = new Set();

function helpResponse (query) {
function helpResponseMessage (query) {
const cursor = query.reduce(function (cursor, topic) {
if (typeof cursor !== 'object') {
return undefined;
Expand Down Expand Up @@ -44,22 +51,24 @@ module.exports = {
client.notice('ModHelp', '!help being handled.');
// Default to showing the help for the help module if no args given.
const query = command.args.length === 0 ? ['help'] : command.args.slice();
const response = helpResponse(query);
return response;
const response = helpResponseMessage(query);
return {
message: response,
query: true,
intent: 'say'
};
},

'!commands': function (command) {
client.notice('ModHelp', '!commands being handled.');

const start = ["List of known commands: "];
return start.concat(commandset.array().map(function (command) {
return format(" * %s", command);
}));
return start.concat(commandset.array().join(", "));
}
},

exports: {
help: helpResponse,
help: helpResponseMessage,
helpObject: function () { return JSON.parse(JSON.stringify(registry)); },
HELP_NOT_FOUND: HELP_NOT_FOUND
},
Expand Down
File renamed without changes.
110 changes: 45 additions & 65 deletions test/client.js → test-src/client.sjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const logfn = debug ? console.log.bind(console) : function () {};
const logger = {debug: logfn, info: logfn, notice: logfn, warn: logfn, error: logfn};

const Client = require('../lib/client.js');
const NetSocket = require('./mock-net-socket.js');
const NetSocket = require('../test-lib/mock-net-socket.js');

const network = {
nick: 'testbot',
Expand Down Expand Up @@ -60,10 +60,10 @@ const boxfn = function (value) {
return function () { return value; };
};

describe('Tennu Client', function () {
describe 'Tennu Client' {
var netsocket, tennu;

beforeEach(function () {
beforeEach {
logfn(/* newline */);

fakeWrite.spy = sinon.spy();
Expand All @@ -75,102 +75,82 @@ describe('Tennu Client', function () {
NetSocket: boxfn(netsocket),
Logger: boxfn(logger)
});
});
}

afterEach(function () {
afterEach {
logfn('End of test.');
});
}

it('Basic Connecting and Disconnecting', function () {
it 'Basic Connecting and Disconnecting' {
assert(tennu.connected === false);
tennu.connect();
assert(tennu.connected === true);
tennu.disconnect();
assert(tennu.connected === false);
});
}

// Move this to its own file.
describe('Nickname Tracking', function () {
beforeEach(function (done) {
netsocket.on('connect', function () {
done();
});

describe 'Nickname Tracking' {
beforeEach (done) {
netsocket.on('connect', done);
tennu.connect();
});

afterEach(function (done) {
netsocket.on('close', function () {
done();
});
}

afterEach (done) {
netsocket.on('close', done);
tennu.disconnect();
});
}

it('tracks its initial nickname', function () {
it 'tracks its initial nickname' {
assert(tennu.nickname() === 'testbot');
});

it('test', function () {});

describe('changing nick', function () {
beforeEach(function (done) {
tennu.on('nick', function () {
done();
});
}

describe 'changing nick' {
beforeEach (done) {
tennu.on('nick', function () { done() });
tennu.nick('newNick');
});
}

it('tracks its changed nick', function () {
it 'tracks its changed nick' {
assert(tennu.nickname() === 'newNick');
});
});
});

describe('autojoin', function () {
beforeEach(function (done) {
tennu.on('join', function () {
done();
});
}
}
}

describe 'autojoin' {
beforeEach (done) {
tennu.on('join', function () { done() });
tennu.connect();
});

afterEach(function (done) {
netsocket.on('close', function () {
done();
});
}

afterEach (done) {
netsocket.on('close', done);
tennu.disconnect();
});
}

it('automatically joins specified channels.', function () {
it 'automatically joins specified channels.' {
assert(fakeWrite.spy.calledWith('JOIN :#test\r\n', 'utf-8'));
});
});
}
}

describe('autoidentify', function () {
beforeEach(function (done) {
describe 'autoidentify' {
beforeEach (done) {
tennu.on('notice', function(e) {
if (e.nickname === 'nickserv') {
done();
}
});

tennu.connect();
});

afterEach(function (done) {
netsocket.on('close', function () {
done();
});
}

afterEach (done) {
netsocket.on('close', done);
tennu.disconnect();
});
}

it('automatically identifies to services.', function () {
it 'automatically identifies to services.' {
assert(fakeWrite.spy.calledWith('PRIVMSG nickserv :identify testpass\r\n', 'utf-8'));
});
});
});
}
}
}
Loading

0 comments on commit b436cbc

Please sign in to comment.