Skip to content

Commit 6f2be8a

Browse files
committed
Refactor type stubs and improve code formatting across multiple files
- Cleaned up whitespace and formatting in backend, client, events, exceptions, helpers, and types stubs. - Enhanced readability by removing unnecessary blank lines and aligning code structure. - Updated type hints and annotations for better clarity and consistency. - Improved the organization of imports in various modules. - Ensured compatibility with Python 3.10+ by using TypeAlias where applicable. - Added utility functions for better error handling in Rust client implementations. - Adjusted media upload handling to ensure proper byte array conversions in Rust.
1 parent 68cd99c commit 6f2be8a

17 files changed

Lines changed: 136 additions & 413 deletions

examples.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
2+
23
from tryx.backend import SqliteBackend
3-
from tryx.client import TryxClient, Tryx # , Test, K
4+
from tryx.client import Tryx, TryxClient # , Test, K
45
from tryx.events import EvMessage
56
from tryx.waproto.whatsapp_pb2 import Message as msg
67

examples/command_bot.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ async def on_message(client: TryxClient, event: EvMessage) -> None:
6969
if not text:
7070
return
7171

72-
print(f"[message] from={jid_to_text(sender_jid)} chat={jid_to_text(chat_jid)} text={text!r}")
72+
print(
73+
f"[message] from={jid_to_text(sender_jid)} chat={jid_to_text(chat_jid)} text={text!r}"
74+
)
7375

7476
if text in {"help", "menu"}:
7577
await client.send_text(
@@ -96,25 +98,37 @@ async def on_message(client: TryxClient, event: EvMessage) -> None:
9698
return
9799

98100
user_info = next(iter(info_map.values()), None)
99-
status_text = "(tidak ada)" if user_info is None or not user_info.status else user_info.status
101+
status_text = (
102+
"(tidak ada)"
103+
if user_info is None or not user_info.status
104+
else user_info.status
105+
)
100106
await client.send_text(chat_jid, f"Bio: {status_text}", quoted=event)
101107
return
102108

103109
if text == "pp":
104110
try:
105-
profile_picture = await client.contact.get_profile_picture(sender_jid, False)
111+
profile_picture = await client.contact.get_profile_picture(
112+
sender_jid, False
113+
)
106114
except Exception as exc:
107-
await client.send_text(chat_jid, f"Gagal ambil profile picture: {exc}", quoted=event)
115+
await client.send_text(
116+
chat_jid, f"Gagal ambil profile picture: {exc}", quoted=event
117+
)
108118
return
109119

110120
if not profile_picture.url:
111-
await client.send_text(chat_jid, "Profile picture tidak tersedia.", quoted=event)
121+
await client.send_text(
122+
chat_jid, "Profile picture tidak tersedia.", quoted=event
123+
)
112124
return
113125

114126
try:
115127
photo_data = await download_bytes(profile_picture.url)
116128
except Exception as exc:
117-
await client.send_text(chat_jid, f"Gagal download profile picture: {exc}", quoted=event)
129+
await client.send_text(
130+
chat_jid, f"Gagal download profile picture: {exc}", quoted=event
131+
)
118132
return
119133

120134
await client.send_photo(

libs/whatsapp-rust

python/tryx/__init__.pyi

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,3 @@
11
"""Public package re-exports for Tryx Python bindings."""
22

3-
from .backend import BackendBase, SqliteBackend
4-
from .client import (
5-
BlockingClient,
6-
BlocklistEntry,
7-
ChatActionsClient,
8-
ChatstateClient,
9-
ChatStateType,
10-
CommunityClient,
11-
CommunitySubgroup,
12-
ContactClient,
13-
CreateGroupOptions,
14-
CreateGroupResult,
15-
CreateCommunityOptions,
16-
CreateCommunityResult,
17-
GroupInfo,
18-
GroupMetadata,
19-
GroupParticipantOptions,
20-
GroupsClient,
21-
JoinGroupResult,
22-
MemberAddMode,
23-
MemberLinkMode,
24-
MembershipApprovalMode,
25-
MembershipRequest,
26-
ParticipantChangeResponse,
27-
GroupParticipant,
28-
GroupType,
29-
LinkSubgroupsResult,
30-
NewsletterClient,
31-
NewsletterMessage,
32-
NewsletterMetadata,
33-
NewsletterReactionCount,
34-
NewsletterRole,
35-
NewsletterState,
36-
NewsletterVerification,
37-
PollOptionResult,
38-
PollsClient,
39-
PresenceClient,
40-
PresenceStatus,
41-
PrivacyCategory,
42-
PrivacyClient,
43-
PrivacySetting,
44-
PrivacyValue,
45-
DisallowedListAction,
46-
DisallowedListUpdate,
47-
DisallowedListUserEntry,
48-
ProfileClient,
49-
StatusClient,
50-
StatusPrivacySetting,
51-
StatusSendOptions,
52-
Tryx,
53-
TryxClient,
54-
UnlinkSubgroupsResult,
55-
)
56-
from .exceptions import (
57-
BuildBotError,
58-
EventDispatchError,
59-
FailedBuildBot,
60-
FailedToDecodeProto,
61-
PyPayloadBuildError,
62-
UnsupportedBackend,
63-
UnsupportedBackendError,
64-
UnsupportedEventType,
65-
UnsupportedEventTypeError,
66-
)
67-
from .types import JID, MediaReuploadResult, MessageInfo, MessageSource, ProfilePicture, SendResult, UploadResponse
68-
from .wacore import MediaType
69-
from .helpers import (
70-
BlockingHelpers,
71-
ChatstateHelpers,
72-
GroupsHelpers,
73-
NewsletterHelpers,
74-
PollsHelpers,
75-
PresenceHelpers,
76-
StatusHelpers,
77-
)
78-
793
__all__: list[str]

python/tryx/backend.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
from abc import ABC
44

5-
65
class BackendBase(ABC):
76
"""Base class for all backend implementations used by Tryx."""
87

9-
108
class SqliteBackend(BackendBase):
119
"""SQLite-backed backend implementation.
1210

0 commit comments

Comments
 (0)