Skip to content

Commit b436cbc

Browse files
committed
Tennu 0.8.2: Response Object + disable-help + sjs tests + fez
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.
1 parent 7858633 commit b436cbc

File tree

17 files changed

+350
-335
lines changed

17 files changed

+350
-335
lines changed

doc/changelog.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,14 @@ Changelog
154154
0.8.1:
155155
* client.ctcp() and client.act() fixed.
156156
* client.initialize() renamed to client.initializeModule()
157-
* client.isInitializable() renamed to client.isModuleInitializable()
157+
* client.isInitializable() renamed to client.isModuleInitializable()
158+
159+
0.8.2:
160+
* config['disable-help'] set to true will disable the help module.
161+
* Response can now be an object with the following fields:
162+
* message (string) Required, message(s) to say.
163+
* intent ('say' | 'act') Defaults to 'say'.
164+
* query (boolean) Defaults to false. If true, responds in query.
165+
* Added fez and sweet.js into the developer dependencies.
166+
* Note that fez doesn't do anything yet. I (havvy) need to write fez-sweet.js first.
167+
* Tests are now using sweet-bdd (also by havvy), but I haven't compiled them yet.

examples/bare-config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"realname": "tennu 0.8.0",
1111
"trigger": "!",
1212
"capab": false,
13-
"secure": false
13+
"secure": false,
14+
"disable-help": false
1415
}

fez.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var fez = require('fez');
2+
var sweetjs = require('fez-sweet.js');
3+
4+
exports.build = function(rule) {
5+
rule.each("test-src/*.sjs", fez.mapFile("test/%f.js"), sweetjs({'modules': ['sweet-bdd']}));
6+
};
7+
8+
exports.default = exports.build;
9+
10+
fez(module);

lib/command-handler.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function CommandParser (config, nickname, logger) {
6363
parser.after(function (err, res, type, command) {
6464
logger.debug(inspect(arguments));
6565
// Response types allowed:
66-
// string U [string] U Promise<string U [string]>
66+
// string U [string] U {message: string, query: boolean?, intent: ('say' | 'act')?}
6767

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

8181
if (Array.isArray(res) || typeof res === 'string') {
8282
command.receiver.say(command.channel, res);
83-
} else {
84-
logger.error('Command Handler', format(badResponseFormat, command.command, String(res)));
83+
return;
84+
}
85+
86+
if (typeof res === 'object' && res.message) {
87+
const channel = res.query ? command.nickname : command.channel;
88+
const intent = res.intent === 'act' ? 'act' : 'say';
89+
90+
command.receiver[intent](channel, res.message);
91+
return;
8592
}
93+
94+
logger.error('Command Handler', format(badResponseFormat, command.command, inspect(res)));
8695
});
8796

8897
return parser;

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tennu",
3-
"version": "0.8.1",
4-
"description": "Tennu Node.js IRC Framework",
3+
"version": "0.8.2",
4+
"description": "Tennu - Modular IRC Bot Framework for Node.js",
55
"maintainers": [
66
{
77
"name": "Ryan Scheel",
@@ -49,7 +49,10 @@
4949
"devDependencies": {
5050
"sinon": "~1.7.3",
5151
"deep-eql": "~0.1.3",
52-
"better-assert": "~1.0.0"
52+
"better-assert": "~1.0.0",
53+
"sweet-bdd": "~1.0.0",
54+
"fez-sweet.js": "~0.1.0",
55+
"fez": "0.0.3"
5356
},
5457
"scripts": {
5558
"test": "mocha -R spec"

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ Sets the command `!help`.
293293

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

296+
[0.8.2+]
297+
298+
If you don't want this functionality, set `disable-help` to `true` in your configuration object.
299+
296300
#### channels ####
297301

298302
Unimplemented.

tennu_modules/help.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@ const Set = require('simplesets').Set;
77

88
module.exports = {
99
init: function (client, imports) {
10+
const enabled = !(client.config('disable-help'));
11+
12+
if (!enabled) {
13+
// Empty module.
14+
return {};
15+
}
16+
1017
const registry = {};
1118
const commandset = new Set();
1219

13-
function helpResponse (query) {
20+
function helpResponseMessage (query) {
1421
const cursor = query.reduce(function (cursor, topic) {
1522
if (typeof cursor !== 'object') {
1623
return undefined;
@@ -44,22 +51,24 @@ module.exports = {
4451
client.notice('ModHelp', '!help being handled.');
4552
// Default to showing the help for the help module if no args given.
4653
const query = command.args.length === 0 ? ['help'] : command.args.slice();
47-
const response = helpResponse(query);
48-
return response;
54+
const response = helpResponseMessage(query);
55+
return {
56+
message: response,
57+
query: true,
58+
intent: 'say'
59+
};
4960
},
5061

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

5465
const start = ["List of known commands: "];
55-
return start.concat(commandset.array().map(function (command) {
56-
return format(" * %s", command);
57-
}));
66+
return start.concat(commandset.array().join(", "));
5867
}
5968
},
6069

6170
exports: {
62-
help: helpResponse,
71+
help: helpResponseMessage,
6372
helpObject: function () { return JSON.parse(JSON.stringify(registry)); },
6473
HELP_NOT_FOUND: HELP_NOT_FOUND
6574
},

test/client.js renamed to test-src/client.sjs

Lines changed: 45 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const logfn = debug ? console.log.bind(console) : function () {};
99
const logger = {debug: logfn, info: logfn, notice: logfn, warn: logfn, error: logfn};
1010

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

1414
const network = {
1515
nick: 'testbot',
@@ -60,10 +60,10 @@ const boxfn = function (value) {
6060
return function () { return value; };
6161
};
6262

63-
describe('Tennu Client', function () {
63+
describe 'Tennu Client' {
6464
var netsocket, tennu;
6565

66-
beforeEach(function () {
66+
beforeEach {
6767
logfn(/* newline */);
6868

6969
fakeWrite.spy = sinon.spy();
@@ -75,102 +75,82 @@ describe('Tennu Client', function () {
7575
NetSocket: boxfn(netsocket),
7676
Logger: boxfn(logger)
7777
});
78-
});
78+
}
7979

80-
afterEach(function () {
80+
afterEach {
8181
logfn('End of test.');
82-
});
82+
}
8383

84-
it('Basic Connecting and Disconnecting', function () {
84+
it 'Basic Connecting and Disconnecting' {
8585
assert(tennu.connected === false);
8686
tennu.connect();
8787
assert(tennu.connected === true);
8888
tennu.disconnect();
8989
assert(tennu.connected === false);
90-
});
90+
}
9191

9292
// Move this to its own file.
93-
describe('Nickname Tracking', function () {
94-
beforeEach(function (done) {
95-
netsocket.on('connect', function () {
96-
done();
97-
});
98-
93+
describe 'Nickname Tracking' {
94+
beforeEach (done) {
95+
netsocket.on('connect', done);
9996
tennu.connect();
100-
});
101-
102-
afterEach(function (done) {
103-
netsocket.on('close', function () {
104-
done();
105-
});
97+
}
10698

99+
afterEach (done) {
100+
netsocket.on('close', done);
107101
tennu.disconnect();
108-
});
102+
}
109103

110-
it('tracks its initial nickname', function () {
104+
it 'tracks its initial nickname' {
111105
assert(tennu.nickname() === 'testbot');
112-
});
113-
114-
it('test', function () {});
115-
116-
describe('changing nick', function () {
117-
beforeEach(function (done) {
118-
tennu.on('nick', function () {
119-
done();
120-
});
106+
}
121107

108+
describe 'changing nick' {
109+
beforeEach (done) {
110+
tennu.on('nick', function () { done() });
122111
tennu.nick('newNick');
123-
});
112+
}
124113

125-
it('tracks its changed nick', function () {
114+
it 'tracks its changed nick' {
126115
assert(tennu.nickname() === 'newNick');
127-
});
128-
});
129-
});
130-
131-
describe('autojoin', function () {
132-
beforeEach(function (done) {
133-
tennu.on('join', function () {
134-
done();
135-
});
116+
}
117+
}
118+
}
136119

120+
describe 'autojoin' {
121+
beforeEach (done) {
122+
tennu.on('join', function () { done() });
137123
tennu.connect();
138-
});
139-
140-
afterEach(function (done) {
141-
netsocket.on('close', function () {
142-
done();
143-
});
124+
}
144125

126+
afterEach (done) {
127+
netsocket.on('close', done);
145128
tennu.disconnect();
146-
});
129+
}
147130

148-
it('automatically joins specified channels.', function () {
131+
it 'automatically joins specified channels.' {
149132
assert(fakeWrite.spy.calledWith('JOIN :#test\r\n', 'utf-8'));
150-
});
151-
});
133+
}
134+
}
152135

153-
describe('autoidentify', function () {
154-
beforeEach(function (done) {
136+
describe 'autoidentify' {
137+
beforeEach (done) {
155138
tennu.on('notice', function(e) {
156139
if (e.nickname === 'nickserv') {
157140
done();
158141
}
159142
});
160143

161144
tennu.connect();
162-
});
163-
164-
afterEach(function (done) {
165-
netsocket.on('close', function () {
166-
done();
167-
});
145+
}
168146

147+
afterEach (done) {
148+
netsocket.on('close', done);
169149
tennu.disconnect();
170-
});
150+
}
171151

172-
it('automatically identifies to services.', function () {
152+
it 'automatically identifies to services.' {
173153
assert(fakeWrite.spy.calledWith('PRIVMSG nickserv :identify testpass\r\n', 'utf-8'));
174-
});
175-
});
176-
});
154+
}
155+
}
156+
}

0 commit comments

Comments
 (0)