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"),
"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"
)

View file

@ -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

View file

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