zigdon / xkcd-Bucket

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

Early "addressed" exit after "Mathing!" filters out "take this..." and "have a..." #71

Open SoobNauce opened 8 years ago

SoobNauce commented 8 years ago

line 1623-1626, right after the "#Mathing!" section:

elsif ( $bag{addressed} ) {
            &error( $bag{chl}, $bag{who} );
            return;
        }

leaving the function (db_success, I believe). But later in the section, after the hardcoded "hum a few bars" response, ass hyphenation (clearly, none of which are meant to respond to bucket being addressed), is the "hands bucket $1" section. After that section is the problematic part, which responds to "bucket, take this $1" and "bucket, have a(n) $1".

Relevant lines (1668-1683):

elsif (
            $bag{orig} !~ /\?\s*$/
            and $bag{editable}
            and $bag{orig} =~ /^(?:
                               puts \s (\S.+) \s in \s (the \s)? $nick\b
                             | (?:gives|hands) \s $nick \s (\S.+)
                             | (?:gives|hands) \s (\S.+) \s to $nick\b
                            )/ix
            or (
                    $bag{addressed}
                and $bag{orig} =~ /^(?:
                                 take \s this \s (\S.+)
                               | have \s (an? \s \S.+)
                              )/x
            )
          )

I don't know perl very well but I can probably work on a PR over a few days or weeks if nobody else wants to work on it.

dgw commented 7 years ago

Found this while looking through open issues to see if another issue I've run into is represented, and yes, this is a bug. Code that can handle lines in which Bucket has been addressed shouldn't occur after that check and &error() call.

Unless I'm misreading the code, the whole elsif section that handles giving Bucket items should just be moved above the $bag{addressed} bit, which is now at line 1625.