maxibot 0.98.1__py3-none-any.whl → 1.0.7__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.
maxibot/__init__.py CHANGED
@@ -8,7 +8,7 @@ from typing import Dict, Any, List, Optional, Callable, Union
8
8
  from maxibot.apihelper import Api
9
9
  from maxibot.types import Message, CallbackQuery, InputMedia
10
10
  from maxibot.types import UpdateType, InlineKeyboardMarkup
11
- from maxibot.util import extract_command, get_text, get_parce_mode
11
+ from maxibot.util import extract_command, get_text, get_parse_mode
12
12
  from maxibot.core.attachments.photo import Photo
13
13
  from maxibot.core.network.polling import Polling
14
14
 
@@ -219,7 +219,8 @@ class MaxiBot:
219
219
  # print(f"Full update: {json.dumps(update, indent=2)}")
220
220
 
221
221
  update_type = update.get("update_type")
222
- if update_type == UpdateType.MESSAGE_CREATED and "message" in update.keys():
222
+ if update_type == UpdateType.MESSAGE_CREATED and "message" in update.keys() or \
223
+ update_type == UpdateType.BOT_STARTED:
223
224
  context = Message(update, self.api)
224
225
  self._process_text_message(context)
225
226
  elif update_type == UpdateType.MESSAGE_CALLBACK:
@@ -412,7 +413,7 @@ class MaxiBot:
412
413
  chat_id: Union[str, int],
413
414
  message_id: str,
414
415
  reply_markup: Union[InlineKeyboardMarkup, Any] = None,
415
- parce_mode: Union[str, Any] = None
416
+ parse_mode: Union[str, Any] = None
416
417
  ):
417
418
  """
418
419
  Метод изменения текстового сообщения `message_id` в чате `chat_id`
@@ -437,7 +438,7 @@ class MaxiBot:
437
438
  text=text,
438
439
  method="PUT",
439
440
  attachments=final_attachments,
440
- parse_mode=parce_mode
441
+ parse_mode=parse_mode
441
442
  )
442
443
  return {}
443
444
 
@@ -447,7 +448,7 @@ class MaxiBot:
447
448
  chat_id: Union[str, int],
448
449
  message_id: str,
449
450
  reply_markup: Union[InlineKeyboardMarkup, Any] = None,
450
- parce_mode: Union[str, Any] = "markdown"
451
+ parse_mode: Union[str, Any] = "markdown"
451
452
  ):
452
453
  """
453
454
  Метод изменения медиа сообщения `message_id` в чате `chat_id`
@@ -474,13 +475,13 @@ class MaxiBot:
474
475
  else:
475
476
  final_attachments.append(reply_markup)
476
477
  text = get_text(media=media)
477
- parce_mode = get_parce_mode(media=media, parse_mode=parce_mode)
478
+ parse_mode = get_parse_mode(media=media, parse_mode=parse_mode)
478
479
  self.api.send_message(
479
480
  msg_id=message_id,
480
481
  text=text,
481
482
  method="PUT",
482
483
  attachments=final_attachments,
483
- parse_mode=parce_mode
484
+ parse_mode=parse_mode
484
485
  )
485
486
  return {}
486
487
 
@@ -489,7 +490,7 @@ class MaxiBot:
489
490
  chat_id: Union[str, int],
490
491
  message_id: str,
491
492
  reply_markup: Union[InlineKeyboardMarkup, Any] = None,
492
- parce_mode: Union[str, Any] = "markdown"
493
+ parse_mode: Union[str, Any] = "markdown"
493
494
  ):
494
495
  """
495
496
  Метод изменения клавиатуры сообщения `message_id` в чате `chat_id`
@@ -516,7 +517,7 @@ class MaxiBot:
516
517
  msg_id=message_id,
517
518
  method="PUT",
518
519
  attachments=final_attachments,
519
- parse_mode=parce_mode.lower()
520
+ parse_mode=parse_mode.lower()
520
521
  )
521
522
  return {}
522
523
 
@@ -526,7 +527,7 @@ class MaxiBot:
526
527
  text: str,
527
528
  attachments: Optional[List[Dict[str, Any]]] = None,
528
529
  reply_markup: Optional[Any] = None,
529
- parce_mode: str = "markdown",
530
+ parse_mode: str = "markdown",
530
531
  notify: bool = True
531
532
  ) -> Message:
532
533
  """
