Closed SephVelut closed 7 years ago
Yeah, that script should work. Out of interest are you using the source or the published npm 1.0.0-alphax
version?
Also is it possible that the reply gets exhausted because it doesn't have the {keep}
flag on, or does this happen when you say qq
as the first trigger after start up?
Interesting, we have a test for this and It seems to still be passing (in V1.0) Im wondering if the polarity of the boolean is inverted and making it hard to grok.
Er, I didn't look closely enough.
exports.sigh = function(bool, cb) {
cb(null, false);
};
This always returns false so it'll always be filtered out. (I think? @silentrob)
+ my name is <name>
- {^hasName("false")} ^save("name",<cap1>) Nice to meet you, <cap1>.
- {^hasName("true")} I know, you already told me your name.
const hasName = function hasName(bool, cb) {
this.user.getVar('name', (e, name) => {
if (name !== null) {
cb(null, (bool === 'true'));
} else {
// We have no name
cb(null, (bool === 'false'));
}
});
};
I installed "superscript": "alpha"
on npm. I have the custom function using false deliberately. I just want to see a reply true or false, but I'm not seeing anything. I'm using the telnet client and loading the plugins directory with pluginsPath
set in options.
I think the custom function should return true
if you want to see the reply, and false
if you want to filter it out, though I may be going crazy. Maybe it should be the other way around?
Okay I tried with true and it replies. I always thought filters worked liked a conditional with true and false alternate replies? At least that was the previous behavior. How would I reply or call another custom function on a false a condition?
I do agree that is miss leading.. by definition filter functions should be filter based on a true condition / value.
Just for clarity: in the plugin function that you write as a filter, you'll want to either return true if you want the reply to be used (not filtered), or false if you want it to not be used (filtered).
const myPlugin = myPlugin(some, args, here, callback) {
if (someCondition) {
// filter the reply
return callback(null, false)
}
return callback(null, true)
}
I agree the filter functionality should pass only on true. Giving false to the callback isn't necessary in that case; the filter will only pass on true.
So that leaves conditional replies. Anyway to make this happen?
+ *
- {condition1} a
- {condition2} b
- {condition3} ^saveSomething(<cap1>)
- {condition4} ^doSomething() c
You could either create four different plugin functions, or if they share common functionality, one plugin function that accepts different arguments:
+ *
- {^myNameIsBen()} a
- {^myNameIsRob()} b
- {^myNameIsAlice()} ^saveSomething(<cap1>)
- {^myNameIsDavid()} ^doSomething() c
or (preferably):
+ *
- {^myName("Ben")} a
- {^myName("Rob")} b
- {^myName("Alice")} ^saveSomething(<cap1>)
- {^myName("David")} ^doSomething() c
The second, single function is preferable but consider if I want to {^myName(<cap1>)}
because I don't know what the input will be. Wouldn't filters breakdown at this point for conditionals?
+ *
- {^myName(<cap1>)} a
- {^myName(<cap1>)} b
- {^myName(<cap1>)} ^saveSomething(<cap1>)
- {^myName(<cap1>)} ^doSomething() c
Wouldn't work. You would have to use separate functions, which is less than ideal
{^myNameIsBen(<cap1>)}
{^myNameIsRob(<cap1>)}
{^myNameIsDingo(<cap1>)}
We have processed the trigger and have all the captured input, so passing <cap1>
in should work.
What I mean is
+ *
- {^myName(<cap1>)} a
- {^myName(<cap1>)} b
- {^myName(<cap1>)} ^saveSomething(<cap1>)
- {^myName(<cap1>)} ^doSomething() c
which filter gets to pass? What I would really like to do is
+ *
- {<cap1> == "Rob"} a
- {<cap1> == "Ben"} b
- {<cap1> == "Jake"} c
I suppose you could
+ *
- {^myNameIs(<cap1>, "Rob")} a
- {^myNameIs(<cap1>, "Ben")} b
- {^myNameIs(<cap1>, "Jake")} c
But it feels like it could be more 'built in'. Thanks for the help btw.
For the sake of completion, we do have another system that might work.. but it is for managing conversation state/flow.
+ __start__
- match here {id=123, bool=true, str="string" }
%% (bool == true)
+ boo ya
- YES
%% (id == 123)
- winning
Yeah, that last one is probably what I'd do right now! :)
We could introduce some shorthand for simple comparisons like the second example. Probably lower down the priority list though.
On branch v1.0.0
The filter function does get fired off, but the bot never replies with anything.