Untitled

 avatar
unknown
plain_text
a year ago
6.3 kB
9
Indexable
import telebot
from telebot import types


# Replace 'YOUR_BOT_TOKEN' with your actual Telegram bot token
# Create an instance of the Telebot class
bot = telebot.TeleBot('2115459292:AAFa03PKoj3ZiL_QpTEyNX0sVHUBywpqhKw')
# Dictionary to store questions and answers
# Define the dictionary of phrases for each language
phrases = {
 "Russian": {
        "welcome": "Добро пожаловать в Pygame Telegram бот!",
        "name" : "Как вас зовут?",
        "home" : "Где вы живете?",
        "hobby" : "Какое у вас хобби?",
        "language_selected": "Вы выбрали русский язык!",
        "до свидания" : "Пока пока!"
    },
 "Kazakh": {
        "welcome": "Pygame Telegram ботына қош келдіңіз!",
        "name" : "Сенін атын кім?",
        "home" : "Қай жердесін сен?",
        "hobby" : "Қандай сенде хобби?",
        "language_selected": "Сіз қазақ тілін таңдадыңыз!",
        "сау бол" : "Сау бол досым"
    },
 "English": {
        "welcome": "Welcome to the Pygame Telegram bot!",
        "name" : "What is your name?",
        "home" : "Where are you living?",
        "hobby" : "What is your hobby?",
        "language_selected": "You have chosen English!",
        "goodbye":"Goodbye bro"
    },
  "поменять":'Вы успешно поменяли язык на русский!'
}
# Handler for '/start' command



@bot.message_handler(commands=['start'])
def handle_start(message):
    # Create a keyboard with language options
    keyboard = types.ReplyKeyboardMarkup(row_width=1, resize_keyboard=True)
    button1 = types.KeyboardButton(text="Русский")
    button2 = types.KeyboardButton(text="Қазақ")
    button3 = types.KeyboardButton(text="English")
    keyboard.add(button1, button2, button3)
    # Send a welcome message with the language selection keyboard
    bot.send_message(message.chat.id, "Welcome to the Telegram bot! Please choose your language:\nДобро пожаловать в телеграм бот! Пожалуйста выберите язык:\nTelegram ботына қош келдіңіз! Тілді таңдаңыз:", reply_markup=keyboard)

# Handler for 'hello' message
@bot.message_handler(func=lambda message: message.text.lower() == 'русский')
def send_greeting(message):
    bot.send_message(message.chat.id, phrases["Russian"]["language_selected"])
    bot.send_message(message.chat.id, phrases["Russian"]["welcome"])
    bot.send_message(message.chat.id, phrases["Russian"]["name"])
    bot.register_next_step_handler(message, nameR)
def nameR(message):
    bot.send_message(message.chat.id, 'Прекрасное имя!')
    bot.send_message(message.chat.id, phrases["Russian"]['home'])
    bot.register_next_step_handler(message, homeR)
def homeR(message):
    bot.send_message(message.chat.id, 'О круто, мне нравится '+message.text)
    bot.send_message(message.chat.id, 'Какое у тебя хобби?')
    bot.register_next_step_handler(message, hobbyR)
def hobbyR(message):
    bot.send_message(message.chat.id, 'Классное хобби')
    

@bot.message_handler(func=lambda message: message.text.lower() == 'қазақ')
def send_greeting(message):
    bot.send_message(message.chat.id, phrases["Kazakh"]["language_selected"])
    bot.send_message(message.chat.id, phrases["Kazakh"]["welcome"])
    bot.send_message(message.chat.id, phrases["Kazakh"]["name"])
    bot.register_next_step_handler(message, nameK)
def nameK(message):
    bot.send_message(message.chat.id, 'Әдемі есім')
    bot.send_message(message.chat.id, phrases["Kazakh"]['home'])
    bot.register_next_step_handler(message, homeK)
def homeK(message):
    bot.send_message(message.chat.id, 'Ооо, мағанда ұнайды '+message.text)
    bot.send_message(message.chat.id, phrases["Kazakh"]['hobby'])
    bot.register_next_step_handler(message, hobbyK)
def hobbyK(message):
    bot.send_message(message.chat.id, 'Жаксы хобби!')
    

@bot.message_handler(func=lambda message: message.text.lower() == 'english')
def send_greeting(message):
    bot.send_message(message.chat.id, phrases["English"]["language_selected"])
    bot.send_message(message.chat.id, phrases["English"]["welcome"])
    bot.send_message(message.chat.id, phrases["English"]["name"])
    bot.register_next_step_handler(message, name)
def name(message):
    bot.send_message(message.chat.id, 'Beatiful name!')
    bot.send_message(message.chat.id, phrases["English"]['home'])
    bot.register_next_step_handler(message, home)
def home(message):
    bot.send_message(message.chat.id, 'Oh nice, I like the '+message.text)
    bot.send_message(message.chat.id, phrases["English"]['hobby'])
    bot.register_next_step_handler(message, hobby)
def hobby(message):
    bot.send_message(message.chat.id, 'Awesome hobby!')

# Handler for other messages
@bot.message_handler(func=lambda message: True)
def handle_message(message):
    text = message.text.lower()
    
    if text in phrases["Russian"]:
        bot.reply_to(message, phrases["Russian"][text])
        if text.find('свидания') != -1:
            img = open('bebrach.gif', 'rb')
            bot.send_video(message.chat.id, img, None, 'Text')
            img.close()
            
    elif text in phrases["English"]:
        bot.reply_to(message, phrases["English"][text])
        if text.find('goodbye') != -1:
            img = open('demoman.gif', 'rb')
            bot.send_video(message.chat.id, img, None, 'Text')
            img.close()
    elif text in phrases["Kazakh"]:
        bot.reply_to(message, phrases["Kazakh"][text])
        if text.find('сау') != -1:
            img = open('nazarbayev.gif', 'rb')
            bot.send_video(message.chat.id, img, None, 'Text')
            img.close()
    else:
    # If the message is not a question in the dictionary, echo back the message
        bot.reply_to(message, "I'm sorry, but I don't understand you!")
# Start the bot
bot.polling()
Editor is loading...
Leave a Comment