libapitelethon 1.0__tar.gz → 2.0__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 (23) hide show
  1. {libapitelethon-1.0 → libapitelethon-2.0}/PKG-INFO +1 -1
  2. {libapitelethon-1.0 → libapitelethon-2.0}/pyproject.toml +1 -1
  3. {libapitelethon-1.0 → libapitelethon-2.0}/pyproject.toml.orig +1 -1
  4. libapitelethon-2.0/src/libapitelethon/client/__init__.py +6 -0
  5. {libapitelethon-1.0 → libapitelethon-2.0}/src/libapitelethon/client/api_telethon.py +35 -15
  6. libapitelethon-2.0/src/libapitelethon/exceptions.py +14 -0
  7. libapitelethon-2.0/src/libapitelethon/integrations/aiogram/__init__.py +6 -0
  8. libapitelethon-2.0/src/libapitelethon/integrations/aiogram/client.py +20 -0
  9. libapitelethon-2.0/src/libapitelethon/integrations/telethon/__init__.py +6 -0
  10. libapitelethon-2.0/src/libapitelethon/integrations/telethon/client.py +120 -0
  11. libapitelethon-1.0/src/libapitelethon/exceptions.py +0 -2
  12. libapitelethon-1.0/src/libapitelethon/integrations/__init__.py +0 -0
  13. {libapitelethon-1.0 → libapitelethon-2.0}/README.md +0 -0
  14. {libapitelethon-1.0 → libapitelethon-2.0}/src/libapitelethon/__init__.py +0 -0
  15. {libapitelethon-1.0/src/libapitelethon/client → libapitelethon-2.0/src/libapitelethon/integrations}/__init__.py +0 -0
  16. {libapitelethon-1.0 → libapitelethon-2.0}/src/libapitelethon/models/__init__.py +0 -0
  17. {libapitelethon-1.0 → libapitelethon-2.0}/src/libapitelethon/models/dict_user.py +0 -0
  18. {libapitelethon-1.0 → libapitelethon-2.0}/src/libapitelethon/models/dict_user_aiogram.py +0 -0
  19. {libapitelethon-1.0 → libapitelethon-2.0}/src/libapitelethon/py.typed +0 -0
  20. {libapitelethon-1.0 → libapitelethon-2.0}/src/libapitelethon/types/__init__.py +0 -0
  21. {libapitelethon-1.0 → libapitelethon-2.0}/src/libapitelethon/types/user_id.py +0 -0
  22. {libapitelethon-1.0 → libapitelethon-2.0}/src/libapitelethon/types/user_id_or_username.py +0 -0
  23. {libapitelethon-1.0 → libapitelethon-2.0}/src/libapitelethon/types/user_username.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: libapitelethon
3
- Version: 1.0
3
+ Version: 2.0
4
4
  Summary: Асинхронный клиент для https://codeberg.org/ourempirecommunity/api_telethon
5
5
  Keywords: telegram,api,async,client
6
6
  Author: ibrvtk
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "libapitelethon"
3
- version = "1.0"
3
+ version = "2.0"
4
4
  description = "Асинхронный клиент для https://codeberg.org/ourempirecommunity/api_telethon"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.14"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "libapitelethon"
3
- version = "1.0"
3
+ version = "2.0"
4
4
  description = "Асинхронный клиент для https://codeberg.org/ourempirecommunity/api_telethon"
5
5
  readme = "README.md"
6
6
  license = {text = "GPL-3.0-or-later"}
@@ -0,0 +1,6 @@
1
+ from .api_telethon import ApiTelethonBase
2
+
3
+
4
+ __all__: list[str] = (
5
+ 'ApiTelethonBase',
6
+ )
@@ -7,10 +7,10 @@ if TYPE_CHECKING:
7
7
 
8
8
  from aiohttp import ClientSession
9
9
 
10
- from ..exceptions import ApiTelethonException
10
+ from ..exceptions import ApiTelethonHttpError
11
11
 
12
12
 
