maxapi-python 1.1.2__tar.gz → 1.1.4__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.
Files changed (41) hide show
  1. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/PKG-INFO +1 -1
  2. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/examples/example.py +13 -11
  3. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/pyproject.toml +1 -1
  4. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/filters.py +4 -0
  5. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/mixins/group.py +1 -1
  6. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/mixins/message.py +2 -10
  7. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/mixins/socket.py +1 -3
  8. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/mixins/websocket.py +1 -1
  9. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/types.py +17 -12
  10. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/.github/FUNDING.yml +0 -0
  11. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/.github/workflows/publish.yml +0 -0
  12. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/.gitignore +0 -0
  13. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/LICENSE +0 -0
  14. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/README.md +0 -0
  15. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/assets/icon.svg +0 -0
  16. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/assets/logo.svg +0 -0
  17. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/docs/api.md +0 -0
  18. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/docs/assets/icon.svg +0 -0
  19. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/docs/examples.md +0 -0
  20. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/docs/index.md +0 -0
  21. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/mkdocs.yml +0 -0
  22. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/ruff.toml +0 -0
  23. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/scripts/build.py +0 -0
  24. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/__init__.py +0 -0
  25. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/core.py +0 -0
  26. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/crud.py +0 -0
  27. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/exceptions.py +0 -0
  28. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/files.py +0 -0
  29. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/interfaces.py +0 -0
  30. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/mixins/__init__.py +0 -0
  31. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/mixins/auth.py +0 -0
  32. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/mixins/channel.py +0 -0
  33. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/mixins/handler.py +0 -0
  34. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/mixins/self.py +0 -0
  35. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/mixins/telemetry.py +0 -0
  36. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/mixins/user.py +0 -0
  37. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/models.py +0 -0
  38. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/navigation.py +0 -0
  39. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/payloads.py +0 -0
  40. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/static.py +0 -0
  41. {maxapi_python-1.1.2 → maxapi_python-1.1.4}/src/pymax/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maxapi-python
3
- Version: 1.1.2
3
+ Version: 1.1.4
4
4
  Summary: Python wrapper для API мессенджера Max
5
5
  Project-URL: Homepage, https://github.com/noxzion/PyMax
6
6
  Project-URL: Repository, https://github.com/noxzion/PyMax
@@ -9,8 +9,8 @@ from pymax.static import AttachType
9
9
  phone = "+1234567890"
10
10
 
11
11
 
12
- # client = MaxClient(phone=phone, work_dir="cache")
13
- client = SocketMaxClient(phone=phone, work_dir="cache")
12
+ client = MaxClient(phone=phone, work_dir="cache")
13
+ # client = SocketMaxClient(phone=phone, work_dir="cache")
14
14
 
15
15
 
16
16
  async def main() -> None:
@@ -38,7 +38,7 @@ async def main() -> None:
38
38
  await client.close()
39
39
 
40
40
 
41
- @client.on_message(filter=Filter(text=["Привет"]))
41
+ @client.on_message(filter=Filter(chat_id=0))
42
42
  async def handle_message(message: Message) -> None:
43
43
  print(str(message.sender) + ": " + message.text)
44
44
 
@@ -50,22 +50,24 @@ async def handle_start() -> None:
50
50
  if history:
51
51
  for message in history:
52
52
  user_id = message.sender
53
+ chat_id = message.chat_id
54
+ print(chat_id)
53
55
  user = await client.get_user(user_id)
54
56
 
55
57
  if user:
56
58
  print(f"{user.names[0].name}: {message.text}")
57
59
 
58
- print(client.me.names[0].first_name)
59
- user = await client.get_user(client.me.id)
60
+ # print(client.me.names[0].first_name)
61
+ # user = await client.get_user(client.me.id)
60
62
 
61
- print(user.names[0].first_name)
63
+ # print(user.names[0].first_name)
62
64
 
63
- photo1 = Photo(path="tests/test.jpeg")
64
- photo2 = Photo(path="tests/test.jpg")
65
+ # photo1 = Photo(path="tests/test.jpeg")
66
+ # photo2 = Photo(path="tests/test.jpg")
65
67
 
66
- await client.send_message(
67
- "Hello with photo!", chat_id=0, photos=[photo1, photo2], notify=True
68
- )
68
+ # await client.send_message(
69
+ # "Hello with photo!", chat_id=0, photos=[photo1, photo2], notify=True
70
+ # )
69
71
 
70
72
 
71
73
  if __name__ == "__main__":
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "maxapi-python"
3
- version = "1.1.2"
3
+ version = "1.1.4"
4
4
  description = "Python wrapper для API мессенджера Max"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -5,6 +5,7 @@ from .types import Message
5
5
  class Filter:
6
6
  def __init__(
7
7
  self,
8
+ chat_id: int | None = None,
8
9
  user_id: int | None = None,
9
10
  text: list[str] | None = None,
10
11
  status: MessageStatus | str | None = None,
@@ -12,6 +13,7 @@ class Filter:
12
13
  text_contains: str | None = None,
13
14
  reaction_info: bool | None = None,
14
15
  ) -> None:
16
+ self.chat_id = chat_id
15
17
  self.user_id = user_id
16
18
  self.text = text
17
19
  self.status = status
@@ -20,6 +22,8 @@ class Filter:
20
22
  self.text_contains = text_contains
21
23
 
22
24
  def match(self, message: Message) -> bool:
25
+ if self.chat_id is not None and message.chat_id != self.chat_id:
26
+ return False
23
27
  if self.user_id is not None and message.sender != self.user_id:
24
28
  return False
