pyrogram-client 0.0.9__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.9 → pyrogram_client-0.0.11.dev0}/.pre-commit-config.yaml +1 -1
  2. {pyrogram_client-0.0.9/pyrogram_client.egg-info → pyrogram_client-0.0.11.dev0}/PKG-INFO +1 -1
  3. {pyrogram_client-0.0.9 → pyrogram_client-0.0.11.dev0}/pyro_client/client/base.py +18 -5
  4. {pyrogram_client-0.0.9 → pyrogram_client-0.0.11.dev0}/pyro_client/client/bot.py +2 -1
  5. {pyrogram_client-0.0.9 → pyrogram_client-0.0.11.dev0}/pyro_client/client/file.py +36 -4
  6. {pyrogram_client-0.0.9 → pyrogram_client-0.0.11.dev0}/pyro_client/client/user.py +1 -1
  7. {pyrogram_client-0.0.9 → pyrogram_client-0.0.11.dev0/pyrogram_client.egg-info}/PKG-INFO +1 -1
  8. {pyrogram_client-0.0.9 → pyrogram_client-0.0.11.dev0}/.env.sample +0 -0
  9. {pyrogram_client-0.0.9 → pyrogram_client-0.0.11.dev0}/.gitignore +0 -0
  10. {pyrogram_client-0.0.9 → pyrogram_client-0.0.11.dev0}/makefile +0 -0
  11. {pyrogram_client-0.0.9 → pyrogram_client-0.0.11.dev0}/pyproject.toml +0 -0
  12. {pyrogram_client-0.0.9 → pyrogram_client-0.0.11.dev0}/pyro_client/client/dc.json +0 -0
  13. {pyrogram_client-0.0.9 → pyrogram_client-0.0.11.dev0}/pyro_client/client/filler.py +0 -0
  14. {pyrogram_client-0.0.9 → pyrogram_client-0.0.11.dev0}/pyro_client/loader.py +0 -0
  15. {pyrogram_client-0.0.9 → pyrogram_client-0.0.11.dev0}/pyro_client/storage.py +0 -0
  16. {pyrogram_client-0.0.9 → pyrogram_client-0.0.11.dev0}/pyrogram_client.egg-info/SOURCES.txt +0 -0
  17. {pyrogram_client-0.0.9 → pyrogram_client-0.0.11.dev0}/pyrogram_client.egg-info/dependency_links.txt +0 -0
  18. {pyrogram_client-0.0.9 → pyrogram_client-0.0.11.dev0}/pyrogram_client.egg-info/requires.txt +0 -0
  19. {pyrogram_client-0.0.9 → pyrogram_client-0.0.11.dev0}/pyrogram_client.egg-info/top_level.txt +0 -0
  20. {pyrogram_client-0.0.9 → 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.9
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
@@ -6,7 +6,14 @@ from pyrogram import Client
6
6
  from pyrogram.errors import AuthKeyUnregistered, Unauthorized
7
7
  from pyrogram.filters import chat, contact
8
8
  from pyrogram.handlers import MessageHandler
9
- 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
+ )
10
17
  from x_auth.models import Session, App, Username
11
18
 
12
19
  from pyro_client.storage import PgStorage
@@ -41,7 +48,10 @@ class BaseClient(Client):
41
48
  self.api_id = app.id
42
49
  self.api_hash = app.hsh
43
50
  # await session.fetch_related("api")
44
- 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
45
55
 
46
56
  async def start(self, use_qr: bool = False, except_ids: list[int] = None):
47
57
  if not self.is_connected:
@@ -97,6 +107,9 @@ class BaseClient(Client):
97
107
 
98
108
  async def got_msg(self, _, msg: Message):
99
109
  if tpc := self.storage.session.state.get(msg.from_user.id, {}).pop("waiting_for", None):
100
- self.storage.session.state[msg.from_user.id] = {
101
- tpc: msg.contact.phone_number if tpc == "phone" else msg.text
102
- }
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:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyrogram-client
3
- Version: 0.0.9
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