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 addadmin(message): chat_id = message.chat.id if chat_id in alice_vars.superuser: msg = bot.reply_to(message, "What's the ID you want to add to Admins?") bot.register_next_step_handler(msg, bot_functions.add_admin) else: bot.send_message(chat_id, "oops! you're not a superuser. Only a superuser can add new admins.")
def telegramid(message): chat_id = message.chat.id f_name = message.from_user.first_name print(f_name, "asked for telegram ID.\n") bot.send_message(chat_id, chat_id, 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 createReminder(message): reminderDetails = {} reminderDetails['ID'] = message.chat_id bot.send_message(message.chat_id, "Enter Title of the Reminder") reminderDetails['Title'] = message.text msg = bot.send_message(message.chat_id, "Describe the Reminder") reminderDetails['Description'] = gatherDescription(msg) reminderDetails['DueDate'] = getDate( bot.send_message(message.chat_id, "Enter Date")) sql_functions.addReminder(alice_vars.db_name, reminderDetails)
def add_user(message): user_class = message.text chat_id = message.chat.id f_name = message.from_user.first_name l_name = message.from_user.last_name name = f_name + " " + l_name sql_functions.add_user(alice_vars.db_name, 'Users', chat_id, name, user_class) bot.send_message(chat_id, "It appears you are new here. send /help to get help.", reply_markup=alice_vars.keyboard_default)
def docs_upload(message): doc_type = message.document.mime_type.split('/')[-1] if not (doc_type == 'pdf'): bot.send_message(message.chat.id, "Please send a pdf file", reply_markup=alice_vars.keyboard_admin) else: adddocs['id'] = message.document.file_id sql_functions.add_docs(alice_vars.db_name, adddocs) bot.send_message(message.chat.id, "Document uploaded successfully.", reply_markup=alice_vars.keyboard_admin)
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 readReminder(message): chat_id = message.chat.id result = sql_functions.getReminded(alice_vars.reminder) if result == False: bot.send_message(chat_id, "No works due") else: feedback_msg = "" for entry in result: reminderMsg = reminderMSg+"\n" + \ str(entry)+": "+sql_functions.reminder_fetch(alice_vars.db_name + "\n\n", 'Reminder: ', entry) bot.send_message(chat_id, reminderMsg, reply_markup=alice_vars.keyboard_default)
def sendfeedback(message): chat_id = message.chat.id if chat_id in alice_vars.superuser: result = sql_functions.read_feedback(alice_vars.db_name, 'Feedback') if result == False: bot.send_message(chat_id, "No feedbacks recorded yet!", reply_markup = alice_vars.keyboard_admin) else: feedback_msg = "" for entry in result: feedback_msg = feedback_msg+"\n"+str(entry)+": "+sql_functions.feedback_fetch(alice_vars.db_name+"\n\n", 'Feedback', entry) bot.send_message(chat_id, feedback_msg, reply_markup = alice_vars.keyboard_admin) else: msg = bot.send_message(chat_id, "So, What do you think about me ?") bot.register_next_step_handler(msg, bot_functions.feedback)
def add_admin(message): try: admin_id = int(message.text) print(admin_id, "will be added to admins.") if isinstance(admin_id, int): sql_functions.add_admin(alice_vars.db_name, 'Admins', admin_id) bot.send_message(message.chat.id, str(admin_id) + " added to Admins.", reply_markup=alice_vars.keyboard_admin) else: raise Exception() except Exception as e: bot.send_message(message.chat.id, "oops! something went wrong. try again.", reply_markup=alice_vars.keyboard_admin)
def dept(message): docs['dept'] = message.text msg = bot.send_message(message.chat.id, "Select a subject:", reply_markup=create_keyboard( alice_vars.subjects[docs['dept']])) bot.register_next_step_handler(msg, subject)
def docs(message): chat_id = message.chat.id 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.dept)
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 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 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 docs_module(message): adddocs['module'] = int(message.text) msg = bot.send_message(message.chat.id, "send me the document(pdf)") bot.register_next_step_handler(msg, docs_upload)
def docs_subject(message): adddocs['subject'] = message.text msg = bot.send_message(message.chat.id, "Select a module(0 to upload the syllabus)", reply_markup=alice_vars.keyboard_modules) bot.register_next_step_handler(msg, docs_module)