pyrogram-client 0.0.8.dev1__tar.gz → 0.0.11.dev0__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 (20) hide show
  1. {pyrogram_client-0.0.8.dev1 → pyrogram_client-0.0.11.dev0}/.pre-commit-config.yaml +1 -1
  2. {pyrogram_client-0.0.8.dev1/pyrogram_client.egg-info → pyrogram_client-0.0.11.dev0}/PKG-INFO +1 -1
  3. {pyrogram_client-0.0.8.dev1 → pyrogram_client-0.0.11.dev0}/pyro_client/client/base.py +29 -24
  4. {pyrogram_client-0.0.8.dev1 → pyrogram_client-0.0.11.dev0}/pyro_client/client/bot.py +2 -1
  5. {pyrogram_client-0.0.8.dev1 → pyrogram_client-0.0.11.dev0}/pyro_client/client/file.py +36 -4
  6. {pyrogram_client-0.0.8.dev1 → pyrogram_client-0.0.11.dev0}/pyro_client/client/user.py +5 -2
  7. {pyrogram_client-0.0.8.dev1 → pyrogram_client-0.0.11.dev0}/pyro_client/storage.py +2 -0
  8. {pyrogram_client-0.0.8.dev1 → pyrogram_client-0.0.11.dev0/pyrogram_client.egg-info}/PKG-INFO +1 -1
  9. {pyrogram_client-0.0.8.dev1 → pyrogram_client-0.0.11.dev0}/.env.sample +0 -0
  10. {pyrogram_client-0.0.8.dev1 → pyrogram_client-0.0.11.dev0}/.gitignore +0 -0
  11. {pyrogram_client-0.0.8.dev1 → pyrogram_client-0.0.11.dev0}/makefile +0 -0
  12. {pyrogram_client-0.0.8.dev1 → pyrogram_client-0.0.11.dev0}/pyproject.toml +0 -0
  13. {pyrogram_client-0.0.8.dev1 → pyrogram_client-0.0.11.dev0}/pyro_client/client/dc.json +0 -0
  14. {pyrogram_client-0.0.8.dev1 → pyrogram_client-0.0.11.dev0}/pyro_client/client/filler.py +0 -0
  15. {pyrogram_client-0.0.8.dev1 → pyrogram_client-0.0.11.dev0}/pyro_client/loader.py +0 -0
  16. {pyrogram_client-0.0.8.dev1 → pyrogram_client-0.0.11.dev0}/pyrogram_client.egg-info/SOURCES.txt +0 -0
  17. {pyrogram_client-0.0.8.dev1 → pyrogram_client-0.0.11.dev0}/pyrogram_client.egg-info/dependency_links.txt +0 -0
  18. {pyrogram_client-0.0.8.dev1 → pyrogram_client-0.0.11.dev0}/pyrogram_client.egg-info/requires.txt +0 -0
  19. {pyrogram_client-0.0.8.dev1 → pyrogram_client-0.0.11.dev0}/pyrogram_client.egg-info/top_level.txt +0 -0
  20. {pyrogram_client-0.0.8.dev1 → pyrogram_client-0.0.11.dev0}/setup.cfg +0 -0
@@ -23,7 +23,7 @@ repos:
23
23
 
24
24
  - repo: https://github.com/astral-sh/ruff-pre-commit
25
25
  ### Ruff version.
26
- rev: v0.12.4
26
+ rev: v0.15.5
27
27
  hooks:
28
28
  ### Run the linter.
29
29
  - id: ruff
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyrogram-client
3
- Version: 0.0.8.dev1
3
+ Version: 0.0.11.dev0
4
4
  Author-email: Mike Artemiev <mixartemev@gmail.com>
5
5
  Project-URL: Homepage, https://gitlab.com/XyncNet/pyro-client
6
6
  Project-URL: Repository, https://gitlab.com/XyncNet/pyro-client
@@ -1,13 +1,19 @@
1
1
  import asyncio
2
- from collections import OrderedDict
3
2
  from io import BytesIO
4
3
  from typing import Literal
5
4
 
6
5
  from pyrogram import Client
7
6
  from pyrogram.errors import AuthKeyUnregistered, Unauthorized
8
- from pyrogram.filters import chat, contact, AndFilter
7
+ from pyrogram.filters import chat, contact
9
8
  from pyrogram.handlers import MessageHandler
10
- from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, ReplyKeyboardMarkup, KeyboardButton
9
+ from pyrogram.types import (
10
+ Message,
11
+ InlineKeyboardMarkup,
12
+ InlineKeyboardButton,
13
+ ReplyKeyboardMarkup,
14
+ KeyboardButton,
15
+ ReplyKeyboardRemove,
16
+ )
11
17
  from x_auth.models import Session, App, Username
12
18
 
13
19
  from pyro_client.storage import PgStorage
