コード例 #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"))
コード例 #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)
コード例 #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)
コード例 #4
0
def userfromjson(jsonedjson):
    return User(jsonedjson["id"], jsonedjson["first_name"], pybotFuncs.testfor(jsonedjson, "last_name"), pybotFuncs.testfor(jsonedjson, "username"))
コード例 #5
0
def contactfromjson(jsonedjson):
    return Contact(jsonedjson["phone_number"], jsonedjson["first_name"], pybotFuncs.testfor(jsonedjson, "last_name"), pybotFuncs.testfor(jsonedjson, "user_id"))
コード例 #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"))
コード例 #7
0
def stickerfromjson(jsonedjson):
    return Sticker(jsonedjson["file_id"], jsonedjson["width"], jsonedjson["height"], photosizefromjson(jsonedjson["thumb"]), pybotFuncs.testfor(jsonedjson, "file_size", True))
コード例 #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))
コード例 #9
0
def audiofromjson(jsonedjson):
    return Audio(jsonedjson["file_id"], jsonedjson["duration"], pybotFuncs.testfor(jsonedjson, "mime_type"), pybotFuncs.testfor(jsonedjson, "file_size", True))
コード例 #10
0
def photosizefromjson(jsonedjson):
    return PhotoSize(jsonedjson["file_id"], jsonedjson["width"], jsonedjson["height"], pybotFuncs.testfor(jsonedjson, "file_size", True))
コード例 #11
0
def contactfromjson(jsonedjson):
    return Contact(jsonedjson["phone_number"], jsonedjson["first_name"],
                   pybotFuncs.testfor(jsonedjson, "last_name"),
                   pybotFuncs.testfor(jsonedjson, "user_id"))
コード例 #12
0
def userfromjson(jsonedjson):
    return User(jsonedjson["id"], jsonedjson["first_name"],
                pybotFuncs.testfor(jsonedjson, "last_name"),
                pybotFuncs.testfor(jsonedjson, "username"))
コード例 #13
0
def stickerfromjson(jsonedjson):
    return Sticker(jsonedjson["file_id"],
                   jsonedjson["width"], jsonedjson["height"],
                   photosizefromjson(jsonedjson["thumb"]),
                   pybotFuncs.testfor(jsonedjson, "file_size", True))
コード例 #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))
コード例 #15
0
def audiofromjson(jsonedjson):
    return Audio(jsonedjson["file_id"], jsonedjson["duration"],
                 pybotFuncs.testfor(jsonedjson, "mime_type"),
                 pybotFuncs.testfor(jsonedjson, "file_size", True))
コード例 #16
0
def photosizefromjson(jsonedjson):
    return PhotoSize(jsonedjson["file_id"], jsonedjson["width"],
                     jsonedjson["height"],
                     pybotFuncs.testfor(jsonedjson, "file_size", True))