@@ -563,7 +564,7 @@ class MaxiBot:
563
564
  chat_id=chat_id,
564
565
  text=text,
565
566
  attachments=final_attachments,
566
- parse_mode=parce_mode.lower(),
567
+ parse_mode=parse_mode.lower(),
567
568
  notify=notify
568
569
  ),
569
570
  api=self.api
maxibot/types.py CHANGED
@@ -1,4 +1,4 @@
1
- from dataclasses import dataclass
1
+ # from dataclasses import dataclass
2
2
  from datetime import datetime
3
3
  from typing import List, Dict, Any, Optional
4
4
 
@@ -6,6 +6,15 @@ from maxibot.apihelper import Api
6
6
  from maxibot.util import is_pil_image, pil_image_to_bytes
7
7
 
8
8
 
9
+ class JsonDeserializable(object):
10
+ def __str__(self):
11
+ d = {
12
+ x: y.__dict__ if hasattr(y, '__dict__') else y
13
+ for x, y in self.__dict__.items()
14
+ }
15
+ return str(d)
16
+
17
+
9
18
  class UpdateType:
10
19
  """
11
20
  Типы обновлений, которые можно получать от MAX API
@@ -173,7 +182,7 @@ class InlineKeyboardMarkup:
173
182
  )
174
183
 
175
184
 
176
- class ImagePayload:
185
+ class ImagePayload(JsonDeserializable):
177
186
  """
178
187
  Класс для хранения данных изображения
179
188
 
@@ -187,7 +196,7 @@ class ImagePayload:
187
196
  self.url = payload.get("url")
188
197
 
189
198
 
190
- class ImageAttachment:
199
+ class ImageAttachment(JsonDeserializable):
191
200
  """
192
201
  Класс для работы с вложениями типа "image"
193
202
 
@@ -216,7 +225,7 @@ class ImageAttachment:
216
225
  }
217
226
 
218
227
 
219
- class Recipient:
228
+ class Recipient(JsonDeserializable):
220
229
  """
221
230
  Класс получателя сообщения
222
231
 
@@ -230,7 +239,7 @@ class Recipient:
230
239
  self.user_id = rec.get("user_id")
231
240
 
232
241
 
233
- class Body:
242
+ class Body(JsonDeserializable):
234
243
  """
235
244
  Класс тела сообщения
236
245
 
@@ -245,7 +254,7 @@ class Body:
245
254
  self.attachments = body.get("attachments")
246
255
 
247
256
 
248
- class User:
257
+ class User(JsonDeserializable):
249
258
  """
250
259
  Класс пользователя
251
260
 
@@ -262,6 +271,14 @@ class User:
262
271
  self.username = update.get("callback").get("user").get("name")
263
272
  self.last_name = update.get("callback").get("user").get("last_name")
264
273
  self.language_code = update.get("user_locale")
274
+ elif update.get("update_type") == UpdateType.BOT_STARTED:
275
+ self.id = update.get("chat_id")
276
+ self.real_id = update.get("user").get("user_id")
277
+ self.is_bot = update.get("user").get("is_bot")
278
+ self.first_name = update.get("user").get("first_name")
279
+ self.username = update.get("user").get("name")
280
+ self.last_name = update.get("user").get("last_name")
281
+ self.language_code = update.get("user_locale")
265
282
  else:
266
283
  self.id = update.get("message").get("recipient").get("chat_id")
267
284
  self.real_id = update.get("message").get("sender").get("user_id")
@@ -272,7 +289,7 @@ class User:
272
289
  self.language_code = update.get("user_locale")
273
290
 
274
291
 
275
- class Chat:
292
+ class Chat(JsonDeserializable):
276
293
  """
277
294
  Класс чата
278
295
 
@@ -281,12 +298,17 @@ class Chat:
281
298
  """
