Skip to content

Commit

Permalink
chore: staticmethod
Browse files Browse the repository at this point in the history
  • Loading branch information
krypton-byte committed Oct 27, 2024
1 parent f27e968 commit 1c0c81d
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 26 deletions.
1 change: 1 addition & 0 deletions examples/multisession_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ async def handler(client: NewAClient, message: MessageEv):
),
)


@client_factory.event(PairStatusEv)
async def PairStatusMessage(_: NewAClient, message: PairStatusEv):
log.info(f"logged as {message.ID.User}")
Expand Down
5 changes: 3 additions & 2 deletions goneonize/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,6 @@ def build_android():
# shell=os.name == "nt",
# )

if __name__ == '__main__':
build()

if __name__ == "__main__":
build()
5 changes: 1 addition & 4 deletions neonize/_binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,7 @@ def get_bytes(self):
ctypes.c_int,
]
gocode.SendFBMessage.restype = Bytes
gocode.SendPresence.argtypes = [
ctypes.c_char_p,
ctypes.c_char_p
]
gocode.SendPresence.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
gocode.SendPresence.restype = ctypes.c_char_p
else:
gocode: Any = object()
30 changes: 18 additions & 12 deletions neonize/aioze/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@


class GoCode:
@staticmethod
def execute_sync_function(
self, func: Callable[SyncFunctionParams, ReturnType]
func: Callable[SyncFunctionParams, ReturnType],
) -> Callable[SyncFunctionParams, Awaitable[ReturnType]]:
def call(
*args: SyncFunctionParams.args, **kwargs: SyncFunctionParams.kwargs
Expand Down Expand Up @@ -2672,13 +2673,12 @@ 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)
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
Expand Down Expand Up @@ -2723,8 +2723,6 @@ def disconnect(self) -> None:
self.__client.Disconnect(self.uuid)




class ClientFactory:
def __init__(self, database_name: str = "neonize.db") -> None:
"""
Expand Down Expand Up @@ -2753,7 +2751,12 @@ def get_all_devices_from_db(db: str) -> List[Device]:
id, server = id.split("@")
jid = build_jid(id, server)

device = Device(JID=jid, PushName=push_name, BussinessName=bussniess_name, Initialized=initialized == "true")
device = Device(
JID=jid,
PushName=push_name,
BussinessName=bussniess_name,
Initialized=initialized == "true",
)
devices.append(device)

return devices
Expand All @@ -2763,7 +2766,10 @@ def get_all_devices(self) -> List["Device"]:
return self.get_all_devices_from_db(self.database_name)

def new_client(
self, jid: Optional[JID] = None, uuid: Optional[str] = None, props: Optional[DeviceProps] = None
self,
jid: Optional[JID] = None,
uuid: Optional[str] = None,
props: Optional[DeviceProps] = None,
) -> NewAClient:
"""
This function creates a new instance of the client. If the jid parameter is not provided, a new client will be created.
Expand All @@ -2787,4 +2793,4 @@ def new_client(
return client

async def run(self):
return await asyncio.gather(*[client.connect() for client in self.clients])
return await asyncio.gather(*[client.connect() for client in self.clients])
5 changes: 4 additions & 1 deletion neonize/aioze/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def callback(func: Callable[[NewAClient, EventType], Awaitable[None]]) -> None:

return callback


class EventsManager:
def __init__(self, client_factory: ClientFactory):
self.client_factory = client_factory
Expand All @@ -165,6 +166,8 @@ def __call__(
:return: A decorator that registers the callback function.
:rtype: Callable[[Callable[[NewClient, EventType], None]], None]
"""

def callback(func: Callable[[NewAClient, EventType], Awaitable[None]]) -> None:
self.list_func.update({EVENT_TO_INT[event]: func})
return callback

return callback
14 changes: 9 additions & 5 deletions neonize/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2522,13 +2522,12 @@ 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
)
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
Expand Down Expand Up @@ -2601,7 +2600,12 @@ def get_all_devices_from_db(db: str) -> List[Device]:
id, server = id.split("@")
jid = build_jid(id, server)

device = Device(JID=jid, PushName=push_name, BussinessName=bussniess_name, Initialized=initialized == "true")
device = Device(
JID=jid,
PushName=push_name,
BussinessName=bussniess_name,
Initialized=initialized == "true",
)
devices.append(device)

return devices
Expand Down
1 change: 1 addition & 0 deletions neonize/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class EventsManager:
def __init__(self, client_factory: ClientFactory):
self.client_factory = client_factory
self.list_func: Dict[int, Callable[[NewClient, Message], None]] = {}

def __call__(
self, event: Type[EventType]
) -> Callable[[Callable[[NewClient, EventType], None]], None]:
Expand Down
2 changes: 1 addition & 1 deletion neonize/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,4 @@ class GetChatSettingsError(Exception):


class SendPresenceError(Exception):
pass
pass
3 changes: 2 additions & 1 deletion neonize/utils/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ class ParticipantRequestChange(Enum):
APPROVE = "approve"
REJECT = "reject"


class Presence(Enum):
AVAILABLE = b"available"
UNAVAILABLE = b"unavailable"
UNAVAILABLE = b"unavailable"

0 comments on commit 1c0c81d

Please sign in to comment.