xn-auth 0.2.33__tar.gz → 0.2.34__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xn-auth
3
- Version: 0.2.33
3
+ Version: 0.2.34
4
4
  Summary: Auth adapter for XN-Api framework
5
5
  Author-email: Artemiev <mixartemev@gmail.com>
6
6
  License: MIT
@@ -1,9 +1,9 @@
1
1
  from datetime import datetime
2
2
 
3
- from aiogram.types import User as TgUser
4
- from aiogram.utils.web_app import WebAppUser
5
3
  from aiohttp import ClientSession
6
4
  from msgspec import convert
5
+ from pyrogram.enums.client_platform import ClientPlatform
6
+ from pyrogram.types import User as TgUser
7
7
  from tortoise.fields import (
8
8
  BigIntField,
9
9
  BooleanField,
@@ -14,6 +14,7 @@ from tortoise.fields import (
14
14
  IntField,
15
15
  BinaryField,
16
16
  OneToOneRelation,
17
+ OneToOneNullableRelation,
17
18
  OneToOneField,
18
19
  SmallIntField,
19
20
  BackwardOneToOneRelation,
@@ -21,6 +22,8 @@ from tortoise.fields import (
21
22
  ForeignKeyNullableRelation,
22
23
  JSONField,
23
24
  )
25
+ from tortoise.fields.data import CharEnumFieldInstance
26
+
24
27
  from x_auth import types
25
28
  from x_model.field import DatetimeSecField
26
29
  from x_model.models import Model, TsTrait
@@ -38,7 +41,7 @@ class Username(TortModel):
38
41
 
39
42
  user: BackwardOneToOneRelation["User"]
40
43
  peers: BackwardFKRelation["Peer"]
41
- sessions: BackwardFKRelation["Session"]
44
+ session: BackwardOneToOneRelation["Session"]
42
45
 
43
46
 
44
47
  class User(Model):
@@ -56,9 +59,15 @@ class User(Model):
56
59
  return AuthUser.model_validate(self, from_attributes=True)
57
60
 
58
61
  @classmethod
59
- async def tg2in(cls, u: TgUser | WebAppUser, blocked: bool = None) -> BaseUpd:
62
+ async def tg2in(cls, u: TgUser, blocked: bool = None) -> BaseUpd:
63
+ un, _ = await cls._meta.fields_map["username"].related_model.update_or_create({"username": u.username}, id=u.id)
60
64
  user = cls.validate(
61
- {**u.model_dump(), "username": u.username or u.id, "lang": u.language_code and Lang[u.language_code]}
65
+ {
66
+ "first_name": u.first_name,
67
+ "last_name": u.last_name,
68
+ "username_id": un.id,
69
+ "lang": u.language_code and Lang[u.language_code],
70
+ }
62
71
  )
63
72
  if blocked is not None:
64
73
  user.blocked = blocked
@@ -72,6 +81,13 @@ class User(Model):
72
81
  # abstract = True
73
82
 
74
83
 
84
+ # @pre_save(User)
85
+ # async def username(_meta, user: User, _db, _updated: dict) -> None:
86
+ # if user.username_id:
87
+ # return
88
+ # user.username = await Username.create(name=user.username)
89
+
90
+
75
91
  class Country(Model):
76
92
  id = SmallIntField(True)
77
93
  code: int | None = IntField(null=True)
@@ -144,6 +160,9 @@ class Proxy(Model, TsTrait):
144
160
  reps = [convert(r, types.Replacement) for r in lst]
145
161
  return reps
146
162
 
163
+ def dict(self):
164
+ return dict(scheme="socks5", hostname=self.host, port=self.port, username=self.username, password=self.password)
165
+
147
166
 
148
167
  class Dc(TortModel):
149
168
  id: int = SmallIntField(True)
@@ -151,6 +170,7 @@ class Dc(TortModel):
151
170
  pub = CharField(495, null=True)
152
171
 
153
172
  apps: BackwardFKRelation["App"]
173
+ sessions: BackwardFKRelation["App"]
154
174
 
155
175
 
156
176
  class Fcm(TortModel):
@@ -169,7 +189,8 @@ class App(Model):
169
189
  ver = CharField(18, default="0.0.1")
170
190
  fcm: ForeignKeyNullableRelation[Fcm] = ForeignKeyField("models.Fcm", "apps", null=True)
171
191
  fcm_id: int
172
- owner: OneToOneRelation["User"] = OneToOneField("models.User", "app")
192
+ platform: ClientPlatform = CharEnumFieldInstance(ClientPlatform)
193
+ owner: OneToOneNullableRelation["User"] = OneToOneField("models.User", "app", null=True)
173
194
 
174
195
  sessions: BackwardFKRelation["Session"]
175
196
 
@@ -178,10 +199,12 @@ class Session(TortModel):
178
199
  id = CharField(85, primary_key=True)
179
200
  api: ForeignKeyRelation[App] = ForeignKeyField("models.App", "sessions")
180
201
  api_id: int
202
+ dc: ForeignKeyRelation[Dc] = ForeignKeyField("models.Dc", "sessions", default=2)
203
+ dc_id: int
181
204
  test_mode = BooleanField(default=False)
182
205
  auth_key = BinaryField(null=True)
183
206
  date = IntField(default=0) # todo: refact to datetime?
184
- user: ForeignKeyNullableRelation[Username] = ForeignKeyField("models.Username", "sessions", null=True)
207
+ user: OneToOneNullableRelation[Username] = OneToOneField("models.Username", "session", null=True)
185
208
  user_id: int
186
209
  is_bot = CharField(42, null=True)
187
210
  state: dict = JSONField(default={})
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xn-auth
3
- Version: 0.2.33
3
+ Version: 0.2.34
4
4
  Summary: Auth adapter for XN-Api framework
5
5
  Author-email: Artemiev <mixartemev@gmail.com>
6
6
  License: MIT
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes