Advertisement
OtsoSilver

Untitled

Jan 28th, 2022
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.08 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.  
  9.  
  10. def get_data_from_file(day):
  11.     f = open(day, "r", encoding="utf-8")
  12.     data = f.read()
  13.     f.close()
  14.     return data
  15.  
  16.  
  17. def start(update, context):
  18.     context.bot.send_message(update.effective_chat.id, "Это бот для расписания! Ничего не забывай!")
  19.     # keyboard = [
  20.     #     [InlineKeyboardButton("Расписание", callback_data='table',switch_inline_query_current_chat="/get_day" ),
  21.     #     InlineKeyboardButton("Доска", callback_data='desk')]
  22.     # ]
  23.     # update.message.reply_text('Функции:', reply_markup=InlineKeyboardMarkup(keyboard))
  24.  
  25.  
  26. def get_day(update, context):
  27.     keyboard = [
  28.         [InlineKeyboardButton("Понедельник", callback_data='Mon'),
  29.          InlineKeyboardButton("Вторник", callback_data='Tue')],
  30.         [InlineKeyboardButton("Среда", callback_data='Wed'),
  31.          InlineKeyboardButton("Четверг", callback_data='Thu')],
  32.         [InlineKeyboardButton("Пятница", callback_data='Fri')]
  33.     ]
  34.     update.message.reply_text('Выбери день недели', reply_markup=InlineKeyboardMarkup(keyboard))
  35.  
  36.  
  37. def button(update, context):
  38.     query = update.callback_query
  39.     query.answer()
  40.     if query.data == "Mon":
  41.         context.bot.send_message(update.effective_chat.id, get_data_from_file('mon.txt'))
  42.     elif query.data == "Tue":
  43.         context.bot.send_message(update.effective_chat.id, get_data_from_file('tue.txt'))
  44.     elif query.data == "Wed":
  45.         context.bot.send_message(update.effective_chat.id, get_data_from_file('wed.txt'))
  46.     elif query.data == "Thu":
  47.         context.bot.send_message(update.effective_chat.id, get_data_from_file('thu.txt'))
  48.     elif query.data == "Fri":
  49.         context.bot.send_message(update.effective_chat.id, get_data_from_file('fri.txt'))
  50.     else:
  51.         context.bot.send_message(update.effective_chat.id, "Нет такого дня пока что!")
  52.  
  53.  
  54. def write_to_wall(update, context):
  55.     wall = open('wall.txt', 'a', encoding="utf-8")
  56.     wall.write(str(update.message.from_user["username"]) + ": " + context.args[0] + '\n')
  57.     wall.close()
  58.  
  59. def show_wall(update, context):
  60.     context.bot.send_message(update.effective_chat.id, get_data_from_file("wall.txt"))
  61.  
  62. show_wall_handler = CommandHandler('show_wall', show_wall)
  63. write_to_wall_handler = CommandHandler('write_to_wall', write_to_wall)
  64. button_handler = CallbackQueryHandler(button)
  65. start_handler = CommandHandler("start", start)
  66. get_day_handler = CommandHandler('get_day', get_day)
  67. dispatcher.add_handler(start_handler)
  68. dispatcher.add_handler(show_wall_handler)
  69. dispatcher.add_handler(write_to_wall_handler)
  70. dispatcher.add_handler(get_day_handler)
  71. dispatcher.add_handler(button_handler)
  72. updater.start_polling()
  73. updater.idle()
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement