heroku ps -a test-webhook-tasdsgbot
Free dyno hours quota remaining this month: 549h 16m (99%)
Free dyno usage for this app: 0h 0m (0%)
For more information on dyno sleeping and how to upgrade, see:
https://devcenter.heroku.com/articles/dyno-sleeping
No dynos on ⬢ test-webhook-tasdsgbot
async def inline_edit_handler(call: types.CallbackQuery):
command: str = call.data.split('|')[0]
task_id: str = call.data.split('|')[1]
if command == 'edit':
StateEdit.edit_id = task_id
def register_handlers_list_task(dp: Dispatcher):
dp.register_message_handler(list_tasks, commands=['list'])
dp.register_callback_query_handler(inline_edit_handler)
register_handler_edit_task(dp)
from aiogram import Dispatcher, types
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup
from Tasker_bot.app.base import edit_task
class StateEdit(StatesGroup):
edit_id: str = ''
edit_title = State()
edit_body = State()
async def editing_title(message: types.Message):
await message.answer('Введите новый заголовок:')
await StateEdit.edit_title.set()
async def editing_body(message: types.Message, state: FSMContext):
await state.update_data(title=message.text)
await StateEdit.next()
await message.answer('Введите новый текст:')
async def editing_task(message: types.Message, state: FSMContext):
await state.update_data(body=message.text)
task_edit: dict = await state.get_data()
try:
edit_id: int = int(StateEdit.edit_id)
title: str = task_edit['title']
body: str = task_edit['body']
edit_task(edit_id, title, body)
await message.answer('Запись успешно отредактирована.')
except ValueError:
await message.answer('id может содержать только цифры.')
finally:
await state.finish()
def register_handler_edit_task(dp: Dispatcher):
dp.register_message_handler(editing_title, state='*')
dp.register_message_handler(editing_body, state=StateEdit.edit_title)
dp.register_message_handler(editing_task, state=StateEdit.edit_body)
from aiogram import Dispatcher, types
from aiogram.utils.callback_data import CallbackData
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup
from aiogram.dispatcher.filters import Text, IDFilter
from .edit_tasks import register_handler_edit_task
from ..base import get_list_tasks, del_task, edit_task
def get_keyboard(task_id: str):
buttons: list = [
types.InlineKeyboardButton(text='Редактировать', callback_data=f'edit|{task_id}'),
types.InlineKeyboardButton(text='Удалить', callback_data=f'del|{task_id}')
]
keyboard = types.InlineKeyboardMarkup(row_width=2)
keyboard.add(*buttons)
return keyboard
async def list_tasks(message: types.Message):
user_id: int = message.from_user.id
lt: list = get_list_tasks(user_id)
if len(lt) == 0:
await message.answer('Ни одного таска ещё не создано.')
else:
for task in lt:
task_id: str = task[-1]
await message.answer(f'{task[0]}\n\n{task[1]}\n\nid: {task[-1]}', reply_markup=get_keyboard(task_id))
async def inline_handler(call: types.CallbackQuery):
task_id: str = call.data.split('|')[1]
command: str = call.data.split('|')[0]
if command == 'del':
del_task(int(task_id))
await call.answer(text='Запись успешно удалена')
elif command == 'edit':
await call.answer(text='EDIT')
def register_handlers_list_task(dp: Dispatcher):
dp.register_message_handler(list_tasks, commands=['list'])
dp.register_callback_query_handler(inline_handler)