@@ -42,7 +48,10 @@ class BaseClient(Client):
42
48
  self.api_id = app.id
43
49
  self.api_hash = app.hsh
44
50
  # await session.fetch_related("api")
45
- self.storage.session = session
51
+ else:
52
+ self.storage.session = session
53
+ self.api_id = session.api.id
54
+ self.api_hash = session.api.hsh
46
55
 
47
56
  async def start(self, use_qr: bool = False, except_ids: list[int] = None):
48
57
  if not self.is_connected:
@@ -78,33 +87,29 @@ class BaseClient(Client):
78
87
  else:
79
88
  return await self.send_message(uid, txt, reply_markup=ikm)
80
89
 
81
- async def wait_from(self, uid: int, topic: str, past: int = 0, timeout: int = 10) -> str | None:
90
+ def subscribe_for(self, uid: int, topic: str) -> tuple[MessageHandler, int]:
82
91
  fltr = chat(uid)
83
92
  if topic == "phone":
84
93
  fltr &= contact
85
- handler = MessageHandler(self.got_msg, fltr)
86
- # handler, g = self.add_handler(handler, 1)
87
- g = 0
88
- if g not in self.dispatcher.groups:
89
- self.dispatcher.groups[g] = []
90
- self.dispatcher.groups = OrderedDict(sorted(self.dispatcher.groups.items()))
91
- self.dispatcher.groups[g].append(handler)
92
94
  self.storage.session.state |= {uid: {"waiting_for": topic}}
93
- #
95
+ return self.add_handler(MessageHandler(self.got_msg, fltr))
96
+
97
+ async def wait_from(
98
+ self, uid: int, topic: str, hg: tuple[MessageHandler, int], past: int = 0, timeout: int = 10
99
+ ) -> str | None:
94
100
  while past < timeout:
95
101
  if txt := self.storage.session.state.get(uid, {}).pop(topic, None):
96
- # self.remove_handler(handler)
97
- self.dispatcher.groups[g].remove(handler)
98
- #
102
+ self.remove_handler(*hg)
99
103
  return txt
100
- await asyncio.sleep(1)
101
- past += 1
102
- return self.remove_handler(handler, g)
104
+ await asyncio.sleep(2)
105
+ past += 2
106
+ return self.remove_handler(*hg)
103
107
 
104
108
  async def got_msg(self, _, msg: Message):
105
109
  if tpc := self.storage.session.state.get(msg.from_user.id, {}).pop("waiting_for", None):
106
- self.storage.session.state[msg.from_user.id][tpc] = msg.contact.phone_number if tpc == "phone" else msg.text
107
-
108
- def rm_handler(self, uid: int):
109
- for gi, grp in self.dispatcher.groups.items():
110
- [self.remove_handler(h, gi) for h in grp if isinstance(h.filters, AndFilter) and uid in h.filters.base]
110
+ if tpc == "phone":
111
+ res = msg.contact.phone_number
112
+ await msg.reply("Thanks👌", reply_markup=ReplyKeyboardRemove())
113
+ else:
114
+ res = msg.text
115
+ self.storage.session.state[msg.from_user.id] = {tpc: res}
@@ -18,7 +18,8 @@ class BotClient(BaseClient):
18
18
  super().__init__(bid, bot_token=bt or None)
19
19
 
20
20
  async def wait_auth_from(self, uid: int, topic: AuthTopic, past: int = 0, timeout: int = 60) -> str:
21
- return await super().wait_from(uid, topic, past, timeout)
21
+ hg = self.subscribe_for(uid, topic)
22
+ return await super().wait_from(uid, topic, hg, past, timeout)
22
23
 
23
24
 
24
25
  async def main():
@@ -1,5 +1,9 @@
1
+ import logging
1
2
  from io import BytesIO
3
+ from x_model import init_db
4
+ from pyro_client.loader import TORM
2
5
 
6
+ from aiohttp import ClientSession
3
7
  from pyrogram.raw.functions.messages import UploadMedia
4
8
  from pyrogram.raw.functions.upload import GetFile
