I am attempting to have a bot reply to Reddit comments when they contain any one of a number of certain phrases, however it seemingly replies to any comment at all due to the large number of phrases. I am not sure if I should put the phrases in a string, a list, etc. I'm using Python 3.5, and the latest version of PRAW. It should be noted that I am very much a beginner in Python. Thanks. Here is the code:
if " stupid phrase" or " dumb phrase" or " lame phrase" or " bad phrase" or " terrible phrase" or " me another phrase" or " idiotic phrase" or " awful phrase" or " me a better phrase" or " phrase sucks" or " phrase is stupid" or " phrase is dumb" or " phrase is lame" or " phrase is bad" or " phrase is not funny" or " phrase is terrible" or " phrase is idiotic" or " phrase is awful" in comment.body:
print(str(AUTHOR) + str(comment.body))
comment.reply((random.choice(REPLIES0)) + (random.choice(REPLIES1)) + (random.choice(REPLIES2)) + (random.choice(REPLIES3)))
comments_replied_to.append(comment.id)
with open("comments_replied_to.txt", "w") as f:
for comment.id in comments_replied_to:
f.write(comment.id + "\n")
else:
comments_not_replied_to.append(comment.id)
with open("comments_not_replied_to.txt", "w") as f:
for comment.id in comments_not_replied_to:
f.write(comment.id + "\n")
EDIT: My problem has been solved. I turned the phrases into a list, which I then changed into a set, and it's working fine using if any(word in comment.body.split() for word in WORDLISTSSET):
. Thanks all.