282
299
 
283
300
  def __init__(self, update: Dict[str, Any]):
284
- self.id = update.get("message").get("recipient").get("chat_id")
285
- self.type = update.get("message").get("recipient").get("chat_type")
286
- self.user_id = update.get("message").get("recipient").get("user_id")
301
+ if update.get("update_type") == UpdateType.BOT_STARTED:
302
+ self.id = update.get("chat_id")
303
+ self.type = None
304
+ self.user_id = None
305
+ else:
306
+ self.id = update.get("message").get("recipient").get("chat_id")
307
+ self.type = update.get("message").get("recipient").get("chat_type")
308
+ self.user_id = update.get("message").get("recipient").get("user_id")
287
309
 
288
310
 
289
- class ChatLink:
311
+ class ChatLink(JsonDeserializable):
290
312
  """
291
313
  Класс ссылки на чат
292
314
 
@@ -298,7 +320,7 @@ class ChatLink:
298
320
  self.id = update.get("chat_id")
299
321
 
300
322
 
301
- class Link:
323
+ class Link(JsonDeserializable):
302
324
  """
303
325
  Класс ссылки на сообщение
304
326
 
@@ -314,7 +336,7 @@ class Link:
314
336
  self.chat: ChatLink = ChatLink(update=link)
315
337
 
316
338
 
317
- class Photo:
339
+ class Photo(JsonDeserializable):
318
340
  """
319
341
  Класс для работы с фотографиями
320
342
 
@@ -323,7 +345,7 @@ class Photo:
323
345
  """
324
346
 
325
347
  def __init__(self, update: Dict[str, Any]):
326
- attach = update.get("message").get("body").get("attachments")
348
+ attach = update.get("message", {}).get("body", {}).get("attachments", None)
327
349
  if attach:
328
350
  for att in attach:
329
351
  if att.get("type") == "image":
@@ -332,7 +354,7 @@ class Photo:
332
354
  self.url: str = att.get("payload").get("url")
333
355
 
334
356
 
335
- class InputMedia:
357
+ class InputMedia(JsonDeserializable):
336
358
  """
337
359
  Класс формирования объекта attachments для отправки медиа
338
360
 
@@ -422,7 +444,7 @@ class InputMedia:
422
444
  }
423
445
 
424
446
 
425
- class InputMediaPhoto(InputMedia):
447
+ class InputMediaPhoto(InputMedia, JsonDeserializable):
426
448
  """
427
449
  Класс для отправки фотографий
428
450
 
@@ -440,7 +462,7 @@ class InputMediaPhoto(InputMedia):
440
462
  super().__init__(type="photo", media=media, caption=caption, parse_mode=parse_mode)
441
463
 
442
464
 
443
- class InputMediaVideo(InputMedia):
465
+ class InputMediaVideo(InputMedia, JsonDeserializable):
444
466
  """
445
467
  Класс для отправки видео
446
468
 
@@ -458,7 +480,7 @@ class InputMediaVideo(InputMedia):
458
480
  super().__init__(type="video", media=media, caption=caption, parse_mode=parse_mode)
459
481
 
460
482
 
461
- class Message:
483
+ class Message(JsonDeserializable):
462
484
  """
463
485
  Класс для работы с сообщениями (аналог telebot.types.Message)
464
486
 
@@ -502,13 +524,16 @@ class Message:
502
524
  :return: Тип контента
503
525
  :rtype: str
504
526
  """
505
- if update.get("message").get("body").get("attachments"):
506
- c_type = update.get("message").get("body").get("attachments")[0].get("type")
507
- if c_type == "image":
508
- return "photo"
527
+ try:
528
+ if update.get("message").get("body").get("attachments"):
529
+ c_type = update.get("message").get("body").get("attachments")[0].get("type")
530
+ if c_type == "image":
531
+ return "photo"
532
+ else:
533
+ return c_type
509
534
  else:
510
- return c_type
511
- else:
535
+ return "text"
536
+ except Exception:
512
537
  return "text"
513
538
 
514
539
  @staticmethod
@@ -522,11 +547,14 @@ class Message:
522
547
  :return: ID сообщения или None
523
548
  :rtype: Optional[str]
524
549
  """
