telegram_libs 0.1.11__tar.gz → 0.1.13__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.11 → telegram_libs-0.1.13}/PKG-INFO +1 -1
- {telegram_libs-0.1.11 → telegram_libs-0.1.13}/pyproject.toml +1 -1
- {telegram_libs-0.1.11 → telegram_libs-0.1.13}/src/telegram_libs/__init__.py +1 -1
- {telegram_libs-0.1.11 → telegram_libs-0.1.13}/src/telegram_libs/utils.py +58 -43
- {telegram_libs-0.1.11 → telegram_libs-0.1.13}/LICENSE +0 -0
- {telegram_libs-0.1.11 → telegram_libs-0.1.13}/README.md +0 -0
- {telegram_libs-0.1.11 → telegram_libs-0.1.13}/src/telegram_libs/constants.py +0 -0
- {telegram_libs-0.1.11 → telegram_libs-0.1.13}/src/telegram_libs/locales/en.json +0 -0
- {telegram_libs-0.1.11 → telegram_libs-0.1.13}/src/telegram_libs/locales/ru.json +0 -0
- {telegram_libs-0.1.11 → telegram_libs-0.1.13}/src/telegram_libs/mongo.py +0 -0
- {telegram_libs-0.1.11 → telegram_libs-0.1.13}/src/telegram_libs/subscription.py +0 -0
- {telegram_libs-0.1.11 → telegram_libs-0.1.13}/src/telegram_libs/translation.py +0 -0
@@ -1,13 +1,24 @@
|
|
1
|
+
from functools import partial
|
2
|
+
from logging import basicConfig, getLogger, INFO
|
3
|
+
from datetime import datetime
|
1
4
|
from telegram import (
|
2
5
|
InlineKeyboardButton,
|
3
6
|
InlineKeyboardMarkup,
|
4
7
|
)
|
5
8
|
from telegram import Update
|
6
9
|
from telegram.ext import ContextTypes, Application, CommandHandler, MessageHandler, filters
|
10
|
+
from telegram.ext.filters import BaseFilter
|
7
11
|
from telegram_libs.constants import BOTS_AMOUNT
|
8
12
|
from telegram_libs.translation import t
|
9
13
|
from telegram_libs.mongo import mongo_client
|
10
|
-
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
basicConfig(
|
18
|
+
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=INFO
|
19
|
+
)
|
20
|
+
logger = getLogger(__name__)
|
21
|
+
|
11
22
|
|
12
23
|
FEEDBACK_WAITING = "feedback_waiting"
|
13
24
|
SUPPORT_WAITING = "support_waiting"
|
@@ -54,7 +65,7 @@ async def more_bots_list_command(update: Update, context: ContextTypes.DEFAULT_T
|
|
54
65
|
await update.message.reply_text(message, disable_web_page_preview=True, parse_mode='HTML')
|
55
66
|
|
56
67
|
|
57
|
-
async def
|
68
|
+
async def handle_support_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
58
69
|
"""Support command handler"""
|
59
70
|
await update.message.reply_text(
|
60
71
|
t("support.message", update.effective_user.language_code, common=True)
|
@@ -62,55 +73,59 @@ async def support_command(update: Update, context: ContextTypes.DEFAULT_TYPE) ->
|
|
62
73
|
context.user_data[SUPPORT_WAITING] = True
|
63
74
|
|
64
75
|
|
65
|
-
async def
|
66
|
-
"""Handle user's support message"""
|
67
|
-
if context.user_data.get(
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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
|
82
95
|
|
83
|
-
|
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:
|
84
112
|
"""Feedback command handler"""
|
85
113
|
await update.message.reply_text(
|
86
114
|
t("feedback.message", update.effective_user.language_code, common=True)
|
87
115
|
)
|
88
116
|
context.user_data[FEEDBACK_WAITING] = True
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
feedback_doc = {
|
97
|
-
"user_id": update.effective_user.id,
|
98
|
-
"username": update.effective_user.username,
|
99
|
-
"feedback": update.message.text,
|
100
|
-
"bot_name": bot_name,
|
101
|
-
"timestamp": update.message.date.isoformat(),
|
102
|
-
}
|
103
|
-
feedback_collection.insert_one(feedback_doc)
|
104
|
-
await update.message.reply_text(t("feedback.response", update.effective_user.language_code, common=True))
|
105
|
-
context.user_data[FEEDBACK_WAITING] = False
|
106
|
-
|
107
|
-
|
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
|
+
|
108
124
|
def register_feedback_and_support_handlers(app: Application, bot_name: str) -> None:
|
109
125
|
"""Register feedback and support handlers for the bot"""
|
110
|
-
app.add_handler(CommandHandler("feedback",
|
111
|
-
app.add_handler(
|
112
|
-
app.add_handler(
|
113
|
-
app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, partial(handle_support_response, bot_name=bot_name)))
|
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)))
|
114
129
|
|
115
130
|
|
116
131
|
def register_common_handlers(app: Application, bot_name: str) -> None:
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|