Skip to content

Commit

Permalink
update to aiogram 3.0
Browse files Browse the repository at this point in the history
added Makefile for convenience
  • Loading branch information
Forden committed Sep 15, 2023
1 parent a50db2e commit 07bcb87
Show file tree
Hide file tree
Showing 8 changed files with 678 additions and 524 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PROJECT_DIR=aiogram_bot_template

all: lint

lint:
poetry run python -m ruff $(PROJECT_DIR) --config pyproject.toml --fix
poetry run python -m isort $(PROJECT_DIR)
poetry run python -m mypy $(PROJECT_DIR) --config-file pyproject.toml
poetry run python -m black $(PROJECT_DIR) --config pyproject.toml
2 changes: 1 addition & 1 deletion aiogram_bot_template/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from aiogram import Bot, Dispatcher
from aiogram.client.session.aiohttp import AiohttpSession
from aiogram.client.telegram import TelegramAPIServer
from aiogram.fsm.storage.redis import RedisStorage, DefaultKeyBuilder
from aiogram.fsm.storage.redis import DefaultKeyBuilder, RedisStorage
from aiohttp import web
from redis.asyncio import Redis
from tenacity import _utils
Expand Down
1 change: 1 addition & 0 deletions aiogram_bot_template/filters/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .chat_type import ChatTypeFilter as ChatTypeFilter
from .text import TextFilter as TextFilter
18 changes: 18 additions & 0 deletions aiogram_bot_template/filters/text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from aiogram.filters import BaseFilter
from aiogram.types import CallbackQuery, Message


class TextFilter(BaseFilter):
def __init__(self, text: str | list[str]):
if isinstance(text, str):
self.text = [text]
else:
self.text = text

async def __call__(self, obj: Message | CallbackQuery) -> bool:
if isinstance(obj, Message):
txt = obj.text or obj.caption
return any(i == txt for i in self.text)
elif isinstance(obj, CallbackQuery):
return obj.data in self.text
return False
8 changes: 5 additions & 3 deletions aiogram_bot_template/handlers/user/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from aiogram import Router
from aiogram.filters import CommandStart, StateFilter, Text
from aiogram.filters import CommandStart, StateFilter

from aiogram_bot_template import states
from aiogram_bot_template.filters import ChatTypeFilter
from aiogram_bot_template.filters import ChatTypeFilter, TextFilter

from . import start

Expand All @@ -13,7 +13,9 @@ def prepare_router() -> Router:

user_router.message.register(start.start, CommandStart())
user_router.message.register(
start.start, Text("🏠В главное меню"), StateFilter(states.user.UserMainMenu.menu)
start.start,
TextFilter("🏠В главное меню"),
StateFilter(states.user.UserMainMenu.menu),
)

return user_router
1 change: 0 additions & 1 deletion aiogram_bot_template/web_handlers/tg_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


async def process_update(upd: types.Update, bot: Bot, dp: Dispatcher) -> None:
Bot.set_current(bot)
await dp.feed_webhook_update(bot, upd)


Expand Down
1,146 changes: 635 additions & 511 deletions poetry.lock

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ignore-init-module-imports = true

[tool.poetry]
name = "aiogram-bot-template"
version = "2.1.0"
version = "2.2.0"
description = "Template for creating scalable bots with aiogram"
authors = ["Forden <[email protected]>"]
readme = "README.md"
Expand All @@ -58,14 +58,14 @@ aiogram_bot_template = "aiogram_bot_template.bot:main"
[tool.poetry.dependencies]
python = "^3.10"
environs = "^9.5.0"
aiohttp = "^3.8.4"
aiojobs = "^1.1.0"
aiogram = "3.0.0b7"
asyncpg = "^0.27.0"
redis = "^4.5.5"
orjson = "^3.9.0"
aiohttp = "3.8.5"
aiojobs = "1.2.0"
aiogram = "3.0.0"
asyncpg = "0.28.0"
redis = "5.0.0"
orjson = "3.9.7"
structlog = "^23.1.0"
tenacity = "^8.2.2"
tenacity = "8.2.3"

[tool.poetry.group.dev]
optional = true
Expand All @@ -75,6 +75,7 @@ mypy = "^1.3.0"
black = { extras = ["d"], version = "^23.3.0" }
ruff = "^0.0.267"
types-redis = "^4.5.5.2"
isort= "5.12.0"



Expand Down

0 comments on commit 07bcb87

Please sign in to comment.