telegram_libs 0.1.13__py3-none-any.whl → 0.1.15__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 +1 -0
- telegram_libs/locales/en.json +1 -5
- telegram_libs/locales/ru.json +1 -5
- telegram_libs/support_handlers.py +57 -0
- telegram_libs/utils.py +6 -75
- {telegram_libs-0.1.13.dist-info → telegram_libs-0.1.15.dist-info}/METADATA +1 -1
- telegram_libs-0.1.15.dist-info/RECORD +13 -0
- telegram_libs-0.1.13.dist-info/RECORD +0 -12
- {telegram_libs-0.1.13.dist-info → telegram_libs-0.1.15.dist-info}/LICENSE +0 -0
- {telegram_libs-0.1.13.dist-info → telegram_libs-0.1.15.dist-info}/WHEEL +0 -0
telegram_libs/__init__.py
CHANGED
telegram_libs/constants.py
CHANGED
@@ -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))
|
telegram_libs/locales/en.json
CHANGED
@@ -9,11 +9,7 @@
|
|
9
9
|
"info": "Buying a subscription you will get unlimited access to other {0} bots, to see all bots click /more"
|
10
10
|
},
|
11
11
|
"support": {
|
12
|
-
"message": "
|
12
|
+
"message": "Write down any questions, issues or suggestions you have, and we will resolve them as soon as possible 👇 ",
|
13
13
|
"response": "Thank you! Our support team will contact you soon."
|
14
|
-
},
|
15
|
-
"feedback": {
|
16
|
-
"message": "We appreciate your feedback! Please send your suggestions or issues and we will review them as soon as possible.",
|
17
|
-
"response": "Thank you for your feedback!"
|
18
14
|
}
|
19
15
|
}
|
telegram_libs/locales/ru.json
CHANGED
@@ -9,11 +9,7 @@
|
|
9
9
|
"info": "Купив подписку, вы получите неограниченный доступ к другим {0} ботам, чтобы увидеть всех ботов, нажмите /more"
|
10
10
|
},
|
11
11
|
"support": {
|
12
|
-
"message": "
|
12
|
+
"message": "Напишите любые вопросы, проблемы, или предложения и мы решим их как можно скорее 👇 ",
|
13
13
|
"response": "Спасибо! Наша служба поддержки свяжется с вами в ближайшее время."
|
14
|
-
},
|
15
|
-
"feedback": {
|
16
|
-
"message": "Мы ценим ваш отзыв! Пожалуйста, присылайте ваши предложения или проблемы, и мы рассмотрим их как можно скорее.",
|
17
|
-
"response": "Спасибо за ваш отзыв!"
|
18
14
|
}
|
19
15
|
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
from functools import partial
|
2
|
+
from datetime import datetime
|
3
|
+
from telegram import Update
|
4
|
+
from telegram.ext import ContextTypes, Application, CommandHandler, MessageHandler, filters
|
5
|
+
from telegram.ext.filters import BaseFilter
|
6
|
+
from telegram_libs.mongo import mongo_client
|
7
|
+
from telegram_libs.translation import t
|
8
|
+
|
9
|
+
|
10
|
+
SUPPORT_WAITING = "support_waiting"
|
11
|
+
|
12
|
+
|
13
|
+
async def handle_support_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
14
|
+
"""Support command handler"""
|
15
|
+
await update.message.reply_text(
|
16
|
+
t("support.message", update.effective_user.language_code, common=True)
|
17
|
+
)
|
18
|
+
context.user_data[SUPPORT_WAITING] = True
|
19
|
+
|
20
|
+
|
21
|
+
async def _handle_user_response(update: Update, context: ContextTypes.DEFAULT_TYPE, bot_name: str) -> None:
|
22
|
+
"""Handle user's support message"""
|
23
|
+
if context.user_data.get(SUPPORT_WAITING):
|
24
|
+
db_name = "support"
|
25
|
+
collection_name = "support"
|
26
|
+
message_key = "support.response"
|
27
|
+
doc_field_name = "message"
|
28
|
+
context_key = SUPPORT_WAITING
|
29
|
+
extra_fields = {"resolved": False}
|
30
|
+
else:
|
31
|
+
# Should not happen if filter is correct
|
32
|
+
return
|
33
|
+
|
34
|
+
db = mongo_client[db_name]
|
35
|
+
collection = db[collection_name]
|
36
|
+
doc = {
|
37
|
+
"user_id": update.effective_user.id,
|
38
|
+
"username": update.effective_user.username,
|
39
|
+
doc_field_name: update.message.text,
|
40
|
+
"bot_name": bot_name,
|
41
|
+
"timestamp": datetime.now().isoformat(),
|
42
|
+
}
|
43
|
+
doc.update(extra_fields)
|
44
|
+
collection.insert_one(doc)
|
45
|
+
await update.message.reply_text(t(message_key, update.effective_user.language_code, common=True))
|
46
|
+
context.user_data[context_key] = False
|
47
|
+
|
48
|
+
|
49
|
+
class SupportFilter(BaseFilter):
|
50
|
+
def __call__(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> bool:
|
51
|
+
return context.user_data.get(SUPPORT_WAITING, False)
|
52
|
+
|
53
|
+
|
54
|
+
def register_support_handlers(app: Application, bot_name: str) -> None:
|
55
|
+
"""Register support handlers for the bot"""
|
56
|
+
app.add_handler(CommandHandler("support", handle_support_command))
|
57
|
+
app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND & SupportFilter(), partial(_handle_user_response, bot_name=bot_name)))
|
telegram_libs/utils.py
CHANGED
@@ -1,17 +1,13 @@
|
|
1
|
-
from functools import partial
|
2
1
|
from logging import basicConfig, getLogger, INFO
|
3
|
-
from datetime import datetime
|
4
2
|
from telegram import (
|
5
3
|
InlineKeyboardButton,
|
6
4
|
InlineKeyboardMarkup,
|
7
5
|
)
|
8
6
|
from telegram import Update
|
9
|
-
from telegram.ext import ContextTypes, Application, CommandHandler
|
10
|
-
from telegram.ext.filters import BaseFilter
|
7
|
+
from telegram.ext import ContextTypes, Application, CommandHandler
|
11
8
|
from telegram_libs.constants import BOTS_AMOUNT
|
12
9
|
from telegram_libs.translation import t
|
13
|
-
from telegram_libs.
|
14
|
-
|
10
|
+
from telegram_libs.support_handlers import register_support_handlers
|
15
11
|
|
16
12
|
|
17
13
|
basicConfig(
|
@@ -20,10 +16,6 @@ basicConfig(
|
|
20
16
|
logger = getLogger(__name__)
|
21
17
|
|
22
18
|
|
23
|
-
FEEDBACK_WAITING = "feedback_waiting"
|
24
|
-
SUPPORT_WAITING = "support_waiting"
|
25
|
-
|
26
|
-
|
27
19
|
async def get_subscription_keyboard(update: Update, lang: str) -> InlineKeyboardMarkup:
|
28
20
|
"""Get subscription keyboard
|
29
21
|
|
@@ -55,7 +47,9 @@ async def get_subscription_keyboard(update: Update, lang: str) -> InlineKeyboard
|
|
55
47
|
|
56
48
|
|
57
49
|
async def more_bots_list_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
58
|
-
message = """Here is the list of all bots:
|
50
|
+
message = """Here is the list of all bots:
|
51
|
+
|
52
|
+
|
59
53
|
- <a href="https://t.me/MagMediaBot">Remove Background</a>
|
60
54
|
- <a href="https://t.me/UpscaleImageGBot">Upscale Image</a>
|
61
55
|
- <a href="https://t.me/GenerateBackgroundGBot">Generate a Background</a>
|
@@ -65,70 +59,7 @@ async def more_bots_list_command(update: Update, context: ContextTypes.DEFAULT_T
|
|
65
59
|
await update.message.reply_text(message, disable_web_page_preview=True, parse_mode='HTML')
|
66
60
|
|
67
61
|
|
68
|
-
async def handle_support_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
69
|
-
"""Support command handler"""
|
70
|
-
await update.message.reply_text(
|
71
|
-
t("support.message", update.effective_user.language_code, common=True)
|
72
|
-
)
|
73
|
-
context.user_data[SUPPORT_WAITING] = True
|
74
|
-
|
75
|
-
|
76
|
-
async def _handle_user_response(update: Update, context: ContextTypes.DEFAULT_TYPE, bot_name: str) -> None:
|
77
|
-
"""Handle user's support or feedback message"""
|
78
|
-
if context.user_data.get(FEEDBACK_WAITING):
|
79
|
-
db_name = "feedback"
|
80
|
-
collection_name = "feedback"
|
81
|
-
message_key = "feedback.response"
|
82
|
-
doc_field_name = "feedback"
|
83
|
-
context_key = FEEDBACK_WAITING
|
84
|
-
extra_fields = {}
|
85
|
-
elif context.user_data.get(SUPPORT_WAITING):
|
86
|
-
db_name = "support"
|
87
|
-
collection_name = "support"
|
88
|
-
message_key = "support.response"
|
89
|
-
doc_field_name = "message"
|
90
|
-
context_key = SUPPORT_WAITING
|
91
|
-
extra_fields = {"resolved": False}
|
92
|
-
else:
|
93
|
-
# Should not happen if filter is correct
|
94
|
-
return
|
95
|
-
|
96
|
-
db = mongo_client[db_name]
|
97
|
-
collection = db[collection_name]
|
98
|
-
doc = {
|
99
|
-
"user_id": update.effective_user.id,
|
100
|
-
"username": update.effective_user.username,
|
101
|
-
doc_field_name: update.message.text,
|
102
|
-
"bot_name": bot_name,
|
103
|
-
"timestamp": datetime.now().isoformat(),
|
104
|
-
}
|
105
|
-
doc.update(extra_fields)
|
106
|
-
collection.insert_one(doc)
|
107
|
-
await update.message.reply_text(t(message_key, update.effective_user.language_code, common=True))
|
108
|
-
context.user_data[context_key] = False
|
109
|
-
|
110
|
-
|
111
|
-
async def handle_feedback_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
112
|
-
"""Feedback command handler"""
|
113
|
-
await update.message.reply_text(
|
114
|
-
t("feedback.message", update.effective_user.language_code, common=True)
|
115
|
-
)
|
116
|
-
context.user_data[FEEDBACK_WAITING] = True
|
117
|
-
|
118
|
-
|
119
|
-
class CombinedFeedbackSupportFilter(BaseFilter):
|
120
|
-
def __call__(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> bool:
|
121
|
-
return context.user_data.get(FEEDBACK_WAITING, False) or context.user_data.get(SUPPORT_WAITING, False)
|
122
|
-
|
123
|
-
|
124
|
-
def register_feedback_and_support_handlers(app: Application, bot_name: str) -> None:
|
125
|
-
"""Register feedback and support handlers for the bot"""
|
126
|
-
app.add_handler(CommandHandler("feedback", handle_feedback_command))
|
127
|
-
app.add_handler(CommandHandler("support", handle_support_command))
|
128
|
-
app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND & CombinedFeedbackSupportFilter(), partial(_handle_user_response, bot_name=bot_name)))
|
129
|
-
|
130
|
-
|
131
62
|
def register_common_handlers(app: Application, bot_name: str) -> None:
|
132
63
|
"""Register common handlers for the bot"""
|
133
64
|
app.add_handler(CommandHandler("more", more_bots_list_command))
|
134
|
-
|
65
|
+
register_support_handlers(app, bot_name)
|
@@ -0,0 +1,13 @@
|
|
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=7UOy_cE0ofIbH7QiiirAjOgo_FM9JImtgxQ8ouEsFeo,245
|
6
|
+
telegram_libs/subscription.py,sha256=d7xmzplUrm1nNlWlkqW6dddOYa3t_7PAM3iPme0K5F0,1690
|
7
|
+
telegram_libs/support_handlers.py,sha256=T0ukR2gak0XknkA5RZ8Kjd1KeZAxH1BftQNg6bub5kw,2165
|
8
|
+
telegram_libs/translation.py,sha256=8Kb2cgqKKZH4X_i2Le0V_K1imZdoaCzYAca831DOBig,2049
|
9
|
+
telegram_libs/utils.py,sha256=0eBy7psB0XJQL9dPUeq5c2Ymg7ZPA54sdYJW3x2fI4M,2231
|
10
|
+
telegram_libs-0.1.15.dist-info/LICENSE,sha256=ZXkWPZbCc61L29Gz6ZHPwn1c4Pm0TnfIqtx8jGWi9F4,1069
|
11
|
+
telegram_libs-0.1.15.dist-info/METADATA,sha256=vwa1lBhRpsx6KwevbYqQ-kXyaTudqR3FPZvSE4J0FyM,804
|
12
|
+
telegram_libs-0.1.15.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
13
|
+
telegram_libs-0.1.15.dist-info/RECORD,,
|
@@ -1,12 +0,0 @@
|
|
1
|
-
telegram_libs/__init__.py,sha256=dNLCvwrJMaT89UiB1LKABg-r7VCBVbkhcHZvZlnHpSQ,82
|
2
|
-
telegram_libs/constants.py,sha256=F6pgwAuv2FgGZxxFwYYJomM4_hosexLoYsvHXQiuVNg,538
|
3
|
-
telegram_libs/locales/en.json,sha256=kMGNE9ThGbaKH3PwappBGkWRgTupPETTG46zCMU5myk,749
|
4
|
-
telegram_libs/locales/ru.json,sha256=lShsh98seaHRtanmq1IRv8_bgRLieTaq-jHjaoOwS0M,1134
|
5
|
-
telegram_libs/mongo.py,sha256=7UOy_cE0ofIbH7QiiirAjOgo_FM9JImtgxQ8ouEsFeo,245
|
6
|
-
telegram_libs/subscription.py,sha256=d7xmzplUrm1nNlWlkqW6dddOYa3t_7PAM3iPme0K5F0,1690
|
7
|
-
telegram_libs/translation.py,sha256=8Kb2cgqKKZH4X_i2Le0V_K1imZdoaCzYAca831DOBig,2049
|
8
|
-
telegram_libs/utils.py,sha256=KmywKbWBlkP2fYGywiEsMhNYPQsmSD5CNTO4qKtvmDQ,4999
|
9
|
-
telegram_libs-0.1.13.dist-info/LICENSE,sha256=ZXkWPZbCc61L29Gz6ZHPwn1c4Pm0TnfIqtx8jGWi9F4,1069
|
10
|
-
telegram_libs-0.1.13.dist-info/METADATA,sha256=_HA97HXjehOltJk52MqoAwrfWo3FNydulQYxA9hRcDo,804
|
11
|
-
telegram_libs-0.1.13.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
12
|
-
telegram_libs-0.1.13.dist-info/RECORD,,
|
File without changes
|
File without changes
|