zarpa 0.1.0__py3-none-any.whl
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.
- zarpa/__init__.py +58 -0
- zarpa/api/_async/__init__.py +5 -0
- zarpa/api/_async/altteam.py +42 -0
- zarpa/api/_async/auth.py +74 -0
- zarpa/api/_async/chats.py +129 -0
- zarpa/api/_async/communities.py +60 -0
- zarpa/api/_async/sub/__init__.py +6 -0
- zarpa/api/_async/sub/adm.py +403 -0
- zarpa/api/_async/sub/altacm.py +73 -0
- zarpa/api/_async/sub/blogs.py +99 -0
- zarpa/api/_async/sub/chats.py +273 -0
- zarpa/api/_async/sub/community.py +64 -0
- zarpa/api/_async/sub/users.py +144 -0
- zarpa/api/_async/users.py +37 -0
- zarpa/api/_sync/__init__.py +4 -0
- zarpa/api/_sync/auth.py +76 -0
- zarpa/api/_sync/chats.py +78 -0
- zarpa/api/_sync/sub/__init__.py +1 -0
- zarpa/api/_sync/sub/chats.py +44 -0
- zarpa/api/base.py +68 -0
- zarpa/clients/__init__.py +0 -0
- zarpa/clients/_async/__init__.py +0 -0
- zarpa/clients/_async/client.py +114 -0
- zarpa/clients/_async/sub_client.py +26 -0
- zarpa/clients/client.py +105 -0
- zarpa/clients/sub_client.py +22 -0
- zarpa/objects/__init__.py +0 -0
- zarpa/objects/args/__init__.py +35 -0
- zarpa/objects/args/administrators_rank.py +24 -0
- zarpa/objects/args/chat_types.py +8 -0
- zarpa/objects/args/client_types.py +13 -0
- zarpa/objects/args/community_join_types.py +15 -0
- zarpa/objects/args/community_modules.py +50 -0
- zarpa/objects/args/embed_types.py +29 -0
- zarpa/objects/args/feature_days.py +14 -0
- zarpa/objects/args/gender.py +18 -0
- zarpa/objects/args/leaderboard_types.py +23 -0
- zarpa/objects/args/message_type.py +22 -0
- zarpa/objects/args/object_types.py +9 -0
- zarpa/objects/args/promotion_types.py +13 -0
- zarpa/objects/args/proxy.py +117 -0
- zarpa/objects/args/purchase_types.py +13 -0
- zarpa/objects/args/qmode.py +14 -0
- zarpa/objects/args/repair_method.py +17 -0
- zarpa/objects/args/sorting.py +19 -0
- zarpa/objects/args/sorting2.py +14 -0
- zarpa/objects/args/strike_time.py +9 -0
- zarpa/objects/args/upload_type.py +21 -0
- zarpa/objects/args/users_types.py +23 -0
- zarpa/objects/args/vc_join_permissions.py +19 -0
- zarpa/objects/args/ws_event_types.py +136 -0
- zarpa/objects/resp/__init__.py +19 -0
- zarpa/objects/resp/account.py +34 -0
- zarpa/objects/resp/auth.py +11 -0
- zarpa/objects/resp/base_object.py +15 -0
- zarpa/objects/resp/blogs.py +148 -0
- zarpa/objects/resp/chat.py +178 -0
- zarpa/objects/resp/comments.py +23 -0
- zarpa/objects/resp/communities.py +75 -0
- zarpa/objects/resp/event.py +60 -0
- zarpa/objects/resp/from_code.py +32 -0
- zarpa/objects/resp/media.py +11 -0
- zarpa/objects/resp/store.py +82 -0
- zarpa/objects/resp/user.py +42 -0
- zarpa/utils/__init__.py +2 -0
- zarpa/utils/constants.py +116 -0
- zarpa/utils/exceptions.py +985 -0
- zarpa/utils/generators.py +196 -0
- zarpa/utils/logger.py +92 -0
- zarpa/utils/requester.py +307 -0
- zarpa/utils/state.py +555 -0
- zarpa/ws/__init__.py +3 -0
- zarpa/ws/_async/__init__.py +0 -0
- zarpa/ws/_async/actions.py +224 -0
- zarpa/ws/_async/handler.py +80 -0
- zarpa/ws/_async/router.py +25 -0
- zarpa/ws/_async/socket.py +322 -0
- zarpa/ws/actions.py +204 -0
- zarpa/ws/handler.py +72 -0
- zarpa/ws/router.py +118 -0
- zarpa/ws/socket.py +166 -0
- zarpa-0.1.0.dist-info/METADATA +118 -0
- zarpa-0.1.0.dist-info/RECORD +86 -0
- zarpa-0.1.0.dist-info/WHEEL +5 -0
- zarpa-0.1.0.dist-info/licenses/LICENSE +22 -0
- zarpa-0.1.0.dist-info/top_level.txt +1 -0
zarpa/__init__.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import PackageNotFoundError
|
|
4
|
+
from importlib.metadata import version as _version
|
|
5
|
+
|
|
6
|
+
from zarpa.utils import log, loglevel
|
|
7
|
+
|
|
8
|
+
from zarpa.utils.generators import Generator
|
|
9
|
+
import zarpa.utils.exceptions as exceptions
|
|
10
|
+
import zarpa.objects.resp as respObject
|
|
11
|
+
import zarpa.objects.args as args
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
from zarpa.clients.client import Client
|
|
15
|
+
from zarpa.clients.sub_client import SubClient
|
|
16
|
+
|
|
17
|
+
from zarpa.clients._async.client import Client as AsyncClient
|
|
18
|
+
from zarpa.clients._async.sub_client import SubClient as AsyncSubClient
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def set_log_level(level: int | str = loglevel.INFO):
|
|
24
|
+
"""
|
|
25
|
+
Sets the logging level.
|
|
26
|
+
|
|
27
|
+
:param level: The new logging level (loglevel.DISABLE, loglevel.INFO ...).
|
|
28
|
+
"""
|
|
29
|
+
log.set_level(level)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def enable_file_logging(log_file: str = 'zarpa.log'):
|
|
33
|
+
"""
|
|
34
|
+
Enables logging to a file.
|
|
35
|
+
|
|
36
|
+
:param log_file: The file where logs will be written.
|
|
37
|
+
"""
|
|
38
|
+
log.enable_file_logging(log_file)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def disable_file_logging():
|
|
42
|
+
"""
|
|
43
|
+
Disables logging to a file.
|
|
44
|
+
"""
|
|
45
|
+
if log.log_to_file:
|
|
46
|
+
log.log_to_file = False
|
|
47
|
+
log.logger.removeHandler(log.logger.handlers[-1])
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
try:
|
|
51
|
+
__version__ = _version("zarpa")
|
|
52
|
+
except PackageNotFoundError:
|
|
53
|
+
#sin instalar (por ejemplo, ejecutando desde el código fuente)
|
|
54
|
+
__version__ = "0.1.0"
|
|
55
|
+
__title__ = "zarpa"
|
|
56
|
+
__license__ = "MIT"
|
|
57
|
+
__copyright__ = "Copyright 2025 alx0rr; Copyright 2026 mihzuk"
|
|
58
|
+
__project_link__ = "https://github.com/mihzuk/zarpa"
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from zarpa.api.base import AsyncBaseClass
|
|
3
|
+
from zarpa.objects import args, resp
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AltTeamModule(AsyncBaseClass):
|
|
7
|
+
|
|
8
|
+
async def reset_password_by_support(self, email: str) -> dict:
|
|
9
|
+
"""
|
|
10
|
+
Reset password by support.
|
|
11
|
+
|
|
12
|
+
**Parameters**
|
|
13
|
+
- email : Email of the account for sending new password.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
result = await self.req.make_async_request("POST", "/g/s/altteam/reset-password", {
|
|
17
|
+
"email": email,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
return await result.json()
|
|
21
|
+
|
|
22
|
+
async def link_telegram(self, telegram_id: int, amino_id: str | None = None) -> dict:
|
|
23
|
+
"""
|
|
24
|
+
Link Telegram ID to AltAmino account.
|
|
25
|
+
"""
|
|
26
|
+
payload = {"telegramId": telegram_id}
|
|
27
|
+
if amino_id:
|
|
28
|
+
payload["aminoId"] = amino_id
|
|
29
|
+
|
|
30
|
+
result = await self.req.make_async_request("POST", "/g/s/altteam/telegram/link", payload)
|
|
31
|
+
return await result.json()
|
|
32
|
+
|
|
33
|
+
async def unlink_telegram(self, amino_id: str | None = None) -> dict:
|
|
34
|
+
"""
|
|
35
|
+
Unlink Telegram ID from AltAmino account.
|
|
36
|
+
"""
|
|
37
|
+
payload = {}
|
|
38
|
+
if amino_id:
|
|
39
|
+
payload["aminoId"] = amino_id
|
|
40
|
+
|
|
41
|
+
result = await self.req.make_async_request("POST", "/g/s/altteam/telegram/unlink", payload)
|
|
42
|
+
return await result.json()
|
zarpa/api/_async/auth.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from zarpa.api.base import AsyncBaseClass
|
|
4
|
+
from zarpa.utils.generators import Generator
|
|
5
|
+
|
|
6
|
+
from zarpa import args, respObject
|
|
7
|
+
from zarpa.utils import exceptions
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AuthModule(AsyncBaseClass):
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
async def login(self, email: str, password: str | None = None, secret: str | None = None, client_type: int = args.ClientTypes.User) -> respObject.AuthData:
|
|
14
|
+
"""
|
|
15
|
+
Login into an account.
|
|
16
|
+
|
|
17
|
+
**Parameters**
|
|
18
|
+
- email : Email of the account.
|
|
19
|
+
- password : Password of the account.
|
|
20
|
+
- secret : secret of the account
|
|
21
|
+
- client_type: Type of Client.
|
|
22
|
+
"""
|
|
23
|
+
if password is None and secret is None: raise exceptions.SpecifyType("Either password or secret must be provided.")
|
|
24
|
+
result = await self.req.make_async_request("POST", "/g/s/auth/login", {
|
|
25
|
+
"email": email,
|
|
26
|
+
"v": 2,
|
|
27
|
+
"secret": secret if secret else f"0 {password}",
|
|
28
|
+
"deviceID": self.deviceId,
|
|
29
|
+
"clientType": client_type,
|
|
30
|
+
"action": "normal",
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
data = await result.json()
|
|
34
|
+
self.me = respObject.AuthData(data)
|
|
35
|
+
|
|
36
|
+
self.set_sid(self.me.sid)
|
|
37
|
+
self.set_userId(self.me.auid)
|
|
38
|
+
await self.ws_connect()
|
|
39
|
+
return self.me
|
|
40
|
+
|
|
41
|
+
async def get_account_info(self) -> respObject.UserProfile:
|
|
42
|
+
"""
|
|
43
|
+
Getting account info about you.
|
|
44
|
+
"""
|
|
45
|
+
return respObject.UserProfile(await (await self.req.make_async_request("GET", "/g/s/account")).json())
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
async def login_sid(self, sid: str) -> respObject.AuthData:
|
|
49
|
+
"""
|
|
50
|
+
Login into an account.
|
|
51
|
+
|
|
52
|
+
**Parameters**
|
|
53
|
+
- sid : auth sid
|
|
54
|
+
"""
|
|
55
|
+
self.set_sid(sid)
|
|
56
|
+
self.set_userId(Generator.sid_to_uid(sid))
|
|
57
|
+
await self.ws_connect()
|
|
58
|
+
self.me = respObject.AuthData({"auid": self.userId, "sid": self.sid})
|
|
59
|
+
return self.me
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
async def logout(self, client_type: int = args.ClientTypes.User) -> respObject.BaseObject:
|
|
63
|
+
"""
|
|
64
|
+
Logout from an account.
|
|
65
|
+
"""
|
|
66
|
+
result = await (await self.req.make_async_request("POST", "/g/s/auth/logout", {
|
|
67
|
+
"deviceID": self.deviceId,
|
|
68
|
+
"clientType": client_type#Generator.sid_to_client_type(self.sid),
|
|
69
|
+
})).json()
|
|
70
|
+
self.set_sid(None)
|
|
71
|
+
self.set_userId(None)
|
|
72
|
+
self.me = respObject.AuthData({})
|
|
73
|
+
await self.ws_disconnect()
|
|
74
|
+
return respObject.BaseObject(result)
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from zarpa.api.base import AsyncBaseClass
|
|
3
|
+
from zarpa.objects import args, resp
|
|
4
|
+
from zarpa.utils.generators import b64encode
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
from typing import BinaryIO
|
|
8
|
+
from mimetypes import guess_type
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class GlobalChatsModule(AsyncBaseClass):
|
|
12
|
+
|
|
13
|
+
async def get_my_chats(self, start: int = 0, size: int = 25) -> list[resp.Chat]:
|
|
14
|
+
"""
|
|
15
|
+
List of Chats the account is in.
|
|
16
|
+
|
|
17
|
+
**Parameters**
|
|
18
|
+
- start : Where to start the list.
|
|
19
|
+
- size : Size of the list.
|
|
20
|
+
|
|
21
|
+
"""
|
|
22
|
+
result = (await (await self.req.make_async_request("GET", f"/g/s/chat/thread?type=joined-me&start={start}&size={size}")).json())["threadList"]
|
|
23
|
+
return [resp.Chat(x) for x in result]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
async def get_chat(self, chatId: str) -> resp.Chat:
|
|
27
|
+
"""
|
|
28
|
+
Get the Chat Object from an Chat ID.
|
|
29
|
+
|
|
30
|
+
**Parameters**
|
|
31
|
+
- chatId : ID of the Chat.
|
|
32
|
+
"""
|
|
33
|
+
return resp.Chat(await (await self.req.make_async_request("GET", f"/g/s/chat/thread/{chatId}")).json())
|
|
34
|
+
|
|
35
|
+
async def get_chat_users(self, chatId: str, start: int = 0, size: int = 25) -> list[resp.UserProfile]:
|
|
36
|
+
"""
|
|
37
|
+
Getting users in chat.
|
|
38
|
+
|
|
39
|
+
**Parameters**:
|
|
40
|
+
- chatId : ID of the Chat.
|
|
41
|
+
- start : Where to start the list.
|
|
42
|
+
- size : Size of the list.
|
|
43
|
+
"""
|
|
44
|
+
result = (await (await self.req.make_async_request("GET", f"/g/s/chat/thread/{chatId}/member?cv=1.2&type=default&start={start}&size={size}")).json())["memberList"]
|
|
45
|
+
return [resp.UserProfile(x) for x in result]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
async def join_chat(self, chatId: str) -> resp.BaseObject:
|
|
49
|
+
"""
|
|
50
|
+
Join an Chat.
|
|
51
|
+
|
|
52
|
+
**Parameters**
|
|
53
|
+
- chatId : ID of the Chat.
|
|
54
|
+
"""
|
|
55
|
+
return resp.BaseObject(await (await self.req.make_async_request("POST", f"/g/s/chat/thread/{chatId}/member/{self.userId}", headers={"Content-Type": "application/x-www-form-urlencoded"})).json())
|
|
56
|
+
|
|
57
|
+
async def leave_chat(self, chatId: str) -> resp.BaseObject:
|
|
58
|
+
"""
|
|
59
|
+
Leave an Chat.
|
|
60
|
+
|
|
61
|
+
**Parameters**
|
|
62
|
+
- chatId : ID of the Chat.
|
|
63
|
+
"""
|
|
64
|
+
return resp.BaseObject(await (await self.req.make_async_request("DELETE", f"/g/s/chat/thread/{chatId}/member/{self.userId}", headers={"Content-Type": "application/x-www-form-urlencoded"})).json())
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
async def send_message(self, chatId: str, message: str, replyId: str | None = None, mentionUserIds: list | None = None) -> resp.Message:
|
|
69
|
+
|
|
70
|
+
message = message.replace("<@", "").replace("@>", "")
|
|
71
|
+
|
|
72
|
+
data = {
|
|
73
|
+
"type": args.MessageTypes.Text,
|
|
74
|
+
"content": message,
|
|
75
|
+
"attachedObject": None,
|
|
76
|
+
"uid": self.userId
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if replyId:data["replyMessageId"] = replyId
|
|
80
|
+
if mentionUserIds:
|
|
81
|
+
mentions = [{"uid": mention_uid} for mention_uid in mentionUserIds]
|
|
82
|
+
data["extensions"] = {"mentionedArray": mentions}
|
|
83
|
+
|
|
84
|
+
return resp.Message(await (await self.req.make_async_request("POST", f"/g/s/chat/thread/{chatId}/message", data)).json())
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
async def send_sticker(self, chatId: str, stickerId: str) -> resp.Message:
|
|
89
|
+
|
|
90
|
+
data = {
|
|
91
|
+
"type": args.MessageTypes.Sticker,
|
|
92
|
+
#"clientRefId": clientrefid(),
|
|
93
|
+
"uid": self.userId,
|
|
94
|
+
"stickerId": stickerId
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return resp.Message(await (await self.req.make_async_request("POST", f"/g/s/chat/thread/{chatId}/message", data)).json())
|
|
98
|
+
|
|
99
|
+
async def send_media(self, chatId: str, file: BinaryIO, fileType: str | None = None, mediaUhqEnabled: bool = False) -> resp.Message:
|
|
100
|
+
|
|
101
|
+
if fileType is None:
|
|
102
|
+
fileType = guess_type(file.name)[0]
|
|
103
|
+
|
|
104
|
+
data = {
|
|
105
|
+
"type": args.MessageTypes.Text,
|
|
106
|
+
"content": None,
|
|
107
|
+
#"clientRefId": clientrefid(),
|
|
108
|
+
"attachedObject": None,
|
|
109
|
+
"mediaUploadValueContentType": fileType,
|
|
110
|
+
"uid": self.userId
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
data["mediaUploadValue"] = b64encode(file.read()).decode()
|
|
115
|
+
if fileType == args.UploadType.audio:
|
|
116
|
+
#TODO FIX
|
|
117
|
+
data["type"] = args.MessageTypes.Voice
|
|
118
|
+
data["mediaType"] = 110
|
|
119
|
+
elif fileType in [
|
|
120
|
+
args.UploadType.gif,
|
|
121
|
+
args.UploadType.image_jpeg,
|
|
122
|
+
args.UploadType.image_jpg,
|
|
123
|
+
args.UploadType.image_png]:
|
|
124
|
+
data["mediaUhqEnabled"] = mediaUhqEnabled
|
|
125
|
+
data["mediaType"] = 100
|
|
126
|
+
|
|
127
|
+
return resp.Message(await (await self.req.make_async_request("POST", f"/g/s/chat/thread/{chatId}/message", data)).json())
|
|
128
|
+
|
|
129
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from zarpa.api.base import AsyncBaseClass
|
|
3
|
+
from zarpa.objects.resp import Community, BaseObject
|
|
4
|
+
|
|
5
|
+
class GlobalCommunitiesModule(AsyncBaseClass):
|
|
6
|
+
|
|
7
|
+
async def get_joined_communities(self, start: int = 0, size: int = 25) -> list[Community]:
|
|
8
|
+
"""
|
|
9
|
+
List of Communities the account is in.
|
|
10
|
+
|
|
11
|
+
**Parameters**
|
|
12
|
+
- start : Where to start the list.
|
|
13
|
+
- size : Size of the list.
|
|
14
|
+
"""
|
|
15
|
+
result = await (await self.req.make_async_request("GET", f"/g/s/community/joined?v=1&start={start}&size={size}")).json()
|
|
16
|
+
return [Community({"community": x}) for x in result.get("communityList", [])]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
async def get_community_info(self, comId: int) -> Community:
|
|
20
|
+
"""
|
|
21
|
+
Information of an Community.
|
|
22
|
+
|
|
23
|
+
**Parameters**
|
|
24
|
+
- comId : ID of the Community.
|
|
25
|
+
"""
|
|
26
|
+
return Community(await(await self.req.make_async_request("GET", f"/g/s-x{comId}/community/info?withInfluencerList=1&withTopicList=true&influencerListOrderStrategy=fansCount")).json())
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
async def join_community(self, comId: int, invitationId: str | None = None) -> BaseObject:
|
|
31
|
+
"""
|
|
32
|
+
Join a Community.
|
|
33
|
+
|
|
34
|
+
**Parameters**
|
|
35
|
+
- comId : ID of the Community.
|
|
36
|
+
- invitationId : ID of the Invitation Code.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
data = {"uid": self.userId}
|
|
40
|
+
if invitationId:data["invitationId"] = invitationId
|
|
41
|
+
return BaseObject(await (await self.req.make_async_request("POST", f"/x{comId}/s/community/join", data)).json())
|
|
42
|
+
|
|
43
|
+
async def request_join_community(self, comId: int, message: str = "") -> BaseObject:
|
|
44
|
+
"""
|
|
45
|
+
Request to join a Community.
|
|
46
|
+
|
|
47
|
+
**Parameters**
|
|
48
|
+
- comId : ID of the Community.
|
|
49
|
+
- message : Message to be sent.
|
|
50
|
+
"""
|
|
51
|
+
return BaseObject(await (await self.req.make_async_request("POST", f"/x{comId}/s/community/membership-request", {"message": message, "uid": self.userId})).json())
|
|
52
|
+
|
|
53
|
+
async def leave_community(self, comId: int) -> BaseObject:
|
|
54
|
+
"""
|
|
55
|
+
Leave a Community.
|
|
56
|
+
|
|
57
|
+
**Parameters**
|
|
58
|
+
- comId : ID of the Community.
|
|
59
|
+
"""
|
|
60
|
+
return BaseObject(await (await self.req.make_async_request("POST", f"/x{comId}/s/community/leave")).json())
|