def send_welcome(message): if database.is_user_new(user_id=message.chat.id): bot.send_message(chat_id=message.chat.id, text=content.welcome_message) # welcome message database.set_state(user_id=message.chat.id, state='waiting') else: bot.send_message(chat_id=message.chat.id, text=content.welcome_message)
def cmd_start(message): state = get_state(message.chat.id) # IF PROMO AND SALES if state == config.States.S_PROMOSALES.value: set_state(message.chat.id, config.States.S_PROMOSALES.value) bot.send_message(message.chat.id, config.MAIN_ANSWER, reply_markup=markup_MAIN) # IF CATEGORIES elif state == config.States.S_CATEGORIES_PROMO.value or state == config.States.S_CATEGORIES_SALES.value: bot.send_message(message.chat.id, config.CATEGORY_ANSWER, reply_markup=markup_CATEGORY) #IF START else: bot.send_message(message.chat.id, "При возникновении проблем с ботом пропишите /start") bot.send_message(message.chat.id, config.MAIN_ANSWER, reply_markup=markup_MAIN) set_state(message.chat.id, config.States.S_PROMOSALES.value) msg = Message(api_key=config.API_KEY, platform=config.PLATFORM, version=config.VERSION, user_id=str(message.chat.id), message=message.text, intent="/start") msg.send()
def cmd_reset(message): bot.send_message( message.chat.id, "Давайте начнем с начала.\n" "Используйте /info или /commands для того чем и как Я могу помочь.") database.set_state(message.chat.id, config.States.S_CHOICE.value) global last_search last_search = []
def echo_all(message): if not database.is_user_new( user_id=message.chat.id) and database.get_state( user_id=message.chat.id) != 'in_progress': text = message.text urls = url_extractor(text) if len(urls) == 0: bot.reply_to(message, content.answer_for_message_no_links) else: database.set_state(user_id=message.chat.id, state='in_progress') bot.reply_to(message, content.answer_for_message_with_links ) # answer for links it gets for url in urls: if video_id_extractor(url): summary_text = get_video_summary(url) if summary_text is not False: bot.send_message(chat_id=message.chat.id, text=content.uploading_in_progress) video = open('final_video.mp4', 'rb') sended_message = bot.send_video(message.chat.id, video) database.new_summary( user_id=message.chat.id, message_id=sended_message.message_id, summary_text=summary_text, url=url, summary_type='video') database.set_state(user_id=message.chat.id, state='waiting') else: bot.send_message(chat_id=message.chat.id, text=content.cannot_process) database.set_state(user_id=message.chat.id, state='waiting') else: page_text = get_page_text(url) if len(page_text) != 0: summary_text = get_summary(page_text) text_to_speech(summary_text) sended_message = bot.reply_to( message, prettify_output(summary_text)) # Audio audio = open(content.audio_file_name, 'rb') bot.send_audio(message.chat.id, audio) database.new_summary( user_id=message.chat.id, message_id=sended_message.message_id, summary_text=summary_text, url=url, summary_type='article') database.set_state(user_id=message.chat.id, state='waiting') else: bot.send_message(chat_id=message.chat.id, text=content.cannot_process) database.set_state(user_id=message.chat.id, state='waiting') else: bot.send_message(chat_id=message.chat.id, text=content.already_in_progress)
def cmd_start(message): database.set_state(message.chat.id, config.States.S_START.value) bot.send_message( message.chat.id, "Привет, я Youtube Бот \n" "Введите /info для того, что бы узнать ,чем я могу помочь Вам.\n" "Введите /commands для списка доступных комманд.\n" "Введите /reset для начала нового диалога.") bot.send_photo(message.chat.id, pict[randint(0, 3)]) database.set_state(message.chat.id, config.States.S_CHOICE.value)
def user_choosing_sale_section(message): if message.text == config.TECH_BUTTON: bot.send_message(message.chat.id, config.get_text(config.SRC_SALE_TECH), parse_mode='markdown') bot.send_message(message.chat.id, config.MAIN_ANSWER, reply_markup=markup_MAIN) elif message.text == config.CLOTH_BUTTON: bot.send_message(message.chat.id, config.get_text(config.SRC_SALE_CLOTH), parse_mode='markdown') bot.send_message(message.chat.id, config.MAIN_ANSWER, reply_markup=markup_MAIN) elif message.text == config.DOMESTIC_BUTTON: bot.send_message(message.chat.id, config.get_text(config.SRC_SALE_DOMESTIC), parse_mode='markdown') bot.send_message(message.chat.id, config.MAIN_ANSWER, reply_markup=markup_MAIN) elif message.text == config.CHILD_BUTTON: bot.send_message(message.chat.id, config.get_text(config.SRC_SALE_CHILD), parse_mode='markdown') bot.send_message(message.chat.id, config.MAIN_ANSWER, reply_markup=markup_MAIN) elif message.text == config.FOOD_BUTTON: bot.send_message(message.chat.id, config.get_text(config.SRC_SALE_FOOD), parse_mode='markdown') bot.send_message(message.chat.id, config.MAIN_ANSWER, reply_markup=markup_MAIN) elif message.text == config.BACK_BUTTON: bot.send_message(message.chat.id, config.MAIN_ANSWER, reply_markup=markup_MAIN) elif message.text == config.OTHER_BUTTON: bot.send_message(message.chat.id, config.get_text(config.SRC_SALE_OTHER), parse_mode='markdown') bot.send_message(message.chat.id, config.MAIN_ANSWER, reply_markup=markup_MAIN) set_state(message.chat.id, config.States.S_PROMOSALES.value) msg = Message(api_key=config.API_KEY, platform=config.PLATFORM, version=config.VERSION, user_id=str(message.chat.id), message=message.text) msg.send()
def user_choosing_section(message): if message.text == config.PROMOCODES_BUTTON: set_state(message.chat.id, config.States.S_CATEGORIES_PROMO.value) bot.send_message(message.chat.id, config.CATEGORY_ANSWER, reply_markup=markup_CATEGORY) elif message.text == config.SALES_BUTTON: set_state(message.chat.id, config.States.S_CATEGORIES_SALES.value) bot.send_message(message.chat.id, config.CATEGORY_ANSWER, reply_markup=markup_CATEGORY) elif message.text == config.CONTACT_BUTTON: bot.send_message(message.chat.id, config.get_text(config.SRC_CONTACT), parse_mode='markdown') msg = Message(api_key=config.API_KEY, platform=config.PLATFORM, version=config.VERSION, user_id=str(message.chat.id), message=message.text) msg.send()