krypton-byte / neonize

whatsapp automation library, written in python
http://krypton-byte.me/neonize/
Apache License 2.0
55 stars 15 forks source link

freezed until I press Ctrl-c + funding question #27

Open ghost opened 4 months ago

ghost commented 4 months ago

image After I successfully logged in, the program is blocked until I press Ctrl-c. here is the minimal code to reproduce it

from neonize import NewClient
from neonize.utils.jid import build_jid

client = NewClient("test")
client.connect()
for i in range(50, 100, 2):
    import time
    client.send_message(build_jid("myPhoneNumber"), f"{i}")
    time.sleep(5)

Is there a way to avoid pressing Ctrl-c?

Another question: Is it possible to avoid creating the sqlite3 db?

Another question: where can we fund you? ;)

krypton-byte commented 4 months ago
import logging
import os
from pathlib import Path
import signal
from neonize.client import NewClient
from neonize.events import (
    PairStatusEv,
    event,
)
from neonize.utils import log
from neonize.utils.jid import build_jid
import secrets
import tempfile
import time

def interrupted(*_):
    event.set()

log.setLevel(logging.DEBUG)
signal.signal(signal.SIGINT, interrupted)
db_name = Path()._from_parts([tempfile.gettempdir(), secrets.token_hex() + ".sqlite3"])
client = NewClient(db_name.__str__())

@client.event(PairStatusEv)
def PairStatusMessage(client: NewClient, message: PairStatusEv):
    log.info(f"logged as {message.ID.User}")
    for i in range(50, 100, 2):
        client.send_message(build_jid("myPhoneNumber"), f"{i}")
        time.sleep(5)
    event.set()
    client.logout()

client.connect()
os.remove(db_name)