def edit_app_form(message): editing_item = storage.get_editing_item(message.chat.id) log.making_logs(editing_item) if editing_item: storage.edit_user_string(chat_id=message.chat.id, data=message.text) keyboard = telebot.types.InlineKeyboardMarkup() app_form = utils.send_app_form(storage.get_user_string( message.chat.id)) items = constants.app_form_ru keyboard.add( telebot.types.InlineKeyboardButton(text=items['name'], callback_data='name'), telebot.types.InlineKeyboardButton(text=items['country'], callback_data='country')) keyboard.add( telebot.types.InlineKeyboardButton(text=items['city'], callback_data='city'), telebot.types.InlineKeyboardButton(text=items['occupation'], callback_data='occupation')) keyboard.add( telebot.types.InlineKeyboardButton(text=items['birthdate'], callback_data='birthdate'), telebot.types.InlineKeyboardButton(text=items['favorite'], callback_data='favorite')) keyboard.add( telebot.types.InlineKeyboardButton(text=constants.back, callback_data="back_to_menu")) bot.send_message(message.chat.id, text=app_form, reply_markup=keyboard) log.making_logs(message.text.encode())
def select_language(message): log.making_logs('Bot got "start" command') storage.set_user_string(message.chat.id) keyboard = telebot.types.InlineKeyboardMarkup() keyboard.add( telebot.types.InlineKeyboardButton(text=constants.ru, callback_data='ru')) keyboard.add( telebot.types.InlineKeyboardButton(text=constants.eng, callback_data='eng')) bot.send_message(message.chat.id, text=constants.select_language, reply_markup=keyboard)
def edit_items(call): ''' Собственно, чтобы ты заметил! Не лучше ли вот так организовывать дерево? PyCharm рекомендует. :param call: :return: ''' mes_text = '' # от вот этого надо бы избавиться по-хорошему. В другой файлик, например if call.data == 'name': storage.prepare_edit_user_string(chat_id=call.message.chat.id, editing_item='name') mes_text = constants.redact_name elif call.data == 'country': storage.prepare_edit_user_string(chat_id=call.message.chat.id, editing_item='country') mes_text = constants.redact_country elif call.data == 'city': storage.prepare_edit_user_string(chat_id=call.message.chat.id, editing_item='city') mes_text = constants.redact_city elif call.data == 'occupation': storage.prepare_edit_user_string(chat_id=call.message.chat.id, editing_item='occupation') mes_text = constants.redact_occupation elif call.data == 'birthdate': storage.prepare_edit_user_string(chat_id=call.message.chat.id, editing_item='birthdate') mes_text = constants.redact_birthdate elif call.data == 'favorite': storage.prepare_edit_user_string(chat_id=call.message.chat.id, editing_item='favorite') mes_text = constants.redact_favorite keyboard = telebot.types.InlineKeyboardMarkup() callback_button1 = telebot.types.InlineKeyboardButton( text=constants.back, callback_data="back_to_redact") keyboard.add(callback_button1) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=mes_text, reply_markup=keyboard) log.making_logs(f'\n{storage.get_user_string(call.message.chat.id)}\n')
def photo(message): log.making_logs(message.photo[2]) bot.send_message(chat_id=message.chat.id, text=message.photo[2])
def web_hook(): log.making_logs('Trying set webhook') bot.remove_webhook() bot.set_webhook(url=config.app_address) log.making_logs(bot.get_webhook_info()) return ''
def get_message(): bot.process_new_updates( [telebot.types.Update.de_json(request.stream.read().decode("utf-8"))]) log.making_logs('Bot is processing new message') return ''
def clear_storage(message): storage.clear_all() log.making_logs(utils.send_order_list(message.chat.id))
keyboard.add( telebot.types.InlineKeyboardButton(text=items['city'], callback_data='city'), telebot.types.InlineKeyboardButton(text=items['occupation'], callback_data='occupation')) keyboard.add( telebot.types.InlineKeyboardButton(text=items['birthdate'], callback_data='birthdate'), telebot.types.InlineKeyboardButton(text=items['favorite'], callback_data='favorite')) keyboard.add( telebot.types.InlineKeyboardButton(text=constants.back, callback_data="back_to_menu")) bot.send_message(message.chat.id, text=app_form, reply_markup=keyboard) log.making_logs(message.text.encode()) @bot.message_handler(content_types='photo') def photo(message): log.making_logs(message.photo[2]) bot.send_message(chat_id=message.chat.id, text=message.photo[2]) if __name__ == '__main__': try: log.making_logs('The script was started') log.making_logs(bot.get_webhook_info()) app.run(port=os.environ.get('PORT', 5000)) except Exception as e: log.making_logs(e)