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

feat: implement database to store users email #8

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

R1D3R175
Copy link

Closes #3 with the following changes:

  • Migrate python-telegram-bot from 13.6 to latest (currently 20.6).
  • Create a database with ORM using SQLAlchemy 2.0.23.

Something to know:

  • There's a RuntimeWarning due to add_commands being an async function not being await-ed inside the main function.
  • In data/db/__init_.py there's a very weird import to create the tables, most likely it can be done in a much better way.

module/commands/login.py Outdated Show resolved Hide resolved
requirements.txt Outdated Show resolved Hide resolved
module/commands/login.py Outdated Show resolved Hide resolved
data/db/__init__.py Outdated Show resolved Hide resolved
fix: use ApplicationBuilder.post_init() to add_commands
refactor: rename login to register
@R1D3R175
Copy link
Author

This PR, using the OTP class in #10, can be used to solve #2; there would only be a few edits needed to the /register conversation handler.

data/db/__init__.py Outdated Show resolved Hide resolved
Comment on lines +9 to +11
db_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "db.sqlite3")
engine = create_engine("sqlite:///" + db_path)
Session = sessionmaker(engine)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Evita sempre di mettere direttive a questo livello, in quanto verranno eseguite nel momento in cui il modulo viene importato. Senza saperlo sto provocando un side-effect (creando un file).
Inoltre rendi piu' delicati i test (cosa succede se voglio usare un altro path invece di db.sqlite?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per cui come dovrei fare?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essenzialmente l'ideale sarebbe rinchiudere tutto dentro una funzione da chiamare al momento del bisogno, possibilmente anche dal main.
Non c'è bisogno di avere una sessione globale: puoi crearne una nuova ogni volta che ti serve, è praticamente equivalente. Leggi questa risposta da uno degli sviluppatori per approfondire.
Se proprio pensi di aver bisogno di uno stato globale, un Singleton potrebbe fare al caso tuo. Almeno puoi controllare il momento in cui viene inizializzato, piuttosto che fare tutto nel momento il cui il modulo viene importato

module/commands/register.py Outdated Show resolved Hide resolved
module/commands/register.py Outdated Show resolved Hide resolved
Comment on lines +5 to +8
HELP_CMD_TEXT = '\n'.join((
"📬 /report Fornisce la possibilità di poter inviare una segnalazione agli sviluppatori riguardante qualsiasi disservizio",
"🔑 /register Permette di effettuare la registrazione al sistema"
))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puoi usare una stringa piu' lunga con le triple vigolette o il backslash, non c'e' bisogno di creare una tupla e fare il join.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mi sembrava meglio farla cosi' per un discorso di leggibilita' del file in se, pero' se avete fatto sempre con le triple quotes mi adeguo

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Qua ci sono alcune opzioni per ottenere lo stesso risultato. Vedi quali preferisci.

ORIGINAL = "\n".join(
    (
        "📬 /report Fornisce la possibilità di poter inviare una segnalazione agli sviluppatori riguardante qualsiasi disservizio",
        "🔑 /register Permette di effettuare la registrazione al sistema",
    )
)

BACKSLASH = "📬 /report Fornisce la possibilità di poter inviare una segnalazione agli sviluppatori riguardante qualsiasi disservizio\n\
🔑 /register Permette di effettuare la registrazione al sistema"

TRIPLE_QUOTE = """📬 /report Fornisce la possibilità di poter inviare una segnalazione agli sviluppatori riguardante qualsiasi disservizio
🔑 /register Permette di effettuare la registrazione al sistema"""

CONCATENING = (
    "📬 /report Fornisce la possibilità di poter inviare una segnalazione agli sviluppatori riguardante qualsiasi disservizio\n"
    "🔑 /register Permette di effettuare la registrazione al sistema"
)

module/commands/register.py Show resolved Hide resolved
@R1D3R175 R1D3R175 requested a review from TendTo November 21, 2023 17:56
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

Successfully merging this pull request may close these issues.

Implement a database for storing users emails
3 participants