whatsapp-framework icon indicating copy to clipboard operation
whatsapp-framework copied to clipboard

Human behavior still too robotic

Open MarAvFe opened this issue 6 years ago • 6 comments

I added a little bit of logic to the project human behavior related.

The thing is to wait time relatively to your message length. Any human can write 200 characters in 0.4 secs. This is a section added in app/mac.py:50

This is the code in master

def prepate_answer(self, conversation, disconnect_after=True):
    # Code before remains untouched

    # Set is writing
    start_typing(self, conversation)
    time.sleep(random.uniform(0.5, 1.4))

    # Set it not writing
    stop_typing(self, conversation)
    #time.sleep(random.uniform(0.1, 0.3))

    # Code after remains untouched

This is the edited part

def prepate_answer(self, conversation, message_length, disconnect_after=True):
    # Code before remains untouched

    # Set is writing
    start_typing(self, conversation)

    def get_delay(msg_len):
        # Measured seconds per character
        rate = 0.2

        # Estimated time per human writing
        secs_to_write = rate * msg_len
        return secs_to_write + random.uniform(-2,2)

    if message_length < 150:
        time.sleep(get_delay(message_length))
    else:
        while message_length > 0:
            time.sleep(get_delay(message_length))
            message_length -= 150
            stop_typing(self, conversation)
            time.sleep(random.uniform(2,5))
            start_typing(self, conversation)

    # Set it not writing
    time.sleep(random.uniform(0.1, 0.3))
    stop_typing(self, conversation)

    # Code after remains untouched

The measured rate of time taken for writing a character is 0.2 seconds. If the message was shorter than 150 characters, it just calculates like 0.2 * 112 = 22.4. But if the message is longer, maybe a person has to stop to think what to keep writing or rephrasing. So it loops for longer messages waiting 2-5 seconds each stop.

Notice the message length was added as a parameter. Just needing to call the function as len(message).

What do you guys think of a PR?

MarAvFe avatar Jul 12 '18 22:07 MarAvFe

message_length referenced before assignment

x-frst avatar Jul 16 '18 13:07 x-frst

Yes, that was a mockup. Check my edit, where I switched message_length to be the third parameter because it can't go after an optional parameter.

def prepate_answer(self, conversation, message_length, disconnect_after=True):
    ...

Also you have to call that function as

# mac.py:149 (approx.)
def send_message(str_message, conversation, disconnect_after=True):
    ...
    prepate_answer(entity, conversation, len(message), disconnect_after)
    ...

Particularily to your answer, it sounds like you forgot to add message_length to the signature of the function.

MarAvFe avatar Jul 16 '18 16:07 MarAvFe

Yep my mistake sorry!

x-frst avatar Jul 16 '18 18:07 x-frst

This is great. Good job. Soon I'll be adding more functionality. Feel free to make a PR about this

danielcardeenas avatar Jul 19 '18 23:07 danielcardeenas

@danielcardeenas Thank god you're still alive xD please make send_audio feature dude! And please tell me how to do these things #165 #161

x-frst avatar Jul 20 '18 03:07 x-frst

anywone can send me the mac.py modified??

camiu01 avatar Jan 07 '19 19:01 camiu01