Zirak / SO-ChatBot

Other
124 stars 60 forks source link

$encode can't handle commas #252

Open caub opened 9 years ago

caub commented 9 years ago
!!learn encode $encode($0)
!!encode test shit fuck
@crl test%20shit%20fuck
!!encode test, shit , fuck
@crl test

I don't understand where the rest of the string is gone? dropped by SO chat? if yes would there be a way to handle this?

Zirak commented 9 years ago

This happens because I'm an idiot and didn't learn from my predecessors.

The /learn command implements some sort of macro language, which basically acts like a text preprocessor: It searches text for variable denotations and replaces them with their textual value.

So the following happens:

macro = "$encode($foo)
foo = "blah baz"

// first pass of the replacement catches `$encode`, parses its arguments:
macro = $foo
foo = "blah baz"
output = "blah, baz"

// which means it's translated to:
$encode(blah, baz)

Which only encodes the first argument.

This is fucking bash all over again. Because under bash, the solution is: $encode("$foo"), but of course I didn't implement string interpolation, so there is no solution.

Fuck me.

As said in #254, I detest how /learn grew to become something which needs to have computational power, but lacks any sort of semblance to logic (you don't even have fucking if statements). /learnEval would be much, much better.

So lazy though. So lazy.