Advertisement
OtsoSilver

Untitled

Jan 28th, 2022
730
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.52 KB | None | 0 0
  1. from telegram import Update, Bot, InlineKeyboardButton, InlineKeyboardMarkup
  2. from telegram.ext import Updater, CommandHandler, MessageHandler, Filters,CallbackQueryHandler
  3. from credits import bot_token
  4.  
  5. bot = Bot(token=bot_token)
  6. updater = Updater(token=bot_token, use_context=True)
  7. dispatcher = updater.dispatcher
  8. def get_data_from_file(day):
  9.     f = open(day,"r", encoding="utf-8")
  10.     data = f.read()
  11.     f.close()
  12.     return data
  13. def start(update, context):
  14.     context.bot.send_message(update.effective_chat.id, "Это бот для расписания! Ничего не забывай!")
  15.     # keyboard = [
  16.     #     [InlineKeyboardButton("Расписание", callback_data='table',switch_inline_query_current_chat="/get_day" ),
  17.     #     InlineKeyboardButton("Доска", callback_data='desk')]
  18.     # ]
  19.     # update.message.reply_text('Функции:', reply_markup=InlineKeyboardMarkup(keyboard))
  20. def get_day(update,context):
  21.     keyboard = [
  22.         [InlineKeyboardButton("Понедельник", callback_data='Mon'),
  23.          InlineKeyboardButton("Вторник", callback_data='Tue')],
  24.         [InlineKeyboardButton("Среда", callback_data='Wed'),
  25.          InlineKeyboardButton("Четверг", callback_data='Thu')],
  26.         [InlineKeyboardButton("Пятница", callback_data='Fri')]
  27.     ]
  28.     update.message.reply_text('Выбери день недели', reply_markup=InlineKeyboardMarkup(keyboard))
  29. def button(update,context):
  30.     query = update.callback_query
  31.     query.answer()
  32.     if query.data == "Mon":
  33.        context.bot.send_message(update.effective_chat.id, get_data_from_file('mon.txt'))
  34.     elif query.data == "Tue":
  35.        context.bot.send_message(update.effective_chat.id, get_data_from_file('tue.txt'))
  36.     elif query.data == "Wed":
  37.        context.bot.send_message(update.effective_chat.id, get_data_from_file('wed.txt'))
  38.     elif query.data == "Thu":
  39.        context.bot.send_message(update.effective_chat.id, get_data_from_file('thu.txt'))
  40.     elif query.data == "Fri":
  41.        context.bot.send_message(update.effective_chat.id, get_data_from_file('fri.txt'))
  42.     else:
  43.        context.bot.send_message(update.effective_chat.id, "Нет такого дня пока что!")
  44.  
  45. button_handler = CallbackQueryHandler(button)
  46. start_handler = CommandHandler("start", start)
  47. get_day_handler = CommandHandler('get_day', get_day)
  48. dispatcher.add_handler(start_handler)
  49. dispatcher.add_handler(get_day_handler)
  50. dispatcher.add_handler(button_handler)
  51. updater.start_polling()
  52. updater.idle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement