-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from bomzheg/aiogram3
migrate to Aiogram3
- Loading branch information
Showing
50 changed files
with
560 additions
and
922 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import asyncio | ||
|
||
from app.config.main import load_config | ||
from app.utils.cli import cli | ||
|
||
if __name__ == "__main__": | ||
cli(load_config()) | ||
asyncio.run(cli(load_config())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,7 @@ | ||
from functools import partialmethod | ||
|
||
from aiogram import Dispatcher | ||
|
||
from app.models.config import Config | ||
from app.utils.log import Logger | ||
|
||
from .karma_change import KarmaFilter | ||
from .tg_permissions import BotHasPermissions, HasPermissions | ||
from .has_target import HasTargetFilter | ||
|
||
logger = Logger(__name__) | ||
|
||
|
||
def setup(dispatcher: Dispatcher, config: Config): | ||
logger.info("Configure filters...") | ||
from .superuser import IsSuperuserFilter | ||
from .karma_change import KarmaFilter | ||
from .tg_permissions import BotHasPermissions, HasPermissions | ||
from .has_target import HasTargetFilter | ||
|
||
text_messages = [ | ||
dispatcher.message_handlers, | ||
dispatcher.edited_message_handlers, | ||
dispatcher.callback_query_handlers, | ||
] | ||
IsSuperuserFilter.check = partialmethod(IsSuperuserFilter.check, config.superusers) | ||
|
||
dispatcher.filters_factory.bind(KarmaFilter, event_handlers=text_messages) | ||
dispatcher.filters_factory.bind(IsSuperuserFilter, event_handlers=text_messages) | ||
dispatcher.filters_factory.bind(BotHasPermissions, event_handlers=text_messages) | ||
dispatcher.filters_factory.bind(HasPermissions, event_handlers=text_messages) | ||
dispatcher.filters_factory.bind(HasTargetFilter, event_handlers=text_messages) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,20 @@ | ||
import typing | ||
from dataclasses import dataclass | ||
|
||
from aiogram import types | ||
from aiogram.dispatcher.filters import BoundFilter | ||
from aiogram.filters import BaseFilter | ||
from aiogram.types import Message | ||
|
||
from app.models import dto | ||
from app.services.find_target_user import get_target_user | ||
|
||
|
||
@dataclass | ||
class HasTargetFilter(BoundFilter): | ||
key = "has_target" | ||
has_target: typing.Optional[typing.Dict[str, bool]] | ||
class HasTargetFilter(BaseFilter): | ||
can_be_same: bool = False | ||
can_be_bot: bool = False | ||
|
||
def __post_init__(self): | ||
if self.has_target is True: | ||
self.has_target = {} | ||
|
||
async def check(self, message: types.Message) -> typing.Dict[str, types.User]: | ||
can_be_same = self.has_target.get("can_be_same", False) | ||
can_be_bot = self.has_target.get("can_be_bot", False) | ||
target_user = get_target_user(message, can_be_same, can_be_bot) | ||
async def __call__(self, message: Message) -> dict[str, dto.TargetUser]: | ||
target_user = get_target_user(message, self.can_be_same, self.can_be_bot) | ||
if target_user is None: | ||
return {} | ||
rez = {'target': target_user} | ||
rez = {"target": target_user} | ||
return rez |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
from . import admin_bot | ||
from aiogram import Dispatcher, Bot | ||
|
||
from . import base | ||
from . import change_karma | ||
from . import errors | ||
from . import import_karma | ||
from . import karma | ||
from . import moderator | ||
from . import settings | ||
from . import superuser | ||
from ..models.config import Config | ||
|
||
|
||
__all__ = [ | ||
errors, | ||
admin_bot, | ||
base, | ||
karma, | ||
change_karma, | ||
import_karma, | ||
moderator, | ||
settings, | ||
] | ||
def setup(dp: Dispatcher, bot: Bot, config: Config): | ||
errors.setup(dp, bot, config) | ||
dp.include_router(base.router) | ||
dp.include_router(change_karma.router) | ||
dp.include_router(karma.router) | ||
dp.include_router(moderator.router) | ||
dp.include_router(settings.router) | ||
dp.include_router(superuser.setup_superuser(config)) |
Oops, something went wrong.