Ejemplo n.º 1
0
def videofromjson(jsonedjson):
    return Video(jsonedjson["file_id"], jsonedjson["width"],
                 jsonedjson["height"], jsonedjson["duration"],
                 photosizefromjson(jsonedjson["thumb"]),
                 pybotFuncs.testfor(jsonedjson, "mime_type"),
                 pybotFuncs.testfor(jsonedjson, "file_size", True),
                 pybotFuncs.testfor(jsonedjson, "caption"))
Ejemplo n.º 2
0
def messagefromjson(jsonedjson):
    """create message from json"""
    sender = userfromjson(jsonedjson["from"])
    if pybotFuncs.testfor(jsonedjson["chat"], "title") == UNDEFINED:
        chat = userfromjson(jsonedjson["chat"])
    else:
        chat = groupchatfromjson(jsonedjson["chat"])
    msgtype = pybotFuncs.checkmsgtype(jsonedjson)
    if msgtype == "text" or msgtype == "new_chat_title":
        contain = jsonedjson[msgtype]
    if msgtype == "audio":
        contain = audiofromjson(jsonedjson[msgtype])
    if msgtype == "document":
        contain = documentfromjson(jsonedjson[msgtype])
    if msgtype == "sticker":
        contain = stickerfromjson(jsonedjson[msgtype])
    if msgtype == "photo" or msgtype == "new_chat_photo":
        contain = "WIP"
    if msgtype == "video":
        contain = videofromjson(jsonedjson[msgtype])
    if msgtype == "contact":
        contain = contactfromjson(jsonedjson[msgtype])
    if msgtype == "location":
        contain = locationfromjson(jsonedjson[msgtype])
    if msgtype == "new_chat_participant" or msgtype == "left_chat_participant":
        contain = userfromjson(jsonedjson[msgtype])
    if msgtype == "delete_chat_photo" or msgtype == "group_chat_created":
        contain = True
    if pybotFuncs.testfor(jsonedjson, "forward_from") != UNDEFINED:
        forwardfrom = userfromjson(jsonedjson["forward_from"])
    else:
        forwardfrom = None
    if pybotFuncs.testfor(jsonedjson, "reply_to_message") != UNDEFINED:
        reply2msg = messagefromjson(jsonedjson["reply_to_message"])
    else:
        reply2msg = None
    return Message(jsonedjson["message_id"], sender, jsonedjson["date"], chat,
                   contain, msgtype, forwardfrom,
                   pybotFuncs.testfor(jsonedjson, "forward_date",
                                      True), reply2msg)
Ejemplo n.º 3
0
def messagefromjson(jsonedjson):
    """create message from json"""
    sender = userfromjson(jsonedjson["from"])
    if pybotFuncs.testfor(jsonedjson["chat"], "title") == UNDEFINED:
        chat = userfromjson(jsonedjson["chat"])
    else:
        chat = groupchatfromjson(jsonedjson["chat"])
    msgtype = pybotFuncs.checkmsgtype(jsonedjson)
    if msgtype == "text" or msgtype == "new_chat_title":
        contain = jsonedjson[msgtype]
    if msgtype == "audio":
        contain = audiofromjson(jsonedjson[msgtype])
    if msgtype == "document":
        contain = documentfromjson(jsonedjson[msgtype])
    if msgtype == "sticker":
        contain = stickerfromjson(jsonedjson[msgtype])
    if msgtype == "photo" or msgtype == "new_chat_photo":
        contain = "WIP"
    if msgtype == "video":
        contain = videofromjson(jsonedjson[msgtype])
    if msgtype == "contact":
        contain = contactfromjson(jsonedjson[msgtype])
    if msgtype == "location":
        contain = locationfromjson(jsonedjson[msgtype])
    if msgtype == "new_chat_participant" or msgtype == "left_chat_participant":
        contain = userfromjson(jsonedjson[msgtype])
    if msgtype == "delete_chat_photo" or msgtype == "group_chat_created":
        contain = True
    if pybotFuncs.testfor(jsonedjson, "forward_from") != UNDEFINED:
        forwardfrom = userfromjson(jsonedjson["forward_from"])
    else:
        forwardfrom = None
    if pybotFuncs.testfor(jsonedjson, "reply_to_message") != UNDEFINED:
        reply2msg = messagefromjson(jsonedjson["reply_to_message"])
    else:
        reply2msg = None
    return Message(jsonedjson["message_id"], sender, jsonedjson["date"], chat, contain, msgtype, forwardfrom, pybotFuncs.testfor(jsonedjson, "forward_date", True), reply2msg)
