tgalal / yowsup

The WhatsApp lib
GNU General Public License v3.0
7.08k stars 2.23k forks source link

Collection layer.py #1659

Closed langioletto closed 5 years ago

langioletto commented 8 years ago

I invite all users to put in download here their layer.py

It 'very interesting this project and it would be nice to learn new things from all of us

My project is here

Thank you all :+1:

schoerg commented 8 years ago

I think most of your time.sleep() are unnecessary.

langioletto commented 8 years ago

No, it emulates the human, no slip not see, online, you are writing etc etc.

Too much haste? :)

Put here your "layer.py" :+1:

schoerg commented 8 years ago

Yeah, but it is not needed I think, I don't use them. (Not banned or anything)

self.toLower(messageProtocolEntity.ack())
self.toLower(messageProtocolEntity.ack(True)) 

Uppon receiving a message

messageProtocolEntity.setBody(string)
self.onTextMessage(messageProtocolEntity)
self.toLower(messageProtocolEntity.forward(messageProtocolEntity.getFrom()))

For sending a message.

My layer.py would be a bit large.

langioletto commented 8 years ago
        self.toLower(messageProtocolEntity.ack()) #Set received (double v)
        time.sleep(0.5)
        self.toLower(PresenceProtocolEntity(name = name)) #Set name Presence
        time.sleep(0.5)
        self.toLower(AvailablePresenceProtocolEntity()) #Set online
        time.sleep(0.5)
        self.toLower(messageProtocolEntity.ack(True)) #Set read (double v blue)

In this logical order, when accessing whatsapp first is the dual v Gray then double v blue, not together

If you are not online before how can you have read the message?

Put in your project download here.. :+1:

schoerg commented 8 years ago

I am online.

langioletto commented 8 years ago

After that you're online self.toLower(messageProtocolEntity.ack(True)) #Set read (double v blue) Not before

You are always online 24/7 ?

schoerg commented 8 years ago

Yes.

I am online before that too, I could not receive messages if I were not.

Not setting presence will show my number as last seen 27/4/2016 although it is online. It might be good however to set presence.

langioletto commented 8 years ago

v04 Added log unauthorized phone number Is logged: Sender, Number sender, Message text received

Put in download here your layer.py

schoerg commented 8 years ago

https://gist.github.com/schoerg/330a5d7520034801bd9a93915def78a7

If you are interested. I removed the functions, but you get the idea I guess. Needs some refactoring and cleanup too. Sending the message is handled inside the functions.

langioletto commented 8 years ago

you have removed the the most beautiful part.... :)

schoerg commented 8 years ago

It was not really beautiful, that's why I removed it. :/

langioletto commented 8 years ago

can I ask you a question?

if I put a ping too long, waiting to run a script

        if message.lower() == 'ciao':
            answer = "Ciao "+namemitt+" "
            os.system('Find_SMS_SIM_CARD.sh')
            time.sleep(180)
            answer = "Ciao "+namemitt+" "
            self.toLower(textmsg(answer, to = recipient ))
            print answer

At the end of 180 seconds the answer "Ciao " will not is sent to me

but at the terminal I see the print answer, then the .py is not blocked

Now I send a new whatsapp the number does not respond until I do not kill and restart python

Max time.sleep(120) wotk

how do I fix?

Thanks

schoerg commented 8 years ago

time.sleep() will block, and I don't know if yowsup uses threads to do something different in the meantime, so keepalives might not be sent.

I don't know what Find_SMS_SIM_CARD.sh does but you could rearrenge stuff a bit. Use Popen(), which will not block on waiting for the output and just send the "Ciao" message immediateley. Also you have answer = "Cia..." two times in there.

sowerkoku commented 8 years ago

such high values are not necessary.

I occupy something like this in my script:

       self.toLower(messageProtocolEntity.ack())
        time.sleep(random.randrange(4,13))
        self.toLower(AvailablePresenceProtocolEntity())
        time.sleep(random.randrange(2,3))
        self.toLower(messageProtocolEntity.ack(True))
        time.sleep(random.randrange(3,4))

        self.toLower(OutgoingChatstateProtocolEntity(OutgoingChatstateProtocolEntity.STATE_TYPING, Jid.normalize(messageProtocolEntity.getFrom(False)) ))
        time.sleep(random.randrange(4,5))
        self.toLower(OutgoingChatstateProtocolEntity(OutgoingChatstateProtocolEntity.STATE_PAUSED, Jid.normalize(messageProtocolEntity.getFrom(False)) ))
        time.sleep(random.randrange(2,3))
        self.toLower(OutgoingChatstateProtocolEntity(OutgoingChatstateProtocolEntity.STATE_TYPING, Jid.normalize(messageProtocolEntity.getFrom(False)) ))
        time.sleep(random.randrange(5,6))
        self.toLower(OutgoingChatstateProtocolEntity(OutgoingChatstateProtocolEntity.STATE_PAUSED, Jid.normalize(messageProtocolEntity.getFrom(False)) ))
        time.sleep(random.randrange(2,3))

        self.toLower(enviar)
        time.sleep(random.randrange(2,3))
        self.toLower(UnavailablePresenceProtocolEntity())

although it is true, it is not necessary to occupy "time.sleep" and "presence states". But if I want to humanize responses bot, certainly they are.

Gab0 commented 8 years ago

@langioletto Fork yowsup with your code in order to show here, should be better than using mega.nz :+1:

langioletto commented 8 years ago

Better to download the files, they avoid formatting errors

controller-t commented 8 years ago

Dear All, Could someone please add function to upload image/video file. eg If I send Photo then it should upload a file on specific path.

sowerkoku commented 8 years ago

We'll see when we have some time here