Hello
idk what motivated me to make this
(its supposed to say pastebin API Module but ykyk)
Introduction
Basically just allows basic API access to pastebin, which includes creating, deleting, reading and listing pastes, whilst also being able to login to an account and see private pastes and listings. This is purely just to document its methods and hopefully communicate bugs and so on.
Is there any use cases for pastebin?
To be honest, I have no clue. I wouldn’t recommend it for storing large parts of data nor executing code on the site, maybe small bits of data that you can manipulate without having to access roblox studio however this can proably be accomplished by HttpService:GetAsync('pastebin.com/code')
. Anyhow the only other option this module provides is giving access to user’s accounts via pastebinModule:userLogin
to access private pastes and even create/delete pastes under that user!
The api doesnt even allow you to edit pastes, so there is little point. This module also does not contain access to pastebin scraping API since I do not want to pay for a pro membership.
Tutorial
Greetings, so you want to link your roblox game to pastebin? Well no problem with the help of pastebin’s API I was able to create a module that simplifies all the functions it offers! The module script can only be required serverside since it requires the use of HttpService
Setup
It works the same as a normal module
local pastebinModule = require(path_to.pastebinModule)
However inside the module (or outside) you need to set the variable of the devKey
to your dev key on your account by visiting Pastebin API docs whilst you are signed in. This can be found in the script at line 5
-- example one
local pastebinModule = {}
pastebinModule.userDetails = nil
pastebinModule.devKey = '' -- paste it here
-- example two
local pastebinModule = require(path_to.pastebinModule)
pastebinModule.devKey = '' -- or here
Do be careful with this key though if malicous scripts are in your game they can steal this key however it does not grant authorisation to your account. Afterwards you don’t need to worry about a dev key anymore.
Utility
From now you can start creating pastes, however these pastes will be created under a guest account and not a specified user which means you lose the ability to delete/lock or edit even on the main website.
You can see below the documented methods in more detail
local pastebinUrlCode = pastebinModule:createPaste(
true, -- true if guest account, doesn't work if not logged in (see below)
'some code here!' -- the content of your paste
'a paste!'
'10M' -- lifetime (eg 10M = 10 minutes, 3W = 3 weeks, 4S = 4 seconds)
)
local pastebinCode = pastebinUrlCode:gsub('https://pastebin.com/', '') -- code only
print(pastebinUrlCode) -- 'pastebin.com/*randomletters*'
print(pastebinCode) -- '*randomletters*'
pastebinModule:fetchPaste(pastebinCode) -- 'some code here!'
What if I want to use a user account?
This part requires confidential information so read carefully
To simply login you need to pass the username and password of the account you would like to access
local username = 'ilike_bread56' -- not real ofc
local password = 'mmm_bread56'
pastebinModule:userLogin(username, password)
It should then print Successfully logged in as ilike_bread56 at pastebin.com/
if successfull
You can then logout if needed but the game automatically does this when the game ends
pastebinModule:userLogout()
It should then print Successfully logged out of pastebin.com/
Note: The module does not store the password or username given for longer than simply logging in but does store the UserKey
that pastebin returns, so be careful especially in a team create that you trust the people and scripts inside your game.
Important: I would suggest (if your game usually has a lot of active servers) to login before any actions even if repeated. This is due to pastebin only allowing one active UserKey
at a time
while task.wait(5) do
pastebinModule:userLogin(username, password)
pastebinModule:doSomething()
end
After this you should be able to create pastes under the logged in user
Feel free to read the API documentation below
API Documentation
Note that some methods can only be performed if successfully logged in
Properties
devKey
Type: string
The dev key that is provided at pastebin API docs when you are signed into an account, this is Required for this module to work
userDetails
Type: table
{
username : string -- the account's username
email : string -- the account's email
account_type : number -- normal = 0, pro = 1
location : string -- the location set in the account's settings
expiration : string -- default expiration of a user's pastes
private : string -- default privacy of a user's pastes
format_short : string -- default format of a user's pastes
website : string -- the user's website on their account page
}
A table containing data of the current logged in user
Methods
:userLogin(username, password)
username: string -- required, the username of the desired account
password: string -- required, the password of this account
Uses a Http post request
Returns: boolean (based on success)
Important note: of course this is common sense to keep your username
and password
safe but checking scripts and fellow developers on the same project.
Note: This does not log you out of pastebin.com in your browser
This method can login the user into a pastebin account given the correct username
and password
and returns true
if successful This method creates a UserKey
that can then be used through the pastebin API which allows actions on behalf of that account. There can only be one UserKey
active at a time for each account meaning if this module is used on multiple games/servers it can cause a particular instance to be logged out without knowing resulting in a network 422
error
:userLogout()
N/A
Returns: N/A
Logs the user out of the current session clearing the current UserKey
and userDetails
property
Note: This however still means that the UserKey
is still active as far as pastebin is aware.
:createPaste(guest, content, name, lifetime, format, privacy)
guest: boolean -- default: true, Whether the author of the paste should be a guest
content: string -- required, The content that will be present in the paste
name: string -- default: 'Untitled', The name of the paste
lifetime: string -- default: 'N' (none), 10M = 10 minutes, 3D = 3 days etc
format: string -- default: 'text', eg. 'lua', 'py', 'js'
privacy: number -- default: 0, public = 0, unlisted = 1, private = 2
Uses a Http post request
Returns: string (pastebin link)
Creates a pastebin with the given parameters, which you can see more detail at the pastebin API docs. It returns a pastebin link of the new paste if successful. This method can be used without logging in however it will always be under a guest account.
:deletePaste(pasteCode)
pasteCode: string -- the code of the desired paste (eg. 'ZjJzrpqp')
Uses a Http post request
Returns: string (‘Paste Removed’ if successful)
Sends a request to delete a paste. Pastes created by guest accounts cannot be deleted, and only users can delete their own pastes
:fetchPaste(pasteCode, raw)
pasteCode: string -- required, the code of the desired paste (eg. 'ZjJzrpqp')
raw: boolean -- default: false, whether to use a Http Get request instead
Uses a Http post/get request
Returns: string (content of the paste)
Returns the content of the given string if successful. The raw parameter decides whether to use a Http Get request, however this means it will not work for private pastes. To view private pastes ignore the raw
parameter and be logged into the author’s account with :userLogin
and it should work. If not logged in the module will perform a Http Get request anyway.
:listUsersPastes(listLen)
listLen: number -- default: 50, the amount of maximum pastes to list
Uses a Http post request
Returns: table (containing an array of paste’s created by the user
Can only list the currently logged in user’s pastes but not others. Also includes unlisted and private pastes. Requires you to be logged in.
Extra info
Check this post to see further info on actual pastebin API, although its a bit old its still helpful
Pastebin also have a helpful API page however examples are displayed in php
Thanks for reading, feel free to comment below whether this was a stupid idea or on any mistakes I made.