Ejemplo n.º 4
0
def userfromjson(jsonedjson):
    return User(jsonedjson["id"], jsonedjson["first_name"], pybotFuncs.testfor(jsonedjson, "last_name"), pybotFuncs.testfor(jsonedjson, "username"))
Ejemplo n.º 5
0
def contactfromjson(jsonedjson):
    return Contact(jsonedjson["phone_number"], jsonedjson["first_name"], pybotFuncs.testfor(jsonedjson, "last_name"), pybotFuncs.testfor(jsonedjson, "user_id"))
Ejemplo n.º 6
0
def videofromjson(jsonedjson):
    return Video(jsonedjson["file_id"], jsonedjson["width"], jsonedjson["height"], jsonedjson["duration"], photosizefromjson(jsonedjson["thumb"]), pybotFuncs.testfor(jsonedjson, "mime_type"), pybotFuncs.testfor(jsonedjson, "file_size", True), pybotFuncs.testfor(jsonedjson, "caption"))
Ejemplo n.º 7
0
def stickerfromjson(jsonedjson):
    return Sticker(jsonedjson["file_id"], jsonedjson["width"], jsonedjson["height"], photosizefromjson(jsonedjson["thumb"]), pybotFuncs.testfor(jsonedjson, "file_size", True))
Ejemplo n.º 8
0
def documentfromjson(jsonedjson):
    return Document(jsonedjson["file_id"], photosizefromjson(jsonedjson["thumb"]), pybotFuncs.testfor(jsonedjson, "filename"), pybotFuncs.testfor(jsonedjson, "mime_type"), pybotFuncs.testfor(jsonedjson, "file_size", True))
Ejemplo n.º 9
0
def audiofromjson(jsonedjson):
    return Audio(jsonedjson["file_id"], jsonedjson["duration"], pybotFuncs.testfor(jsonedjson, "mime_type"), pybotFuncs.testfor(jsonedjson, "file_size", True))
Ejemplo n.º 10
0
def photosizefromjson(jsonedjson):
    return PhotoSize(jsonedjson["file_id"], jsonedjson["width"], jsonedjson["height"], pybotFuncs.testfor(jsonedjson, "file_size", True))
Ejemplo n.º 11
0
def contactfromjson(jsonedjson):
    return Contact(jsonedjson["phone_number"], jsonedjson["first_name"],
                   pybotFuncs.testfor(jsonedjson, "last_name"),
                   pybotFuncs.testfor(jsonedjson, "user_id"))
Ejemplo n.º 12
0
def userfromjson(jsonedjson):
    return User(jsonedjson["id"], jsonedjson["first_name"],
                pybotFuncs.testfor(jsonedjson, "last_name"),
                pybotFuncs.testfor(jsonedjson, "username"))
Ejemplo n.º 13
0
def stickerfromjson(jsonedjson):
    return Sticker(jsonedjson["file_id"],
                   jsonedjson["width"], jsonedjson["height"],
                   photosizefromjson(jsonedjson["thumb"]),
                   pybotFuncs.testfor(jsonedjson, "file_size", True))
Ejemplo n.º 14
0
def documentfromjson(jsonedjson):
    return Document(jsonedjson["file_id"],
                    photosizefromjson(jsonedjson["thumb"]),
                    pybotFuncs.testfor(jsonedjson, "filename"),
                    pybotFuncs.testfor(jsonedjson, "mime_type"),
                    pybotFuncs.testfor(jsonedjson, "file_size", True))
Ejemplo n.º 15
0
def audiofromjson(jsonedjson):
    return Audio(jsonedjson["file_id"], jsonedjson["duration"],
                 pybotFuncs.testfor(jsonedjson, "mime_type"),
                 pybotFuncs.testfor(jsonedjson, "file_size", True))
Ejemplo n.º 16
0
def photosizefromjson(jsonedjson):
    return PhotoSize(jsonedjson["file_id"], jsonedjson["width"],
                     jsonedjson["height"],
                     pybotFuncs.testfor(jsonedjson, "file_size", True))