IsDebugEnabled

The FireflyAIO Lua API includes an IsDebugEnabled function that allows you to check if Debug mode is enabled. This function returns a boolean value: true if Debug mode is enabled, and false if it is not. You can use this function to conditionally execute debug-specific code, such as printing debug information to the console.

Using the IsDebugEnabled Function

The IsDebugEnabled function is simple to use. You call it without any arguments, and it returns a boolean indicating the Debug mode status.

Here is an example of how to use the IsDebugEnabled function:

-- Check if Debug mode is enabled
if IsDebugEnabled() then
    -- Print a debug message to the console
    Debug("Debug mode is enabled")
else
    -- Print a message indicating that Debug mode is not enabled
    print("Debug mode is not enabled")
end

Example Usage in a Custom Checker

You can use the IsDebugEnabled function to conditionally include debug statements in your custom checker:

function Checker(username, password)
    -- Check if Debug mode is enabled and print a starting message
    if IsDebugEnabled() then
        Debug("Starting checker for username: " .. username)
    end

    local response = Post("https://example.com/api/login", "username=" .. username .. "&password=" .. password, "application/x-www-form-urlencoded")

    -- Check if Debug mode is enabled and print the response
    if IsDebugEnabled() then
        Debug("Received response: " .. response)
    end

    if string.find(response, "access_token") then
        if IsDebugEnabled() then
            Debug("Login successful for username: " .. username)
        end
        return "Hit"
    elseif string.find(response, "invalid credentials") then
        if IsDebugEnabled() then
            Debug("Login failed for username: " .. username)
        end
        return "Fail"
    else
        if IsDebugEnabled() then
            Debug("Request failed for username: " .. username)
        end
        return "Retry"
    end
end

Last updated