obervinov / users-package

This Python module is designed to simplify user management in Telegram bots, providing the necessary functionality for tasks such as user authentication, authorization and compliance with speed limits, ensuring effective management of user attributes and access rights.
MIT License
1 stars 0 forks source link

Incorrect calculation of rate_limit if it is already applied and you need to calculate the timer for additional messages #32

Closed obervinov closed 8 months ago

obervinov commented 8 months ago

Context In a situation when a message exceeding the quota for requests is received, _ratelimit is applied with the time stamp now +1 hour'. But all subsequent messages received after the restrictions are applied receive a timestamp according to the same formulanow + 1 hour'. The result is a situation where after 1 hour 3 will be processed at once (for example) messages, not 1, as specified in the configuration.

Image

Image

requests configuration

        "requests": {
            "requests_per_day": 10,
            "requests_per_hour": 1,
            "random_shift_minutes": 15
        }

To-Do

Tests