Chatgpt
Key RequiredUniversal

Chatgpt

Universal ScriptFienFien 448 views 29 executesUpdated Nov 19, 2025
Unrated
00
Lua Script•135 lines (3481 chars)
-- =========================
--   WINDOWS-13 STYLE CHATGPT
--   MOVEABLE GUI + CLOSE BUTTON
--   WINDOWS-STYLE TEXT BAR
--   ONE FILE ONLY (main.lua)
-- =========================

local http = require("socket.http")
local ltn12 = require("ltn12")
local json = require("dkjson")

local OPENAI = os.getenv("OPENAI_API_KEY")

local win = {
    x = 100, y = 100,
    w = 350, h = 230,
    dragging = false,
    show = true
}

local inputText = ""
local responseText = ""

function ai_query(prompt)
    local body = json.encode({
        model = "gpt-4o-mini",
        messages = { { role = "user", content = prompt } }
    })

    local r = {}
    local _, code = http.request{
        url = "https://api.openai.com/v1/chat/completions",
        method = "POST",
        headers = {
            ["Content-Type"] = "application/json",
            ["Content-Length"] = tostring(#body),
            ["Authorization"] = "Bearer " .. OPENAI
        },
        source = ltn12.source.string(body),
        sink = ltn12.sink.table(r)
    }

    if code ~= 200 then
        return "HTTP error: " .. tostring(code)
    end

    local decoded = json.decode(table.concat(r))
    return decoded.choices[1].message.content
end

function love.load()
    love.window.setTitle("ChatGPT Window")
end

function love.draw()
    if not win.show then return end

    -- Background
    love.graphics.setColor(0.1, 0.1, 0.1, 0.95)
    love.graphics.rectangle("fill", win.x, win.y, win.w, win.h, 6)

    -- Border
    love.graphics.setColor(1, 1, 1)
    love.graphics.rectangle("line", win.x, win.y, win.w, win.h, 6)

    -- Header
    love.graphics.print("ChatGPT", win.x + 10, win.y + 10)

    -- Close button
    love.graphics.print("CLOSE CHATGPT", win.x + win.w - 140, win.y + 10)

    -- Input Label
    love.graphics.print("You:", win.x + 10, win.y + 50)

    -- ============================
    --  NEW WINDOWS-STYLE TEXT BAR
    -- ============================
    love.graphics.setColor(0.2, 0.2, 0.2, 0.9)
    love.graphics.rectangle("fill", win.x + 60, win.y + 45, win.w - 70, 25, 4)

    love.graphics.setColor(1, 1, 1)
    love.graphics.rectangle("line", win.x + 60, win.y + 45, win.w - 70, 25, 4)

    love.graphics.print(inputText, win.x + 65, win.y + 50)
    -- ============================

    -- Response
    love.graphics.print("AI:", win.x + 10, win.y + 90)
    love.graphics.printf(responseText, win.x + 10, win.y + 110, win.w - 20)
end

-- Handle typing
function love.textinput(t)
    inputText = inputText .. t
end

function love.keypressed(key)
    if key == "backspace" then
        inputText = inputText:sub(1, -2)
    end

    if key == "return" and inputText ~= "" then
        responseText = ai_query(inputText)
        inputText = ""
    end
end

function love.mousepressed(mx, my, b)
    if b == 1 then
        -- Close button
        if mx > win.x + win.w - 140 and mx < win.x + win.w - 10 and my > win.y + 5 and my < win.y + 35 then
            win.show = false
            return
        end

        -- Drag area (top bar)
        if mx > win.x and mx < win.x + win.w and my > win.y and my < win.y + 40 then
            win.dragging = true
            win.offx = mx - win.x
            win.offy = my - win.y
        end
    end
end

function love.mousereleased()
    win.dragging = false
end

function love.update()
    if win.dragging and win.show then
        local mx, my = love.mouse.getPosition()
        win.x = mx - win.offx
        win.y = my - win.offy
    end
end

Features & Information

THIS SCEIPT IS STILL IN BETA

Community Comments (0)

No comments yet for this script.

More Scripts for Universal Scripts