bozza del bot di ingresso con funzioni di login e corsi fittizzi

sclero
Luca Lombardo 8 months ago
parent 9140b5f188
commit 5c0755a518

9
.gitignore vendored

@ -0,0 +1,9 @@
# Local files
.env
*.local*
# Python
env/
# Editors
.vscode/

@ -1,4 +1,26 @@
IDEE / COSE DA FARE:
# BOT Telegram per i gruppi dei corsi del dipartimento di matematica
- [ ] 1. Al posto di caricare i libri di testo fisicamente, puntare ad un link IPFS decentralizzato
- [ ] 2. Sezione domande orali
Descrizione TODO
## Development
### Prerequisiti
```bash
pip install -r requirements.txt
```
Il token va messo dentro un file `.env` nella root del progetto. Per crearne uno di esempio:
```bash
echo "BOT_TOKEN=123456789:ABCdefGhIjKlMnOpQrStUvWxYz" > .env
```
### Funzionalità
- [x] Comandi `/start` e `/help`
- [ ] Creare effettivamente i primi gruppi di beta testing ed aggiungere i link effettivi ai comandi `/start` e `/help`
- [ ] Funzione per autenticare tramite account di ateneo usando Google
- [ ] Letteralmente tutto il resto

@ -0,0 +1,54 @@
import os
import asyncio
from dotenv import load_dotenv
from telebot import types
from telebot.async_telebot import AsyncTeleBot
load_dotenv()
BOT_TOKEN = os.getenv("BOT_TOKEN")
bot = AsyncTeleBot(BOT_TOKEN)
def is_mathematician(user_id) -> bool:
return True
# Handle '/start' and '/help'
@bot.message_handler(commands=['help', 'start'])
async def send_welcome(message):
markup = types.InlineKeyboardMarkup()
btn = types.InlineKeyboardButton('Autenticati', callback_data='authenticate')
markup.add(btn)
await bot.reply_to(message, """\
Benvenuto nel bot di ingresso per i gruppi telegram del dipartimento di matematica dell'università di Pisa! Per poter accedere, fai l'autenticazione con il tuo account di ateneo tramite Google. Clicca il pulsante qui sotto!\
""", reply_markup=markup)
buttons = { # {name of the button: courses}
'Primo Anno 📚': 'Analisi 1 🧮: http://example.com/matematica\n Fisica 🧲: http://example.com/fisica\n Informatica 💻: http://example.com/informatica',
'Secondo Anno 📚': 'Algebra 1 : http://example.com/algebra\n Analisi 2 🧮: http://example.com/analisi2\n Programmazione 💻: http://example.com/programmazione',
'Terzo Anno 📚': 'Meccanica Razionale 🧲: http://example.com/meccraz\n Calcolo Scientifico 🧮: http://example.com/cs\n LPL 💻: http://example.com/lpl',
'Magistrale 🎓': 'Intelligenza Artificiale 🤖: http://example.com/intelligenzaartificiale\n Data Science 📊: http://example.com/datascience\n Cyber Security 🔒: http://example.com/cybersecurity',
'Miscellanea 📝': 'Spam 📬: http://example.com/spam\n Eventi 🎉: http://example.com/eventi\n• PHC 🏥: http://example.com/phc',
}
# Handle button click
@bot.callback_query_handler(func=lambda call: call.data == 'authenticate')
async def handle_authenticate(call):
await bot.answer_callback_query(call.id) # Answer the callback query
if is_mathematician(call.from_user.id):
markup = types.InlineKeyboardMarkup()
for button in buttons:
markup.add(types.InlineKeyboardButton(button, callback_data=button))
await bot.send_message(call.message.chat.id, 'Autenticazione riuscita! Adesso puoi accedere a tutti i gruppi disponibili presenti', reply_markup=markup)
else:
await bot.send_message(call.message.chat.id, 'Sembra che tu non sia iscritto al corso di Laurea in matematica. Se pensi che sia un errore o desideri essere aggiunto, manda una mail a macchinisti@phc.dm.unipi.it. Altrimenti puoi chiedere di farti aggiungere manualmente ai gruppi a cui sei interessato da altri studenti di matematica che sono già iscritti.')
# Handle button click
@bot.callback_query_handler(func=lambda call: call.data in buttons)
async def handle_buttons(call):
await bot.answer_callback_query(call.id)
await bot.send_message(call.message.chat.id, buttons[call.data])
asyncio.run(bot.polling())

@ -0,0 +1,2 @@
pyTelegramBotAPI==4.15.2
python-dotenv==1.0.0
Loading…
Cancel
Save