Comparing version 0.4.0 to 0.5.0
@@ -0,1 +1,7 @@ | ||
0.5.0 / 2015-04-05 | ||
================== | ||
* Stream specification separates user and channel for better portability: | ||
- `user` is now a user UID only | ||
- `channel` is an optional channel UID | ||
0.4.0 / 2015-04-02 | ||
@@ -2,0 +8,0 @@ ================== |
12
gu.js
@@ -68,2 +68,3 @@ var smell = require('smell'); | ||
var user = obj.user; | ||
var chan = obj.channel; | ||
@@ -77,3 +78,3 @@ for (var i = 0; i < this.handlers.length; i += 1) { | ||
var match = msg.match(handler.reg); | ||
var preparedSay = this.say.bind(this, user); | ||
var preparedSay = this.say.bind(this, user, chan); | ||
var args = [preparedSay].concat(match.slice(1), obj.name || obj.user); | ||
@@ -95,4 +96,9 @@ | ||
*/ | ||
Gu.prototype.say = function (user, msg) { // TODO: include name? | ||
this.push({message: msg, user: user}); // can be _read later | ||
Gu.prototype.say = function (user, chan, msg) { // TODO: include name? | ||
if (chan) { | ||
this.push({ user: user, channel: chan, message: msg }); | ||
} | ||
else { | ||
this.push({ user: user, message: msg }); | ||
} | ||
}; | ||
@@ -99,0 +105,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"author": "Eirik Albrigtsen <analsandblaster@gmail.com>", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"repository": { | ||
@@ -25,3 +25,3 @@ "type": "git", | ||
"dependencies": { | ||
"smell": "^2.0.0", | ||
"smell": "^2.0.2", | ||
"hot-reload": "1.4.2-beta" | ||
@@ -28,0 +28,0 @@ }, |
@@ -67,2 +67,3 @@ # gu | ||
user: String, // unique identifier of user | ||
channel: String, // unique group chat identifier (if relevant) | ||
message: String, // raw message to be matched by gu | ||
@@ -72,9 +73,11 @@ } | ||
Output objects are identical. The `user` property is passed stright through and is can be anything as long as it can be used to again identify the user to send the response to on the other end. For `irc-stream` it is either the string: "#chan:user" for a channel message or "user" for a personal message. | ||
Output objects are identical. As an example an example message from/to `irc-stream` can look like this `{ user: 'clux', channel: '#quake', message: 'hi' }` for a private message, the `channel` key is unset. | ||
An optional `name` property may be set on the input for the convenience of gu handlers - this name will be passed through to the handlers as the last argument and is assumed to be human readable. | ||
An optional `name` property may be set for the convenience of the stream handler (such as `xmpp-stream`). It is used when doing group chat highlighting without having to necessarily use the larg UID. For IRC it is unused. | ||
## Future | ||
Alternative transport modules. | ||
## Compatible Transports | ||
Best tested: [irc-stream](https://github.com/clux/irc-stream). | ||
Early prototype of [xmpp-stream](https://github.com/clux/xmpp-stream) also available. | ||
## Caveats | ||
@@ -89,3 +92,3 @@ ### What files are reloaded | ||
However, it is possible to save a file that looks valid but will have a runtime error, for instance referencing an undefined variable. This we will not guard on (otherwise we'd have to try-catch _everything_), and your bot will crash. Thus, you should lint on save to prevent this from happening. | ||
However, it is possible to save a file that looks valid but will have a runtime error, for instance referencing an undefined variable. This we will not guard on (otherwise we'd have to try-catch _everything_), and your bot will crash. Thus, you should use a fast-response linter to prevent this from happening. | ||
@@ -92,0 +95,0 @@ ## Options |
@@ -16,6 +16,2 @@ var Gu = require(process.env.GU_COV ? '../gu-cov' : '../') | ||
var xs = [ | ||
{user: '#chan:clux', name: 'clux', message: "roll d8"}, | ||
{user: '#chan:aa', name: 'aa', message: 'weather oslo tuesday'} | ||
]; | ||
var ys = []; | ||
@@ -25,6 +21,6 @@ exBot.on('data', function (y) { | ||
}); | ||
xs.forEach(function (x) { | ||
exBot.write(x); | ||
}); | ||
exBot.write({user: 'clux', message: "roll d8"}); | ||
exBot.write({user: 'aa', message: 'weather oslo tuesday'}); | ||
setTimeout(function () { | ||
@@ -56,3 +52,3 @@ t.equal(ys.length, 2, "got two messages"); | ||
}); | ||
rBot.write({user: '#chan:clux', message: 'hi'}); | ||
rBot.write({user: 'clux', message: 'hi'}); | ||
@@ -63,3 +59,3 @@ setTimeout(function () { | ||
setTimeout(function () { | ||
rBot.write({user: '#chan:clux', message: 'hi2'}); | ||
rBot.write({user: 'clux', message: 'hi2'}); | ||
setTimeout(function () { | ||
@@ -66,0 +62,0 @@ t.equal(ys[1].message, "b", "second message uses second handler"); |
15175
192
137
Updatedsmell@^2.0.2