Пример #1
0
def addUser(id, first_name, last_name, username, language_code):
    from initFunctions import updateJson, getStatus, getUserData
    from var import userdata
    userInfo = {
        "group":"unknown",
        "status":0,
        "id":id,
        "first_name":first_name,
        "last_name":last_name,
        "username":username,
        "language_code":language_code,
        "sticker":True,
        "folder_id":""
    }
    was_known = str(id) in userdata
    if was_known:
        userInfo["status"] = getStatus(id)
        userInfo["sticker"] = getUserData(id, "sticker")
        userInfo["folder_id"] = getUserData(id, "folder_id")
        print("Refresh userInfo, ID:", id, "- username: @"+username)
    else:
        print("Added new user to 'userdata.json', ID: ", id, "- username: @"+username)
    userdata[str(id)] = userInfo
    updateJson(userdata, "userdata.json")
    return was_known
Пример #2
0
def getgd(update, context):
    from initFunctions import getStatus, getUserData
    if getStatus(update.message.from_user.id) > 0:
        from var import userdata
        from publicBotHeader import messageLang
        from privateBotHeader import getDriveInfo, notPermittedResponse
        id = update.message.from_user.id
        update.message.reply_markdown(
            messageLang("getgd", update).format(
                getUserData(id, "first_name"),
                getDriveInfo("url"),
                getUserData(id, "folder_id")
            )
        )
    else:
        notPermittedResponse(update)
    pass
Пример #3
0
def processFileType(update, context):
    from initFunctions import getStatus, getUserData
    message = update.message
    id = message.from_user.id
    if getStatus(id) > 0:
        document = message.document
        from publicBotHeader import messageLang
        if document.file_size < 20971520:
            from publicBotHeader import downloadFile, telegramSettings
            file_name = document.file_name
            file_ext = fileExtention(file_name)
            path = downloadFile(context.bot, document, file_name)
            if file_ext == "stl":
                from driveFunctions import fileToDrive
                print("STL file from", id)
                if fileToDrive(path, getUserData(id, "folder_id")):
                    context.bot.forward_message(telegramSettings("manager"),
                                                message.chat.id,
                                                message.message_id)
                    message.reply_text(
                        messageLang("to_drive", update).format(file_name))
                    print("File Loaded on GoogleDrive")
                else:
                    message.reply_text(messageLang("stl_failed"))
                    print("ERROR: impossible to upload STL file")
            elif file_ext == "gcode":
                from driveFunctions import fileToSpreadsheets
                print("GCode file from", id)
                done = fileToSpreadsheets(update, path)
                if not done:
                    message.reply_text(messageLang("unknown_flavor", update))
                    context.bot.forward_message(telegramSettings("master"),
                                                message.chat.id,
                                                message.message_id)
                    print("Unknown flavor")
                else:
                    message.reply_text(
                        messageLang("to_spreadsheets",
                                    update).format(file_name))
                    context.bot.forward_message(telegramSettings("manager"),
                                                message.chat.id,
                                                message.message_id)
                    print("Sheet filled with print data")
            elif file_ext == "curaprofile" and id == telegramSettings(
                    "manager"):
                from driveFunctions import fileToDrive
                print("Curaprofile file")
                if fileToDrive(path, getDriveInfo("profiles")):
                    message.reply_text(messageLang("profile_loaded"))
                    print("Profile loaded")
                else:
                    message.reply_text(messageLang("profile_failed"))
                    print("ERROR: impossible to upload Curaprofile")
        else:
            message.reply_text(messageLang("too_big", update))
    pass
Пример #4
0
def pngResize(update, context):
    from initFunctions import getUserData
    message = update.message
    id = message.from_user.id
    chat_id = message.chat.id
    if  chat_id > 0 and getUserData(id, "sticker"):
        document = message.document
        path = downloadFile(context.bot, document)
        resized = resizePhoto(path, document.thumb)
        context.bot.send_document(chat_id, open(resized,"rb"))
    pass
Пример #5
0
def userLang(message_key, user):
    from var import messages
    from initFunctions import getUserData
    language = getUserData(user, "language_code")
    if not language == "it":
        language = "en"
    try:
        return messages[message_key][language]
    except KeyError as ke:
        print("ERROR: missing ", ke," key in messages.json fom 'userLang'")
        return ("Errore interno (-.-')")
    pass
Пример #6
0
def sticker_resize(update, context):
    from initFunctions import getUserData
    message = update.message
    id = message.from_user.id
    chat_id = message.chat.id
    if chat_id > 0 and getUserData(id, "sticker"):
        from publicBotHeader import downloadFile, resizePhoto
        photo = message.photo[-1]
        path = downloadFile(context.bot, photo)
        resized = resizePhoto(path, photo)
        context.bot.send_document(chat_id, open(resized, "rb"))
    pass
Пример #7
0
def toall(update, context):
    from initFunctions import getUserData, getStatus
    if getStatus(update.message.from_user.id) > 1:
        from var import userdata
        from publicBotHeader import telegramSettings, messageLang
        if update.message.text == "/toall":
            update.message.reply_text(messageLang("toall_error", update))
            return False
        message = update.message.text[7:] + " - @{}"
        username = update.message.from_user.username
        for user in userdata:
            id = getUserData(user, "id")
            context.bot.send_message(id, message.format(username))
        print("Message: '" + message.format(username) + "' sent to all users")
        return True
    pass
Пример #8
0
def fileToSpreadsheets(update, path):
    from var import sheet
    from extractor import flavorExtract
    from initFunctions import getUserData
    row = flavorExtract(path)
    if len(row) == 0:
        return False
    else:
        to_fill = firstFree(sheet)
        file_from = getUserData(update.message.from_user.id, "first_name")
        try:
            caption = update.message.caption
        except:
            caption = file_from
        row[0] = to_fill - 1
        row[1] = file_from
        row[6] = caption
        sheet.insert_row(row, to_fill)
        return True
    pass