69 lines
2.2 KiB
Python
69 lines
2.2 KiB
Python
import asyncio
|
|
import logging
|
|
|
|
from aiogram import Bot, Dispatcher, types, F
|
|
from aiogram.filters.command import Command
|
|
from aiogram.fsm.context import FSMContext
|
|
from aiogram.types import CallbackQuery
|
|
|
|
from config import TOKEN
|
|
from handlers.daily_type import daily_router
|
|
from handlers.expenses import expenses_router
|
|
from keyboards.inline import start_options
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
bot = Bot(token=TOKEN)
|
|
dp = Dispatcher()
|
|
dp.include_routers(daily_router, expenses_router)
|
|
|
|
|
|
@dp.message(Command("start", ignore_case=True))
|
|
async def cmd_start(message: types.Message, state: FSMContext):
|
|
"""
|
|
Запуск бота
|
|
:param message:
|
|
:param state:
|
|
"""
|
|
data = await state.get_data()
|
|
report_id = data["report"] if 'report' in data else message.message_id - 90
|
|
try:
|
|
await bot.delete_messages(message.chat.id, list(range(max(1, message.message_id - 90, report_id + 1), message.message_id + 1)))
|
|
except Exception:
|
|
pass
|
|
await state.clear()
|
|
await state.update_data(report=report_id)
|
|
await message.answer(text='Выберите тип расхода', reply_markup=start_options.as_markup())
|
|
|
|
|
|
@dp.callback_query(F.data == "start")
|
|
async def return_to_menu(call: CallbackQuery, state: FSMContext):
|
|
"""
|
|
Возврат к начальной позиции
|
|
:param call:
|
|
:param state:
|
|
"""
|
|
data = await state.get_data()
|
|
await bot.edit_message_reply_markup(chat_id=call.message.chat.id, message_id=call.message.message_id, reply_markup=None)
|
|
report_id = data["report"] if 'report' in data else call.message.message_id - 90
|
|
try:
|
|
await bot.delete_messages(call.message.chat.id,
|
|
list(range(max(1, call.message.message_id - 90, report_id + 1), call.message.message_id + 1)))
|
|
except Exception:
|
|
pass
|
|
await state.clear()
|
|
await state.update_data(report=report_id)
|
|
await call.message.answer(text='Выберите тип расхода', reply_markup=start_options.as_markup())
|
|
|
|
|
|
async def main():
|
|
"""
|
|
Запуск бота
|
|
:return:
|
|
"""
|
|
await dp.start_polling(bot)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|