pyrogram-client 0.0.3__tar.gz → 0.0.5__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.3/pyrogram_client.egg-info → pyrogram_client-0.0.5}/PKG-INFO +1 -1
  2. {pyrogram_client-0.0.3 → pyrogram_client-0.0.5}/pyro_client/client/base.py +3 -1
  3. {pyrogram_client-0.0.3 → pyrogram_client-0.0.5}/pyro_client/client/user.py +2 -2
  4. {pyrogram_client-0.0.3 → pyrogram_client-0.0.5}/pyro_client/storage.py +16 -16
  5. {pyrogram_client-0.0.3 → pyrogram_client-0.0.5/pyrogram_client.egg-info}/PKG-INFO +1 -1
  6. {pyrogram_client-0.0.3 → pyrogram_client-0.0.5}/.env.sample +0 -0
  7. {pyrogram_client-0.0.3 → pyrogram_client-0.0.5}/.gitignore +0 -0
  8. {pyrogram_client-0.0.3 → pyrogram_client-0.0.5}/.pre-commit-config.yaml +0 -0
  9. {pyrogram_client-0.0.3 → pyrogram_client-0.0.5}/makefile +0 -0
  10. {pyrogram_client-0.0.3 → pyrogram_client-0.0.5}/pyproject.toml +0 -0
  11. {pyrogram_client-0.0.3 → pyrogram_client-0.0.5}/pyro_client/client/bot.py +0 -0
  12. {pyrogram_client-0.0.3 → pyrogram_client-0.0.5}/pyro_client/client/dc.json +0 -0
  13. {pyrogram_client-0.0.3 → pyrogram_client-0.0.5}/pyro_client/client/file.py +0 -0
  14. {pyrogram_client-0.0.3 → pyrogram_client-0.0.5}/pyro_client/client/single.py +0 -0
  15. {pyrogram_client-0.0.3 → pyrogram_client-0.0.5}/pyro_client/loader.py +0 -0
  16. {pyrogram_client-0.0.3 → pyrogram_client-0.0.5}/pyrogram_client.egg-info/SOURCES.txt +0 -0
  17. {pyrogram_client-0.0.3 → pyrogram_client-0.0.5}/pyrogram_client.egg-info/dependency_links.txt +0 -0
  18. {pyrogram_client-0.0.3 → pyrogram_client-0.0.5}/pyrogram_client.egg-info/requires.txt +0 -0
  19. {pyrogram_client-0.0.3 → pyrogram_client-0.0.5}/pyrogram_client.egg-info/top_level.txt +0 -0
  20. {pyrogram_client-0.0.3 → pyrogram_client-0.0.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyrogram-client
3
- Version: 0.0.3
3
+ Version: 0.0.5
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
@@ -25,7 +25,9 @@ class BaseClient(Client, metaclass=SingleMeta):
25
25
  storage: PgStorage
26
26
 
27
27
  def __init__(self, name: str, api_id, api_hash, *args, **kwargs):
28
- super().__init__(name, api_id=api_id, api_hash=api_hash, *args, storage_engine=PgStorage(name), **kwargs)
28
+ super().__init__(
29
+ name, api_id=api_id, api_hash=api_hash, *args, storage_engine=PgStorage(name), workers=1, **kwargs
30
+ )
29
31
 
30
32
  async def send(
31
33
  self,
@@ -12,7 +12,7 @@ from x_auth.models import Session, Username, Proxy
12
12
 
13
13
  from pyro_client.client.base import BaseClient, AuthTopic
14
14
  from pyro_client.client.bot import BotClient
15
- from pyro_client.loader import WSToken
15
+ from pyro_client.loader import WSToken, TOKEN
16
16
 
17
17
  vers: dict[ClientPlatform, str] = {
18
18
  ClientPlatform.IOS: "18.5",
@@ -181,7 +181,7 @@ async def main():
181
181
 
182
182
  await models.Proxy.load_list(WSToken)
183
183
  # session = await models.Session.filter(is_bot__isnull=True).order_by("-date").prefetch_related("proxy").first()
184
- bc: BotClient = await BotClient("xyncnetbot")
184
+ bc: BotClient = await BotClient(TOKEN)
185
185
  uc: UserClient = await UserClient(5547330178, bc)
186
186
  # try:
187
187
  await uc.start()
@@ -23,6 +23,7 @@ class PgStorage(Storage):
23
23
  VERSION = 1
24
24
  USERNAME_TTL = 8 * 60 * 60
25
25
  session: Session
26
+
26
27
  # me_id: int
27
28
 
28
29
  async def open(self):
@@ -39,10 +40,10 @@ class PgStorage(Storage):
39
40
 
40
41
  async def update_peers(self, peers: list[tuple[int, int, str, str]]):
41
42
  for peer in peers:
42
- uid, ac_hsh, typ, phn = peer
43
- un, _ = await Username.get_or_create(phn and {"phone": phn}, id=uid)
43
+ uid, ac_hsh, typ, phone = peer
44
+ un, _ = await Username.update_or_create(phone and {"phone": phone}, id=uid)
44
45
  await Peer.update_or_create(
45
- {"username": un, "type": typ, "phone_number": phn}, session_id=self.name, id=ac_hsh
46
+ {"username": un, "type": typ, "phone_number": phone}, session_id=self.name, id=ac_hsh
46
47
  )
47
48
 
48
49
  async def update_usernames(self, usernames: list[tuple[int, list[str]]]):
@@ -50,17 +51,17 @@ class PgStorage(Storage):
50
51
  for username in user_list:
51
52
  await Username.update_or_create({"username": username}, id=telegram_id)
52
53
 
53
- async def get_peer_by_id(self, peer_id_or_username: int | str):
54
- attr = "id" if isinstance(peer_id_or_username, int) else "username"
55
- if not (peer := await Peer.get_or_none(session_id=self.name, **{"username__" + attr: peer_id_or_username})):
56
- raise KeyError(f"User not found: {peer_id_or_username}")
54
+ async def get_peer_by_id(self, uin: int | str):
55
+ peer = await (
56
+ Peer.get(session_id=self.name, username_id=uin) if isinstance(uin, int) else self.get_peer_by_username(uin)
57
+ )
57
58
  if peer.last_update_on:
58
59
  if abs(time.time() - peer.last_update_on.timestamp()) > self.USERNAME_TTL:
59
- raise KeyError(f"Username expired: {peer_id_or_username}")
60
+ raise KeyError(f"Username expired: {uin}")
60
61
  return get_input_peer(peer.username_id, peer.id, peer.type)
61
62
 
62
63
  async def get_peer_by_username(self, username: str):
63
- return await self.get_peer_by_id(username)
64
+ return await Peer.get(session_id=self.name, username__username=username)
64
65
 
65
66
  async def update_state(self, value: tuple[int, int, int, int, int] = object):
66
67
  if value is None:
@@ -74,12 +75,9 @@ class PgStorage(Storage):
74
75
  )
75
76
 
76
77
  async def get_peer_by_phone_number(self, phone_number: str):
77
- if not (
78
- peer := await Peer.filter(session_id=self.name, phone_number=phone_number).values_list(
79
- "id", "access_hash", "type"
80
- )
81
- ):
82
- raise KeyError(f"Phone number not found: {phone_number}")
78
+ attrs = "id", "access_hash", "type"
79
+ if not (peer := await Peer.get_or_none(session_id=self.name, phone_number=phone_number).values_list(*attrs)):
80
+ peer = await Peer.get(session_id=self.name, username__phone=phone_number).values_list(*attrs)
83
81
  return get_input_peer(*peer)
84
82
 
85
83
  async def _get(self, attr: str):
@@ -119,7 +117,9 @@ class PgStorage(Storage):
119
117
  return await self._accessor("user_id", value)
120
118
 
121
119
  async def is_bot(self, value: bool = object):
122
- return await self._accessor("is_bot", value)
120
+ if value is not object:
121
+ value = self.session.is_bot if value else None # dirty
122
+ return bool(await self._accessor("is_bot", value))
123
123
 
124
124
  @staticmethod
125
125
  async def version(value: int = object):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyrogram-client
3
- Version: 0.0.3
3
+ Version: 0.0.5
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