telegram_libs 0.1.9__tar.gz → 0.1.11__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: telegram_libs
3
- Version: 0.1.9
3
+ Version: 0.1.11
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
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "telegram_libs"
3
- version = "0.1.9"
3
+ version = "0.1.11"
4
4
  description = "Common libraries for Telegram bots"
5
5
  authors = ["Andrey Gritsaenko gricaenko.95a@gmail.com"]
6
6
  readme = "README.md"
@@ -2,4 +2,4 @@
2
2
  Telegram Libs - Common libraries for Telegram bots
3
3
  """
4
4
 
5
- __version__ = "0.1.9"
5
+ __version__ = "0.1.11"
@@ -0,0 +1,19 @@
1
+ {
2
+ "subscription": {
3
+ "choose_plan": "Choose a subscription plan:",
4
+ "plans": {
5
+ "1month": "1 Month - 1400 Stars",
6
+ "3months": "3 Months - 3500 Stars",
7
+ "1year": "1 Year - 12000 Stars"
8
+ },
9
+ "info": "Buying a subscription you will get unlimited access to other {0} bots, to see all bots click /more"
10
+ },
11
+ "support": {
12
+ "message": "If you have any questions or need help, please write it now and we will solve your issue as soon as possible.",
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
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "subscription": {
3
+ "choose_plan": "Выберите план подписки:",
4
+ "plans": {
5
+ "1month": "1 месяц - 1400 Stars",
6
+ "3months": "3 месяца - 3500 Stars",
7
+ "1year": "1 год - 12000 Stars"
8
+ },
9
+ "info": "Купив подписку, вы получите неограниченный доступ к другим {0} ботам, чтобы увидеть всех ботов, нажмите /more"
10
+ },
11
+ "support": {
12
+ "message": "Если у вас есть вопросы или нужна помощь, пожалуйста, напишите сейчас, и мы решим вашу проблему как можно скорее.",
13
+ "response": "Спасибо! Наша служба поддержки свяжется с вами в ближайшее время."
14
+ },
15
+ "feedback": {
16
+ "message": "Мы ценим ваш отзыв! Пожалуйста, присылайте ваши предложения или проблемы, и мы рассмотрим их как можно скорее.",
17
+ "response": "Спасибо за ваш отзыв!"
18
+ }
19
+ }
@@ -0,0 +1,6 @@
1
+ from pymongo.mongo_client import MongoClient
2
+ from pymongo.server_api import ServerApi
3
+ from telegram_libs.constants import MONGO_URI
4
+
5
+ # Create a new client and connect to the server
6
+ mongo_client = MongoClient(MONGO_URI, server_api=ServerApi("1"))
@@ -1,13 +1,9 @@
1
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"))
2
+ from telegram_libs.constants import SUBSCRIPTION_DB_NAME
3
+ from telegram_libs.mongo import mongo_client
8
4
 
9
5
  # Define the subscription database and collection
10
- subscription_db = client[SUBSCRIPTION_DB_NAME]
6
+ subscription_db = mongo_client[SUBSCRIPTION_DB_NAME]
11
7
  subscription_collection = subscription_db["subscriptions"]
12
8
 
13
9
 
@@ -0,0 +1,119 @@
1
+ from telegram import (
2
+ InlineKeyboardButton,
3
+ InlineKeyboardMarkup,
4
+ )
5
+ from telegram import Update
6
+ from telegram.ext import ContextTypes, Application, CommandHandler, MessageHandler, filters
7
+ from telegram_libs.constants import BOTS_AMOUNT
8
+ from telegram_libs.translation import t
9
+ from telegram_libs.mongo import mongo_client
10
+ from functools import partial
11
+
12
+ FEEDBACK_WAITING = "feedback_waiting"
13
+ SUPPORT_WAITING = "support_waiting"
14
+
15
+
16
+ async def get_subscription_keyboard(update: Update, lang: str) -> InlineKeyboardMarkup:
17
+ """Get subscription keyboard
18
+
19
+ Args:
20
+ update (Update): Update object
21
+ lang (str): Language code
22
+
23
+ Returns:
24
+ InlineKeyboardMarkup: Inline keyboard markup
25
+ """
26
+ await update.message.reply_text(
27
+ t("subscription.info", lang, common=True).format(int(BOTS_AMOUNT) - 1)
28
+ )
29
+ return [
30
+ [
31
+ InlineKeyboardButton(
32
+ t("subscription.plans.1month", lang, common=True), callback_data="sub_1month"
33
+ ),
34
+ InlineKeyboardButton(
35
+ t("subscription.plans.3months", lang, common=True), callback_data="sub_3months"
36
+ ),
37
+ ],
38
+ [
39
+ InlineKeyboardButton(
40
+ t("subscription.plans.1year", lang, common=True), callback_data="sub_1year"
41
+ ),
42
+ ],
43
+ ]
44
+
45
+
46
+ async def more_bots_list_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
47
+ message = """Here is the list of all bots: \n\n
48
+ - <a href="https://t.me/MagMediaBot">Remove Background</a>
49
+ - <a href="https://t.me/UpscaleImageGBot">Upscale Image</a>
50
+ - <a href="https://t.me/GenerateBackgroundGBot">Generate a Background</a>
51
+ - <a href="https://t.me/kudapoyti_go_bot">Recommend a place to visit</a>
52
+ - <a href="https://t.me/TryOnOutfitGBot">Try On Outfit</a>
53
+ """
54
+ await update.message.reply_text(message, disable_web_page_preview=True, parse_mode='HTML')
55
+
56
+
57
+ async def support_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
58
+ """Support command handler"""
59
+ await update.message.reply_text(
60
+ t("support.message", update.effective_user.language_code, common=True)
61
+ )
62
+ context.user_data[SUPPORT_WAITING] = True
63
+
64
+
65
+ async def handle_support_response(update: Update, context: ContextTypes.DEFAULT_TYPE, bot_name: str) -> None:
66
+ """Handle user's support message"""
67
+ if context.user_data.get(SUPPORT_WAITING):
68
+ support_db = mongo_client["support"]
69
+ support_collection = support_db["support"]
70
+ support_doc = {
71
+ "user_id": update.effective_user.id,
72
+ "username": update.effective_user.username,
73
+ "message": update.message.text,
74
+ "bot_name": bot_name,
75
+ "timestamp": update.message.date.isoformat(),
76
+ "resolved": False,
77
+ }
78
+ support_collection.insert_one(support_doc)
79
+ await update.message.reply_text(t("support.response", update.effective_user.language_code, common=True))
80
+ context.user_data[SUPPORT_WAITING] = False
81
+
82
+
83
+ async def feedback_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
84
+ """Feedback command handler"""
85
+ await update.message.reply_text(
86
+ t("feedback.message", update.effective_user.language_code, common=True)
87
+ )
88
+ context.user_data[FEEDBACK_WAITING] = True
89
+
90
+
91
+ async def handle_feedback_response(update: Update, context: ContextTypes.DEFAULT_TYPE, bot_name: str) -> None:
92
+ """Handle user's feedback message"""
93
+ if context.user_data.get(FEEDBACK_WAITING):
94
+ feedback_db = mongo_client["feedback"]
95
+ feedback_collection = feedback_db["feedback"]
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
+
108
+ def register_feedback_and_support_handlers(app: Application, bot_name: str) -> None:
109
+ """Register feedback and support handlers for the bot"""
110
+ app.add_handler(CommandHandler("feedback", feedback_command))
111
+ app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, partial(handle_feedback_response, bot_name=bot_name)))
112
+ app.add_handler(CommandHandler("support", support_command))
113
+ app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, partial(handle_support_response, bot_name=bot_name)))
114
+
115
+
116
+ def register_common_handlers(app: Application, bot_name: str) -> None:
117
+ """Register common handlers for the bot"""
118
+ app.add_handler(CommandHandler("more", more_bots_list_command))
119
+ register_feedback_and_support_handlers(app, bot_name)
@@ -1,10 +0,0 @@
1
- {
2
- "subscription": {
3
- "choose_plan": "Choose a subscription plan:",
4
- "plans": {
5
- "1month": "1 Month - 1400 Stars",
6
- "3months": "3 Months - 3500 Stars",
7
- "1year": "1 Year - 12000 Stars"
8
- }
9
- }
10
- }
@@ -1,10 +0,0 @@
1
- {
2
- "subscription": {
3
- "choose_plan": "Выберите план подписки:",
4
- "plans": {
5
- "1month": "1 месяц - 1400 Stars",
6
- "3months": "3 месяца - 3500 Stars",
7
- "1year": "1 год - 12000 Stars"
8
- }
9
- }
10
- }
@@ -1,49 +0,0 @@
1
- from telegram import (
2
- InlineKeyboardButton,
3
- InlineKeyboardMarkup,
4
- )
5
- from telegram import Update
6
- from telegram.ext import ContextTypes
7
- from telegram_libs.constants import BOTS_AMOUNT
8
- from telegram_libs.translation import t
9
-
10
-
11
- async def get_subscription_keyboard(update: Update, lang: str) -> InlineKeyboardMarkup:
12
- """Get subscription keyboard
13
-
14
- Args:
15
- update (Update): Update object
16
- lang (str): Language code
17
-
18
- Returns:
19
- InlineKeyboardMarkup: Inline keyboard markup
20
- """
21
- await update.message.reply_text(
22
- f"Buying a subscription you will get unlimited access to other {int(BOTS_AMOUNT) - 1} bots, to see all bots click /more"
23
- )
24
- return [
25
- [
26
- InlineKeyboardButton(
27
- t("subscription.plans.1month", lang, common=True), callback_data="sub_1month"
28
- ),
29
- InlineKeyboardButton(
30
- t("subscription.plans.3months", lang, common=True), callback_data="sub_3months"
31
- ),
32
- ],
33
- [
34
- InlineKeyboardButton(
35
- t("subscription.plans.1year", lang, common=True), callback_data="sub_1year"
36
- ),
37
- ],
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/GenerateBackgroundGBot">Generate a Background</a>
46
- - <a href="https://t.me/kudapoyti_go_bot">Recommend a place to visit</a>
47
- - <a href="https://t.me/TryOnOutfitGBot">Try On Outfit</a>
48
- """
49
- await update.message.reply_text(message, disable_web_page_preview=True, parse_mode='HTML')
File without changes
File without changes