xn-auth 0.2.34.dev1__tar.gz → 0.2.36__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.34.dev1
3
+ Version: 0.2.36
4
4
  Summary: Auth adapter for XN-Api framework
5
5
  Author-email: Artemiev <mixartemev@gmail.com>
6
6
  License: MIT
@@ -1,10 +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
7
5
  from pyrogram.enums.client_platform import ClientPlatform
6
+ from pyrogram.types import User as TgUser
8
7
  from tortoise.fields import (
9
8
  BigIntField,
10
9
  BooleanField,
@@ -15,6 +14,7 @@ from tortoise.fields import (
15
14
  IntField,
16
15
  BinaryField,
17
16
  OneToOneRelation,
17
+ OneToOneNullableRelation,
18
18
  OneToOneField,
19
19
  SmallIntField,
20
20
  BackwardOneToOneRelation,
@@ -41,7 +41,7 @@ class Username(TortModel):
41
41
 
42
42
  user: BackwardOneToOneRelation["User"]
43
43
  peers: BackwardFKRelation["Peer"]
44
- sessions: BackwardFKRelation["Session"]
44
+ session: BackwardOneToOneRelation["Session"]
45
45
 
46
46
 
47
47
  class User(Model):
@@ -59,9 +59,15 @@ class User(Model):
59
59
  return AuthUser.model_validate(self, from_attributes=True)
60
60
 
61
61
  @classmethod
62
- 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)
63
64
  user = cls.validate(
64
- {**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
+ }
65
71
  )
66
72
  if blocked is not None:
67
73
  user.blocked = blocked
@@ -75,6 +81,13 @@ class User(Model):
75
81
  # abstract = True
76
82
 
77
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
+
78
91
  class Country(Model):
79
92
  id = SmallIntField(True)
80
93
  code: int | None = IntField(null=True)
@@ -147,6 +160,12 @@ class Proxy(Model, TsTrait):
147
160
  reps = [convert(r, types.Replacement) for r in lst]
148
161
  return reps
149
162
 
163
+ def dict(self):
164
+ return dict(scheme="socks5", hostname=self.host, port=self.port, username=self.username, password=self.password)
165
+
166
+ def str(self):
167
+ return f"http://{self.username}:{self.password}@{self.host}:{self.port}"
168
+
150
169
 
151
170
  class Dc(TortModel):
152
171
  id: int = SmallIntField(True)
@@ -174,13 +193,13 @@ class App(Model):
174
193
  fcm: ForeignKeyNullableRelation[Fcm] = ForeignKeyField("models.Fcm", "apps", null=True)
175
194
  fcm_id: int
176
195
  platform: ClientPlatform = CharEnumFieldInstance(ClientPlatform)
177
- owner: OneToOneRelation["User"] = OneToOneField("models.User", "app")
196
+ owner: OneToOneNullableRelation["User"] = OneToOneField("models.User", "app", null=True)
178
197
 
179
198
  sessions: BackwardFKRelation["Session"]
180
199
 
181
200
 
182
201
  class Session(TortModel):
183
- id = CharField(85, primary_key=True)
202
+ id = BigIntField(True)
184
203
  api: ForeignKeyRelation[App] = ForeignKeyField("models.App", "sessions")
185
204
  api_id: int
186
205
  dc: ForeignKeyRelation[Dc] = ForeignKeyField("models.Dc", "sessions", default=2)
@@ -188,7 +207,7 @@ class Session(TortModel):
188
207
  test_mode = BooleanField(default=False)
189
208
  auth_key = BinaryField(null=True)
190
209
  date = IntField(default=0) # todo: refact to datetime?
191
- user: ForeignKeyNullableRelation[Username] = ForeignKeyField("models.Username", "sessions", null=True)
210
+ user: OneToOneNullableRelation[Username] = OneToOneField("models.Username", "session", null=True)
192
211
  user_id: int
193
212
  is_bot = CharField(42, null=True)
194
213
  state: dict = JSONField(default={})
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xn-auth
3
- Version: 0.2.34.dev1
3
+ Version: 0.2.36
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