Jump to content
  • 0

How can i make my scripts send a message in a paste site?


_insidious
 Share

Question

10 answers to this question

Recommended Posts

  • 0
3 hours ago, MAARS said:

pastebin expose the dev api, the documentation is written in php but you can rewrite it in lua

i tried this code but wont work idk why am i doing something wrong? i pasted my key without any error.. ( i ofc gave perms to internet) it says error, not any syntax error

function publishToPastebin(data, dev_key)
    local url = "https://pastebin.com/api/api_post.php"
    local body = "api_dev_key=" .. dev_key .. "&api_option=paste&api_paste_private=1&api_paste_name=My Private Paste&api_paste_code=" .. data
    local headers = { ["Content-Type"] = "application/x-www-form-urlencoded" }
    local response = gg.makeRequest(url, { method = "POST", body = body, headers = headers })
    if response and response.status == 200 then
        local paste_url = response.body
        gg.alert("Your pastebin has benn published URL: " .. paste_url)
    else
        gg.alert("Error.")
    end
end


local dev_key = "MY API KEY"

-- data to publish
local data = "test"

-- Publish Pastebin
publishToPastebin(data, dev_key)

 

Edited by _insidious
Link to comment
Share on other sites

  • 0
10 hours ago, _insidious said:

i was wondering how to make gg.makeRequest posts a message in a paste site like pastebin as example.

function publishToPastebin(api_dev_key, api_paste_code, api_paste_name, api_user_name, api_user_password)
  local char_to_hex = function(c)
    return string.format("%%%02X", string.byte(c))
  end

  local function urlencode(url)
    if url == nil then
      return
    end
    url = url:gsub("\n", "\r\n")
    url = url:gsub("([^%w ])", char_to_hex)
    url = url:gsub(" ", "+")
    return url
  end

  local api_user_key = ""
  if api_user_name then
    local url = "https://pastebin.com/api/api_login.php"
    local headers = {
      ["Content-Type"] = "application/x-www-form-urlencoded"
    }
    local data = "api_dev_key=" ..
        api_dev_key .. "&api_user_name=" .. api_user_name .. "&api_user_password=" .. api_user_password
    local result = gg.makeRequest(url, headers, data)

    api_user_key = result.content
  end

  local url = "https://pastebin.com/api/api_post.php"
  local api_paste_private = "0"
  local api_paste_expire_date = "N"
  local api_paste_format = "lua"


  api_paste_name = urlencode(api_paste_name)
  api_paste_code = urlencode(api_paste_code)

  local headers = {
    ["Content-Type"] = "application/x-www-form-urlencoded"
  }

  local data = "api_option=paste" ..
      "&api_dev_key=" .. api_dev_key ..
      "&api_user_key=" .. api_user_key ..
      "&api_paste_private=" .. api_paste_private ..
      "&api_paste_name=" .. api_paste_name ..
      "&api_paste_expire_date=" .. api_paste_expire_date ..
      "&api_paste_format=" .. api_paste_format ..
      "&api_paste_code=" .. api_paste_code

  local response = gg.makeRequest(url, headers, data)

  if response.code == 200 then
    return response.content
  else
    return "Error: " .. response.message
  end
end

local api_dev_key = "YOUR_DEV_KEY"
local api_user_name = "YOUR_USERNAME" -- Only needed if you want paste uploaded with username otherwise paste will be uploaded as Guest
local api_user_password = "YOUR_PASSWORD" -- Only needed if you want paste uploaded with username otherwise paste will be uploaded as Guest
local api_paste_code = [[local testText = "Some Text"
gg.alert(testText)]]
local api_paste_name = "file name.lua"

--Upload with username 
print(publishToPastebin(api_dev_key, api_paste_code, api_paste_name, api_user_name, api_user_password))

--Upload without username 
print(publishToPastebin(api_dev_key, api_paste_code, api_paste_name))

 

Edited by BadCase
Link to comment
Share on other sites

  • 0
2 hours ago, BadCase said:
function publishToPastebin(api_dev_key, api_paste_code, api_paste_name, api_user_name, api_user_password)
  local char_to_hex = function(c)
    return string.format("%%%02X", string.byte(c))
  end

  local function urlencode(url)
    if url == nil then
      return
    end
    url = url:gsub("\n", "\r\n")
    url = url:gsub("([^%w ])", char_to_hex)
    url = url:gsub(" ", "+")
    return url
  end

  local api_user_key = ""
  if api_user_name then
    local url = "https://pastebin.com/api/api_login.php"
    local headers = {
      ["Content-Type"] = "application/x-www-form-urlencoded"
    }
    local data = "api_dev_key=" ..
        api_dev_key .. "&api_user_name=" .. api_user_name .. "&api_user_password=" .. api_user_password
    local result = gg.makeRequest(url, headers, data)

    api_user_key = result.content
  end

  local url = "https://pastebin.com/api/api_post.php"
  local api_paste_private = "0"
  local api_paste_expire_date = "N"
  local api_paste_format = "lua"


  api_paste_name = urlencode(api_paste_name)
  api_paste_code = urlencode(api_paste_code)

  local headers = {
    ["Content-Type"] = "application/x-www-form-urlencoded"
  }

  local data = "api_option=paste" ..
      "&api_dev_key=" .. api_dev_key ..
      "&api_user_key=" .. api_user_key ..
      "&api_paste_private=" .. api_paste_private ..
      "&api_paste_name=" .. api_paste_name ..
      "&api_paste_expire_date=" .. api_paste_expire_date ..
      "&api_paste_format=" .. api_paste_format ..
      "&api_paste_code=" .. api_paste_code

  local response = gg.makeRequest(url, headers, data)

  if response.code == 200 then
    return response.content
  else
    return "Error: " .. response.message
  end
end

local api_dev_key = "YOUR_DEV_KEY"
local api_user_name = "YOUR_USERNAME" -- Only needed if you want paste uploaded with username otherwise paste will be uploaded as Guest
local api_user_password = "YOUR_PASSWORD" -- Only needed if you want paste uploaded with username otherwise paste will be uploaded as Guest
local api_paste_code = [[local testText = "Some Text"
gg.alert(testText)]]
local api_paste_name = "file name.lua"

--Upload with username 
print(publishToPastebin(api_dev_key, api_paste_code, api_paste_name, api_user_name, api_user_password))

--Upload without username 
print(publishToPastebin(api_dev_key, api_paste_code, api_paste_name))

thanks it works but, how can i paste them privately? i turned 0 to 1 but it pastes unlisted

 

Edited by _insidious
Link to comment
Share on other sites

  • 0
4 hours ago, _insidious said:

i just pasted some things but after a while still saying error: "unprocessable entity" i did not touch the script, any fix?

 

If you want to post as private, make sure you are posting with username, you can't post private as Guest

Link to comment
Share on other sites

  • 0
1 hour ago, BadCase said:

If you want to post as private, make sure you are posting with username, you can't post private as Guest

i know right and i already fixed, it was pastebin limitation, thx anyway

Edited by _insidious
Link to comment
Share on other sites

  • 0
48 minutes ago, _insidious said:

i know right and i already fixed, it was pastebin limitation, thx anyway

Ah yes I ran into the max paste error while I made the API last night, thought I broke something at first lol

BTW I made this after I posted my reply last night 

BadCase's PasteBin API (#72l4i839)

 

 

Also if the reply I sent with the code in it worked you can mark it as the accepted answer

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.