From 232e126a89697c6c9b601697f8539e1906cd36b0 Mon Sep 17 00:00:00 2001 From: Chistopher Huntwork Date: Mon, 31 Jul 2023 11:35:34 -0700 Subject: [PATCH] added logging of message effects --- demo.py | 2 +- imessage.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/demo.py b/demo.py index 8632445..19afdc0 100644 --- a/demo.py +++ b/demo.py @@ -130,7 +130,7 @@ current_participants = [] while True: msg = im.receive() if msg is not None: - print(f'[{msg.sender}] {msg.text}') + print(msg.to_string()) if len(INPUT_QUEUE) > 0: msg = INPUT_QUEUE.pop() diff --git a/imessage.py b/imessage.py index 08c9476..5c0b59d 100644 --- a/imessage.py +++ b/imessage.py @@ -53,6 +53,8 @@ class iMessage: """Group ID of the message, will be randomly generated if not provided""" body: BalloonBody | None = None """BalloonBody, may be None""" + effect: str | None = None + """iMessage effect sent with this message, may be None""" _compressed: bool = True """Internal property representing whether the message should be compressed""" @@ -103,9 +105,8 @@ class iMessage: sender=message.get("p", [])[-1] if message.get("p", []) != [] else None, _id=uuid.UUID(message.get("r")) if "r" in message else None, group_id=uuid.UUID(message.get("gid")) if "gid" in message else None, - body=BalloonBody(message["bid"], message["b"]) - if "bid" in message - else None, + body=BalloonBody(message["bid"], message["b"]) if "bid" in message else None, + effect=message["iid"] if "iid" in message else None, _compressed=compressed, _raw=message, ) @@ -138,6 +139,12 @@ class iMessage: return d + def to_string(self) -> str: + message_str = f"[{self.sender}] '{self.text}'" + if self.effect is not None: + message_str += f" with effect [{self.effect}]" + return message_str + class iMessageUser: """Represents a logged in and connected iMessage user.