From 1ff4f8098c4a17f04903ce49b3338e8561f4dcdd Mon Sep 17 00:00:00 2001 From: Aleksei Krugliak Date: Sat, 2 Apr 2022 00:23:02 +0400 Subject: [PATCH] Prepare to bot creation #2 --- data/config.py | 1 - handlers/users/__init__.py | 2 ++ handlers/users/add.py | 9 +++++++++ handlers/users/asa.py | 0 handlers/users/echo.py | 36 ++++++++++++++++++------------------ handlers/users/help.py | 11 ++++++++--- handlers/users/settings.py | 9 +++++++++ handlers/users/start.py | 2 +- utils/set_bot_commands.py | 10 ++++++++-- 9 files changed, 55 insertions(+), 25 deletions(-) create mode 100644 handlers/users/add.py delete mode 100644 handlers/users/asa.py create mode 100644 handlers/users/settings.py diff --git a/data/config.py b/data/config.py index 1cb02ee..e216714 100644 --- a/data/config.py +++ b/data/config.py @@ -7,4 +7,3 @@ env.read_env() BOT_TOKEN = env.str("BOT_TOKEN") # Забираем значение типа str ADMINS = env.list("ADMINS") # Тут у нас будет список из админов IP = env.str("ip") # Тоже str, но для айпи адреса хоста - diff --git a/handlers/users/__init__.py b/handlers/users/__init__.py index 34bd645..b4d2505 100644 --- a/handlers/users/__init__.py +++ b/handlers/users/__init__.py @@ -1,3 +1,5 @@ from . import help from . import start from . import echo +from . import add +from . import settings diff --git a/handlers/users/add.py b/handlers/users/add.py new file mode 100644 index 0000000..c34dac5 --- /dev/null +++ b/handlers/users/add.py @@ -0,0 +1,9 @@ +from aiogram import types +from aiogram.dispatcher.filters.builtin import Command + +from loader import dp + + +@dp.message_handler(commands="add") +async def bot_add(message: types.Message): + await message.answer(f"This is ADD command, {message.from_user.username}!") diff --git a/handlers/users/asa.py b/handlers/users/asa.py deleted file mode 100644 index e69de29..0000000 diff --git a/handlers/users/echo.py b/handlers/users/echo.py index f7fa79c..783d559 100644 --- a/handlers/users/echo.py +++ b/handlers/users/echo.py @@ -1,21 +1,21 @@ from aiogram import types from aiogram.dispatcher import FSMContext -from loader import dp - - -# Эхо хендлер, куда летят текстовые сообщения без указанного состояния -@dp.message_handler(state=None) -async def bot_echo(message: types.Message): - await message.answer(f"Эхо без состояния." - f"Сообщение:\n" - f"{message.text}") - - -# Эхо хендлер, куда летят ВСЕ сообщения с указанным состоянием -@dp.message_handler(state="*", content_types=types.ContentTypes.ANY) -async def bot_echo_all(message: types.Message, state: FSMContext): - state = await state.get_state() - await message.answer(f"Эхо в состоянии {state}.\n" - f"\nСодержание сообщения:\n" - f"{message}") +# from loader import dp +# +# +# # Эхо хендлер, куда летят текстовые сообщения без указанного состояния +# @dp.message_handler(state=None) +# async def bot_echo(message: types.Message): +# await message.answer(f"Эхо без состояния." +# f"Сообщение:\n" +# f"{message.text}") +# +# +# # Эхо хендлер, куда летят ВСЕ сообщения с указанным состоянием +# @dp.message_handler(state="*", content_types=types.ContentTypes.ANY) +# async def bot_echo_all(message: types.Message, state: FSMContext): +# state = await state.get_state() +# await message.answer(f"Эхо в состоянии {state}.\n" +# f"\nСодержание сообщения:\n" +# f"{message}") diff --git a/handlers/users/help.py b/handlers/users/help.py index 5420ccb..9a9bed2 100644 --- a/handlers/users/help.py +++ b/handlers/users/help.py @@ -6,8 +6,13 @@ from loader import dp @dp.message_handler(CommandHelp()) async def bot_help(message: types.Message): - text = ("Список команд: ", - "/start - Начать диалог", - "/help - Получить справку") + text = ("Available commands: ", + "/start - Launch bot.", + "/help - Commands list, little help.", + "/add - Add expense.", + "/edit - Edit expense.", + "/list - See my expenses.", + "/settings - Configure bot." + ) await message.answer("\n".join(text)) diff --git a/handlers/users/settings.py b/handlers/users/settings.py new file mode 100644 index 0000000..c01ef78 --- /dev/null +++ b/handlers/users/settings.py @@ -0,0 +1,9 @@ +from aiogram import types +from aiogram.dispatcher.filters.builtin import CommandSettings + +from loader import dp + + +@dp.message_handler(CommandSettings()) +async def bot_settings(message: types.Message): + await message.answer(f"Settings being here...") diff --git a/handlers/users/start.py b/handlers/users/start.py index 539ab70..ec529e7 100644 --- a/handlers/users/start.py +++ b/handlers/users/start.py @@ -6,4 +6,4 @@ from loader import dp @dp.message_handler(CommandStart()) async def bot_start(message: types.Message): - await message.answer(f"Привет, {message.from_user.full_name}!") + await message.answer(f"Hello, {message.from_user.username}!") diff --git a/utils/set_bot_commands.py b/utils/set_bot_commands.py index 30f28ed..6972b12 100644 --- a/utils/set_bot_commands.py +++ b/utils/set_bot_commands.py @@ -4,7 +4,13 @@ from aiogram import types async def set_default_commands(dp): await dp.bot.set_my_commands( [ - types.BotCommand("start", "Start bot."), - types.BotCommand("help", "Help."), + types.BotCommand("start", "Launch bot."), + types.BotCommand("help", "Commands list, little help."), + types.BotCommand("add", "Add expense."), + types.BotCommand("edit", "Edit expense."), + types.BotCommand("list", "See my expenses."), + types.BotCommand("settings", "Configure bot."), + # types.BotCommand("settings2", "Configure bot."), + # types.BotCommand("settings3", "Configure bot."), ] )