telegram_libs 0.1.19__py3-none-any.whl → 0.1.20__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/error.py +9 -0
- telegram_libs/handlers.py +56 -0
- telegram_libs/locales/en.json +6 -3
- telegram_libs/locales/ru.json +6 -3
- telegram_libs/mongo.py +12 -3
- telegram_libs/payment.py +94 -0
- telegram_libs/subscription.py +144 -13
- telegram_libs/{support_handlers.py → support.py} +10 -7
- telegram_libs/utils.py +21 -6
- {telegram_libs-0.1.19.dist-info → telegram_libs-0.1.20.dist-info}/METADATA +1 -1
- telegram_libs-0.1.20.dist-info/RECORD +16 -0
- telegram_libs-0.1.19.dist-info/RECORD +0 -13
- {telegram_libs-0.1.19.dist-info → telegram_libs-0.1.20.dist-info}/LICENSE +0 -0
- {telegram_libs-0.1.19.dist-info → telegram_libs-0.1.20.dist-info}/WHEEL +0 -0
telegram_libs/error.py
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
from logging import getLogger
|
2
|
+
from telegram import Update
|
3
|
+
from telegram.ext import ContextTypes
|
4
|
+
|
5
|
+
logger = getLogger(__name__)
|
6
|
+
|
7
|
+
|
8
|
+
async def error_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
9
|
+
logger.error(f"Update {update} caused error {context.error}")
|
@@ -0,0 +1,56 @@
|
|
1
|
+
from functools import partial
|
2
|
+
from telegram.ext import (
|
3
|
+
Application,
|
4
|
+
CommandHandler,
|
5
|
+
CallbackQueryHandler,
|
6
|
+
MessageHandler,
|
7
|
+
filters,
|
8
|
+
PreCheckoutQueryHandler,
|
9
|
+
)
|
10
|
+
from telegram_libs.mongo import MongoManager
|
11
|
+
from telegram_libs.subscription import subscription_callback, subscribe_command, check_subscription_command
|
12
|
+
from telegram_libs.payment import precheckout_handler, successful_payment
|
13
|
+
from telegram_libs.support import (
|
14
|
+
handle_support_command,
|
15
|
+
_handle_user_response,
|
16
|
+
SupportFilter,
|
17
|
+
)
|
18
|
+
from telegram_libs.utils import more_bots_list_command
|
19
|
+
from telegram_libs.error import error_handler
|
20
|
+
|
21
|
+
|
22
|
+
def register_subscription_handlers(
|
23
|
+
app: Application, mongo_manager: MongoManager
|
24
|
+
) -> None:
|
25
|
+
"""Register subscription-related handlers."""
|
26
|
+
app.add_handler(CallbackQueryHandler(subscription_callback, pattern="^sub_"))
|
27
|
+
app.add_handler(CommandHandler("subscribe", partial(subscribe_command, mongo_manager=mongo_manager)))
|
28
|
+
app.add_handler(CommandHandler("status", partial(check_subscription_command, mongo_manager=mongo_manager)))
|
29
|
+
|
30
|
+
# Payment handlers
|
31
|
+
app.add_handler(PreCheckoutQueryHandler(precheckout_handler))
|
32
|
+
app.add_handler(MessageHandler(filters.SUCCESSFUL_PAYMENT, partial(successful_payment, mongo_manager=mongo_manager)))
|
33
|
+
|
34
|
+
|
35
|
+
def register_support_handlers(app: Application, bot_name: str) -> None:
|
36
|
+
"""Register support handlers for the bot"""
|
37
|
+
app.add_handler(CommandHandler("support", handle_support_command))
|
38
|
+
app.add_handler(
|
39
|
+
MessageHandler(
|
40
|
+
filters.TEXT & ~filters.COMMAND & SupportFilter(),
|
41
|
+
partial(_handle_user_response, bot_name=bot_name),
|
42
|
+
)
|
43
|
+
)
|
44
|
+
|
45
|
+
|
46
|
+
def register_common_handlers(
|
47
|
+
app: Application, bot_name: str, mongo_manager: MongoManager
|
48
|
+
) -> None:
|
49
|
+
"""Register common handlers for the bot"""
|
50
|
+
app.add_handler(CommandHandler("more", more_bots_list_command))
|
51
|
+
|
52
|
+
register_support_handlers(app, bot_name)
|
53
|
+
register_subscription_handlers(app, mongo_manager)
|
54
|
+
|
55
|
+
# Error handler
|
56
|
+
app.add_error_handler(error_handler)
|
telegram_libs/locales/en.json
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"subscription": {
|
3
3
|
"choose_plan": "Choose a subscription plan:",
|
4
|
+
"payment_issue": "Thank you for your payment, but we couldn't determine your subscription plan.",
|
5
|
+
"success": "🎉 Thank you for your subscription! You now have premium access until {date}.",
|
6
|
+
"active": "✅ You have an active premium subscription!\nExpires in {days} days on {date}",
|
4
7
|
"plans": {
|
5
|
-
"1month": "1 Month -
|
6
|
-
"3months": "3 Months -
|
7
|
-
"1year": "1 Year -
|
8
|
+
"1month": "1 Month - 400 Stars",
|
9
|
+
"3months": "3 Months - 1100 Stars",
|
10
|
+
"1year": "1 Year - 3600 Stars"
|
8
11
|
},
|
9
12
|
"info": "Buying a subscription you will get unlimited access to other {0} bots, to see all bots click /more"
|
10
13
|
},
|
telegram_libs/locales/ru.json
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"subscription": {
|
3
3
|
"choose_plan": "Выберите план подписки:",
|
4
|
+
"payment_issue": "Спасибо за ваш платеж, но мы не смогли определить ваш план подписки.",
|
5
|
+
"success": "🎉 Спасибо за вашу подписку! У вас теперь есть премиум доступ до {date}.",
|
6
|
+
"active": "✅ У вас активная премиум подписка!\nИстекает через {days} дней, {date}",
|
4
7
|
"plans": {
|
5
|
-
"1month": "1 месяц -
|
6
|
-
"3months": "3 месяца -
|
7
|
-
"1year": "1 год -
|
8
|
+
"1month": "1 месяц - 400 Stars",
|
9
|
+
"3months": "3 месяца - 1100 Stars",
|
10
|
+
"1year": "1 год - 3600 Stars"
|
8
11
|
},
|
9
12
|
"info": "Купив подписку, вы получите неограниченный доступ к другим {0} ботам, чтобы увидеть всех ботов, нажмите /more"
|
10
13
|
},
|
telegram_libs/mongo.py
CHANGED
@@ -2,16 +2,25 @@ from pymongo.mongo_client import MongoClient
|
|
2
2
|
from pymongo.server_api import ServerApi
|
3
3
|
from telegram_libs.constants import MONGO_URI, DEBUG
|
4
4
|
|
5
|
-
|
5
|
+
|
6
|
+
# mongo_client = MongoClient(MONGO_URI, server_api=ServerApi("1"))
|
6
7
|
|
7
8
|
|
8
9
|
class MongoManager:
|
10
|
+
_mongo_client = None
|
11
|
+
|
12
|
+
@property
|
13
|
+
def mongo_client(self):
|
14
|
+
if self._mongo_client is None:
|
15
|
+
self._mongo_client = MongoClient(MONGO_URI, server_api=ServerApi("1"))
|
16
|
+
return self._mongo_client
|
17
|
+
|
9
18
|
def __init__(self, mongo_database_name: str, **kwargs):
|
10
|
-
self.client = kwargs.get("client") or mongo_client
|
19
|
+
self.client = kwargs.get("client") or self.mongo_client
|
11
20
|
self.db = self.client[mongo_database_name]
|
12
21
|
self.users_collection = self.db["users_test"] if DEBUG else self.db["users"]
|
13
22
|
self.payments_collection = self.db["order_test"] if DEBUG else self.db["order"]
|
14
|
-
self.user_schema = {"user_id": None, **kwargs.get("user_schema")}
|
23
|
+
self.user_schema = {"user_id": None, **(kwargs.get("user_schema") or {})}
|
15
24
|
|
16
25
|
def create_user(self, user_id: int) -> None:
|
17
26
|
"""Create a new user in the database."""
|
telegram_libs/payment.py
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
from datetime import datetime, timedelta
|
2
|
+
from logging import getLogger
|
3
|
+
from telegram import Update
|
4
|
+
from telegram.ext import ContextTypes
|
5
|
+
from telegram_libs.translation import t
|
6
|
+
from telegram_libs.subscription import add_subscription_payment
|
7
|
+
from telegram_libs.utils import get_user_info
|
8
|
+
from telegram_libs.mongo import MongoManager
|
9
|
+
|
10
|
+
logger = getLogger(__name__)
|
11
|
+
|
12
|
+
|
13
|
+
async def precheckout_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
14
|
+
"""Handle the pre-checkout query"""
|
15
|
+
query = update.pre_checkout_query
|
16
|
+
user_id = query.from_user.id
|
17
|
+
|
18
|
+
# Always accept the pre-checkout query in this basic implementation
|
19
|
+
# You could add additional validation here if needed (e.g., check user status, inventory, etc.)
|
20
|
+
|
21
|
+
try:
|
22
|
+
await query.answer(ok=True)
|
23
|
+
logger.info(f"Pre-checkout approved for user {user_id}")
|
24
|
+
except Exception as e:
|
25
|
+
logger.error(f"Error answering pre-checkout query: {e}")
|
26
|
+
# Try to answer with error if something went wrong
|
27
|
+
try:
|
28
|
+
await query.answer(
|
29
|
+
ok=False,
|
30
|
+
error_message="An error occurred while processing your payment",
|
31
|
+
)
|
32
|
+
except Exception as e2:
|
33
|
+
logger.error(f"Error sending pre-checkout error: {e2}")
|
34
|
+
|
35
|
+
|
36
|
+
async def successful_payment(update: Update, context: ContextTypes.DEFAULT_TYPE, mongo_manager: MongoManager) -> None:
|
37
|
+
"""Handle successful payments"""
|
38
|
+
user_info = get_user_info(update, mongo_manager)
|
39
|
+
user_id = user_info["user_id"]
|
40
|
+
lang = user_info["lang"]
|
41
|
+
payment_info = update.message.successful_payment
|
42
|
+
logger.info(f"Payment info received: {payment_info}")
|
43
|
+
|
44
|
+
# Determine which plan was purchased
|
45
|
+
plans = {"1month_sub": 30, "3months_sub": 90, "1year_sub": 365}
|
46
|
+
|
47
|
+
duration_days = plans.get(payment_info.invoice_payload, 0)
|
48
|
+
if duration_days == 0:
|
49
|
+
logger.warning(f"Invalid subscription plan: {payment_info.invoice_payload}")
|
50
|
+
await update.message.reply_text(
|
51
|
+
t("subscription.payment_issue", lang, common=True)
|
52
|
+
)
|
53
|
+
return
|
54
|
+
|
55
|
+
# Add order to bot-specific database
|
56
|
+
mongo_manager.add_order(
|
57
|
+
user_id,
|
58
|
+
{
|
59
|
+
"order_id": payment_info.provider_payment_charge_id,
|
60
|
+
"amount": payment_info.total_amount,
|
61
|
+
"currency": payment_info.currency,
|
62
|
+
"status": "completed",
|
63
|
+
"date": datetime.now().isoformat(),
|
64
|
+
},
|
65
|
+
)
|
66
|
+
|
67
|
+
# Calculate expiration date
|
68
|
+
expiration_date = datetime.now() + timedelta(days=duration_days)
|
69
|
+
current_time = datetime.now()
|
70
|
+
|
71
|
+
# Add subscription payment to shared subscription database
|
72
|
+
add_subscription_payment(
|
73
|
+
user_id,
|
74
|
+
{
|
75
|
+
"order_id": payment_info.provider_payment_charge_id,
|
76
|
+
"amount": payment_info.total_amount,
|
77
|
+
"currency": payment_info.currency,
|
78
|
+
"status": "completed",
|
79
|
+
"date": current_time.isoformat(),
|
80
|
+
"expiration_date": expiration_date.isoformat(),
|
81
|
+
"plan": payment_info.invoice_payload,
|
82
|
+
"duration_days": duration_days
|
83
|
+
}
|
84
|
+
)
|
85
|
+
|
86
|
+
logger.info(
|
87
|
+
f"User {user_id} subscribed successfully. Premium expires on {expiration_date.isoformat()}."
|
88
|
+
)
|
89
|
+
|
90
|
+
await update.message.reply_text(
|
91
|
+
t("subscription.success", lang, common=True).format(
|
92
|
+
date=expiration_date.strftime("%Y-%m-%d")
|
93
|
+
)
|
94
|
+
)
|
telegram_libs/subscription.py
CHANGED
@@ -1,10 +1,19 @@
|
|
1
1
|
from datetime import datetime
|
2
|
-
from
|
3
|
-
from
|
2
|
+
from telegram import Update, LabeledPrice, InlineKeyboardMarkup, InlineKeyboardButton
|
3
|
+
from telegram.ext import ContextTypes
|
4
|
+
from telegram_libs.constants import SUBSCRIPTION_DB_NAME, DEBUG, BOTS_AMOUNT
|
5
|
+
from telegram_libs.mongo import MongoManager
|
6
|
+
from telegram_libs.utils import get_user_info
|
7
|
+
from telegram_libs.translation import t
|
8
|
+
|
4
9
|
|
5
10
|
# Define the subscription database and collection
|
6
|
-
|
7
|
-
subscription_collection =
|
11
|
+
mongo_manager_instance = MongoManager(mongo_database_name=SUBSCRIPTION_DB_NAME)
|
12
|
+
subscription_collection = (
|
13
|
+
mongo_manager_instance.client[SUBSCRIPTION_DB_NAME]["subscriptions"]
|
14
|
+
if not DEBUG
|
15
|
+
else mongo_manager_instance.client[SUBSCRIPTION_DB_NAME]["subscriptions_test"]
|
16
|
+
)
|
8
17
|
|
9
18
|
|
10
19
|
def get_subscription(user_id: int) -> dict:
|
@@ -18,9 +27,7 @@ def get_subscription(user_id: int) -> dict:
|
|
18
27
|
def update_subscription(user_id: int, updates: dict) -> None:
|
19
28
|
"""Update user's subscription data in the shared subscription database."""
|
20
29
|
subscription_collection.update_one(
|
21
|
-
{"user_id": user_id},
|
22
|
-
{"$set": updates},
|
23
|
-
upsert=True
|
30
|
+
{"user_id": user_id}, {"$set": updates}, upsert=True
|
24
31
|
)
|
25
32
|
|
26
33
|
|
@@ -33,19 +40,143 @@ def add_subscription_payment(user_id: int, payment_data: dict) -> None:
|
|
33
40
|
"$set": {
|
34
41
|
"is_premium": True,
|
35
42
|
"premium_expiration": payment_data["expiration_date"],
|
36
|
-
"last_payment": payment_data["date"]
|
37
|
-
}
|
43
|
+
"last_payment": payment_data["date"],
|
44
|
+
},
|
38
45
|
},
|
39
|
-
upsert=True
|
46
|
+
upsert=True,
|
40
47
|
)
|
41
48
|
|
42
49
|
|
43
50
|
def check_subscription_status(user_id: int) -> bool:
|
44
51
|
"""Check if user has an active subscription."""
|
45
52
|
subscription = get_subscription(user_id)
|
46
|
-
|
53
|
+
|
47
54
|
if not subscription.get("is_premium"):
|
48
55
|
return False
|
49
|
-
|
56
|
+
|
50
57
|
expiration = datetime.fromisoformat(subscription["premium_expiration"])
|
51
|
-
return expiration > datetime.now()
|
58
|
+
return expiration > datetime.now()
|
59
|
+
|
60
|
+
|
61
|
+
async def get_subscription_keyboard(update: Update, lang: str) -> InlineKeyboardMarkup:
|
62
|
+
"""Get subscription keyboard
|
63
|
+
|
64
|
+
Args:
|
65
|
+
update (Update): Update object
|
66
|
+
lang (str): Language code
|
67
|
+
|
68
|
+
Returns:
|
69
|
+
InlineKeyboardMarkup: Inline keyboard markup
|
70
|
+
"""
|
71
|
+
await update.message.reply_text(
|
72
|
+
t("subscription.info", lang, common=True).format(int(BOTS_AMOUNT) - 1)
|
73
|
+
)
|
74
|
+
return InlineKeyboardMarkup([
|
75
|
+
[
|
76
|
+
InlineKeyboardButton(
|
77
|
+
t("subscription.plans.1month", lang, common=True), callback_data="sub_1month"
|
78
|
+
),
|
79
|
+
InlineKeyboardButton(
|
80
|
+
t("subscription.plans.3months", lang, common=True), callback_data="sub_3months"
|
81
|
+
),
|
82
|
+
],
|
83
|
+
[
|
84
|
+
InlineKeyboardButton(
|
85
|
+
t("subscription.plans.1year", lang, common=True), callback_data="sub_1year"
|
86
|
+
),
|
87
|
+
],
|
88
|
+
])
|
89
|
+
|
90
|
+
|
91
|
+
async def subscription_callback(
|
92
|
+
update: Update, context: ContextTypes.DEFAULT_TYPE
|
93
|
+
) -> None:
|
94
|
+
"""Handle subscription button clicks"""
|
95
|
+
query = update.callback_query
|
96
|
+
await query.answer()
|
97
|
+
plan = query.data
|
98
|
+
|
99
|
+
# Define subscription plans
|
100
|
+
plans = {
|
101
|
+
"sub_1month": {
|
102
|
+
"title": "1 Month Subscription",
|
103
|
+
"description": "Premium access for 1 month",
|
104
|
+
"payload": "1month_sub",
|
105
|
+
"price": 400 if not DEBUG else 1,
|
106
|
+
"duration": 30,
|
107
|
+
},
|
108
|
+
"sub_3months": {
|
109
|
+
"title": "3 Months Subscription",
|
110
|
+
"description": "Premium access for 3 months",
|
111
|
+
"payload": "3months_sub",
|
112
|
+
"price": 1100 if not DEBUG else 1,
|
113
|
+
"duration": 90,
|
114
|
+
},
|
115
|
+
"sub_1year": {
|
116
|
+
"title": "1 Year Subscription",
|
117
|
+
"description": "Premium access for 1 year",
|
118
|
+
"payload": "1year_sub",
|
119
|
+
"price": 3600 if not DEBUG else 1,
|
120
|
+
"duration": 365,
|
121
|
+
},
|
122
|
+
}
|
123
|
+
|
124
|
+
selected_plan = plans.get(plan)
|
125
|
+
if not selected_plan:
|
126
|
+
await query.message.reply_text("Invalid subscription option")
|
127
|
+
return
|
128
|
+
|
129
|
+
# Create invoice for Telegram Stars
|
130
|
+
prices = [LabeledPrice(selected_plan["title"], selected_plan["price"])]
|
131
|
+
|
132
|
+
await context.bot.send_invoice(
|
133
|
+
chat_id=query.message.chat_id,
|
134
|
+
title=selected_plan["title"],
|
135
|
+
description=selected_plan["description"],
|
136
|
+
payload=selected_plan["payload"],
|
137
|
+
provider_token="",
|
138
|
+
currency="XTR",
|
139
|
+
prices=prices,
|
140
|
+
start_parameter="subscription",
|
141
|
+
)
|
142
|
+
|
143
|
+
|
144
|
+
async def subscribe_command(
|
145
|
+
update: Update, context: ContextTypes.DEFAULT_TYPE, mongo_manager: MongoManager
|
146
|
+
) -> None:
|
147
|
+
"""Show subscription options"""
|
148
|
+
user_info = get_user_info(update, mongo_manager)
|
149
|
+
lang = user_info["lang"]
|
150
|
+
|
151
|
+
reply_markup = await get_subscription_keyboard(update, lang)
|
152
|
+
|
153
|
+
await update.message.reply_text(
|
154
|
+
t("subscription.choose_plan", lang, common=True), reply_markup=reply_markup
|
155
|
+
)
|
156
|
+
|
157
|
+
|
158
|
+
async def check_subscription_command(
|
159
|
+
update: Update, context: ContextTypes.DEFAULT_TYPE, mongo_manager: MongoManager
|
160
|
+
):
|
161
|
+
"""Check user's subscription status"""
|
162
|
+
user_info = get_user_info(update, mongo_manager)
|
163
|
+
user_id = user_info["user_id"]
|
164
|
+
lang = user_info["lang"]
|
165
|
+
|
166
|
+
subscription = get_subscription(user_id)
|
167
|
+
if subscription.get("is_premium"):
|
168
|
+
expiration = datetime.fromisoformat(subscription["premium_expiration"])
|
169
|
+
remaining = (expiration - datetime.now()).days
|
170
|
+
|
171
|
+
if remaining > 0:
|
172
|
+
await update.message.reply_text(
|
173
|
+
t("subscription.active", lang, common=True).format(
|
174
|
+
days=remaining,
|
175
|
+
date=expiration.strftime("%Y-%m-%d"),
|
176
|
+
)
|
177
|
+
)
|
178
|
+
else:
|
179
|
+
update_subscription(user_id, {"is_premium": False})
|
180
|
+
await update.message.reply_text(t("subscription.expired", lang))
|
181
|
+
else:
|
182
|
+
await update.message.reply_text(t("subscription.none", lang))
|
@@ -3,13 +3,15 @@ from datetime import datetime
|
|
3
3
|
from telegram import Update
|
4
4
|
from telegram.ext import ContextTypes, Application, CommandHandler, MessageHandler, filters
|
5
5
|
from telegram.ext.filters import BaseFilter
|
6
|
-
from telegram_libs.mongo import
|
7
|
-
from telegram_libs.constants import DEBUG
|
6
|
+
from telegram_libs.mongo import MongoManager
|
7
|
+
from telegram_libs.constants import DEBUG, SUBSCRIPTION_DB_NAME
|
8
8
|
from telegram_libs.translation import t
|
9
9
|
|
10
10
|
|
11
11
|
SUPPORT_WAITING = "support_waiting"
|
12
12
|
|
13
|
+
mongo_manager_instance = MongoManager(mongo_database_name=SUBSCRIPTION_DB_NAME) # Use an existing or create a new MongoManager instance
|
14
|
+
|
13
15
|
|
14
16
|
async def handle_support_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
15
17
|
"""Support command handler"""
|
@@ -32,7 +34,7 @@ async def _handle_user_response(update: Update, context: ContextTypes.DEFAULT_TY
|
|
32
34
|
# Should not happen if filter is correct
|
33
35
|
return
|
34
36
|
|
35
|
-
db =
|
37
|
+
db = mongo_manager_instance.client[db_name]
|
36
38
|
collection = db[collection_name]
|
37
39
|
doc = {
|
38
40
|
"user_id": update.effective_user.id,
|
@@ -52,7 +54,8 @@ class SupportFilter(BaseFilter):
|
|
52
54
|
return context.user_data.get(SUPPORT_WAITING, False)
|
53
55
|
|
54
56
|
|
55
|
-
def register_support_handlers(
|
56
|
-
""
|
57
|
-
|
58
|
-
|
57
|
+
def register_support_handlers(application: Application, bot_name: str):
|
58
|
+
application.add_handler(CommandHandler("support", handle_support_command))
|
59
|
+
application.add_handler(
|
60
|
+
MessageHandler(SupportFilter() & filters.TEXT, partial(_handle_user_response, bot_name=bot_name))
|
61
|
+
)
|
telegram_libs/utils.py
CHANGED
@@ -4,10 +4,11 @@ from telegram import (
|
|
4
4
|
InlineKeyboardMarkup,
|
5
5
|
)
|
6
6
|
from telegram import Update
|
7
|
-
from telegram.ext import ContextTypes, Application, CommandHandler
|
7
|
+
from telegram.ext import ContextTypes, Application, CommandHandler, CallbackQueryHandler
|
8
8
|
from telegram_libs.constants import BOTS_AMOUNT
|
9
9
|
from telegram_libs.translation import t
|
10
|
-
from telegram_libs.
|
10
|
+
from telegram_libs.support import register_support_handlers
|
11
|
+
from telegram_libs.mongo import MongoManager
|
11
12
|
|
12
13
|
|
13
14
|
basicConfig(
|
@@ -58,8 +59,22 @@ async def more_bots_list_command(update: Update, context: ContextTypes.DEFAULT_T
|
|
58
59
|
"""
|
59
60
|
await update.message.reply_text(message, disable_web_page_preview=True, parse_mode='HTML')
|
60
61
|
|
62
|
+
|
63
|
+
def get_user_info(update: Update, mongo_manager: MongoManager) -> dict:
|
64
|
+
"""Get user information from the update object."""
|
65
|
+
user = update.effective_user
|
66
|
+
user_data = mongo_manager.get_user_data(user.id)
|
67
|
+
|
68
|
+
return {
|
69
|
+
"user_id": user.id,
|
70
|
+
"username": user.username,
|
71
|
+
"first_name": user.first_name,
|
72
|
+
"last_name": user.last_name,
|
73
|
+
"lang": user_data.get("language", "en"),
|
74
|
+
**user_data,
|
75
|
+
}
|
61
76
|
|
62
|
-
def register_common_handlers(
|
63
|
-
"""Register common handlers
|
64
|
-
|
65
|
-
register_support_handlers(
|
77
|
+
def register_common_handlers(application: Application, bot_name: str) -> None:
|
78
|
+
"""Register common handlers to the application."""
|
79
|
+
application.add_handler(CommandHandler("more", more_bots_list_command))
|
80
|
+
register_support_handlers(application, bot_name)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
telegram_libs/__init__.py,sha256=xrsD5r6ZiJxPapHf1UhQ61z2gHtCCWrzW0CZHvlvXRc,82
|
2
|
+
telegram_libs/constants.py,sha256=7-L1uK9UKCVAZNKYnqmM4B18JDxfxHMpZgTIjh0rATg,606
|
3
|
+
telegram_libs/error.py,sha256=YtI2qCweDmANzPp3jae6yNzMQMtC9Z5TIeZ2-utGi_4,270
|
4
|
+
telegram_libs/handlers.py,sha256=5c8jRL4eEC4UyCugi5SaoUM7zEbgPHZum9i6Jh8WswM,2059
|
5
|
+
telegram_libs/locales/en.json,sha256=4VVkME7lCKW6ZjkopaoA6Uq3DLbEVkWacGei3GNSXFM,843
|
6
|
+
telegram_libs/locales/ru.json,sha256=LYI6rAlwdNLaTGgkrALn31Lt7jC3SZteei8P_i7ZpQI,1208
|
7
|
+
telegram_libs/mongo.py,sha256=urUvtIamU_WAqf1S6fDiX4ZOzOaTuRph-ovACKIAjlM,2519
|
8
|
+
telegram_libs/payment.py,sha256=CCB7xtODlR_0o3layVjtE9hhHxJTZ3mhptDPDqfqYSg,3381
|
9
|
+
telegram_libs/subscription.py,sha256=0ubzbDeyENMAdB2shH9qgH_eNzxr_zRsYgkhjolZqHo,6047
|
10
|
+
telegram_libs/support.py,sha256=UCgJPLJdQUfsbKTIIsNfOpP9CCdw5GjlcSl6aBwNw1U,2378
|
11
|
+
telegram_libs/translation.py,sha256=8Kb2cgqKKZH4X_i2Le0V_K1imZdoaCzYAca831DOBig,2049
|
12
|
+
telegram_libs/utils.py,sha256=OuFcSZ8LEqfDlW5F5t-R7qpjfBwmrRGfsbgIWdh23OI,2772
|
13
|
+
telegram_libs-0.1.20.dist-info/LICENSE,sha256=ZXkWPZbCc61L29Gz6ZHPwn1c4Pm0TnfIqtx8jGWi9F4,1069
|
14
|
+
telegram_libs-0.1.20.dist-info/METADATA,sha256=4A6P8BJTeYj_O-lFDkJb_J2vGsjPB1MXRt14cPl2QQM,804
|
15
|
+
telegram_libs-0.1.20.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
16
|
+
telegram_libs-0.1.20.dist-info/RECORD,,
|
@@ -1,13 +0,0 @@
|
|
1
|
-
telegram_libs/__init__.py,sha256=xrsD5r6ZiJxPapHf1UhQ61z2gHtCCWrzW0CZHvlvXRc,82
|
2
|
-
telegram_libs/constants.py,sha256=7-L1uK9UKCVAZNKYnqmM4B18JDxfxHMpZgTIjh0rATg,606
|
3
|
-
telegram_libs/locales/en.json,sha256=TDueYazTaytYCs8_6Z7-HeulGyqz5ze3Cm4mXYKFX8Q,549
|
4
|
-
telegram_libs/locales/ru.json,sha256=bHIuq9MFIhqIEvbf5j5HM1E9egtsjrTTIx50s6C9PpY,785
|
5
|
-
telegram_libs/mongo.py,sha256=TzCOB4rXiYQ6Y0ptDXqrJmoGcnZuxYPRPdC7GkDZiDs,2278
|
6
|
-
telegram_libs/subscription.py,sha256=d7xmzplUrm1nNlWlkqW6dddOYa3t_7PAM3iPme0K5F0,1690
|
7
|
-
telegram_libs/support_handlers.py,sha256=SrJGmP9WJp6vpsCE6k0lgs5ftlZR_mRBf-NQThIXkmU,2240
|
8
|
-
telegram_libs/translation.py,sha256=8Kb2cgqKKZH4X_i2Le0V_K1imZdoaCzYAca831DOBig,2049
|
9
|
-
telegram_libs/utils.py,sha256=0eBy7psB0XJQL9dPUeq5c2Ymg7ZPA54sdYJW3x2fI4M,2231
|
10
|
-
telegram_libs-0.1.19.dist-info/LICENSE,sha256=ZXkWPZbCc61L29Gz6ZHPwn1c4Pm0TnfIqtx8jGWi9F4,1069
|
11
|
-
telegram_libs-0.1.19.dist-info/METADATA,sha256=FM92PKEb7fmGx8KgyoHhm6J0KqAwj9z5Jjgx01BVd_M,804
|
12
|
-
telegram_libs-0.1.19.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
13
|
-
telegram_libs-0.1.19.dist-info/RECORD,,
|
File without changes
|
File without changes
|