525
- if update.get("message").get("body"):
526
- return update.get("message").get("body").get("mid")
527
- elif update.get("message").get("mid"):
528
- return update.get("message").get("mid")
529
- else:
550
+ try:
551
+ if update.get("message").get("body"):
552
+ return update.get("message").get("body").get("mid")
553
+ elif update.get("message").get("mid"):
554
+ return update.get("message").get("mid")
555
+ else:
556
+ return None
557
+ except Exception:
530
558
  return None
531
559
 
532
560
  @staticmethod
@@ -560,8 +588,10 @@ class Message:
560
588
  :return: Текст сообщения или None
561
589
  :rtype: Optional[str]
562
590
  """
563
- if update.get("message").get("body"):
591
+ if update.get("message", {}).get("body", None):
564
592
  return update.get("message").get("body").get("text")
593
+ elif update.get("update_type") == UpdateType.BOT_STARTED:
594
+ return "/start"
565
595
  else:
566
596
  return None
567
597
 
@@ -577,7 +607,7 @@ class Message:
577
607
  self.from_user: Optional[User] = User(update=update)
578
608
  self.date: Optional[datetime] = self._get_msg_timestamp(update=update)
579
609
  self.chat: Chat = Chat(update=update)
580
- self.reply_to_message: Link = Link(link=update.get("message").get("link"))
610
+ self.reply_to_message: Link = Link(link=update.get("message", {}).get("link", None))
581
611
  self.text: Optional[str] = self._get_msg_text(update=update)
582
612
  self.photo: Optional[ImageAttachment] = self._get_photo_from_attachments(update=update)
583
613
  self.photo_reply: Photo = Photo(update=update)
maxibot/util.py CHANGED
@@ -83,7 +83,7 @@ def get_text(media):
83
83
  return text
84
84
 
85
85
 
86
- def get_parce_mode(media, parse_mode: str):
86
+ def get_parse_mode(media, parse_mode: str):
87
87
  """
88
88
  Метод получения parce_mode из media
89
89
 
@@ -1,14 +1,42 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maxibot
3
- Version: 0.98.1
3
+ Version: 1.0.7
4
4
  Summary: Library for build bot in MAX
5
+ Project-URL: Homepage, https://github.com/mrProduktivnyy/maxibot
6
+ Project-URL: Documentation, https://github.com/mrProduktivnyy/maxibot/tree/main/maxibot/docs
7
+ Project-URL: Repository, https://github.com/mrProduktivnyy/maxibot
8
+ Project-URL: Issues, https://github.com/mrProduktivnyy/maxibot/issues
9
+ Keywords: max,bot,api,tools
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Environment :: Console
18
+ Classifier: License :: OSI Approved :: GNU General Public License v2 (GPLv2)
19
+ Requires-Python: >=3.8
5
20
  Description-Content-Type: text/markdown
6
21
  Requires-Dist: requests==2.32.5
7
22
 
