telegram_libs 0.1.4__py3-none-any.whl → 0.1.5__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/__init__.py CHANGED
@@ -2,4 +2,4 @@
2
2
  Telegram Libs - Common libraries for Telegram bots
3
3
  """
4
4
 
5
- __version__ = "0.1.4"
5
+ __version__ = "0.1.5"
@@ -3,7 +3,12 @@ import os
3
3
  required_constants = []
4
4
 
5
5
  BOTS_AMOUNT = os.getenv("BOTS_AMOUNT")
6
+ MONGO_URI = os.getenv("MONGO_URI")
7
+ SUBSCRIPTION_DB_NAME = os.getenv("SUBSCRIPTION_DB_NAME")
8
+
6
9
  required_constants.append(("BOTS_AMOUNT", BOTS_AMOUNT))
10
+ required_constants.append(("MONGO_URI", MONGO_URI))
11
+ required_constants.append(("SUBSCRIPTION_DB_NAME", SUBSCRIPTION_DB_NAME))
7
12
 
8
13
  missing_constants = [name for name, value in required_constants if not value]
9
14
  if missing_constants:
@@ -0,0 +1,55 @@
1
+ from datetime import datetime
2
+ from pymongo.mongo_client import MongoClient
3
+ from pymongo.server_api import ServerApi
4
+ from telegram_libs.constants import MONGO_URI, SUBSCRIPTION_DB_NAME
5
+
6
+ # Create a new client and connect to the server
7
+ client = MongoClient(MONGO_URI, server_api=ServerApi("1"))
8
+
9
+ # Define the subscription database and collection
10
+ subscription_db = client[SUBSCRIPTION_DB_NAME]
11
+ subscription_collection = subscription_db["subscriptions"]
12
+
13
+
14
+ def get_subscription(user_id: int) -> dict:
15
+ """Get user's subscription data from the shared subscription database."""
16
+ subscription = subscription_collection.find_one({"user_id": user_id})
17
+ if not subscription:
18
+ return {"user_id": user_id, "is_premium": False}
19
+ return subscription
20
+
21
+
22
+ def update_subscription(user_id: int, updates: dict) -> None:
23
+ """Update user's subscription data in the shared subscription database."""
24
+ subscription_collection.update_one(
25
+ {"user_id": user_id},
26
+ {"$set": updates},
27
+ upsert=True
28
+ )
29
+
30
+
31
+ def add_subscription_payment(user_id: int, payment_data: dict) -> None:
32
+ """Add a subscription payment record."""
33
+ subscription_collection.update_one(
34
+ {"user_id": user_id},
35
+ {
36
+ "$push": {"payments": payment_data},
37
+ "$set": {
38
+ "is_premium": True,
39
+ "premium_expiration": payment_data["expiration_date"],
40
+ "last_payment": payment_data["date"]
41
+ }
42
+ },
43
+ upsert=True
44
+ )
45
+
46
+
47
+ def check_subscription_status(user_id: int) -> bool:
48
+ """Check if user has an active subscription."""
49
+ subscription = get_subscription(user_id)
50
+
51
+ if not subscription.get("is_premium"):
52
+ return False
53
+
54
+ expiration = datetime.fromisoformat(subscription["premium_expiration"])
55
+ return expiration > datetime.now()
telegram_libs/utils.py CHANGED
@@ -41,7 +41,7 @@ async def get_subscription_keyboard(update: Update, lang: str) -> InlineKeyboard
41
41
  async def more_bots_list_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
42
42
  message = """Here is the list of all bots: \n\n
43
43
  - <a href="https://t.me/MagMediaBot">Remove Background</a>
44
- - <a href="https://t.me/upscale_image_bot">Upscale Image</a>
44
+ - <a href="https://t.me/UpscaleImageGBot">Upscale Image</a>
45
45
  - <a href="https://t.me/kudapoyti_go_bot">Recommend a place to visit</a>
46
46
  """
47
47
  await update.message.reply_text(message, disable_web_page_preview=True, parse_mode='HTML')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: telegram_libs
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: Common libraries for Telegram bots
5
5
  Author: Andrey Gritsaenko gricaenko.95a@gmail.com
6
6
  Requires-Python: >=3.11,<4.0
@@ -8,6 +8,7 @@ Classifier: Programming Language :: Python :: 3
8
8
  Classifier: Programming Language :: Python :: 3.11
9
9
  Classifier: Programming Language :: Python :: 3.12
10
10
  Classifier: Programming Language :: Python :: 3.13
11
+ Requires-Dist: pymongo (>=4.13.0,<5.0.0)
11
12
  Requires-Dist: pytest (>=8.3.5,<9.0.0)
12
13
  Requires-Dist: pytest-asyncio (>=1.0.0,<2.0.0)
13
14
  Requires-Dist: python-telegram-bot (>=22.1,<23.0)
@@ -0,0 +1,9 @@
1
+ telegram_libs/__init__.py,sha256=fo5Zc0080sDtseiBrQUIJw7X1l5eLxPMiHz2TTSVxVg,82
2
+ telegram_libs/constants.py,sha256=F6pgwAuv2FgGZxxFwYYJomM4_hosexLoYsvHXQiuVNg,538
3
+ telegram_libs/subscription.py,sha256=3NenqG9JL7FJEu56TqnYBF5piJg-r4j8mT4-TjPtoBM,1845
4
+ telegram_libs/translation.py,sha256=OB89EyvwA89hxDfOJQcod96xoR5FSM4hsexl3_muqq0,1434
5
+ telegram_libs/utils.py,sha256=S7_eRyyAAWUd1Q1SFreLxKAK0rqeDNDSddCLNWsD6CE,1594
6
+ telegram_libs-0.1.5.dist-info/LICENSE,sha256=ZXkWPZbCc61L29Gz6ZHPwn1c4Pm0TnfIqtx8jGWi9F4,1069
7
+ telegram_libs-0.1.5.dist-info/METADATA,sha256=97vMNd0jGrDk4vjJsrpA8iup0h1oLB9mPhdlN2Cf22E,803
8
+ telegram_libs-0.1.5.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
9
+ telegram_libs-0.1.5.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- telegram_libs/__init__.py,sha256=UhMFbEOlA6Z8p2gBV8NxotAQTsstl7Ad9gxb-o66qPY,82
2
- telegram_libs/constants.py,sha256=mZC3_2_Favn01sI10VMz9RiQpNpShqdbFfv3aMA3DKg,319
3
- telegram_libs/translation.py,sha256=OB89EyvwA89hxDfOJQcod96xoR5FSM4hsexl3_muqq0,1434
4
- telegram_libs/utils.py,sha256=S2T6uPyhHJKq9zbcvTGXGUlvW3GetQ9jtA484h_Xqcc,1595
5
- telegram_libs-0.1.4.dist-info/LICENSE,sha256=ZXkWPZbCc61L29Gz6ZHPwn1c4Pm0TnfIqtx8jGWi9F4,1069
6
- telegram_libs-0.1.4.dist-info/METADATA,sha256=Qg3fWn6RaIamqUkuEj0fnvdYWhzyVv3ap-NrULCX1K4,762
7
- telegram_libs-0.1.4.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
8
- telegram_libs-0.1.4.dist-info/RECORD,,