25
29
  if self.text is not None and any(
@@ -51,7 +51,7 @@ class GroupMixin(ClientProtocol):
51
51
  return None
52
52
 
53
53
  chat = Chat.from_dict(data["payload"]["chat"])
54
- message = Message.from_dict(data["payload"]["message"])
54
+ message = Message.from_dict(data["payload"])
55
55
 
56
56
  if chat:
57
57
  cached_chat = await self._get_chat(chat.id)
@@ -143,11 +143,7 @@ class MessageMixin(ClientProtocol):
143
143
  self.logger.error("Send message error: %s", error)
144
144
  print(data)
145
145
  return None
146
- msg = (
147
- Message.from_dict(data["payload"]["message"])
148
- if data.get("payload")
149
- else None
150
- )
146
+ msg = Message.from_dict(data["payload"]) if data.get("payload") else None
151
147
  self.logger.debug("send_message result: %r", msg)
152
148
  return msg
153
149
  except Exception:
@@ -174,11 +170,7 @@ class MessageMixin(ClientProtocol):
174
170
  data = await self._send_and_wait(opcode=Opcode.MSG_EDIT, payload=payload)
175
171
  if error := data.get("payload", {}).get("error"):
176
172
  self.logger.error("Edit message error: %s", error)
177
- msg = (
178
- Message.from_dict(data["payload"]["message"])
179
- if data.get("payload")
180
- else None
181
- )
173
+ msg = Message.from_dict(data["payload"]) if data.get("payload") else None
182
174
  self.logger.debug("edit_message result: %r", msg)
183
175
  return msg
184
176
  except Exception:
@@ -214,9 +214,7 @@ Socket connections may be unstable, SSL issues are possible.
214
214
  for handler, filter in self._on_message_handlers:
215
215
  payload = data_item.get("payload", {})
216
216
  msg_dict = (
217
- payload.get("message")
218
- if isinstance(payload, dict)
219
- else None
217
+ payload if isinstance(payload, dict) else None
220
218
  )
221
219
  msg = (
222
220
  Message.from_dict(msg_dict)
@@ -118,7 +118,7 @@ class WebSocketMixin(ClientProtocol):
118
118
  try:
119
119
  for handler, filter in self._on_message_handlers:
120
120
  payload = data.get("payload", {})
121
- msg = Message.from_dict(payload.get("message"))
121
+ msg = Message.from_dict(payload)
122
122
  if msg:
123
123
  if msg.status:
124
124
  continue # TODO: заглушка! сделать отдельный хендлер
@@ -47,7 +47,7 @@ class PhotoAttach:
47
47
  width: int,
48
48
  photo_id: int,
49
49
  photo_token: str,
50
- preview_data: str,
50
+ preview_data: str | None,
51
51
  type: AttachType,
52
52
  ) -> None:
53
53
  self.base_url = base_url
@@ -66,7 +66,7 @@ class PhotoAttach:
66
66
  width=data["width"],
67
67
  photo_id=data["photoId"],
68
68
  photo_token=data["photoToken"],
69
- preview_data=data["previewData"],
69
+ preview_data=data.get("previewData"),
70
70
  type=AttachType(data["_type"]),
71
71
  )
72
72
 
@@ -230,6 +230,7 @@ class Element:
230
230
  class Message:
231
231
  def __init__(
232
232
  self,
233
+ chat_id: int | None,
233
234
  sender: int | None,
234
235
  elements: list[Element] | None,
235
236
  reaction_info: dict[str, Any] | None,
@@ -241,6 +242,7 @@ class Message:
241
242
  type: MessageType | str,
242
243
  attaches: list[PhotoAttach | VideoAttach | FileAttach],
243
244
  ) -> None:
245
+ self.chat_id = chat_id
244
246
  self.sender = sender
245
247
  self.elements = elements
246
248
  self.options = options
@@ -254,8 +256,9 @@ class Message:
254
256
 
255
257
  @classmethod
256
258
  def from_dict(cls, data: dict[Any, Any]) -> "Message":
259
+ message = data["message"] if data.get("message") else data
257
260
  attaches = []
258
- for a in data.get("attaches", []):
261
+ for a in message.get("attaches", []):
259
262
  if a["_type"] == AttachType.PHOTO:
260
263
  attaches.append(PhotoAttach.from_dict(a))
261
264
  elif a["_type"] == AttachType.VIDEO:
@@ -263,16 +266,17 @@ class Message:
263
266
  elif a["_type"] == AttachType.FILE:
264
267
  attaches.append(FileAttach.from_dict(a))
265
268
  return cls(
266
- sender=data.get("sender"),
267
- elements=[Element.from_dict(e) for e in data.get("elements", [])],
268
- options=data.get("options"),
269
- id=data["id"],
270
- time=data["time"],
271
- text=data["text"],
272
- type=data["type"],
269
+ chat_id=data.get("chatId"),
270
+ sender=message.get("sender"),
271
+ elements=[Element.from_dict(e) for e in message.get("elements", [])],
272
+ options=message.get("options"),
273
+ id=message["id"],
274
+ time=message["time"],
275
+ text=message["text"],
276
+ type=message["type"],
273
277
  attaches=attaches,
274
- status=data.get("status"),
275
- reaction_info=data.get("reactionInfo"),
278
+ status=message.get("status"),
279
+ reaction_info=message.get("reactionInfo"),
276
280
  )
277
281
 
278
282
  @override
@@ -280,6 +284,7 @@ class Message:
280
284
  return (
281
285
  f"Message(id={self.id!r}, sender={self.sender!r}, text={self.text!r}, "
282
286
  f"type={self.type!r}, status={self.status!r}, elements={self.elements!r})"
287
+ f"attaches={self.attaches!r}, chat_id={self.chat_id!r}, time={self.time!r}, options={self.options!r}, reactionInfo={self.reactionInfo!r})"
283
288
  )
284
289
 
285
290
  @override
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes