R
R
Roman Roman2020-05-09 00:52:33
Python
Roman Roman, 2020-05-09 00:52:33

The code does not work, it will help to fix it! I will be grateful?

import telebot
from telebot import types
import time
with open('menu.txt') as file: #Читаем файл
  lines = file.read().splitlines() # read().splitlines() - чтобы небыло пустых строк

dic = {} # Создаем пустой словарь

for line in lines: # Проходимся по каждой строчке
  key,value = line.split(': ') # Разделяем каждую строку по двоеточии(в key будет - пицца, в value - 01)
  dic.update({key:value})	 # Добавляем в словарь


menu = ["Піца", "Чай","Кава","Морозиво","Суші"]
a = 0
bot = telebot.TeleBot('1087018832:AAEUODlCX-NUC8LOumeedO1<img src="https://habrastorage.org/webt/5e/b5/d0/5eb5d09f0f205013860572.png" alt="image"/>')
@bot.message_handler(commands=["Меню","menu","start"])
def start(m):
    msg = bot.send_message(m.chat.id, "Доброго дня! Що хочете замовити?")
    keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
    keyboard.add(*[types.KeyboardButton(name) for name in menu])
    bot.send_message(m.chat.id, 'Вибери в меню що тобі інтересно(Приймається останє замовлення)', reply_markup=keyboard)
    bot.register_next_step_handler(msg, name)
@bot.message_handler(content_types=['text'])
def name(m):
    if m.text in menu:
        keyboard_n = types.ReplyKeyboardMarkup(resize_keyboard=True)
        keyboard_n.add(*[types.KeyboardButton(name) for name in ["1", "2", "3", "4", "5"]])
        bot.send_message(m.chat.id, "Яка кілкість?", reply_markup=keyboard_n)
        how(m);
    if m.text == "Морозиво":
            keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
            keyboard.add(*[types.KeyboardButton(name) for name in ["Бананове","Шоколадне"]])
            bot.send_message(m.chat.id, 'Яке морозиво ви бажаєте?', reply_markup=keyboard)
@bot.message_handler(content_types=['text'])
def how(message):
    print(message.text)
    if message.text == "1" or message.text == "2" or message.text == "3" or message.text == "4" or message.text == "5": 
        markup_2 = types.InlineKeyboardMarkup()
        item1 = types.InlineKeyboardButton("Так", callback_data = "good")
        item2 = types.InlineKeyboardButton("Ні", callback_data = "bad")
        markup_2.add(item1, item2)
        bot.send_message(message.chat.id, "Це все?", reply_markup = markup_2)
@bot.callback_query_handler(func=lambda call: True)                                                  #Інлайнова клавіатура
def this_all(call):
    try:
        if call.message:
            if call.data == 'good':
                bot.send_message(call.message.chat.id, "ви замовили:",)
            elif call.data == 'bad':
               bot.send_message(call.message.chat.id, "Ок")
                   
            bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=" ",reply_markup=None)       #Видалення кнопки після нажимання
    except Exception as e:
        print(repr(e))
bot.polling(none_stop=True, interval=1)

    #elif m.text == 'Прайс-лист':
        #keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
        #keyboard.add(*[types.KeyboardButton(advert) for advert in ['Общий', 'Одиночный']])
        #keyboard.add(*[types.KeyboardButton(advert) for advert in ['В начало']])
       # bot.send_message(m.chat.id, 'Выберите прайс который нужен.',
            #reply_markup=keyboard)
    #elif m.text == 'Акции':
       # keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
       # keyboard.add(*[types.KeyboardButton(advert) for advert in ['В начало']])
        #bot.send_message(m.chat.id, 'Сожалею, но в данный момент акций нет(',
           # reply_markup=keyboard)

5eb5d0eccc86a400052242.png
I know that the code is shit. But how can I fix it so that after choosing the amount the program goes on

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-05-09
@sanya84

import os
import datetime
import telebot
from telebot import types


bot = telebot.TeleBot('')


class TestTeleBot:
    def __init__(self):

        self.bot_polling()

    @bot.message_handler(commands=['start'])
    def start_message(message):
        print('-------------------------------------------------------------------')
        print(datetime.datetime.fromtimestamp(message.date).strftime('%H:%M:%S %d-%m-%Y'))
        print(message.text)
        print(message.from_user.id)
        print(message.from_user.first_name)
        print(message.from_user.last_name)
        print(message.from_user.username)
        print('-------------------------------------------------------------------')
        bot.send_message(message.chat.id, "Здравствуте, что хотите заказать?")

        keyboard_menu = types.InlineKeyboardMarkup()
        pizza = types.InlineKeyboardButton(text="Пицца", callback_data="pizza")
        tea = types.InlineKeyboardButton(text="Чай", callback_data="tea")
        keyboard_menu.add(pizza, tea)
        bot.send_message(message.chat.id, 'Выбери в меню что тебе интересно', reply_markup=keyboard_menu)

    @bot.callback_query_handler(func=lambda call:True)
    def handler_item_menu(callback):
        print(callback.data)
        if callback.data == "pizza":
            keyboard_name = types.InlineKeyboardMarkup()
            #Пицца “Маргарита” (Margherita)
            margherita = types.InlineKeyboardButton(text="Маргарита", callback_data="margherita")
            #Пицца “Карбонара” (Carbonara)
            carbonara = types.InlineKeyboardButton(text="Карбонара", callback_data="carbonara")
            keyboard_name.add(margherita, carbonara)
            bot.send_message(callback.from_user.id, 'Какую?', reply_markup=keyboard_name)
        elif callback.data == "margherita":
            bot.send_message(callback.from_user.id, "Ваш заказ принят...")
        if callback.data == "tea":
            pass

    def bot_polling(self):
        return bot.polling(none_stop=True)

def main():
    testTeleBot = TestTeleBot()
if __name__ == '__main__':
    main()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question