telegram_libs 0.1.3__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 +1 -1
- telegram_libs/constants.py +5 -0
- telegram_libs/subscription.py +55 -0
- telegram_libs/translation.py +9 -2
- telegram_libs/utils.py +12 -3
- {telegram_libs-0.1.3.dist-info → telegram_libs-0.1.5.dist-info}/METADATA +2 -1
- telegram_libs-0.1.5.dist-info/RECORD +9 -0
- telegram_libs-0.1.3.dist-info/RECORD +0 -8
- {telegram_libs-0.1.3.dist-info → telegram_libs-0.1.5.dist-info}/LICENSE +0 -0
- {telegram_libs-0.1.3.dist-info → telegram_libs-0.1.5.dist-info}/WHEEL +0 -0
telegram_libs/__init__.py
CHANGED
telegram_libs/constants.py
CHANGED
@@ -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/translation.py
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
import json
|
2
2
|
import os
|
3
|
+
from typing import Any
|
3
4
|
|
4
|
-
|
5
|
+
|
6
|
+
def load_translations() -> dict:
|
7
|
+
"""Load translations from locales directory
|
8
|
+
|
9
|
+
Returns:
|
10
|
+
dict: Translations dictionary
|
11
|
+
"""
|
5
12
|
translations = {}
|
6
13
|
# Get the project's root directory (where the script is being run from)
|
7
14
|
project_root = os.path.abspath(os.getcwd())
|
@@ -21,7 +28,7 @@ def load_translations():
|
|
21
28
|
|
22
29
|
TRANSLATIONS = load_translations()
|
23
30
|
|
24
|
-
def t(key, lang='ru', **kwargs):
|
31
|
+
def t(key: str, lang: str = 'ru', **kwargs: Any) -> str:
|
25
32
|
"""Get translation for a key with optional formatting"""
|
26
33
|
try:
|
27
34
|
# Support nested keys like "buttons.start"
|
telegram_libs/utils.py
CHANGED
@@ -3,11 +3,11 @@ from telegram import (
|
|
3
3
|
InlineKeyboardMarkup,
|
4
4
|
)
|
5
5
|
from telegram import Update
|
6
|
+
from telegram.ext import ContextTypes
|
6
7
|
from telegram_libs.constants import BOTS_AMOUNT
|
7
8
|
from telegram_libs.translation import t
|
8
9
|
|
9
10
|
|
10
|
-
|
11
11
|
async def get_subscription_keyboard(update: Update, lang: str) -> InlineKeyboardMarkup:
|
12
12
|
"""Get subscription keyboard
|
13
13
|
|
@@ -19,7 +19,7 @@ async def get_subscription_keyboard(update: Update, lang: str) -> InlineKeyboard
|
|
19
19
|
InlineKeyboardMarkup: Inline keyboard markup
|
20
20
|
"""
|
21
21
|
await update.message.reply_text(
|
22
|
-
f"Buying a subscription you will get unlimited access to other {BOTS_AMOUNT} bots, to see all bots click /more"
|
22
|
+
f"Buying a subscription you will get unlimited access to other {int(BOTS_AMOUNT) - 1} bots, to see all bots click /more"
|
23
23
|
)
|
24
24
|
return [
|
25
25
|
[
|
@@ -35,4 +35,13 @@ async def get_subscription_keyboard(update: Update, lang: str) -> InlineKeyboard
|
|
35
35
|
t("subscription.plans.1year", lang), callback_data="sub_1year"
|
36
36
|
),
|
37
37
|
],
|
38
|
-
]
|
38
|
+
]
|
39
|
+
|
40
|
+
|
41
|
+
async def more_bots_list_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
42
|
+
message = """Here is the list of all bots: \n\n
|
43
|
+
- <a href="https://t.me/MagMediaBot">Remove Background</a>
|
44
|
+
- <a href="https://t.me/UpscaleImageGBot">Upscale Image</a>
|
45
|
+
- <a href="https://t.me/kudapoyti_go_bot">Recommend a place to visit</a>
|
46
|
+
"""
|
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.
|
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=70j0wY1ZGtZQWN4EOWmM3recKj_K6pXSGUernohm4uQ,82
|
2
|
-
telegram_libs/constants.py,sha256=mZC3_2_Favn01sI10VMz9RiQpNpShqdbFfv3aMA3DKg,319
|
3
|
-
telegram_libs/translation.py,sha256=LCJLzKzAfd-65pAvSpW7MFr8o34nsdfWuVWonHI7SQU,1270
|
4
|
-
telegram_libs/utils.py,sha256=DAhnilUE7-WlXMoK1LnwcIJ4kgHDdmM3HV06ScyarMY,1089
|
5
|
-
telegram_libs-0.1.3.dist-info/LICENSE,sha256=ZXkWPZbCc61L29Gz6ZHPwn1c4Pm0TnfIqtx8jGWi9F4,1069
|
6
|
-
telegram_libs-0.1.3.dist-info/METADATA,sha256=NHNMoASTZNfeF1IVfP6_I_jRcpAtkxaH44QkNjexyaw,762
|
7
|
-
telegram_libs-0.1.3.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
8
|
-
telegram_libs-0.1.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|