Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ghost opened this issue May 22, 2024 · 2 comments
Open

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

ghost opened this issue May 22, 2024 · 2 comments

Comments

@ghost
Copy link

ghost commented May 22, 2024

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
Copy link
Owner

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)

@krypton-byte
Copy link
Owner

Thank you for your interest! You can support me directly through GitHub Sponsors, which is available on this repo page 😊👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant