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 config import bot_token
- bot = Bot(token=bot_token)
- updater = Updater(token=bot_token, use_context=True)
- dispatcher = updater.dispatcher
- def start(update, context):
- context.bot.send_message(update.effective_chat.id, "Это бот для расписания! Ничего не забывай! /help, чтобы узнать команды")
- def help_(update, context):
- context.bot.send_message(update.effective_chat.id, '''
- Доступные команды:
- /start - приветное сообщение
- /help - показывает доступные команды
- УРОКИ
- /getday - показывает рассписание дня
- /getsubj - показывает подсказки по урокам
- СТЕНА
- /writewall (сообщение) - написать
- /showwall - показывает стену
- ЛИЧНЫЕ ЗАМЕТКИ
- /addzametka - добавляет вашу заметку
- /showzametka (заметка) - показывает ваши заметки
- ''')
- def get_info_from_file(name_file, encoding_='utf-8'):
- name_file = f'for_telegram_bot3/{name_file}'
- f = open(name_file, "r", encoding=encoding_)
- data = f.read()
- f.close()
- return data
- 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')],
- [InlineKeyboardButton("Суббота", callback_data='sat')],
- [InlineKeyboardButton("ВОСКРЕСЕНЬЕ!", callback_data='sun')]
- ]
- update.message.reply_text('Выбери день недели', reply_markup=InlineKeyboardMarkup(keyboard))
- def button(update, context):
- query = update.callback_query
- query.answer()
- if query.data in week or query.data in uroki:
- context.bot.send_message(update.effective_chat.id, get_info_from_file(str(query.data) + '.txt'))
- else:
- context.bot.send_message(update.effective_chat.id, "Произошла ошибка")
- def get_subj(update, context):
- keyboard = [
- [InlineKeyboardButton("Математика", callback_data='math'),
- InlineKeyboardButton("Русский язык", callback_data='rus')],
- [InlineKeyboardButton("Литература", callback_data='lit'),
- InlineKeyboardButton("Английский язык", callback_data='eng')]
- ]
- update.message.reply_text('Выбери предмет', reply_markup=InlineKeyboardMarkup(keyboard))
- def show_wall(update, context):
- context.bot.send_message(update.effective_chat.id, get_info_from_file('wall.txt', encoding_=None))
- def write_to_wall(update, context):
- wall = open('for_telegram_bot3/wall.txt', 'a')
- result = ''
- for arg in context.args:
- result += arg + ' '
- if len(result) > 0:
- wall.write(str(update.message.from_user['username']) + ": " + result + '\n') # имя: сообщение
- wall.close()
- context.bot.send_message(update.effective_chat.id, 'Успешно!')
- else:
- context.bot.send_message(update.effective_chat.id, 'Нельзя отправить пустое сообщение!')
- def add_zametka(update, context):
- zametka = open(f'for_telegram_bot3/{update.message.from_user["username"]}.txt', 'a')
- result = ''
- for arg in context.args:
- result += arg + ' '
- if len(result) > 0:
- zametka.write(str(result + '\n')) # заметка
- zametka.close()
- context.bot.send_message(update.effective_chat.id, 'Успешно!')
- else:
- context.bot.send_message(update.effective_chat.id, 'Нельзя добавить в заметку пустое сообщение!')
- def show_zametka(update, context):
- name = str(update.message.from_user["username"])
- context.bot.send_message(update.effective_chat.id, f'''
- Все ваши заметки на ник {name}:
- {get_info_from_file(name+'.txt', encoding_=None)}''')
- week = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']
- uroki = ["math", "rus", "lit", "eng"]
- dispatcher.add_handler(
- CommandHandler('start', start)
- )
- dispatcher.add_handler(
- CommandHandler('help', help_)
- )
- dispatcher.add_handler(
- CommandHandler('getday', get_day)
- )
- dispatcher.add_handler(
- CommandHandler('getsubj', get_subj)
- )
- dispatcher.add_handler(
- CallbackQueryHandler(button)
- )
- dispatcher.add_handler(
- CommandHandler('writewall', write_to_wall)
- )
- dispatcher.add_handler(
- CommandHandler('showwall', show_wall)
- )
- dispatcher.add_handler(
- CommandHandler('addzametka', add_zametka)
- )
- dispatcher.add_handler(
- CommandHandler('showzametka', show_zametka)
- )
- updater.start_polling()
- updater.idle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement