async def list_orders(message):
cur.execute("SELECT * FROM orders WHERE userId=?", (message.from_user.id,))
user = cur.fetchall()
if user:
for i in user:
msg = await message.answer(text=order#{i[2]}\n\n'
''
"TEXT: <b>{i[3]}</b>', parse_mode='HTML', reply_markup=func_delete_order(user))
else:
await message.answer("no orders.")
def func_delete_order(data):
builder = KeyboardBuilder(button_type=InlineKeyboardButton)
for i in data:
button = InlineKeyboardButton(text='Delete', callback_data=i[4])
builder.add(button)
builder.adjust(1)
return builder.as_markup()
from aiogram import Bot, Dispatcher, executor, types
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
bot = Bot('')
dp = Dispatcher(bot)
user_1 = {'orders': {'заказ 1', 'заказ 2', 'заказ 3'}}
@dp.message_handler(commands=['start'])
async def list_orders(message: types.Message):
if user_1['orders']:
for order in user_1['orders']:
await message.answer(
text=order,
reply_markup=InlineKeyboardMarkup().add(InlineKeyboardButton('Удалить', callback_data='Удалить заказ'))
)
else:
await message.answer("no orders.")
@dp.callback_query_handler(text='Удалить заказ')
async def delete_order(callback: types.CallbackQuery):
await callback.answer()
order = callback.message.text
if order in user_1['orders']:
user_1['orders'].remove(order)
await callback.message.answer(text=f'{order} удален')
else:
await callback.message.answer(text=f'{order} не найден')
print(user_1['orders']) # Для проверки
executor.start_polling(dp)