Автоотправка скринов на имгур

bakhusse

Активный
Автор темы
111
69
ищу скрипт, который делая скриншот игры автоматически заливает его на имгур
 
  • Вау
Реакции: silentium2006

LUE

Участник
116
17
Я не знаю почему неактуально.
Других скриптов не нашел, хоть и говорят что они есть.
 

Isov

Известный
102
16
Понимаю что тема старая но сам столкнулся с данной проблемой, и закину сюда что бы другие могли воспользоваться.

Lua:
local api_key = "your_api_key_here" -- замените на свой API-ключ

function upload_screenshot()
    local timestamp = os.time()
    local screenshot_path = string.format("screenshots/screenshot_%d.png", timestamp) -- путь к скриншоту
    samp.takeScreenshot(screenshot_path) -- делаем скриншот

    local file = io.open(screenshot_path, "rb")
    local contents = file:read("*all")
    file:close()

    local url = "https://api.imgur.com/3/image"
    local headers = {
        ["Authorization"] = "Client-ID " .. api_key,
        ["Content-Type"] = "application/x-www-form-urlencoded",
        ["Content-Length"] = #contents
    }
    local body = {
        ["image"] = contents
    }

    local response = {}
    local success, err = http.request{
        url = url,
        method = "POST",
        headers = headers,
        source = ltn12.source.string(http.urlencode(body)),
        sink = ltn12.sink.table(response)
    }

    if success and response ~= nil then
        local resp = table.concat(response)
        local json = utils.from_json(resp)

        if json.success then
            sampAddChatMessage(string.format("Screenshot uploaded to Imgur: %s", json.data.link)) -- сообщение о успешной загрузке
        else
            sampAddChatMessage("Failed to upload screenshot to Imgur") -- сообщение об ошибке
        end
    else
        sampAddChatMessage("Failed to upload screenshot to Imgur") -- сообщение об ошибке
    end

    os.remove(screenshot_path) -- удаляем скриншот
end

function onScriptTerminate(script, quitGame)
    if script == thisScript() then
        sampAddChatMessage("Imgur uploader terminated") -- сообщение об остановке скрипта
    end
end

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while true do
        wait(0)
        if isKeyDown(0x2E) and not sampIsChatInputActive() then -- проверяем, что нажата клавиша Print Screen и не открыто окно чата
            upload_screenshot()
        end
    end
end

function imgur_uploader()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    sampRegisterChatCommand("imgur", function() upload_screenshot() end) -- регистрируем команду /imgur для ручной загрузки скриншота
    while true do
        wait(0)
    end
end

function onScriptLoad()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    print("Imgur uploader loaded")
    thisScript():registerEvent("onScriptTerminate")
    imgur_uploader_thread = lua_thread.create(imgur_uploader)
end

function onScriptUnload()
    if imgur_uploader_thread ~= nil then
        imgur_uploader_thread:terminate()
    end
end
 
  • Нравится
  • Вау
Реакции: MLycoris и Arz rpg