mm-telegram 0.2.0__py3-none-any.whl → 0.3.0__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.
mm_telegram/bot.py
CHANGED
@@ -22,16 +22,22 @@ type TelegramHandler = BaseHandler[Any, CallbackContext[ExtBot[None], dict[Any,
|
|
22
22
|
|
23
23
|
|
24
24
|
async def ping(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
25
|
+
"""Responds with 'pong' to /ping command."""
|
25
26
|
if update.effective_chat is not None:
|
26
27
|
await context.bot.send_message(chat_id=update.effective_chat.id, text="pong")
|
27
28
|
|
28
29
|
|
29
30
|
async def unknown(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
31
|
+
"""Handles unknown commands with a default response."""
|
30
32
|
if update.effective_chat is not None:
|
31
33
|
await context.bot.send_message(chat_id=update.effective_chat.id, text="Sorry, I didn't understand that command.")
|
32
34
|
|
33
35
|
|
34
36
|
async def is_admin(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
37
|
+
"""Checks if user is admin and blocks access if not.
|
38
|
+
|
39
|
+
Raises ApplicationHandlerStop if user is not in the admins list.
|
40
|
+
"""
|
35
41
|
admins: list[int] = context.bot_data.get("admins", [])
|
36
42
|
|
37
43
|
if update.effective_user is None or update.message is None:
|
@@ -44,14 +50,21 @@ async def is_admin(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
|
44
50
|
|
45
51
|
|
46
52
|
class TelegramBot:
|
53
|
+
"""Telegram bot wrapper that manages application lifecycle and handlers."""
|
54
|
+
|
47
55
|
app: Application[Any, Any, Any, Any, Any, Any] | None
|
48
56
|
|
49
57
|
def __init__(self, handlers: list[TelegramHandler], bot_data: dict[str, object]) -> None:
|
58
|
+
"""Initialize bot with custom handlers and initial bot data."""
|
50
59
|
self.handlers = handlers
|
51
60
|
self.bot_data = bot_data
|
52
61
|
self.app = None
|
53
62
|
|
54
63
|
async def start(self, token: str, admins: list[int]) -> None:
|
64
|
+
"""Start the bot with given token and admin list.
|
65
|
+
|
66
|
+
Raises ValueError if no admins are provided.
|
67
|
+
"""
|
55
68
|
if not admins:
|
56
69
|
raise ValueError("No admins provided")
|
57
70
|
logger.debug("Starting telegram bot...")
|
@@ -75,6 +88,7 @@ class TelegramBot:
|
|
75
88
|
self.app = app
|
76
89
|
|
77
90
|
async def shutdown(self) -> None:
|
91
|
+
"""Stop the bot and clean up resources."""
|
78
92
|
if self.app is not None:
|
79
93
|
await self.app.shutdown()
|
80
94
|
self.app = None
|
mm_telegram/message.py
CHANGED
@@ -0,0 +1,7 @@
|
|
1
|
+
mm_telegram/__init__.py,sha256=MfDt-Y42ew8LaQW34MElvgrpkPcs_RWCW_coQSyFYOE,142
|
2
|
+
mm_telegram/bot.py,sha256=VNs2yPulCQosIe_Db9HKPQ7IAGLaVbZaoDAT0i7d3oE,3186
|
3
|
+
mm_telegram/message.py,sha256=bEJl_ctSEdTjFQbY14g3dlwZKcTef7RfaM-8Jqn4INA,2307
|
4
|
+
mm_telegram/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
+
mm_telegram-0.3.0.dist-info/METADATA,sha256=6vzPzU_D0XFfhmyuayP0wvaEXeWPWXSkneBJkr1lx64,182
|
6
|
+
mm_telegram-0.3.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
7
|
+
mm_telegram-0.3.0.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
mm_telegram/__init__.py,sha256=MfDt-Y42ew8LaQW34MElvgrpkPcs_RWCW_coQSyFYOE,142
|
2
|
-
mm_telegram/bot.py,sha256=ZQeKONCiFkmuinCpgvbfYc1clvd2lB26YR9NAuL8eMs,2614
|
3
|
-
mm_telegram/message.py,sha256=nbBWG58PjKU74NYqxwMANBLax0HJqgJ0B6r3FOAeVxg,2285
|
4
|
-
mm_telegram/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
-
mm_telegram-0.2.0.dist-info/METADATA,sha256=o0WxxaffFumRugRsp9zfbrXpNy8-fUn0QipGaCupXjw,150
|
6
|
-
mm_telegram-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
7
|
-
mm_telegram-0.2.0.dist-info/RECORD,,
|
File without changes
|