def submit_name_edit(update, context): name_v = update.message.text event_type = "Activities" event = db.child(event_type).child(event_id).get().val() if not event: #if id not found, search in activities event = db.child("Events").child(event_id).get().val() event_type = "Events" userinfo["name"] = str(name_v) userinfo["date"] = event['Date'] userinfo["location"] = event['Location'] userinfo["description"] = event['Description'] data_db_new = { "Name": userinfo["name"], "Date": userinfo["date"], "Location": userinfo["location"], "Description": userinfo["description"] } db.child(event_type).child(event_id).update(data_db_new) context.bot.send_message(chat_id=update.effective_chat.id, text='The event name has been updated to ' + name_v + '.') return ConversationHandler.END
def schedule(update, context): query = update.callback_query query.answer() output = "Upcoming Events\n\n" event_dict = db.child("Users").child( update.effective_chat.id).child("Registered Events").get().val() if event_dict: output += "This are the Upcoming Events you have registered for:\n\n" for event_id in event_dict.keys(): output += f"{event_dict[event_id]} | /details_{event_id}\n" output += "\n\n" if not event_dict: output += "You have not signed up for any Upcoming Events\n\n" output += "Weekly Activities\n\n" act_dict = db.child("Users").child( update.effective_chat.id).child("Activities").get().val() if act_dict: output += "This are the Weekly Activities you have registered for:\n\n" for act_id in act_dict.keys(): output += f"{act_dict[act_id]} | /details_{act_id}\n" output += "\n\n" if not act_dict: output += "You have not signed up for any Weekly Activities\n\n" output += "Tap below to view upcoming events and activties:" query.edit_message_text(text=output, reply_markup=schedule_keyboard())
def execute_delete(update, context): event_type = "Activities" event = db.child(event_type).child(event_id).get().val() if not event: event = db.child("Events").child(event_id).get().val() event_type = "Events" db.child(event_type).child(event_id).remove() context.bot.send_message(chat_id=update.effective_chat.id, text='The entry has been deleted successfully.')
def delete(update, context): word = str(update.message.text) event_id = word.replace('/delete_', '') event_type = "Activities" event = db.child(event_type).child(event_id).get().val() if not event: event = db.child("Events").child(event_id).get().val() event_type = "Events" update.message.reply_text(text=delete_menu_message(), reply_markup=delete_menu_keyboard())
def edit(update, context): word = str(update.message.text) event_id = word.replace('/edit_', '') event_type = "Activities" event = db.child(event_type).child(event_id).get().val() if not event: #if id not found, search in activities event = db.child("Events").child(event_id).get().val() event_type = "Events" update.message.reply_text(text=edit_menu_message(update, context), reply_markup=edit_menu_keyboard())
def done(update: Update, context: CallbackContext) -> int: user = update.message.from_user info = db.child("Users").child( user.id).child("Personal Particulars").child("Contact").get().val() #temporary manual return button to my_profile #is there a way to automatically call my_profile? keyboard = [[ InlineKeyboardButton("Back", callback_data="callback_my_profile"), ]] if info: #check if existing user update.message.reply_text( "Personal particulars updated.", reply_markup=InlineKeyboardMarkup(keyboard), #temp manual return ) else: #new user #segue into contact details for first time user keyboard = [[ InlineKeyboardButton("Continue", callback_data="callback_contact_new") ]] reply_markup = InlineKeyboardMarkup(keyboard) update.message.reply_text( "The following section requires your contact details.", reply_markup=reply_markup, ) #odd/even calculator if int(userinfo["matnum"]) % 2 == 0: oddeven = "Even" else: oddeven = "Odd" #database push! data_db_new = { "name": userinfo["name"], "gender": userinfo["gender"], "matnum": userinfo["matnum"], "dob": userinfo["dob"], "nationality": userinfo["nationality"], "telehandle": user.username, "oddeven": oddeven, } db.child("Users").child(user.id).child("Personal Particulars").child( "Personal").set(data_db_new) logger.info( "User <%s> confirmed their personal details. Uploaded to database.", user.first_name) #database done pushing #how to integrate back into main menu return ConversationHandler.END
def submit_image_edit(update, context): image_v = update.message.photo[-1].get_file() image_v.download("image.jpg") photo_folder = "activities/" event = db.child("Activities").child(event_id).get().val() if not event: #if id not found, search in events event = db.child("Events").child(event_id).get().val() photo_folder = "events/" path_on_cloud = 'images/' + photo_folder + event['Name'] + '.jpg' storage.child(path_on_cloud).put("image.jpg") update.message.reply_text( 'Thank you! The image has been updated accordingly.') return ConversationHandler.END
def display_events(update: Update, context: CallbackContext) -> str: bot = context.bot output = "" events_dict = db.child("Events").get().val() for event_id in events_dict.keys(): user_present = db.child("Users").child(update.effective_chat.id).child( "Registered Events").child(event_id).get().val() output += f"{events_dict[event_id]['Name']} | /details_{event_id}" if user_present: output += "\t(Registered)\n" else: output += "\n" output += f"Date/Time: {events_dict[event_id]['Date']}\n" output += f"Location: {events_dict[event_id]['Location']}\n" output += "\n\n" return output
def getblock(qtype): # specific type of data demanding code # lang resp need # can be defined more precisely # block returning code qtype = str(qtype) allBlocks = db.child(qtype).get() return allBlocks
def edit_menu_message(update, context): word = str(update.message.text) global event_id event_id = word.replace('/edit_', '') event_type = "Activities" global event event = db.child(event_type).child(event_id).get().val() if not event: #if id not found, search in activities event = db.child("Events").child(event_id).get().val() event_type = "Events" output = "" output += f"Name:{event['Name']}\n" output += f"Date: {event['Date']}\n" output += f"Location: {event['Location']}\n" output += f"Description: {event['Description']}\n\n" output += f"What would you like to edit?" return output
def edit_medical_entry(update: Update, context: CallbackContext) -> int: user = update.message.from_user data = db.child("Users").child( user.id).child("Personal Particulars").child("Medical").get().val() medicalinfo["bloodtype"] = data["bloodtype"] medicalinfo["medical_conditions"] = data["medical_conditions"] medicalinfo["dietary_requirements"] = data["dietary_requirements"] medicalinfo["drug_allergies"] = data["drug_allergies"] logger.info("User <%s> Medical data received.", user.first_name) update.message.reply_text(editmedicalinfo_message(), reply_markup=ReplyKeyboardRemove()) return EDIT
def details(update, context): word = str(update.message.text) global event_id event_id = word.replace('/details_', '') photo_folder = "activities/" event = db.child("Activities").child(event_id).get().val() if not event: #if id not found, search in events event = db.child("Events").child(event_id).get().val() photo_folder = "events/" count = 1 output = "" output += f"{event['Name']}\n" output += f"Date/Time: {event['Date']}\n" output += f"Location: {event['Location']}\n" output += f"Description: {event['Description']}\n\n" output += f"Participants:\n" ppl_list = db.child("Events").child(event_id).child( "Participants").get().val() if ppl_list is None: output += "There are currently no participants registered." else: for users in ppl_list: tele_h = db.child("Users").child(users).child( "Personal Particulars").child("Self").child( "telehandle").get().val() output += f"{count}. @{tele_h}\n" count += 1 output += "\n\n" output += f"Edit the event: /edit_{event_id}\n" output += "\n" output += f"Delete the event: /delete_{event_id}\n" output += "\n\n" context.bot.send_message(chat_id=update.effective_chat.id, text=output) storage.child("images/" + photo_folder + event['Name'] + ".jpg").download("edm.jpg") context.bot.send_photo(chat_id=update.effective_chat.id, photo=open('edm.jpg', 'rb'))
def edit_contact_entry(update: Update, context: CallbackContext) -> int: user = update.message.from_user data = db.child("Users").child( user.id).child("Personal Particulars").child("Contact").get().val() contactinfo["email_smu"] = data["email_smu"] contactinfo["email_personal"] = data["email_personal"] contactinfo["contactno_mobile"] = data["contactno_mobile"] contactinfo["contactno_home"] = data["contactno_home"] contactinfo["address"] = data["address"] logger.info("User <%s> Contact data received.", user.first_name) update.message.reply_text(editcontactinfo_message(), reply_markup=ReplyKeyboardRemove()) return EDIT
def activity_desc(update, context): desc_v = update.message.text userinfo["description"] = str(desc_v) str_code = hash(userinfo["name"] + userinfo["date"]) % 10**8 data_db_new = { "Name": userinfo["name"], "Date": userinfo["date"], "Location": userinfo["location"], "Description": userinfo["description"] } db.child("Activities").child(str_code).set(data_db_new) context.bot.send_message(chat_id=update.effective_chat.id, text='Your description has been recorded.') update.message.reply_text( '(OPTIONAL) Please attach an image or marketing material if available/relevant. Otherwise, you may /skip to complete the activity creation process.' ) return ACTIVITY_PHOTO
def display_events(update, context): output = "" events_dict = db.child("Events").get().val() if not events_dict: context.bot.send_message( chat_id=update.effective_chat.id, text='There are currently no upcoming events.') else: for event_id in events_dict.keys(): output += f"{events_dict[event_id]['Name']} | /details_{event_id}\n" output += f"Date/Time: {events_dict[event_id]['Date']}\n" output += f"Location: {events_dict[event_id]['Location']}\n" output += "\n\n" context.bot.send_message(chat_id=update.effective_chat.id, text=output)
def edit_personal_entry(update: Update, context: CallbackContext) -> int: user = update.message.from_user data = db.child("Users").child( user.id).child("Personal Particulars").child("Personal").get().val() userinfo["name"] = data["name"] userinfo["gender"] = data["gender"] userinfo["matnum"] = data["matnum"] userinfo["dob"] = data["dob"] userinfo["nationality"] = data["nationality"] logger.info("User <%s> Personal data received.", user.first_name) update.message.reply_text(edituserinfo_message(), reply_markup=ReplyKeyboardRemove()) return EDIT
def details(update: Update, context: CallbackContext) -> None: keyboard = [[ InlineKeyboardButton("Back", callback_data="callback_activities") ]] word = str(update.message.text) event_id = word.replace('/details_', '') event = db.child("Activities").child(event_id).get().val() if not event: #if id not found, search in events event = db.child("Events").child(event_id).get().val() keyboard = [[ InlineKeyboardButton("Back", callback_data="callback_events") ]] #change the button to return to events instead of activties user_present = db.child("Users").child(update.effective_chat.id).child( "Registered Events").child(event_id).get().val() if not user_present: user_present = db.child("Users").child(update.effective_chat.id).child( "Registered Activities").child(event_id).get().val() if user_present: update.message.reply_text( f"{event['Name']}\n" f"Date/Time: {event['Date']}\n" f"Location: {event['Location']}\n" f"Description: {event['Description']}\n\n" f"/unregister_{event_id}", reply_markup=InlineKeyboardMarkup(keyboard)) else: update.message.reply_text( f"{event['Name']}\n" f"Date/Time: {event['Date']}\n" f"Location: {event['Location']}\n" f"Description: {event['Description']}\n\n" f"/register_{event_id}", reply_markup=InlineKeyboardMarkup(keyboard))
def contact_done(update: Update, context: CallbackContext) -> int: user = update.message.from_user info = db.child("Users").child( user.id).child("Personal Particulars").child("Medical").get().val() #temporary manual return button to my_profile #is there a way to automatically call my_profile? for streamlining considerations keyboard = [[ InlineKeyboardButton("Back", callback_data="callback_my_profile"), ]] if info: #check if existing user update.message.reply_text( "Contact information updated.", reply_markup=InlineKeyboardMarkup(keyboard), #temp manual return ) else: #new user #segue into medical information for first time user keyboard = [[ InlineKeyboardButton("Continue", callback_data="callback_medical_new") ]] reply_markup = InlineKeyboardMarkup(keyboard) update.message.reply_text( "The following section requires your medical details.", reply_markup=reply_markup, ) #database push! db.child("Users").child(user.id).child("Personal Particulars").child( "Contact").set(contactinfo) logger.info( "User <%s> confirmed their Contact details. Uploaded to database.", user.first_name) #database done pushing return ConversationHandler.END
def start(update, context): # context.bot.send_message(chat_id=update.effective_chat.id, text="Welcome to SMUX's Membership Management System, You may begin accessing your account via /menu. For more information regarding functionalities, please use /faq.") user = update.message.from_user info = db.child("Users").child(user.id).child("Personal Particulars").get().val() if info: logger.info("User <%s> logged in.", user.first_name) keyboard = [[ InlineKeyboardButton("Continue", callback_data="callback_main_menu"), ]] context.bot.send_message(chat_id=update.effective_chat.id, text=f"Welcome back, {user.first_name}.") context.bot.send_message(chat_id=update.effective_chat.id, text=motd()) context.bot.send_message(chat_id=update.effective_chat.id, text="You can /menu anytime to bring up the buttons, or /help for other commands.", reply_markup=InlineKeyboardMarkup(keyboard),) else: logger.info("User <%s> First time log in.", user.first_name) keyboard = [[ InlineKeyboardButton("Continue", callback_data="callback_signup"), InlineKeyboardButton("View PDPA", callback_data="callback_disposable") ]] context.bot.send_message(chat_id=update.effective_chat.id, text=f"Hello {user.first_name}! Welcome to SMUX's Membership Management System. Before you can use this bot's functionality, please fill in your details.\n\n" "By using this bot, you agree to our PDPA clause.", reply_markup=InlineKeyboardMarkup(keyboard), )
def register(update: Update, context: CallbackContext) -> None: keyboard = [[ InlineKeyboardButton("Back", callback_data="callback_activities") ]] word = str(update.message.text) event_id = word.replace('/register_', '') event_type = "Activities" event = db.child("Activities").child(event_id).get().val() if not event: #if id not found, search in events event = db.child("Events").child(event_id).get().val() event_type = "Events" keyboard = [[ InlineKeyboardButton("Back", callback_data="callback_events") ]] db.child(event_type).child(event_id).child("Participants").child( update.effective_chat.id).set("date registered") db.child("Users").child(update.effective_chat.id).child( f"Registered {event_type}").child(event_id).set(event['Name']) update.message.reply_text(f"Successfully registered for {event['Name']}", reply_markup=InlineKeyboardMarkup(keyboard))
#cv2.imshow('', env) #cv2.waitKey(1) #network_input = np.array(channel_data).reshape(reshape) network_input = np.array(channel_data).reshape((-1,16,60,1)) #print(network_input) out = model.predict(network_input) #print(out[0]) #kelas data1 = float(out[0][0])*10 data2 = float(out[0][1])*10 data3 = float(out[0][2])*10 data4 = float(out[0][3])*10 #print(data1,data2,data3) if data1 > 9: print("kiri") db.child("suara").set("3") elif data2 >9 : print ("maju") db.child("suara").set("1") elif data3 >9 : print ("idle") db.child("suara").set("0") elif data4 >9: print("kanan") db.child("suara").set("4") else : print("null") db.child("suara").set("0") #time.sleep(0.25)
MessageHandler, Filters, ConversationHandler ) from telegram import InlineKeyboardButton, InlineKeyboardMarkup from dotenv import load_dotenv import os from database import db import pyrebase #Security def security(update, context): context.bot.send_message(chat_id=update.effective_chat.id, text="You appear to be using an account not associated with any of the SMUX EXCOs, please email [email protected] with your Unique ID if you believe this is a mistake. \n\n Your Unique ID is: " + str(update.effective_chat.id)) list_of_exco = [] user = db.child('EXCO').get().val() for uid in user.values(): list_of_exco.append(uid) security_handler = MessageHandler(~Filters.chat(chat_id=list_of_exco), security) #Token load_dotenv('.env') updater = Updater(token=os.getenv('SMUX_EXCO_BOT_TOKEN'), use_context=True) dispatcher = updater.dispatcher dispatcher.add_handler(security_handler) #Start def start(update, context): valid_user = False for user in list_of_exco: if (update.effective_chat.id == user):
def user_detail(users_by_name): detail_list = [] for key in users_by_name.keys(): detail = db.child("companies").child(key).get().val() detail_list.append(detail) return detail_list
async def path_and_query_params(path: str): companies_by_name = db.child("companies").child(path).child("user_list").get().val() company_detail_list = company_detail(companies_by_name) user_list = [i["name"] for i in company_detail_list] return {'company': f"{path}", 'user_name': user_list}
async def path_and_query_params(path: str): users_by_name = db.child("users").child(path).child("used_company").get().val() user_detail_list = user_detail(users_by_name) cname_list = [i["cname"] for i in user_detail_list] local_list = [i["local"] for i in user_detail_list] return {'user': f"{path}", 'company_name': cname_list, "local": local_list}
def motd(): output = db.child("Admin").child("MOTD").get().val() return output