def req_bclink(bot, update): global live_broadcast_link member_status = get_member_status(update.message.chat_id) if member_status != "Active": update.message.reply_sticker("CAADAgADQAADVSx4CwnTmrLuK3GoAg") update.message.reply_text( "This is embarrassing, but we're unable to send a link to you right now. Please get in contact with the LHC church leader.." ) print "INACTIVE member {} requests for link".format( get_user_engname(update.message.chat_id)) #inform admin on the request of bc link from inactive members bot.sendMessage( chat_id=admin_onduty_tel_id, text="*INACTIVE* member {} requested bc link.. Link is not sent! " "Please get in touch with the member..".format( get_user_engname(update.message.chat_id)), parse_mode=telegram.ParseMode.MARKDOWN) elif live_broadcast_link is None: update.message.reply_text( emojize( "Here you go the bc link is.... :cake:\n" "Haha! There's no live broadcast link at the moment!", use_aliases=True)) elif datetime.datetime.now() > bclink_end_time: update.message.reply_sticker("BQADAgADSgADVSx4C_alFsjOJxXLAg") update.message.reply_text( "I'm so sorry the broadcast has ended.. Please get in touch with the admin personnel on duty.\n" "The admin on duty today is: {}".format( get_user_engname(telegram_id=admin_onduty_tel_id))) else: update.message.reply_text( "Here you go: {}".format(live_broadcast_link)) requester_telegram_id = update.message.chat_id requester_engname = get_user_engname(requester_telegram_id) # the admin on duty is the one who uploaded the link. Admin on duty will get information on every link send out bot.sendMessage( chat_id=admin_onduty_tel_id, text="{} requested bc link. Link sent!".format(requester_engname)) print "{} requested bc link at {}".format(requester_engname, datetime.datetime.now()) if requester_engname not in list_of_bc_attendees_nick and requester_engname not in list_of_live_attendees: list_of_bc_attendees_nick.append(requester_engname)
def end_conv(bot, update, user_data): update.message.reply_sticker("BQADAgADSgADVSx4C_alFsjOJxXLAg") update.message.reply_text( "Thank you for talking to me! Type /start or press on *Start Conversation* when you wanna talk again.. ", parse_mode=telegram.ParseMode.MARKDOWN) try: print "[{}] {} left conversation".format( datetime.datetime.now(), get_user_engname(update.message.chat_id)) except Exception as e: print "[{}] {} Anonymous user left conversation".format( datetime.datetime.now(), update.message.chat_id) finally: user_data.clear() return ConversationHandler.END
def remove_bclink(bot, update): global live_broadcast_link global list_of_bc_attendees_nick live_broadcast_link = None list_of_live_attendees.sort() # show those who broadcasted before removing link percent_live_attendees = (len(list_of_live_attendees) / float(count_total_active_members())) * 100.0 percent_bc_attendees = (len(list_of_bc_attendees_nick) / float(count_total_active_members())) * 100.0 update.message.reply_text( "Attendance taken at {}\n\n" "Live Attendees:\n{}\n\nBroadcast Attendees:\n{}\n\n" "Live Attendees: {} %\n" "Broadcast Attendees: {} %".format( datetime.datetime.now().strftime("%Y-%b-%d, %A at %X"), format_attlist_intostring(att_namelist=list_of_live_attendees), format_attlist_intostring(att_namelist=list_of_bc_attendees_nick), round(percent_live_attendees, 2), round(percent_bc_attendees, 2))) # update.message.reply_text("Broadcast link removed") # update.message.reply_text("Attendance taken at {}\n\n" # "Live Attendees:\n{}\n\nBroadcast Attendees:\n{}" # .format(datetime.datetime.now().strftime("%Y-%b-%d, %A at %X"), # format_attlist_intostring(att_namelist=list_of_live_attendees), # format_attlist_intostring(att_namelist=list_of_bc_attendees_nick))) # update.message.reply_text("These are the those who broadcasted:\n{}".format(format_attlist_intostring(att_namelist=list_of_bc_attendees_nick))) print "{} removed bc link at {}".format( get_user_engname(update.message.chat_id), datetime.datetime.now()) # print ("Live Attendees:\n{}\n\nBroadcast Attendees:\n{}" # .format(format_attlist_intostring(att_namelist=list_of_live_attendees), # format_attlist_intostring(att_namelist=list_of_bc_attendees_nick))) # print "These are the those who broadcasted:\n{}".format(format_attlist_intostring(att_namelist=list_of_bc_attendees_nick)) list_of_bc_attendees_nick[:] = [] list_of_live_attendees[:] = []
def start(bot, update): print "{} is prompting the bot".format(update.message.chat_id) try: user_exists = check_for_existing_user( telegram_id=update.message.chat_id) except Exception as e: print e else: if user_exists: # print "User exists!" user_data_dict = get_user_info(telegram_id=update.message.chat_id) # print "User {} is prompting the bot".format(user_data_dict['eng_name']) print "[{}] {} starts talking".format( datetime.datetime.now(), get_user_engname(update.message.chat_id)) if user_data_dict['isAdmin'] == 'No': update.message.reply_sticker('BQADAgADWgADVSx4CwEjojGmsKGbAg') update.message.reply_text( "Hi *{}*, we meet again, what can I do for you today?". format(user_data_dict['nick_name']), reply_markup=markup_main_menu_kb, parse_mode=telegram.ParseMode.MARKDOWN) else: update.message.reply_sticker('BQADAgADWgADVSx4CwEjojGmsKGbAg') update.message.reply_text( "Hey whatsup boss *{}*, we meet again! What can I do for you today?" .format(user_data_dict['nick_name']), reply_markup=markup_adminmain_menu_kb, parse_mode=telegram.ParseMode.MARKDOWN) return CHOOSING else: print "{} is an unknown user!".format(update.message.chat_id) update.message.reply_sticker('BQADAgADZgADVSx4C4I00LsibnWGAg') update.message.reply_text( "Hi! I am the LHC AutoBot!. I will need some information before we proceed. " "Why don't you tell me something about yourself?", reply_markup=markup) return CHOOSING
def received_bclink_information(bot, update, user_data): text = update.message.text category = user_data['choice'] user_data[category] = text del user_data['choice'] if text == "BACK": update.message.reply_text("Back to main menu", reply_markup=markup_adminmain_menu_kb) return CHOOSING global live_broadcast_link live_broadcast_link = text update.message.reply_text( "Thank you! I've got the following broadcast link from you: \n{}". format(text)) print "{} uploaded bc link at {}".format( get_user_engname(update.message.chat_id), datetime.datetime.now()) list_of_bc_attendees_nick[:] = [] list_of_live_attendees[:] = [] global bclink_start_time bclink_start_time = datetime.datetime.now() # assign the admin on duty for constant update of bc link requests global admin_onduty_tel_id admin_onduty_tel_id = update.message.chat_id # assign end time to the link global bclink_end_time bclink_end_time = datetime.datetime.now() + datetime.timedelta( seconds=bclink_uptime_duration) update.message.reply_text( "Broadcast link will be taken down exactly 5 hours from now by {}". format(bclink_end_time.strftime("%Y-%m-%d %H:%M:%S")), reply_markup=markup_adminmain_menu_kb) return CHOOSING