Merge pull request #11 from pixelmonaskarion/main

Sending and receiving iMessage effects
This commit is contained in:
JJTech 2023-07-31 16:14:05 -04:00 committed by GitHub
commit 8b6e1561d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 5 deletions

15
demo.py
View file

@ -127,10 +127,11 @@ threading.Thread(target=input_thread, daemon=True).start()
print("Type 'help' for help") print("Type 'help' for help")
current_participants = [] current_participants = []
current_effect = None
while True: while True:
msg = im.receive() msg = im.receive()
if msg is not None: if msg is not None:
print(f'[{msg.sender}] {msg.text}') print(msg.to_string())
if len(INPUT_QUEUE) > 0: if len(INPUT_QUEUE) > 0:
msg = INPUT_QUEUE.pop() msg = INPUT_QUEUE.pop()
@ -140,10 +141,18 @@ while True:
print('quit (q): quit') print('quit (q): quit')
#print('send (s) [recipient] [message]: send a message') #print('send (s) [recipient] [message]: send a message')
print('filter (f) [recipient]: set the current chat') print('filter (f) [recipient]: set the current chat')
print('effect (e): adds an iMessage effect to the next sent message')
print('note: recipient must start with tel: or mailto: and include the country code') print('note: recipient must start with tel: or mailto: and include the country code')
print('\\: escape commands (will be removed from message)') print('\\: escape commands (will be removed from message)')
elif msg == 'quit' or msg == 'q': elif msg == 'quit' or msg == 'q':
break break
elif msg.startswith("effect ") or msg.startswith("e "):
msg = msg.split(" ")
if len(msg) < 2 or msg[1] == "":
print("effect [effect namespace]")
else:
print(f"next message will be sent with [{msg[1]}]")
current_effect = msg[1]
elif msg.startswith('filter ') or msg.startswith('f '): elif msg.startswith('filter ') or msg.startswith('f '):
# Set the curernt chat # Set the curernt chat
msg = msg.split(' ') msg = msg.split(' ')
@ -158,8 +167,10 @@ while True:
im.send(imessage.iMessage( im.send(imessage.iMessage(
text=msg, text=msg,
participants=current_participants, participants=current_participants,
sender=user.handles[0] sender=user.handles[0],
effect=current_effect
)) ))
current_effect = None
else: else:
print('No chat selected, use help for help') print('No chat selected, use help for help')

View file

@ -53,6 +53,8 @@ class iMessage:
"""Group ID of the message, will be randomly generated if not provided""" """Group ID of the message, will be randomly generated if not provided"""
body: BalloonBody | None = None body: BalloonBody | None = None
"""BalloonBody, may be None""" """BalloonBody, may be None"""
effect: str | None = None
"""iMessage effect sent with this message, may be None"""
_compressed: bool = True _compressed: bool = True
"""Internal property representing whether the message should be compressed""" """Internal property representing whether the message should be compressed"""
@ -103,9 +105,8 @@ class iMessage:
sender=sender if sender is not None else message.get("p", [])[-1] if "p" in message else None, sender=sender if sender is not None else message.get("p", [])[-1] if "p" in message else None,
_id=uuid.UUID(message.get("r")) if "r" in message 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, group_id=uuid.UUID(message.get("gid")) if "gid" in message else None,
body=BalloonBody(message["bid"], message["b"]) body=BalloonBody(message["bid"], message["b"]) if "bid" in message else None,
if "bid" in message effect=message["iid"] if "iid" in message else None,
else None,
_compressed=compressed, _compressed=compressed,
_raw=message, _raw=message,
) )
@ -124,6 +125,7 @@ class iMessage:
"pv": 0, "pv": 0,
"gv": "8", "gv": "8",
"v": "1", "v": "1",
"iid": self.effect
} }
# Remove keys that are None # Remove keys that are None
@ -138,6 +140,12 @@ class iMessage:
return d 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: class iMessageUser:
"""Represents a logged in and connected iMessage user. """Represents a logged in and connected iMessage user.