diff --git a/arigram/msg.py b/arigram/msg.py index c9f3feb..b07c256 100644 --- a/arigram/msg.py +++ b/arigram/msg.py @@ -20,6 +20,10 @@ class MsgProxy: "messageSticker": ("sticker", "thumbnail", "photo"), "messagePoll": (), "messageAnimation": ("animation", "animation"), + "messageAnimatedEmoji": ( + "animated_emoji", + "sticker", + ), } types = { @@ -33,6 +37,7 @@ class MsgProxy: "messageSticker": "sticker", "messagePoll": "poll", "messageAnimation": "animation", + "messageAnimatedEmoji": "animated_emoji", } @classmethod @@ -43,15 +48,19 @@ class MsgProxy: if fields is None: log.error("msg type not supported: %s", _type) return {} + for field in fields[:deep]: if isinstance(field, int): doc = doc[field] else: doc = doc.get(field) - if "file" in doc: - return doc["file"] + if doc is None: return {} + + if "file" in doc: + return doc["file"] + return doc def __init__(self, msg: Dict[str, Any]) -> None: @@ -245,12 +254,26 @@ class MsgProxy: @property def sticker_emoji(self) -> Optional[str]: - if self.content_type != "sticker": + if self.content_type not in ( + "sticker", + "animated_emoji", + ): return None - return self.msg["content"].get("sticker", {}).get("emoji") + + content = self.msg["content"].get(self.content_type, {}) + + return content.get("emoji") or content.get("sticker", {}).get("emoji") @property def is_animated(self) -> Optional[bool]: - if self.content_type != "sticker": + if self.content_type not in ( + "sticker", + "animated_emoji", + ): return None - return self.msg["content"].get("sticker", {}).get("is_animated") + + content = self.msg["content"].get(self.content_type, {}) + + return content.get("is_animated") or content.get("sticker", {}).get( + "is_animated" + ) diff --git a/arigram/views.py b/arigram/views.py index e20e62e..18bbb46 100644 --- a/arigram/views.py +++ b/arigram/views.py @@ -664,24 +664,25 @@ def parse_content(msg: MsgProxy, users: UserModel) -> str: content = msg["content"] _type = content["@type"] - if _type == "messageBasicGroupChatCreate": - return f"[created the group \"{content['title']}\"]" - if _type == "messageChatAddMembers": - user_ids = content["member_user_ids"] - if user_ids[0] == msg.sender_id: - return "[joined the group]" - users_name = ", ".join( - users.get_user_label(user_id) for user_id in user_ids - ) - return f"[added {users_name}]" - if _type == "messageChatDeleteMember": - user_id = content["user_id"] - if user_id == msg.sender_id: - return "[left the group]" - user_name = users.get_user_label(user_id) - return f"[removed {user_name}]" - if _type == "messageChatChangeTitle": - return f"[changed the group name to \"{content['title']}\"]" + match _type: + case "messageBasicGroupChatCreate": + return f"[created the group \"{content['title']}\"]" + case "messageChatAddMembers": + user_ids = content["member_user_ids"] + if user_ids[0] == msg.sender_id: + return "[joined the group]" + users_name = ", ".join( + users.get_user_label(user_id) for user_id in user_ids + ) + return f"[added {users_name}]" + case "messageChatDeleteMember": + user_id = content["user_id"] + if user_id == msg.sender_id: + return "[left the group]" + user_name = users.get_user_label(user_id) + return f"[removed {user_name}]" + case "messageChatChangeTitle": + return f"[changed the group name to \"{content['title']}\"]" if not msg.content_type: # not implemented diff --git a/pyproject.toml b/pyproject.toml index 10bae52..a2fea18 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,6 @@ version = "0.1.1" description = "A fork of tg -- a hackable telegram TUI client" authors = ["TruncatedDinosour "] license = "Unlicense" -packages = [{ include = "arigram"}] readme = "README.md" homepage = "https://github.com/TruncatedDinosour/arigram" repository = "https://github.com/TruncatedDinosour/arigram"