scrapinghub / slackbot

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

@reply_to with list as the trigger #123

Closed SteveChristian70 closed 7 years ago

SteveChristian70 commented 7 years ago

I have the slackbot up and running and I'm trying to make a plugin that responds to a list of keywords then gives out a random response, but I can't get the reply_to command to recognize the list of keywords as the trigger. I can use one keyword and have it respond with the random RESPONSES, but I would rather not use 11 functions when I could use a list. Anybody have any ideas on what I am doing wrong or how I could get this to work?


import re
from slackbot.bot import respond_to
from slackbot.bot import listen_to
import random
KEYWORDS = ("what", "hi", "greetings", "sup", "what's up",)
RESPONSES = ["This aggression will not stand, man.", "hey man ", "Mind if I do a J?"]
@respond_to(KEYWORDS, re.IGNORECASE)
def check_for_greeting(message):    
    response = random.choice(RESPONSES)
    message.reply(response)```
SteveChristian70 commented 7 years ago

Solved it by using:


import re
from slackbot.bot import respond_to
from slackbot.bot import listen_to
import random
KEYWORDS = ("what", "hi", "greetings", "sup", "what's up",)
RESPONSES = ["This aggression will not stand, man.", "hey man ", "Mind if I do a J?"]
@respond_to('(.*)', re.IGNORECASE)
def check_for_greeting(message, KEYWORDS):      
    response = random.choice(RESPONSES)
    message.reply(response)```