2021-07-31 17:37:36 +04:00
|
|
|
|
import telebot
|
|
|
|
|
from random import choice
|
|
|
|
|
|
2021-07-31 17:55:48 +04:00
|
|
|
|
token = ''
|
2021-07-31 17:37:36 +04:00
|
|
|
|
|
|
|
|
|
bot = telebot.TeleBot(token)
|
|
|
|
|
|
|
|
|
|
HELP = '''
|
|
|
|
|
* help - напечатать справку по программе.
|
|
|
|
|
* add - добавить задачу в список (название задачи запрашиваем у пользователя).
|
|
|
|
|
* show - напечатать все добавленные задачи.
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
RANDOM_TASKS = ['123','321']
|
|
|
|
|
|
|
|
|
|
todos =dict()
|
|
|
|
|
|
|
|
|
|
def add_todo(date, task, category):
|
|
|
|
|
if todos.get(date) is not None:
|
|
|
|
|
todos[date].extend([[task, category]])
|
|
|
|
|
else:
|
|
|
|
|
todos[date] = [[task, category]]
|
|
|
|
|
|
|
|
|
|
@bot.message_handler(commands=['help'])
|
|
|
|
|
def echo(message):
|
|
|
|
|
bot.send_message(message.chat.id, HELP)
|
|
|
|
|
|
|
|
|
|
@bot.message_handler(commands=['random'])
|
|
|
|
|
def random_task(message):
|
|
|
|
|
task = choice(RANDOM_TASKS)
|
|
|
|
|
add_todo('сегодня', choice(RANDOM_TASKS), 'рандом')
|
|
|
|
|
bot.send_message(message.chat.id, f'Добавлена случайна задача {task}')
|
|
|
|
|
|
|
|
|
|
@bot.message_handler(commands=['show', 'print'])
|
|
|
|
|
def show(message):
|
|
|
|
|
dates = message.text.split()
|
|
|
|
|
for date in dates[1:]:
|
|
|
|
|
date = date.lower()
|
|
|
|
|
if date in todos:
|
|
|
|
|
reply = date.upper() + '\n'
|
|
|
|
|
print(todos)
|
|
|
|
|
print(todos[date])
|
|
|
|
|
for task, category in todos[date]:
|
|
|
|
|
reply += f'[] {task}, @{category}\n'
|
|
|
|
|
else:
|
|
|
|
|
reply = 'Такой даты нет'
|
|
|
|
|
bot.send_message(message.chat.id, reply)
|
|
|
|
|
|
|
|
|
|
@bot.message_handler(commands=['add', 'todo', 'category'])
|
|
|
|
|
def add(message):
|
|
|
|
|
splitted_command = message.text.split(maxsplit=3)
|
|
|
|
|
date = splitted_command[1]
|
|
|
|
|
task = splitted_command[2]
|
|
|
|
|
category = splitted_command[3]
|
|
|
|
|
if len(task) <3:
|
|
|
|
|
bot.send_message(message.chat.id, f'Задача: {task}, меньше 3х символов, добавлена не будет!')
|
|
|
|
|
else:
|
|
|
|
|
add_todo(date, task, category)
|
|
|
|
|
bot.send_message(message.chat.id, f'Добавлена задача: {task}, в день: {date}, категория: @{category}')
|
|
|
|
|
|
|
|
|
|
bot.polling(none_stop=True)
|