quackamollie.core.bot.middleware.user_filter module¶
- class quackamollie.core.bot.middleware.user_filter.UserFilterMiddleware(data_dir: str, authorized_ids: Set[int], delete_banned_msg: bool, middleware_dir_name: str, unauthorized_activity_file_name: str, banned_users_file_name: str, datetime_format: str = '%Y.%m.%d-%H.%M.%S %z', interval_limit: int = 2, counter_low_limit: int = 3, counter_limit: int = 7)[source]¶
Bases:
BaseMiddlewareManage and log unknown user activities, keep also a list of banned/blocked users. This middleware should be sufficient to ensure basic security against non-authorized.
N.B: This project is thought to be executed locally and exposed on Telegram only to a limited set of users defined through configuration parsed by CLI.
- USER_FILTER_LOCK: ContextLock = <quackamollie.core.bot.utils.bot_utils.ContextLock object>¶
- _abc_impl = <_abc._abc_data object>¶
- quackamollie.core.bot.middleware.user_filter.get_user_filter_outer_middleware_router(delete_banned_msg: bool = False, middleware_dir_name: str = 'user_filter', unauthorized_activity_file_name: str = 'unauthorized_activity.json', banned_users_file_name: str = 'banned_users.json', **kwargs) Router[source]¶
Get an aiogram router to a UserFilterMiddleware initialized from the click context and with given parameters. N.B: this middleware is registered as an outer middleware (cf. aiogram doc for more details)
- Parameters:
delete_banned_msg (str) – This option deletes the messages sent by banned users
middleware_dir_name (str) – The directory where the middleware should save its files inside the ctx.data_dir
unauthorized_activity_file_name (str) – File name where unauthorized activities will be logged, unless the user reaches limits and gets banned
banned_users_file_name (str) – File name where banned users will be saved
kwargs (dict) – Additional parameters to give to the UserFilterMiddleware constructor. For example: * datetime_format=”%Y.%m.%d-%H.%M.%S %z” * interval_limit=2 * counter_limit=7 * counter_low_limit3 # Those are all default values
- Returns:
A router connected to a UserFilterMiddleware initialized from click context
- Return type:
aiogram.Router