From f27e9681c6ad6398325fcb4d2aeffe47d390473f Mon Sep 17 00:00:00 2001 From: krypton-byte Date: Sun, 27 Oct 2024 10:31:05 +0700 Subject: [PATCH] feat: send presence --- goneonize/main.go | 9 +++++++++ neonize/_binder.py | 5 +++++ neonize/aioze/client.py | 10 +++++++++- neonize/client.py | 10 +++++++++- neonize/exc.py | 7 +++++++ neonize/utils/enum.py | 4 ++++ 6 files changed, 43 insertions(+), 2 deletions(-) diff --git a/goneonize/main.go b/goneonize/main.go index 6b49195..266b633 100644 --- a/goneonize/main.go +++ b/goneonize/main.go @@ -1971,6 +1971,15 @@ func GetAllDevices(db *C.char) *C.char { return C.CString(result.String()) } +//export SendPresence +func SendPresence(id *C.char, presence *C.char) *C.char { + err := clients[C.GoString(id)].SendPresence(types.Presence(C.GoString(presence))) + if err != nil { + return C.CString(err.Error()) + } + return C.CString("") +} + //export SendFBMessage func SendFBMessage(id *C.char, to *C.uchar, toSize C.int, message *C.uchar, messageSize C.int, metadata *C.uchar, metadataSize C.int, extra *C.uchar, extraSize C.int) C.struct_BytesReturn { var toJID defproto.JID diff --git a/neonize/_binder.py b/neonize/_binder.py index c781dc8..550afd6 100644 --- a/neonize/_binder.py +++ b/neonize/_binder.py @@ -466,5 +466,10 @@ def get_bytes(self): ctypes.c_int, ] gocode.SendFBMessage.restype = Bytes + gocode.SendPresence.argtypes = [ + ctypes.c_char_p, + ctypes.c_char_p + ] + gocode.SendPresence.restype = ctypes.c_char_p else: gocode: Any = object() diff --git a/neonize/aioze/client.py b/neonize/aioze/client.py index b1d0f19..6913282 100644 --- a/neonize/aioze/client.py +++ b/neonize/aioze/client.py @@ -56,6 +56,7 @@ ChatPresenceMedia, LogLevel, ParticipantChange, + Presence, ReceiptType, ClientType, ClientName, @@ -105,6 +106,7 @@ ResolveContactQRLinkError, SendAppStateError, SendMessageError, + SendPresenceError, SetDefaultDisappearingTimerError, SetDisappearingTimerError, SetGroupAnnounceError, @@ -2670,7 +2672,13 @@ async def send_fb_message( len(extra_buff), ) return SendResponse.FromString(response.get_bytes()) - + async def send_presence(self, presence: Presence): + response = await self.__client.SendPresence( + self.uuid, + presence.value + ) + if response: + raise SendPresenceError(response) async def connect(self): """Establishes a connection to the WhatsApp servers.""" # Convert the list of functions to a bytearray diff --git a/neonize/client.py b/neonize/client.py index 108f53f..44745c7 100644 --- a/neonize/client.py +++ b/neonize/client.py @@ -32,6 +32,7 @@ PutPinnedError, ResolveContactQRLinkError, SendAppStateError, + SendPresenceError, SetDefaultDisappearingTimerError, SetDisappearingTimerError, SetGroupAnnounceError, @@ -146,6 +147,7 @@ ChatPresenceMedia, LogLevel, ParticipantChange, + Presence, ReceiptType, ClientType, ClientName, @@ -2520,7 +2522,13 @@ def send_fb_message( len(extra_buff), ) return SendResponse.FromString(response.get_bytes()) - + def send_presence(self, presence: Presence): + response = self.__client.SendPresence( + self.uuid, + presence.value + ) + if response: + raise SendPresenceError(response) def connect(self): """Establishes a connection to the WhatsApp servers.""" # Convert the list of functions to a bytearray diff --git a/neonize/exc.py b/neonize/exc.py index 70b24f6..b47100c 100644 --- a/neonize/exc.py +++ b/neonize/exc.py @@ -1,5 +1,8 @@ # class InvalidInviteLink(Exception): # pass +from re import L + + class UploadError(Exception): pass @@ -234,3 +237,7 @@ class PutArchivedError(Exception): class GetChatSettingsError(Exception): pass + + +class SendPresenceError(Exception): + pass \ No newline at end of file diff --git a/neonize/utils/enum.py b/neonize/utils/enum.py index 80e60a4..45531ab 100644 --- a/neonize/utils/enum.py +++ b/neonize/utils/enum.py @@ -347,3 +347,7 @@ class ParticipantRequestChange(Enum): APPROVE = "approve" REJECT = "reject" + +class Presence(Enum): + AVAILABLE = b"available" + UNAVAILABLE = b"unavailable" \ No newline at end of file