Source code for tgram.utils.types
import tgram
import os
from typing import Optional, List, Union
from pathlib import Path
from io import BytesIO
from tgram import utils
[docs]
def message_origin_parse(
d: Optional[dict] = None, me: Optional["tgram.TgBot"] = None
) -> Optional["tgram.types.MessageOrigin"]:
if d is None:
return None
origin_type = d["type"]
return (
tgram.types.MessageOriginUser._parse(me=me, d=d)
if origin_type == "user"
else tgram.types.MessageOriginHiddenUser._parse(me=me, d=d)
if origin_type == "hidden_user"
else tgram.types.MessageOriginChat._parse(me=me, d=d)
if origin_type == "chat"
else tgram.types.MessageOriginChannel._parse(me=me, d=d)
)
[docs]
def reaction_type_parse(
bot: "tgram.TgBot",
x: Optional[Union[List[dict], dict]],
) -> "tgram.types.ReactionType":
if x is None:
return None
x = x if isinstance(x, list) else [x]
return [
(
tgram.types.ReactionTypeCustomEmoji._parse(bot, i)
if i["type"] == "custom_emoji"
else tgram.types.ReactionTypeEmoji._parse(bot, i)
if i["type"] == "emoji"
else tgram.types.ReactionTypePaid._parse(bot, i)
)
for i in x
]