Since I'm not sure if it's already implemented, can you tell me if we could use Druplicon like they have configured bots on other IRC channels such as #ubuntu.
Now:
madjoe> ask?
Druplicon> If you have a question, please go ahead and ask it. No need to ask permission. Tips on getting good help in IRC: http://blog.freenode.net/2008/03/helping-others-help-you/
After:
madjoe> ask | beanluc
Druplicon> Beanluc, if you have a question, please go ahead and ask it. No need to ask permission. Tips on getting good help in IRC: http://blog.freenode.net/2008/03/helping-others-help-you/
I know there's a "!who" that we could use as a placeholder, but it would be nice to use that placeholder in a more dynamic way. Currently it's only a placeholder for a self-reference nickname, but this way it could be anything.
Now:
madjoe> Druplicon: abc is Hello, !who!
madjoe> abc?
Druplicon> Hello, madjoe!
After:
madjoe> Druplicon: abc is Hello, !who!
madjoe> abc | beanluc
Druplicon> Hello, beanluc!
Comments
Comment #1
morbus iffThe bot can't currently do this, no, but it's been talked about a few times:
http://drupal.org/node/458508
http://drupal.org/node/316340
I'm not adverse to the feature - I think if I were to do it nowadays, it'd be something like you've defined, only using !1 .. !9, similar to a regexp's \1 (in PHP at least).
Comment #2
jazzitup commentedThis is a fully working prototype with just few lines of code and I think it would fit nicely in bot_factoid.module:
http://drupal.pastebin.com/HYw19fCZ
Before submitting a patch, can you please test it and tell me your opinion on this?
Comment #3
morbus iffHow does this satisfy the "ask?" factoid, which seems to intelligently know how to modify its statement if no placeholders were passed? Does the ubuntu bot only handle placeholders as prefixes? I'm slightly adverse to having factoids appear broken because folks didn't pass a placeholder into them.
Maybe we do something like "!1|you" in the factoid itself, to specify a default value?
Comment #4
jazzitup commentedHere, you can try it online: http://jazzit.hr/test/index.php
The "ask?" factoid will work independently as it already works right now. Take a look at these examples:
EXAMPLE 1:
=======
factoid: ask
statement: Hello world!
command: ask is <reply>Hello world!
usage: ask | madjoe
Bot output: Hello world!
EXAMPLE 2:
=======
factoid: ask
statement: Hello world, said $1!
command: ask is <reply>Hello world, said $1!
usage: ask | madjoe
Bot output: Hello world, said madjoe!
EXAMPLE 3:
=======
factoid: ask
statement: Hello world, said $1 $3$2!
command: ask is <reply>Hello world, said $1 $3$2!
usage: ask |
Bot output: Hello world, said !
EXAMPLE 4:
=======
factoid: ask
statement: Hello world, said $1, $3!
command: ask is <reply>Hello world, said $1, $3!
usage: ask | madjoe | morbus | beanluc ||
Bot output: Hello world, said madjoe, beanluc!
EXAMPLE 5:
=======
factoid: ask
statement: Hello world, said $1!
command: ask is <reply>Hello world, said $1!
usage: ask
Bot output: *NOTHING*
EXAMPLE 6:
=======
factoid: ask
statement: Hello world, said $1!
command: ask is <reply>Hello world, said $1!
usage: ask?
Bot output: THE SAME AS #3: Hello world, said !
The usage for the last example (#6) is not implemented in this script, since that piece of code is already included in Bot module.
This small script could already work for any existing factoid that doesn't have placeholders defined at all.
Slightly updated dev-version of the same code: http://drupal.pastebin.com/KVw3LkJR
Comment #5
jazzitup commentedSince I've already mentioned a bot from #ubuntu, here's the description: http://ubottu.com/devel/wiki/Plugins
Ubottu factoids: http://ubottu.com/factoids.cgi
I'd like to study their usecase before I start working on that patch. All suggestions are welcome.
Comment #6
jazzitup commented@Morbus: Maybe we do something like "!1|you" in the factoid itself, to specify a default value?
Actually I love this idea. To be sure I understood you correctly, can you please give me an example of it?
Comment #7
morbus iffAh, the Ubuntu bot is just a derivative of supybot.
Comment #8
morbus iff#6: BOTNAME: support is Hello (!1|user)! Have a bowl of (!2|ice cream)!
support?
Hello user! Have a bowl of ice cream!
support | Morbus
Hello Morbus! Have a bowl of ice cream!
support | Morbus | humble pie
Hello Morbus! Have a bowl of humble pie!
support | | humble pie
Hello user! Have a bowl of humble pie!
Maybe. It might be getting too complex.
Comment #9
jazzitup commentedGreat! That is exactly what I had on mind... I love the idea... I will work on that to update the current code.
I also thought of implementing something else: should we include some simple predefined commands as a user's input?
For this example I'll try to use a slightly complicated usecase:
> BOTNAME: support is Hello !(1|user) Have a cup of !(2). Go here: http://lmgtfy.com/q=!url(3)
> support || stfu | bot module site:drupal
> Hello user! Have a cup of stfu. Go here: http://lmgtfy.com/q=bot+module+site%3Adrupal
Notes:
1. !2 should be equal to: !(2) and !(2|)
2. Syntax: ![1-9] or !([1-9]|optional default value) or !COMMAND(Text goes here) or !COMMAND([1-9]|optional default value)
Besides !url() that could engage urlencode(), is there any other need for a predefined command from that perspective?
Comment #10
jazzitup commentedI've made the syntax exactly like I described in my previous comment. Currently available commands: !url() and !enc() - case insensitive.
URL: - stands for urlencode()
ENC: - stands for str_rot13()
Do you have any other idea to expand the list of commands with useful features?
Demo: http://jazzit.hr/test/index.php
P.S. I didn't apply the automata theory, so you won't be able to use nested commands, but I don't see it as an issue here.
TODO: Allow some spacing between elements for easier reading.
Comment #11
morbus iffFor what it's worth, I'm not interested in including any command functionality.
Secondly, I'm not interested in supporting multiple syntaxes for !2. The goal of "!2" is solely to make it easier to use strtr() from within the code. I won't accept "!(2)" and "!(2|)". The syntax should either be "!2" (there's no default value) or "(!2|value)".
Comment #12
jazzitup commented1. Do you think you can handle default value without a regex pattern?
2. Regex is more powerful than strtr() and just because of possible usage of commands I suggested two syntaxes: for simple variables "!2" and commands with variables - expressions "!(2) and "!(2|)" represent those variables as "empty" commands - a better example of a command would be "!command(2|default)". If we get rid of commands, then it's ok, we can accept just that primitive option as a single syntax.
3. BTW, my both syntaxes are held by a single regular expression.
4. Why are you so adverse to having commands in syntax? I find it quite handy to use it for urlencode() like in this example:
BOTNAME: find is <reply>!1: Go here: http://drupal.org/search/apachesolr_search/!URL(2|how to contribute Drupal)?filters=type:!(3|book)
find | zed | views 2 theming
zed: Go here: http://drupal.org/search/apachesolr_search/views+2+theming?filters=type:...