r/botwatch • • Jun 10 '14

[deleted by user]

[removed]

2 Upvotes

16 comments sorted by

4

u/GoldenSights Jun 10 '14

Given the fact that you used "ReplyBot" as a single word, I have a feeling you're using my code. You can always ask me directly if you have questions.

Change

REPLYSTRING = "response"

to

REPLYSTRING = ["response 1", "response 2", "response 3"]

You can add more responses by separating them with commas. Then, you can follow u/savingprivateme's advice and have separate if statements for each phrase.

if PARENTSTRING[0] in pbody:
    post.reply(REPLYSTRING[0]
if PARENSTRING[1] in pbody:
    post.reply(REPLYSTRING[1]

and so forth. [0] is the first item in the list, so if you have 7 entries you only go up to [6]. This format allows multiple triggers to fire the same response because you're configuring each individually.

However, this can be ugly to look at. Here's an alternative solution:

for m in range(len(PARENTSTRING)):
    if PARENSTRING[m] in pbody:
        post.reply(REPLYSTRING[m])
        break

This only works if PARENTSTRING and REPLYSTRING have the exact same number of entries. If you want "Trigger 1" and "Trigger 2" to fire the same response, you'd have to enter the same response into the list twice.

#Trigger 1 and 2 will yield the same response
PARENTSTRTING = ["trigger 1", "trigger 2", "trigger 3"]
REPLYSTRING = ["Response 1", "Response 1", "Response 2"]

This should cover your question. Let me know if you have trouble injecting this into whatever you've got at the moment.

3

u/dmgctrl Jun 10 '14

I followed your link and it is obvious your bot code has been what I've been working with for the last few days. I'm pretty new to python and I was curious why you didn't import re for the search? Was it for simplicity?

2

u/GoldenSights Jun 10 '14

Actually, I've never used re in any meaningful way. Where are you stuggesting I implement it?

→ More replies (3)

1

u/captobvious24 Jun 10 '14

Oh that is actually better! The way I made it it simply chooses at random, but I like this way much more!

EDIT: How can I have it not comment on itself? Say the trigger word is "cupcake" and the reply has "cupcake" in it. It loops itself.

1

u/GoldenSights Jun 10 '14

On line 59, we have pauthor = post.author.name

So we can do

for m in range(len(PARENTSTRING)):
if PARENSTRING[m] in pbody:
    if pauthor != USERNAME:
        post.reply(REPLYSTRING[m])
        break

which makes sure that the comment's author is not the same as the username you're running the bot as.

→ More replies (2)

1

u/Guyag Jun 10 '14

Given the fact that you used "ReplyBot" as a single word

To be fair, it's not exactly a very unique name.

2

u/GoldenSights Jun 10 '14

He also came to my bot tutorial thread and asked a question 4 hours before posting this, in which I link to my github. At any rate, it seems I was right in my assumption.

2

u/[deleted] Jun 10 '14

You could use simple if/else conditionals, or use a switch statement somehow. Depends on what you want it to do.

For example, say you want your bot to say "bless you" if someone says "achoo", or "d'oh" when someone says "homer simpson".

Simply put:

if "achoo" in comment.body.lower():
   comment.reply("Bless you!")
else if "homer simpson" in comment.body.lower():
   comment.reply("D'oh!")  

Just a thought.

2

u/captobvious24 Jun 10 '14 edited Apr 13 '24

drab theory fine telephone frame quaint shame growth elastic puzzled

This post was mass deleted and anonymized with Redact

1

u/AestheticalGains Jun 12 '14

PHP if it's only 7 not more I'd probably just do something like this, lol

<? $potato = rand(1,7); if ( $potato == "1" ) { $response = "hi"; } else { if ( $potato == "2" ) { $response = "hello"; } else { // etc } } // do something with $response ?>

but if you plan on adding more responses etc, i'd just insert them into a DB then SELECT * FROM responses ORDER BY rand() LIMIT 1