5
9
  from pyrogram.raw.types import (
@@ -13,6 +17,8 @@ from pyrogram.raw.types import (
13
17
  )
14
18
  from pyrogram.raw.types.upload import File
15
19
  from pyrogram.types import Message
20
+ from xync_schema import models
21
+ from xync_schema.enums import FileType
16
22
 
17
23
  from pyro_client.client.bot import BotClient
18
24
 
@@ -24,8 +30,8 @@ class FileClient(BotClient):
24
30
 
25
31
  @staticmethod
26
32
  def ref_dec(full_ref: bytes) -> tuple[int, int, bytes]:
27
- pid, ah = int.from_bytes(full_ref[:8], "big"), int.from_bytes(full_ref[8:16], "big", signed=True)
28
- return pid, ah, full_ref[16:]
33
+ pid, access_hash = int.from_bytes(full_ref[:8], "big"), int.from_bytes(full_ref[8:16], "big", signed=True)
34
+ return pid, access_hash, full_ref[16:]
29
35
 
30
36
  async def save_doc(self, byts: bytes, ctype: str) -> tuple[MessageMediaDocument, bytes]:
31
37
  in_file = await self.save_file(BytesIO(byts))
@@ -44,8 +50,8 @@ class FileClient(BotClient):
44
50
  return upp, self.ref_enc(upp.photo.id, upp.photo.access_hash, upp.photo.file_reference)
45
51
 
46
52
  async def get_doc(self, fid: bytes) -> File:
47
- pid, ah, ref = self.ref_dec(fid)
48
- loc = InputDocumentFileLocation(id=pid, access_hash=ah, file_reference=ref, thumb_size="x")
53
+ pid, access_hash, ref = self.ref_dec(fid)
54
+ loc = InputDocumentFileLocation(id=pid, access_hash=access_hash, file_reference=ref, thumb_size="x")
49
55
  return await self.invoke(GetFile(location=loc, offset=0, limit=512 * 1024))
50
56
 
51
57
  async def get_photo(self, fid: bytes, st: str) -> File:
@@ -56,3 +62,29 @@ class FileClient(BotClient):
56
62
  async def bot_got_msg(self, _, msg: Message):
57
63
  if state := self.storage.session.state.pop("bot", None):
58
64
  self.storage.session.state[state] = msg.text
65
+
66
+
67
+ async def main():
68
+ cn = await init_db(TORM)
69
+
70
+ logging.basicConfig(level=logging.INFO)
71
+
72
+ bc: FileClient = FileClient(6806432376)
73
+ # bc1: BotClient = BotClient(TOKEN)
74
+ await bc.start()
75
+ ss = ClientSession()
76
+ url = "https://xync.net/images/logo.png"
77
+ if (resp := await ss.get(url)).ok:
78
+ byts = await resp.read()
79
+ upf, ref = await bc.save_doc(byts, resp.content_type)
80
+ typ = FileType[resp.content_type.split("/")[-1].split("+")[0]]
81
+ file, _ = await models.File.update_or_create({"ref": ref, "size": len(byts), "typ": typ}, name=url, using_db=cn)
82
+ return file
83
+ # await bc1.start()
84
+ return await bc.stop()
85
+
86
+
87
+ if __name__ == "__main__":
88
+ from asyncio import run
89
+
90
+ run(main())
@@ -98,7 +98,7 @@ class UserClient(BaseClient):
98
98
  user = await Username[self.storage.session.id]
99
99
  if not (user.phone and (phone := str(user.phone))):
100
100
  phone = await self.ask_for("phone", "Phone plz")
101
- user.phone = phone
101
+ user.phone = phone and int(phone[1:] if phone.startswith("+") else phone)
102
102
  await user.save()
103
103
  self.phone_number = phone
104
104
  if (dc := self.get_dc()) != 2:
@@ -175,11 +175,14 @@ async def main():
175
175
  # await models.Proxy.load_list(WSToken)
176
176
  # session = await models.Session.filter(is_bot__isnull=True).order_by("-date").prefetch_related("proxy").first()
177
177
  bc: BotClient = BotClient(6806432376)
178
- uc: UserClient = UserClient(7314099964, bc)
178
+ uc: UserClient = UserClient(193017646, bc)
179
179
  # try:
180
180
  await uc.start()
181
181
  # b = await uc.resolve_peer('xyncnetbot')
182
182
  await uc.send("/start", bc.me.username)
183
+
184
+ hg = uc.subscribe_for(1038938370, "code")
185
+ await uc.wait_from(1038938370, "code", hg)
183
186
  # except Exception as e:
184
187
  # print(e.MESSAGE)
185
188
  # await uc.send(e.MESSAGE)
@@ -14,6 +14,8 @@ def get_input_peer(peer_id: int, access_hash: int, peer_type: PeerType):
14
14
  return raw.types.InputPeerChat(chat_id=-peer_id)
15
15
  if peer_type in [PeerType.channel, PeerType.supergroup]:
16
16
  return raw.types.InputPeerChannel(channel_id=utils.get_channel_id(peer_id), access_hash=access_hash)
17
+ if peer_type in [PeerType.forum]:
18
+ return raw.types.InputPeerChannel(channel_id=utils.get_channel_id(peer_id), access_hash=access_hash)
17
19
  raise ValueError(f"Invalid peer type: {peer_type.name}")
18
20
 
19
21
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyrogram-client
3
- Version: 0.0.8.dev1
3
+ Version: 0.0.11.dev0
4
4
  Author-email: Mike Artemiev <mixartemev@gmail.com>
5
5
  Project-URL: Homepage, https://gitlab.com/XyncNet/pyro-client
6
6
  Project-URL: Repository, https://gitlab.com/XyncNet/pyro-client