Skip to content

Commit bd8a2a2

Browse files
committed
0.8.0pre4
1 parent 855a58e commit bd8a2a2

File tree

10 files changed

+92
-99
lines changed

10 files changed

+92
-99
lines changed

examples/bare-config.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"server": "irc.network.net",
3+
"channels": ["#channel"],
4+
"nickserv": "nickserv",
5+
"password": null,
6+
"nick": "tennu-bot",
7+
"user": "tennu",
8+
"port": 6667,
9+
"modules": [],
10+
"realname": "tennu 0.8.0",
11+
"trigger": "!",
12+
"capab": false,
13+
"secure": false
14+
}

lib/bisubscriber.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ BiEventSubscriber.prototype = {
5151

5252
_onMap : function (typemap) {
5353
for (var type in typemap) {
54-
this._onceString(type, typemap[type]);
54+
this._onString(type, typemap[type]);
5555
}
5656
},
5757

lib/client.js

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
/**
2-
*
3-
* The public contract of the Client object is documented by readme.md.
4-
*
5-
* Public Methods:
6-
* connect() -> void
7-
* disconnect() -> void
8-
* Configuration Storage iface
9-
* IrcOutputSocket iface
10-
* Bisubscriber iface
11-
* Modules iface
12-
*/
13-
14-
/*
15-
I should see if there's a better way to make this class than
16-
all of these wrapped methods.
17-
*/
18-
19-
const util = require('util');
201
const lodash = require('lodash');
212

223
const defaultFactoryConfiguration = {
@@ -119,7 +100,7 @@ const delegate = function (property, method) {
119100
client.say(config.nickserv, 'identify ' + config.password);
120101
}
121102

122-
if (util.isArray(config.channels)) {
103+
if (Array.isArray(config.channels)) {
123104
client.notice('Joining default channels.');
124105
config.channels.forEach(function (channel) {
125106
client.join(channel);
@@ -136,6 +117,8 @@ const delegate = function (property, method) {
136117
client.notice('Closing IRC Connection.');
137118
client.disconnect();
138119
});
120+
// End of Startup stuff
121+
139122

140123
client.out = client._outputSocket;
141124
client.events = client._subscriber;
@@ -218,21 +201,14 @@ Client.prototype.nick = function () {
218201
Client.prototype.on = delegate('_subscriber', 'on');
219202
Client.prototype.once = delegate('_subscriber', 'once');
220203

221-
// partially implements ModuleSubscriber
222-
223-
Client.prototype.load = function (module) {
224-
return this._modules.load(module);
225-
};
226-
227-
Client.prototype.require = function (module) {
228-
return this._modules.require(module);
229-
};
204+
// implements ModuleSystem
230205

231-
Client.prototype.exports = Client.prototype.require;
232-
233-
Client.prototype.loaded = function () {
234-
return this._modules.loadedModules()
235-
};
206+
Client.prototype.use = delegate('modules', 'use');
207+
Client.prototype.getModule = delegate('modules', 'getModule');
208+
Client.prototype.getRole = delegate('modules', 'getRole');
209+
Client.prototype.initialize = delegate('modules', 'initialize');
210+
Client.prototype.isInitializable = delegate('modules', 'isInitializable');
211+
Client.prototype.addHook = delegate('modules', 'addHook');
236212

237213
// implements Logger
238214
Client.prototype.debug = delegate('_logger', 'debug');

lib/command-handler.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ function CommandParser (config, nickname, logger) {
5656
const command = Command(privmsg, maybeCommand);
5757
logger.notice('Command Handler', 'Emitting command:', command.command);
5858
this.emit(command.command, command);
59+
return command;
5960
}
60-
61-
return command;
6261
};
6362

6463
parser.after(function (err, res, type, command) {
64+
logger.debug(inspect(arguments));
6565
// Response types allowed:
6666
// string U [string] U Promise<string U [string]>
67+
6768
if (err) {
6869
logger.error('Command Handler', 'Error thrown in command handler!');
6970
logger.error('Command Handler', err.stack);
@@ -75,19 +76,13 @@ function CommandParser (config, nickname, logger) {
7576
return;
7677
}
7778

78-
if (Array.isArray(res) || typeof res === 'string') {
79-
res = Q(res);
80-
}
79+
logger.debug('Command Handler', 'Response exists.');
8180

82-
if (typeof res.then !== 'function') {
81+
if (Array.isArray(res) || typeof res === 'string') {
82+
command.receiver.say(command.channel, res);
83+
} else {
8384
logger.error('Command Handler', format(badResponseFormat, command.command, String(res)));
84-
return;
8585
}
86-
87-
res.then(function (res) {
88-
// FIXME: Pass receiver to Command Handler at initialization.
89-
command.receiver.say(command.channel, res);
90-
});
9186
});
9287

9388
return parser;

lib/event-emitter.js

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@
2828
*/
2929

3030

31-
var Set = require('simplesets').Set; // Still waiting on that ES6 Set API.
31+
const Set = require('simplesets').Set; // Still waiting on that ES6 Set API.
32+
const Q = require('q');
3233

33-
var EventEmitter = function () {
34-
var events = {}; // Object[Set[Fn]]
35-
var postListenerCallback = null; // Fn
34+
const EventEmitter = function () {
35+
const events = {}; // Object (Set Fn)
36+
var postListenerCallback = function () {}; // Error -> any -> string -> ...any -> void
3637

3738
return {
3839
on: function (type, listener) {
@@ -43,11 +44,11 @@ var EventEmitter = function () {
4344
events[type].add(listener);
4445
},
4546
once: function (type, listener) {
46-
var that = this;
47+
const that = this;
4748

4849
function o () {
49-
listener.apply(null, Array.prototype.slice.call(arguments));
5050
that.off(type, o);
51+
return listener.apply(null, Array.prototype.slice.call(arguments));
5152
}
5253

5354
this.on(type, o);
@@ -57,41 +58,27 @@ var EventEmitter = function () {
5758
events[type].remove(listener);
5859
}
5960
},
60-
emit: function recur (type) {
61-
var args = Array.prototype.slice.call(arguments, 1);
62-
63-
if (Array.isArray(type)) {
64-
args.unshift(null);
65-
66-
type.forEach(function (t) {
67-
args[0] = t;
68-
recur.apply(this, args);
69-
});
70-
71-
return;
72-
}
61+
emit: function (type) {
62+
const args = Array.prototype.slice.call(arguments, 1);
7363

7464
if (!events[type]) {
7565
return;
7666
}
7767

7868
events[type].each(function (listener) {
7969
setImmediate(function () {
80-
try {
81-
var res = listener.apply(null, args);
82-
} catch (e) {
83-
var err = e;
84-
}
85-
86-
try {
87-
// TODO: Give special treatment to promises.
88-
if (postListenerCallback) {
89-
postListenerCallback.apply(null, [err, res, type].concat(args));
90-
}
91-
} catch (e) {
92-
console.log(e.stack);
93-
throw e;
94-
}
70+
Q.fapply(listener, args)
71+
.then(function (res) {
72+
postListenerCallback.apply(null, [undefined, res, type].concat(args));
73+
}, function (err) {
74+
postListenerCallback.apply(null, [err, undefined, type].concat(args));
75+
})
76+
.catch(function (err) {
77+
console.log(err.name);
78+
console.log(err.stack);
79+
throw err;
80+
})
81+
.done();
9582
});
9683
});
9784
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tennu",
3-
"version": "0.8.0pre3",
3+
"version": "0.8.0pre4",
44
"description": "Tennu Node.js IRC Framework",
55
"maintainers": [
66
{

readme.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,11 @@ For example, a command of "!do-it ARG1 ARG2" will have args be ["ARG1", "ARG2"]
168168

169169
## Actions ##
170170

171-
All of the following are methods on Tennu for doing things once connected.
171+
All of the following are methods on Tennu that can be used once connected.
172172

173173
These methods are also available on the client's 'out' property.
174+
In Tennu 0.9.0, the 'out' property will go away, and the 'actions' module
175+
will export these methods.
174176

175177
### say(channel, message) ###
176178

@@ -244,18 +246,19 @@ users is either a string or an array of strings.
244246

245247
Retrieves the userhost of the user(s).
246248

247-
### _raw(message) ###
249+
### raw(message) ###
248250

249-
Our IrcOutputSocket class does not have all commands. If you need to use one
250-
that is not listed here, you can use the internal _raw method, which takes
251-
the entire message as is as a string, use your own IrcOutputSocket class, or
252-
send in a patch.
251+
For actions that are lacking a command, you can use raw to perform them.
252+
You must either pass an array of arguments (and the multiword argument must
253+
be in a single index without the colon) or pass the full string.
253254

254-
### _rawf(format, args...) ###
255+
If you find yourself using raw(), please file an issue.
256+
257+
### rawf(format, args...) ###
255258

256259
[0.7.1]
257260

258-
As _raw(message), but the arguments are passed through util.format() first.
261+
As raw(message), but the arguments are passed through util.format() first.
259262

260263
--------
261264

@@ -268,9 +271,11 @@ You may access the module system's methods via the Client.modules property
268271
or by using one of the following methods:
269272

270273
* client.require()
271-
* client.exports() [an alias of client.require()]
272-
* client.load()
273-
* client.loaded()
274+
* client.getModule()
275+
* client.getRole()
276+
* client.use()
277+
* client.initialize()
278+
* client.isInitializable()
274279

275280
### Creating Your Own Modules ###
276281

tennu_modules/help.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const HELP_NOT_FOUND = 'Help file for selected topic does not exist.';
22

33
const isArray = require('util').isArray;
44
const format = require('util').format;
5+
const inspect = require('util').inspect;
56
const Set = require('simplesets').Set;
67

78
module.exports = {
@@ -40,13 +41,16 @@ module.exports = {
4041
return {
4142
handlers: {
4243
'!help': function (command) {
44+
client.notice('ModHelp', '!help being handled.');
4345
// Default to showing the help for the help module if no args given.
44-
const query = command.params.length === 0 ? ['help'] : command.params.slice();
45-
46-
return helpResponse(query)
46+
const query = command.args.length === 0 ? ['help'] : command.args.slice();
47+
const response = helpResponse(query);
48+
return response;
4749
},
4850

4951
'!commands': function (command) {
52+
client.notice('ModHelp', '!commands being handled.');
53+
5054
const start = ["List of known commands: "];
5155
return start.concat(commandset.array().map(function (command) {
5256
return format(" * %s", command);
@@ -104,7 +108,7 @@ module.exports = {
104108
help: {
105109
help: [
106110
'!help <query>',
107-
'',
111+
' ',
108112
'Display the help message for the topic located at the given query.',
109113
'Query can be made of multiple subtopics',
110114
'Without a query, shows this help message.',
@@ -115,7 +119,7 @@ module.exports = {
115119

116120
commands: [
117121
'!commands',
118-
'',
122+
' ',
119123
'Show the list of commands.'
120124
]
121125
},

test/command-handler.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ describe('Command Handler', function () {
138138
const after = handler.getAfter;
139139

140140
handler.after(function () {
141+
logfn("After function called.");
141142
after.apply(handler, arguments);
142143
setImmediate(function () {
143144
assert(!receiver.say.called);

test/event-emitter.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const format = require('util').format;
77
const debug = false;
88
const logfn = debug ? console.log.bind(console) : function () {};
99

10-
var EventEmiter = require('../lib/event-emitter.js');
10+
const EventEmiter = require('../lib/event-emitter.js');
1111

1212
describe('After Event Emitter', function () {
1313
var EE;
@@ -45,5 +45,16 @@ describe('After Event Emitter', function () {
4545
});
4646
EE.emit('x', true, false);
4747
});
48+
49+
it('passes the error to err if an error is thrown', function (done) {
50+
const error = new Error();
51+
EE.on('x', function () {throw error});
52+
EE.after(function (err, res, emitted) {
53+
assert(err === error);
54+
assert(res === undefined);
55+
done();
56+
});
57+
EE.emit('x');
58+
});
4859
});
4960
});

0 commit comments

Comments
 (0)