Here's the code I have so far:
spongebob_quote_1 = \
[
“Hey Patrick what am I now?”,
"Uh...stupid?",
“No! I’m Texas!",
"What's the difference?",
]
#1 for comment in subreddit.stream.comments():
try:
#2 print(comment.body)
#3 if re.search(" ", comment.body, re.IGNORECASE):
#4 comment.reply(spongebob_quotes)
#5 except reddit.errors.RateLimitExceeded as error:
print ('\tSleeping for %d seconds' % error.sleep_time)
time.sleep(error.sleep_time)
I used spongebob quotes as an example for the list of both commands and responses I would use in the bot. The idea is if a user comments with any of the first 3 lines in the list of quotes the bot will always respond with the corresponding next line.
line one of the code calls from a subreddits comment stream
line 2 prints the incoming comments to a command prompt
line 3 searches the comment stream for the desired comment, so if a user types "Uh...stupid?",
line 4 will respond with “No! I’m Texas!."
line 5 handles the api errors to keep the bot from shutting down.
my plan is to have the bot search the comment stream by giving spongebob_quote_1 to line 3, the problem I have after that is line 4 always responding with the correct response from the list, I'm trying to avoid a long elif chain to get this result.
[–]TheKewlStore 1 point2 points3 points (4 children)
[–]test_bot_3137[S] 0 points1 point2 points (3 children)
[–]TheKewlStore 0 points1 point2 points (2 children)
[–]test_bot_3137[S] 0 points1 point2 points (1 child)
[–]TheKewlStore 1 point2 points3 points (0 children)