telegram_libs 0.1.14__tar.gz → 0.1.16__tar.gz
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-0.1.14 → telegram_libs-0.1.16}/PKG-INFO +1 -1
- {telegram_libs-0.1.14 → telegram_libs-0.1.16}/pyproject.toml +1 -1
- {telegram_libs-0.1.14 → telegram_libs-0.1.16}/src/telegram_libs/__init__.py +1 -1
- {telegram_libs-0.1.14 → telegram_libs-0.1.16}/src/telegram_libs/constants.py +1 -0
- telegram_libs-0.1.16/src/telegram_libs/mongo.py +54 -0
- {telegram_libs-0.1.14 → telegram_libs-0.1.16}/src/telegram_libs/support_handlers.py +2 -1
- {telegram_libs-0.1.14 → telegram_libs-0.1.16}/src/telegram_libs/utils.py +0 -1
- telegram_libs-0.1.14/src/telegram_libs/mongo.py +0 -6
- {telegram_libs-0.1.14 → telegram_libs-0.1.16}/LICENSE +0 -0
- {telegram_libs-0.1.14 → telegram_libs-0.1.16}/README.md +0 -0
- {telegram_libs-0.1.14 → telegram_libs-0.1.16}/src/telegram_libs/locales/en.json +0 -0
- {telegram_libs-0.1.14 → telegram_libs-0.1.16}/src/telegram_libs/locales/ru.json +0 -0
- {telegram_libs-0.1.14 → telegram_libs-0.1.16}/src/telegram_libs/subscription.py +0 -0
- {telegram_libs-0.1.14 → telegram_libs-0.1.16}/src/telegram_libs/translation.py +0 -0
@@ -5,6 +5,7 @@ required_constants = []
|
|
5
5
|
BOTS_AMOUNT = os.getenv("BOTS_AMOUNT")
|
6
6
|
MONGO_URI = os.getenv("MONGO_URI")
|
7
7
|
SUBSCRIPTION_DB_NAME = os.getenv("SUBSCRIPTION_DB_NAME")
|
8
|
+
DEBUG = os.getenv("DEBUG", "False").lower() in ("true", "1", "yes")
|
8
9
|
|
9
10
|
required_constants.append(("BOTS_AMOUNT", BOTS_AMOUNT))
|
10
11
|
required_constants.append(("MONGO_URI", MONGO_URI))
|
@@ -0,0 +1,54 @@
|
|
1
|
+
from pymongo.mongo_client import MongoClient
|
2
|
+
from pymongo.server_api import ServerApi
|
3
|
+
from telegram_libs.constants import MONGO_URI, DEBUG
|
4
|
+
|
5
|
+
mongo_client = MongoClient(MONGO_URI, server_api=ServerApi("1"))
|
6
|
+
|
7
|
+
|
8
|
+
class MongoManager:
|
9
|
+
def __init__(self, mongo_database_name: str, **kwargs):
|
10
|
+
self.client = kwargs.get("client") or mongo_client
|
11
|
+
self.db = self.client[mongo_database_name]
|
12
|
+
self.users_collection = self.db["users_test"] if DEBUG else self.db["users"]
|
13
|
+
self.payments_collection = self.db["order_test"] if DEBUG else self.db["order"]
|
14
|
+
self.user_schema = {"user_id": None, **kwargs.get("user_schema")}
|
15
|
+
|
16
|
+
def create_user(self, user_id: int) -> None:
|
17
|
+
"""Create a new user in the database."""
|
18
|
+
user_data = self.user_schema.copy()
|
19
|
+
user_data["user_id"] = user_id
|
20
|
+
self.users_collection.insert_one(user_data)
|
21
|
+
return user_data
|
22
|
+
|
23
|
+
def get_user_data(self, user_id: int) -> dict:
|
24
|
+
"""Retrieve user data from the database."""
|
25
|
+
user_data = self.users_collection.find_one({"user_id": user_id})
|
26
|
+
if not user_data:
|
27
|
+
# Initialize user data if not found
|
28
|
+
return self.create_user(user_id)
|
29
|
+
return user_data
|
30
|
+
|
31
|
+
def update_user_data(self, user_id: int, updates: dict) -> None:
|
32
|
+
"""Update user data in the database."""
|
33
|
+
result = self.users_collection.update_one({"user_id": user_id}, {"$set": updates})
|
34
|
+
if result.matched_count == 0:
|
35
|
+
# If no document was matched, create a new user
|
36
|
+
self.create_user(user_id)
|
37
|
+
self.users_collection.update_one({"user_id": user_id}, {"$set": updates})
|
38
|
+
|
39
|
+
def add_order(self, user_id: int, order: dict) -> None:
|
40
|
+
"""Add an order to the user's data."""
|
41
|
+
self.payments_collection.insert_one({"user_id": user_id, **order})
|
42
|
+
|
43
|
+
|
44
|
+
def get_orders(self, user_id: int) -> list:
|
45
|
+
"""Get all orders for a user."""
|
46
|
+
orders = self.payments_collection.find({"user_id": user_id})
|
47
|
+
return list(orders)
|
48
|
+
|
49
|
+
|
50
|
+
def update_order(self, user_id: int, order_id: int, updates: dict) -> None:
|
51
|
+
"""Update an order for a user."""
|
52
|
+
self.payments_collection.update_one(
|
53
|
+
{"user_id": user_id, "order_id": order_id}, {"$set": updates}
|
54
|
+
)
|
@@ -4,6 +4,7 @@ from telegram import Update
|
|
4
4
|
from telegram.ext import ContextTypes, Application, CommandHandler, MessageHandler, filters
|
5
5
|
from telegram.ext.filters import BaseFilter
|
6
6
|
from telegram_libs.mongo import mongo_client
|
7
|
+
from telegram_libs.constants import DEBUG
|
7
8
|
from telegram_libs.translation import t
|
8
9
|
|
9
10
|
|
@@ -22,7 +23,7 @@ async def _handle_user_response(update: Update, context: ContextTypes.DEFAULT_TY
|
|
22
23
|
"""Handle user's support message"""
|
23
24
|
if context.user_data.get(SUPPORT_WAITING):
|
24
25
|
db_name = "support"
|
25
|
-
collection_name = "support"
|
26
|
+
collection_name = "support" if not DEBUG else "support_test"
|
26
27
|
message_key = "support.response"
|
27
28
|
doc_field_name = "message"
|
28
29
|
context_key = SUPPORT_WAITING
|
@@ -7,7 +7,6 @@ from telegram import Update
|
|
7
7
|
from telegram.ext import ContextTypes, Application, CommandHandler
|
8
8
|
from telegram_libs.constants import BOTS_AMOUNT
|
9
9
|
from telegram_libs.translation import t
|
10
|
-
from telegram_libs.mongo import mongo_client
|
11
10
|
from telegram_libs.support_handlers import register_support_handlers
|
12
11
|
|
13
12
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|