def welcome(message): chat_type = message.chat.type chat_id = message.chat.id f_name = message.from_user.first_name l_name = message.from_user.last_name name = f_name+" "+l_name if chat_type == "private": print(f_name,"with id",chat_id,"is a user.") user_exist = sql_functions.check_user(alice_vars.db_name, 'Users', chat_id) admin_exist = sql_functions.check_user(alice_vars.db_name, 'Admins', chat_id) if user_exist == True: print("User already exists in db.") if admin_exist == True: bot.send_message(chat_id, "Hi, Welcome back. If you want any help, just send /help", reply_markup=alice_vars.keyboard_admin) else: bot.send_message(chat_id, "Hi, Welcome back. If you want any help, just send /help", reply_markup=alice_vars.keyboard_default) else: print("Adding",f_name,"to db.") msg = bot.send_message(chat_id, "Hi, "+ f_name +" May I know your class?", reply_markup=alice_vars.keyboard_classes) bot.register_next_step_handler(msg, bot_functions.add_user) elif (chat_type == "group") | (chat_type == "supergroup"): print(chat_id,"is a group\n") bot.send_message(chat_id, 'This is a group, and I hate crowd. PM me for a better bot experience.')
def helper(message): chat_id = message.chat.id print("Help requested.") if sql_functions.check_user(alice_vars.db_name, 'Admins', chat_id): bot.send_message(chat_id, alice_vars.helpmsg_default+ alice_vars.helpmsg_admin+ alice_vars.helpmsg_feedback, reply_markup=alice_vars.keyboard_admin) else: bot.send_message(chat_id, alice_vars.helpmsg_default+alice_vars.helpmsg_feedback, reply_markup=alice_vars.keyboard_default)
def addremind(message): chat_id = message.chat.id user_exist = sql_functions.check_user(alice_vars.db_name, 'Admins', chat_id) if user_exist == False: bot.send_message(chat_id, "Oops! You're not a bot Admin.", markup=alice_vars.keyboard_default) print(message.from_user.first_name, "thinks he's an admin.") else: print("Adding new reminder.")
def adddocs(message): chat_id = message.chat.id user_exist = sql_functions.check_user(alice_vars.db_name, 'Admins', chat_id) if user_exist == False: bot.send_message(chat_id, "Oops! You're not a bot Admin.", markup=alice_vars.keyboard_default) print(message.from_user.first_name, "thinks he's an admin.") else: msg = bot.send_message(chat_id, "Select the Department: ", reply_markup=bot_functions.create_keyboard(alice_vars.depts)) bot.register_next_step_handler(msg, bot_functions.docs_dept)
def module(message): if sql_functions.check_user(alice_vars.db_name, 'Admins', message.chat.id): keyboard = alice_vars.keyboard_admin else: keyboard = alice_vars.keyboard_default docs['module'] = int(message.text) results = sql_functions.get_docs(alice_vars.db_name, docs) for result in results: bot.send_document(message.chat.id, result, reply_markup=keyboard)
def addremind(message): chat_id = message.chat.id user_exist = sql_functions.check_user(alice_vars.db_name, 'Admins', chat_id) if user_exist == False: bot.send_message(chat_id, "Oops! You're not a bot Admin.", markup=alice_vars.keyboard_default) print(message.from_user.first_name, "thinks he's an admin.") else: msg = send_message(message.chat_id, "Enter Reminder Title") bot.register_next_step_handler(msg, bot_functions.createReminder) print("Adding new reminder.")
def voti_command(chat, message): old_grades = sql_functions.get_old_grades(message.sender.id) m = "Ecco i tuoi voti:\n" for i in old_grades: m += f"{i[3]}\n*{i[2]}* - {i[4]}\n\n" if m != "Ecco i tuoi voti:\n": chat.send(m) else: chat.send("Non hai ancora nessun voto") nuovi_voti = check_new_vote(sql_functions.check_user(message.sender.id)[0]) if nuovi_voti == False: return if len(nuovi_voti): m = "*Ehi, ho trovato anche dei nuovi voti, eccoli:*\n" for i in nuovi_voti: m += f"{i['subjectDesc']}\n*{i['decimalValue']}* - {i['evtDate']}\n\n" chat.send(m)
def feedback(message): chat_id = message.chat.id if sql_functions.check_user(alice_vars.db_name, 'Admins', chat_id): keyboard = alice_vars.keyboard_admin else: keyboard = alice_vars.keyboard_default name = message.from_user.first_name + " " + message.from_user.last_name text = message.text try: sql_functions.add_feedback(alice_vars.db_name, 'Feedback', name, text) bot.send_message(chat_id, "Thanks! Your feedback has been recorded", reply_markup=keyboard) except Exception as e: bot.send_message(chat_id, "oops! something went wrong. Try again!", reply_markup=keyboard)
def quote(message): chat_id = message.chat.id if sql_functions.check_user(alice_vars.db_name, 'Admins', chat_id): keyboard = alice_vars.keyboard_admin else: keyboard = alice_vars.keyboard_default try: quote = urllib.request.urlopen( 'http://quotes.rest/qod.json').read().decode('utf-8') quote_json = json.loads(quote) bot.send_message(chat_id, "Quote of the day:\n\n", quote_json['contents']['quotes'][0]['quote'], "\n", quote_json['contents']['quotes'][0]['author'], reply_markup=keyboard) except Exception as e: bot.send_message(chat_id, "oops! something went wrong! try again.", reply_markup=keyboard)
def cat(message): chat_id = message.chat.id if sql_functions.check_user(alice_vars.db_name, 'Admins', chat_id): keyboard = alice_vars.keyboard_admin else: keyboard = alice_vars.keyboard_default try: f_name = message.from_user.first_name print(f_name, "requested for a kitty") photo = urllib.request.urlopen('http://thecatapi.com/api/images/get') if chat_id < 0: bot.send_photo(chat_id, photo) print("Kitty launched.\n") elif chat_id > 0: bot.send_photo(chat_id, photo, reply_markup=keyboard) print("Kitty launched.\n") except Exception as e: bot.send_message(chat_id, "oops! something went wrong! try again.", reply_markup=keyboard)
def start2(chat, message): chat.sendAction('typing') s0 = classeviva.Session() s = login(s0, sql_functions.check_user(message.sender.id)[0][1], message.text) if s == False: chat.send("I dati di login che hai inserito non sono corretti", no_keyboard=True) chat.send("Scrivimi il tuo username/email", no_keyboard=True) sql_functions.change_status("start1", message.sender.id) return password_crypted = triple_des(key.master_key).encrypt(message.text, padmode=2) sql_functions.register_password(message.sender.id, password_crypted) sql_functions.change_status("", message.sender.id) write_first_vote(message.sender.id, s) print("REGISTER " + message.sender.first_name) chat.send( "Ottimo, registrazione completata\n" "Ora il bot controllera' se ti arriveranno nuovi voti!\n" "Intanto puoi visualizzare quelli che hai gia' usando i comandi qua sotto" )
def start(chat, message): print("START from" + message.sender.first_name) user = sql_functions.check_user(message.sender.id) chat.send( "Benvenuto su *ClasseVivaVotiBot*\n" "Questo bot controlla ogni 2 ore l'arrivo di nuovi voti, inoltre ti permette di visualizzarli facilemte tramite i suoi comandi\n\n" "*Continuando con il login si dichiara di aver letto ed accettato l'Informativa per il Trattamento dei Dati Personali* accessibile a [questo indirizzo](http://infopz.hopto.org/votibot.html).\n" "\nIl bot e' completamente [open-source](https://github.com/infopz/botVoti2)\n" "Per problemi contattare @infopz", disable_preview=True) if user: if user[0][1] is None or user[0][2] is None or user[0][3] != "": chat.send( "Sei gia registrato, ma devi reinserire i dati, inviami il tuo username:"******"Avevi gia' inserito i tuoi dati, puoi utilizzare il bot!") else: sql_functions.register_user(message.sender.id, 'start1') chat.send("Per iniziare, inviami il tuo username/email di ClasseViva", no_keyboard=True)
def check_status(chat, message): status = sql_functions.check_user(message.sender.id)[0][3] if status == 'start1': start1(chat, message) elif status == 'start2': start2(chat, message)