scrapinghub / slackbot

A chat bot for Slack (https://slack.com).
MIT License
1.26k stars 394 forks source link

Limit responses to one controlling if more than one apply #124

Closed benjiyamin closed 7 years ago

benjiyamin commented 7 years ago

Right now I have two commands that apply when I write the command "tell me about yourself". The first is suppose to tell me bot details and the second is suppose to run a wikipedia search.

Not sure if there's currently a way to make it so the first command controls and only responds in in this case. Right now, two responses are given because they both apply at the same time.

"tell me about yourself" "tell me about [query]"


@respond_to('tell me about yourself', re.IGNORECASE)
def about(msg):
    msg.reply('I am blah blah blah..'')

@respond_to('tell me about (.*)', re.IGNORECASE)
def wikipedia(msg, query):
    ...
    [wikipedia search code]
    ...
lukeconvertdigital commented 7 years ago

The matching is regex, so you could exclude the word 'yourself'. Example: \b(?!yourself)\b\w+

Alternatively you could look for the 'yourself' word after matching in the wikipedia function and just return if it's there.

benjiyamin commented 7 years ago

@helloitsluke can't believe I didn't think of those. Thanks!