add animated_sticker

Signed-off-by: Ari Archer <ari.web.xyz@gmail.com>
This commit is contained in:
Ari Archer 2023-01-13 18:08:03 +02:00
parent be1781416a
commit 2f79df3812
Signed by untrusted user who does not match committer: ari
GPG key ID: A50D5B4B599AF8A2
3 changed files with 48 additions and 25 deletions

View file

@ -20,6 +20,10 @@ class MsgProxy:
"messageSticker": ("sticker", "thumbnail", "photo"), "messageSticker": ("sticker", "thumbnail", "photo"),
"messagePoll": (), "messagePoll": (),
"messageAnimation": ("animation", "animation"), "messageAnimation": ("animation", "animation"),
"messageAnimatedEmoji": (
"animated_emoji",
"sticker",
),
} }
types = { types = {
@ -33,6 +37,7 @@ class MsgProxy:
"messageSticker": "sticker", "messageSticker": "sticker",
"messagePoll": "poll", "messagePoll": "poll",
"messageAnimation": "animation", "messageAnimation": "animation",
"messageAnimatedEmoji": "animated_emoji",
} }
@classmethod @classmethod
@ -43,15 +48,19 @@ class MsgProxy:
if fields is None: if fields is None:
log.error("msg type not supported: %s", _type) log.error("msg type not supported: %s", _type)
return {} return {}
for field in fields[:deep]: for field in fields[:deep]:
if isinstance(field, int): if isinstance(field, int):
doc = doc[field] doc = doc[field]
else: else:
doc = doc.get(field) doc = doc.get(field)
if "file" in doc:
return doc["file"]
if doc is None: if doc is None:
return {} return {}
if "file" in doc:
return doc["file"]
return doc return doc
def __init__(self, msg: Dict[str, Any]) -> None: def __init__(self, msg: Dict[str, Any]) -> None:
@ -245,12 +254,26 @@ class MsgProxy:
@property @property
def sticker_emoji(self) -> Optional[str]: def sticker_emoji(self) -> Optional[str]:
if self.content_type != "sticker": if self.content_type not in (
"sticker",
"animated_emoji",
):
return None 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 @property
def is_animated(self) -> Optional[bool]: def is_animated(self) -> Optional[bool]:
if self.content_type != "sticker": if self.content_type not in (
"sticker",
"animated_emoji",
):
return None 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"
)

View file

@ -664,24 +664,25 @@ def parse_content(msg: MsgProxy, users: UserModel) -> str:
content = msg["content"] content = msg["content"]
_type = content["@type"] _type = content["@type"]
if _type == "messageBasicGroupChatCreate": match _type:
return f"[created the group \"{content['title']}\"]" case "messageBasicGroupChatCreate":
if _type == "messageChatAddMembers": return f"[created the group \"{content['title']}\"]"
user_ids = content["member_user_ids"] case "messageChatAddMembers":
if user_ids[0] == msg.sender_id: user_ids = content["member_user_ids"]
return "[joined the group]" if user_ids[0] == msg.sender_id:
users_name = ", ".join( return "[joined the group]"
users.get_user_label(user_id) for user_id in user_ids users_name = ", ".join(
) users.get_user_label(user_id) for user_id in user_ids
return f"[added {users_name}]" )
if _type == "messageChatDeleteMember": return f"[added {users_name}]"
user_id = content["user_id"] case "messageChatDeleteMember":
if user_id == msg.sender_id: user_id = content["user_id"]
return "[left the group]" if user_id == msg.sender_id:
user_name = users.get_user_label(user_id) return "[left the group]"
return f"[removed {user_name}]" user_name = users.get_user_label(user_id)
if _type == "messageChatChangeTitle": return f"[removed {user_name}]"
return f"[changed the group name to \"{content['title']}\"]" case "messageChatChangeTitle":
return f"[changed the group name to \"{content['title']}\"]"
if not msg.content_type: if not msg.content_type:
# not implemented # not implemented

View file

@ -4,7 +4,6 @@ version = "0.1.1"
description = "A fork of tg -- a hackable telegram TUI client" description = "A fork of tg -- a hackable telegram TUI client"
authors = ["TruncatedDinosour <truncateddinosour@gmail.com>"] authors = ["TruncatedDinosour <truncateddinosour@gmail.com>"]
license = "Unlicense" license = "Unlicense"
packages = [{ include = "arigram"}]
readme = "README.md" readme = "README.md"
homepage = "https://github.com/TruncatedDinosour/arigram" homepage = "https://github.com/TruncatedDinosour/arigram"
repository = "https://github.com/TruncatedDinosour/arigram" repository = "https://github.com/TruncatedDinosour/arigram"