23
+ ### **Библиотека для мессенджера Max**<br>
24
+ Её главная цель — позволить разработчикам использовать знакомые методы и классы из pyTelegramBotAPI (telebot) без изменений. Это позволяет переводить существующего телеграм бота на Max, а также создавать нового бота, заменив import telebot на import maxibot.
25
+
26
+ ![tg_to_max](https://github.com/mrProduktivnyy/maxibot/raw/main/maxibot/docs/tg_to_max.png)
27
+
28
+ [![PyPi Package Version](https://img.shields.io/pypi/v/maxibot.svg)](https://pypi.python.org/pypi/maxibot)
29
+ [![Supported Python versions](https://img.shields.io/pypi/pyversions/maxibot.svg)](https://pypi.python.org/pypi/maxibot)
30
+ [![Documentation Status](https://img.shields.io/badge/docs-passing-green)](https://github.com/mrProduktivnyy/maxibot/tree/main/maxibot/docs)
31
+ [![PyPi downloads](https://img.shields.io/pypi/dm/maxibot.svg)](https://pypi.org/project/maxibot/)
32
+ [![PyPi status](https://img.shields.io/pypi/status/maxibot.svg?style=flat-square)](https://pypi.python.org/pypi/maxibot)
33
+
34
+ ### **Канал связи с разработчиками:** [t.me/maxibot_dev](https://t.me/maxibot_dev)
35
+
8
36
  ## Быстрый старт
9
37
  Необходимо установить библиотеку
10
38
  ```sh
11
- pip install -i https://test.pypi.org/simple/ maxibot
39
+ pip install maxibot
12
40
  ```
13
41
  ## Просто эхо-бот
14
42
  Необходимо создать файл `echo_bot.py` и добавить в него следующий код.
@@ -0,0 +1,11 @@
1
+ maxibot/__init__.py,sha256=rncP36tK_rykvdVtDhYesp79RVWlDMarxVEP2Cpi8nM,24593
2
+ maxibot/apihelper.py,sha256=tX5N7l77GJtCWDXEeCvW2BBDwEnRCYvi_oNm8Hytt1k,9710
3
+ maxibot/types.py,sha256=LYgxK8O9nl_PuzeAC3rmyQ5STq9GseRkDh70g9FlPPk,28258
4
+ maxibot/util.py,sha256=mJ-X99SSDB8Dtdi_SZzG8RjY4ltkc107AmQIA1ybb50,2545
5
+ maxibot/core/attachments/photo.py,sha256=ZaqSHuIw4ik8bxIS3VOQyD949B2AGyY5GSKSbSvf1Dg,1472
6
+ maxibot/core/network/client.py,sha256=-k9fihDINR5tWbU3IIORE4udiliCrLPIpWfDAW1zuEU,3845
7
+ maxibot/core/network/polling.py,sha256=E7z4SWIyiuFv0UMwRpPCQ0ilhbGAQ8VQ9LBFJVdvQDU,2301
8
+ maxibot-1.0.7.dist-info/METADATA,sha256=-KPjlyzqex0Y3yfo-se9A5QUa2d50sWmKwPIlSrGLU0,4903
9
+ maxibot-1.0.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
+ maxibot-1.0.7.dist-info/top_level.txt,sha256=WNdB_JJYD7kB8YacJAru3eguPKZ5UIlkQS_opytFaSE,8
11
+ maxibot-1.0.7.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- maxibot/__init__.py,sha256=yoJtEuiyiEEMAHve9s3UNiPRMc_kqkwZz6WjX30qdTY,24534
2
- maxibot/apihelper.py,sha256=tX5N7l77GJtCWDXEeCvW2BBDwEnRCYvi_oNm8Hytt1k,9710
3
- maxibot/types.py,sha256=pYHk-t6pFNypREEesOtQMvOgZlOy0jGXPOwSBe6l2F0,26769
4
- maxibot/util.py,sha256=Ps263znGfLrHODi6fvYfibhpGOYOzThoQiZoHduwBi0,2545
5
- maxibot/core/attachments/photo.py,sha256=ZaqSHuIw4ik8bxIS3VOQyD949B2AGyY5GSKSbSvf1Dg,1472
6
- maxibot/core/network/client.py,sha256=-k9fihDINR5tWbU3IIORE4udiliCrLPIpWfDAW1zuEU,3845
7
- maxibot/core/network/polling.py,sha256=E7z4SWIyiuFv0UMwRpPCQ0ilhbGAQ8VQ9LBFJVdvQDU,2301
8
- maxibot-0.98.1.dist-info/METADATA,sha256=fuu7UJvqwclY-A3pd8LG61fPmoUu6VzIGF3g8emhu6w,2808
9
- maxibot-0.98.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
- maxibot-0.98.1.dist-info/top_level.txt,sha256=WNdB_JJYD7kB8YacJAru3eguPKZ5UIlkQS_opytFaSE,8
11
- maxibot-0.98.1.dist-info/RECORD,,