Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from telegram import Update, Bot, InlineKeyboardButton, InlineKeyboardMarkup
- from telegram.ext import Updater, CommandHandler, MessageHandler, Filters,CallbackQueryHandler
- from credits import bot_token
- bot = Bot(token=bot_token)
- updater = Updater(token=bot_token, use_context=True)
- dispatcher = updater.dispatcher
- def get_data_from_file(day):
- f = open(day,"r", encoding="utf-8")
- data = f.read()
- f.close()
- return data
- def start(update, context):
- context.bot.send_message(update.effective_chat.id, "Это бот для расписания! Ничего не забывай!")
- # keyboard = [
- # [InlineKeyboardButton("Расписание", callback_data='table',switch_inline_query_current_chat="/get_day" ),
- # InlineKeyboardButton("Доска", callback_data='desk')]
- # ]
- # update.message.reply_text('Функции:', reply_markup=InlineKeyboardMarkup(keyboard))
- def get_day(update,context):
- keyboard = [
- [InlineKeyboardButton("Понедельник", callback_data='Mon'),
- InlineKeyboardButton("Вторник", callback_data='Tue')],
- [InlineKeyboardButton("Среда", callback_data='Wed'),
- InlineKeyboardButton("Четверг", callback_data='Thu')],
- [InlineKeyboardButton("Пятница", callback_data='Fri')]
- ]
- update.message.reply_text('Выбери день недели', reply_markup=InlineKeyboardMarkup(keyboard))
- def button(update,context):
- query = update.callback_query
- query.answer()
- if query.data == "Mon":
- context.bot.send_message(update.effective_chat.id, get_data_from_file('mon.txt'))
- elif query.data == "Tue":
- context.bot.send_message(update.effective_chat.id, get_data_from_file('tue.txt'))
- elif query.data == "Wed":
- context.bot.send_message(update.effective_chat.id, get_data_from_file('wed.txt'))
- elif query.data == "Thu":
- context.bot.send_message(update.effective_chat.id, get_data_from_file('thu.txt'))
- elif query.data == "Fri":
- context.bot.send_message(update.effective_chat.id, get_data_from_file('fri.txt'))
- else:
- context.bot.send_message(update.effective_chat.id, "Нет такого дня пока что!")
- button_handler = CallbackQueryHandler(button)
- start_handler = CommandHandler("start", start)
- get_day_handler = CommandHandler('get_day', get_day)
- dispatcher.add_handler(start_handler)
- dispatcher.add_handler(get_day_handler)
- dispatcher.add_handler(button_handler)
- updater.start_polling()
- updater.idle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement