zigdon / xkcd-Bucket

Bucket is the channel bot for #xkcd
http://wiki.xkcd.com/irc/Bucket
121 stars 31 forks source link

"Do you know ____?" seems to fail matching on certain phrases #64

Closed dgw closed 8 years ago

dgw commented 9 years ago

I'd be happy to PR this, but first I'd like to know if the use of (\w+) intentionally does not match on messages like "Do you know Nowhere Man" or "Do you know Elvis?". Might have to change the check for who/what/how/etc. to do it if desired, but the current behavior doesn't make a whole lot of sense to me.

zigdon commented 9 years ago

Why wouldn't it match on Nowhere Man?

dgw commented 9 years ago

I honestly have no idea. Did some testing just now and came up with this IRC log:

[04:42:32] <~dgw> do you know nowhere man?
[04:42:43] <~dgw> do you know blah?
[04:42:43] <&Kaede> No, but if you hum a few bars I can fake it
[04:42:47] <~dgw> do you know blah?
[04:42:47] <&Kaede> No, but if you hum a few bars I can fake it
[04:42:49] <~dgw> hmm
[04:42:49] Kaede strokes her imaginary beard thoughtfully
[04:42:58] <~dgw> do you know this thing?
[04:42:59] <&Kaede> No, but if you hum a few bars I can fake it
[04:43:01] <~dgw> do you know nowhere man?
[04:43:17] <~dgw> do you know random phrase with several words?
[04:43:18] <&Kaede> No, but if you hum a few bars I can fake it

Seems there are some phrases that inexplicably don't trigger it, "nowhere man" being one of them.

belak commented 8 years ago
        } elsif ( $bag{orig} =~ /^(?:Do you|Does anyone) know (\w+)/i
            and $1 !~ /who|of|if|why|where|what|when|whose|how/i )

I realize this bug hasn't been touched in a while, but I'm pretty sure this is the relevant code. Doesn't this check if any of that list is contained in $1? So if "where" is in the first word after "Do you know" it wouldn't match it.

I'm not very familiar with perl, but this might fix it, depending on the intended behavior.

/^(?:who|of|if|why|where|what|when|whose|how)/i

dgw commented 8 years ago

All hail @belak, Perl Guru.

I forgot about this, to be quite honest. But I just tested with the regex edit you posted et voilà:

[01:09:18] <~dgw> Kaede: restart
[01:09:18] <&Kaede> Restarting at dgw's request
[01:09:18] <&Kaede> Okay, dgw, I'll be right back.
[01:09:55] <~dgw> Kaede: stats
[01:09:56] <&Kaede> I've been awake since Fri Nov 13 02:09:26 2015 (about 29 seconds), and was last changed about 44 seconds ago. I know now a total of 3,603 things about 727 subjects. I know of 279 objects and am carrying 5 of them. 
[01:10:02] <~dgw> OK
[01:10:06] <~dgw> Do you know nowhere man?
[01:10:06] <&Kaede> No, but if you hum a few bars I can fake it
[01:10:09] <~dgw> neat
[01:10:14] <~dgw> that fixes the bug

Prepping a PR right now. I'll use some environment variable magic to credit you as the commit author, @belak, using the email address on your profile.