Beispiel #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
def setgroup(update, context):
    from initFunctions import getStatus, getUserData
    if getStatus(update.message.from_user.id) > 2:
        from publicBotHeader import messageLang, userLang
        from adminBotHeader import idIs, setGroup
        split_message = update.message.text.split(" ")
        group = split_message[1]
        username = split_message[2][1:]
        str_id = idIs(username)
        if str_id == "error":
            update.message.reply_text(
                messageLang("setstatus_error", update).format(username))
            return False
        else:
            setGroup(str_id, group)
            update.message.reply_text(
                messageLang("setgroup", update).format(username, group))
            if (group != ""):
                print("Group: user '" + username + "', added to: '" + group +
                      "'")
                context.bot.send_message(
                    int(str_id),
                    userLang("your_group", int(str_id)).format(group))
            else:
                print("Group: user '" + username + "', removed from '" +
                      group + "'")
                context.bot.send_message(
                    int(str_id), userLang("removed_group", int(str_id)))
            return True
    pass
def getjson(update, context):
    from initFunctions import getStatus
    if getStatus(update.message.from_user.id) > 2:
        context.bot.send_document(update.message.from_user.id,
                                  open("./userdata.json", "rb"))
        return True
    pass
Beispiel #4
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
Beispiel #5
0
def getgss(update, context):
    from initFunctions import getStatus
    if getStatus(update.message.from_user.id) > 0:
        from publicBotHeader import messageLang
        from privateBotHeader import getDriveInfo, notPermittedResponse
        update.message.reply_markdown(
            messageLang("getgss", update).format(
                getDriveInfo("sheets_url")
            )
        )
    else:
        notPermittedResponse(update)
    pass
def adminhelp(update, context):
    from initFunctions import getStatus
    if getStatus(update.message.from_user.id) > 2:
        message = """
adminhelp - get advanced help
toall - message all with signature
setstatus - set user status (0-1-2-3) (/setgroup N userName)
getjson - get local db
[DISABLED] sudo - execute command
[DISABLED] scd - change directory
getip - get public ip
setgroup - set user group (/setgroup groupName userName)
"""
        update.message.reply_text(message)
    pass
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
Beispiel #8
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
def setstatus(update, context):
    from initFunctions import getStatus, getUserData
    if getStatus(update.message.from_user.id) > 2:
        from publicBotHeader import messageLang, userLang
        from adminBotHeader import idIs, setStatus
        username = update.message.text[14:]
        str_id = idIs(username)
        if str_id == "error":
            update.message.reply_text(
                messageLang("setstatus_error", update).format(username))
            return False
        else:
            status = int(update.message.text[11:12])
            setStatus(str_id, status)
            you_are = userLang("status", int(str_id))
            he_is = messageLang("status", update)
            update.message.reply_text(
                messageLang("setstatus",
                            update).format(username, he_is[status], status))
            context.bot.send_message(
                int(str_id),
                userLang("you_are", int(str_id)).format(you_are[status]))
            return True
    pass