13
- class ApiTelethon:
13
+ class ApiTelethonBase:
14
14
  def __init__(
15
15
  self,
16
16
  protocol: Literal['http', 'https'] = 'http',
@@ -31,7 +31,7 @@ class ApiTelethon:
31
31
  else:
32
32
  error_message = data['detail'][0]['msg']
33
33
 
34
- raise ApiTelethonException(error_message)
34
+ raise ApiTelethonHttpError(error_message)
35
35
 
36
36
  @staticmethod
37
37
  def _return_data(data: dict) -> dict:
@@ -50,28 +50,48 @@ class ApiTelethon:
50
50
  return self._return_data(data)
51
51
 
52
52
 
53
- async def ping(self) -> bool:
53
+ async def _ping(self) -> bool:
54
54
  url: str = self._url
55
55
  return await self._request(url)
56
56
 
57
-
58
- async def get_user(self, uid: UserIdOrUsername) -> DictUser:
57
+ async def _get_user(self, uid: UserIdOrUsername) -> DictUser:
59
58
  url: str = self._url_user + str(uid)
60
59
  return await self._request(url)
61
60
 
62
- async def get_user_aiogram(self, uid: UserIdOrUsername) -> DictUserAiogram:
63
- url: str = self._url_user + str(uid) + '/aiogram'
61
+ async def _get_user_aiogram(self, uid: UserIdOrUsername) -> DictUserAiogram:
62
+ url: str = self._url_user + str(uid) + '/' + 'aiogram'
64
63
  return await self._request(url)
65
64
 
65
+ async def _get_user_id(self, username: UserUsername) -> UserId:
66
+ url: str = self._url_user + username + '/' + 'id'
67
+ return await self._request(url)
66
68
 
67
- async def get_user_id(self, username: UserUsername) -> UserId:
68
- url: str = self._url_user + username + '/id'
69
+ async def _get_user_username(self, id: UserId) -> UserUsername:
70
+ url: str = self._url_user + str(id) + '/' + 'username'
69
71
  return await self._request(url)
70
72
 
71
- async def get_user_username(self, id: UserId) -> UserUsername:
72
- url: str = self._url_user + str(id) + '/username'
73
+ async def _get_user_usernames(self, uid: UserIdOrUsername) -> list[UserUsername]:
74
+ url: str = self._url_user + str(uid) + '/' + 'usernames'
73
75
  return await self._request(url)
74
76
 
75
- async def get_user_usernames(self, uid: UserIdOrUsername) -> list[UserUsername]:
76
- url: str = self._url_user + str(uid) + '/usernames'
77
- return await self._request(url)
77
+
78
+ async def ping(self):
79
+ return await self._ping()
80
+
81
+ async def get_user(self, uid: UserIdOrUsername):
82
+ return await self._get_user(uid)
83
+
84
+ async def get_user_aiogram(self, uid: UserIdOrUsername):
85
+ return await self._get_user_aiogram(uid)
86
+
87
+ async def get_user_id(self, username: UserUsername):
88
+ return await self._get_user_id(username)
89
+
90
+ async def get_user_username(self, id: UserId):
91
+ return await self._get_user_username(id)
92
+
93
+ async def get_user_usernames(self, uid: UserIdOrUsername):
94
+ return await self._get_user_usernames(uid)
95
+
96
+ class ApiTelethon(ApiTelethonBase):
97
+ pass
@@ -0,0 +1,14 @@
1
+ class LibApiTelethonError(Exception):
2
+ """Base exception for libapitelethon."""
3
+
4
+
5
+ class ApiTelethonHttpError(LibApiTelethonError):
6
+ """Raised when the API returns an error."""
7
+
8
+
9
+ class IntegrationNotInstalledError(LibApiTelethonError):
10
+ """Raised when the optional integration dependency is missing."""
11
+
12
+
13
+ # class UserNotFoundError(ApiTelethonHttpError):
14
+ # """User not found."""
@@ -0,0 +1,6 @@
1
+ from .client import ApiTelethonAiogram
2
+
3
+
4
+ __all__: list[str] = (
5
+ 'ApiTelethonAiogram',
6
+ )
@@ -0,0 +1,20 @@
1
+ from __future__ import annotations
2
+ from typing import TYPE_CHECKING
3
+
4
+ if TYPE_CHECKING:
5
+ from ...types import UserIdOrUsername
6
+
7
+ from ...exceptions import IntegrationNotInstalledError
8
+ from ...client import ApiTelethonBase
9
+
10
+ try:
11
+ from aiogram.types import User
12
+ except ImportError as exc:
13
+ raise IntegrationNotInstalledError(
14
+ "Для интеграции c aiogram установите: pip install 'libapitelethon[aiogram]'"
15
+ ) from exc
16
+
17
+
18
+ class ApiTelethonAiogram(ApiTelethonBase):
19
+ async def get_user_aiogram(self, uid: UserIdOrUsername) -> User:
20
+ return User(**await self._get_user_aiogram(uid))
@@ -0,0 +1,6 @@
1
+ from .client import ApiTelethonTelethon
2
+
3
+
4
+ __all__: list[str] = (
5
+ 'ApiTelethonTelethon',
6
+ )
@@ -0,0 +1,120 @@
1
+ from __future__ import annotations
2
+ from typing import TYPE_CHECKING
3
+ from datetime import datetime
4
+
5
+ if TYPE_CHECKING:
6
+ from ...types import UserIdOrUsername
7
+ from ...models import DictUser
8
+
9
+ from ...client import ApiTelethonBase
10
+ from ...exceptions import IntegrationNotInstalledError
11
+
12
+ try:
13
+ from telethon.types import User
14
+ from telethon.types import (
15
+ UserProfilePhoto,
16
+ UserStatusOnline, UserStatusOffline, UserStatusRecently, UserStatusEmpty,
17
+ RestrictionReason,
18
+ EmojiStatus,
19
+ Username,
20
+ PeerColor
21
+ )
22
+ except ImportError as exc:
23
+ raise IntegrationNotInstalledError(
24
+ "Для интеграции c telethon установите: pip install 'libapitelethon[telethon]'"
25
+ ) from exc
26
+
27
+
28
+ class ApiTelethonTelethon(ApiTelethonBase):
29
+ @staticmethod
30
+ def _retranslate_data_to_user(data: DictUser) -> User:
31
+ photo: UserProfilePhoto | None = None
32
+ status: UserStatusOnline | UserStatusOffline | UserStatusRecently | UserStatusEmpty | None = None
33
+ restriction_reason: RestrictionReason | None = None
34
+ emoji_status: EmojiStatus | None = None
35
+ usernames: list[Username] | None = None
36
+ color: PeerColor | None = None
37
+ profile_color: PeerColor | None = None
38
+
39
+ if data.get('photo'): photo = UserProfilePhoto(data['photo'], 0)
40
+
41
+ status_data = data.get('status')
42
+ if status_data:
43
+ status_type = status_data.get('type')
44
+ if status_type == 'online':
45
+ status = UserStatusOnline(datetime.fromtimestamp(status_data['expires']))
46
+ elif status_type == 'offline':
47
+ status = UserStatusOffline(datetime.fromtimestamp(status_data['was_online']))
48
+ elif status_type == 'hidden':
49
+ by_me = status_data.get('by_me', False)
50
+ # Точно неизвестно, какой из трёх типов был, поэтому ставится Recently
51
+ status = UserStatusRecently(by_me)
52
+ elif status_type == 'empty':
53
+ status = UserStatusEmpty()
54
+
55
+ if data.get('restriction_reason'): restriction_reason = [RestrictionReason('all', r, '') for r in data['restriction_reason']]
56
+
57
+ if data.get('emoji_status'): emoji_status = EmojiStatus(data['emoji_status'])
58
+
59
+ if data.get('usernames'): usernames = [Username(u) for u in data['usernames']]
60
+
61
+ if data.get('color'): color = PeerColor(data['color'])
62
+
63
+ if data.get('profile_color'): profile_color = PeerColor(data['profile_color'])
64
+
65
+ return User(
66
+ id=data['id'],
67
+ is_self=data.get('is_self'),
68
+ contact=data.get('contact'),
69
+ mutual_contact=data.get('mutual_contact'),
70
+ deleted=data.get('deleted'),
71
+ bot=data.get('bot'),
72
+ bot_chat_history=data.get('bot_chat_history'),
73
+ bot_nochats=data.get('bot_nochats'),
74
+ verified=data.get('verified'),
75
+ restricted=data.get('restricted'),
76
+ min=data.get('min'),
77
+ bot_inline_geo=data.get('bot_inline_geo'),
78
+ support=data.get('support'),
79
+ scam=data.get('scam'),
80
+ apply_min_photo=data.get('apply_min_photo'),
81
+ fake=data.get('fake'),
82
+ bot_attach_menu=data.get('bot_attach_menu'),
83
+ premium=data.get('premium'),
84
+ attach_menu_enabled=data.get('attach_menu_enabled'),
85
+ bot_can_edit=data.get('bot_can_edit'),
86
+ close_friend=data.get('close_friend'),
87
+ stories_hidden=data.get('stories_hidden'),
88
+ stories_unavailable=data.get('stories_unavailable'),
89
+ contact_require_premium=data.get('contact_require_premium'),
90
+ bot_business=data.get('bot_business'),
91
+ bot_has_main_app=data.get('bot_has_main_app'),
92
+ bot_forum_view=data.get('bot_forum_view'),
93
+ bot_forum_can_manage_topics=data.get('bot_forum_can_manage_topics'),
94
+ bot_can_manage_bots=data.get('bot_can_manage_bots'),
95
+ bot_guestchat=data.get('bot_guestchat'),
96
+ bot_guard=data.get('bot_guard'),
97
+ access_hash=data.get('access_hash'),
98
+ first_name=data.get('first_name'),
99
+ last_name=data.get('last_name'),
100
+ username=data.get('username'),
101
+ phone=data.get('phone'),
102
+ photo=photo,
103
+ status=status,
104
+ bot_info_version=data.get('bot_info_version'),
105
+ restriction_reason=restriction_reason,
106
+ bot_inline_placeholder=data.get('bot_inline_placeholder'),
107
+ lang_code=data.get('lang_code'),
108
+ emoji_status=emoji_status,
109
+ usernames=usernames,
110
+ stories_max_id=None,
111
+ color=color,
112
+ profile_color=profile_color,
113
+ bot_active_users=data.get('bot_active_users'),
114
+ bot_verification_icon=data.get('bot_verification_icon'),
115
+ send_paid_messages_stars=data.get('send_paid_messages_stars'),
116
+ linked_community_id=data.get('linked_community_id'),
117
+ )
118
+
119
+ async def get_user(self, uid: UserIdOrUsername) -> User:
120
+ return self._retranslate_data_to_user(await self._get_user(uid))
@@ -1,2 +0,0 @@
1
- class ApiTelethonException(Exception):
2
- pass
File without changes