telegram_libs 0.1.27__py3-none-any.whl → 0.1.28__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- telegram_libs/utils.py +18 -10
- {telegram_libs-0.1.27.dist-info → telegram_libs-0.1.28.dist-info}/METADATA +1 -1
- {telegram_libs-0.1.27.dist-info → telegram_libs-0.1.28.dist-info}/RECORD +5 -5
- {telegram_libs-0.1.27.dist-info → telegram_libs-0.1.28.dist-info}/LICENSE +0 -0
- {telegram_libs-0.1.27.dist-info → telegram_libs-0.1.28.dist-info}/WHEEL +0 -0
telegram_libs/utils.py
CHANGED
@@ -68,12 +68,8 @@ class RateLimitManager:
|
|
68
68
|
self.mongo_manager = mongo_manager
|
69
69
|
self.rate_limit = rate_limit
|
70
70
|
|
71
|
-
def check_limit(self, user_id: int) -> bool:
|
71
|
+
def check_limit(self, user_id: int) -> tuple[bool, dict]:
|
72
72
|
"""Check if user has exceeded the daily rate limit."""
|
73
|
-
# Premium users have no limits
|
74
|
-
if self.mongo_manager.check_subscription_status(user_id):
|
75
|
-
return True
|
76
|
-
|
77
73
|
# Get today's date and reset time to midnight
|
78
74
|
today = datetime.now().date()
|
79
75
|
|
@@ -90,18 +86,30 @@ class RateLimitManager:
|
|
90
86
|
"last_action_date": datetime.now().isoformat(),
|
91
87
|
},
|
92
88
|
)
|
93
|
-
return True
|
89
|
+
return True, user_data
|
94
90
|
|
95
91
|
# Check if user has exceeded the limit
|
96
92
|
actions_today = user_data.get("actions_today", 0)
|
97
93
|
if actions_today >= self.rate_limit:
|
98
|
-
return False
|
94
|
+
return False, user_data
|
99
95
|
|
100
|
-
return True
|
96
|
+
return True, user_data
|
97
|
+
|
98
|
+
def check_and_increment(self, user_id: int) -> bool:
|
99
|
+
"""Check if user can perform an action and increment the count if allowed."""
|
100
|
+
if self.mongo_manager.check_subscription_status(user_id):
|
101
|
+
return True
|
102
|
+
|
103
|
+
can_perform, user_data = self.check_limit(user_id)
|
104
|
+
if can_perform:
|
105
|
+
self.increment_action_count(user_id, user_data)
|
106
|
+
return True
|
107
|
+
return False
|
101
108
|
|
102
|
-
def increment_action_count(self, user_id: int) -> None:
|
109
|
+
def increment_action_count(self, user_id: int, user_data: dict = None) -> None:
|
103
110
|
"""Increment the daily action count for the user."""
|
104
|
-
user_data
|
111
|
+
if user_data is None:
|
112
|
+
user_data = self.mongo_manager.get_user_data(user_id)
|
105
113
|
current_actions = user_data.get("actions_today", 0)
|
106
114
|
self.mongo_manager.update_user_data(
|
107
115
|
user_id,
|
@@ -10,8 +10,8 @@ telegram_libs/payment.py,sha256=cNb2vnBlYI_6KnTGz-PCM0uKahW2uGjHVn1mGYlYG-4,3564
|
|
10
10
|
telegram_libs/subscription.py,sha256=NJlh1kcDfasX1XLpkVfe1UbZslpWSC1hXHaum0kfG8A,4693
|
11
11
|
telegram_libs/support.py,sha256=a3BA7g3seVBUMasv65SzxebLayLigA069wvDcStYbCM,2748
|
12
12
|
telegram_libs/translation.py,sha256=8Kb2cgqKKZH4X_i2Le0V_K1imZdoaCzYAca831DOBig,2049
|
13
|
-
telegram_libs/utils.py,sha256
|
14
|
-
telegram_libs-0.1.
|
15
|
-
telegram_libs-0.1.
|
16
|
-
telegram_libs-0.1.
|
17
|
-
telegram_libs-0.1.
|
13
|
+
telegram_libs/utils.py,sha256=--X13_1iqIEKydwie7_Ak0V0rO04XHtKNK1DHrzGelY,4197
|
14
|
+
telegram_libs-0.1.28.dist-info/LICENSE,sha256=ZXkWPZbCc61L29Gz6ZHPwn1c4Pm0TnfIqtx8jGWi9F4,1069
|
15
|
+
telegram_libs-0.1.28.dist-info/METADATA,sha256=FpuMWElD6Lc-wVVP8U9Etg9gBI6my4oXu7EzkUjT9Pc,804
|
16
|
+
telegram_libs-0.1.28.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
17
|
+
telegram_libs-0.1.28.dist-info/RECORD,,
|
File without changes
|
File without changes
|