-
Notifications
You must be signed in to change notification settings - Fork 145
Utility Functions
-
Utility
Removes the .ROBLOSECURITY cookie from jar. Note that this does not return a new jar, it simply changes the existing one.
Arguments
- jar (CookieJar)
Returns
(Promise)
- session (string)
Gets the verification inputs from url and sends a post request with data from events, returning the original body before the post request according to getBody and obeying the cache based on ignoreCache. Use http for custom request options for the post request; if url is contained, it will not replace the main url but the url used for getting verification tokens. This function is used for primitive site functions that involve ASP viewstates.
Arguments
- url (string)
- events (Object)
-
optional ignoreCache (boolean)
- default false
-
optional getBody (boolean)
- default false
- optional jar (CookieJar)
Returns
(Promise)
- (Object)
- res (Object)
- body (string)
Gets the action row for audit log text. Current supported types are: change rank, delete post, and change group status (shouts).
Arguments
- row (string)
Returns
- action (Object)
- target (id)
- params (Array)
Gets the current user logged into jar and returns an option if specified or all options if not.
Arguments
- optional option (string)
- optional jar (CookieJar)
Returns
(Promise)
- option (string) / options (Object)
{"UserID":2470023,"UserName":"Froast","RobuxBalance":0,"TicketsBalance":0,"ThumbnailUrl":"http://t5.rbxcdn.com/60d4b74ae50199a7f887731cdf19d47a","IsAnyBuildersClubMember":false}
Gets the date for time which originates from a two-letter timezone. This is used to get the time for that timezone despite daylight savings. For example if you did getDate(time, 'CT') it would return the time in CST if daylight savings is inactive or CDT if it is active.
Arguments
- time (string)
- timezone (string)
Returns
- date (Date)
Processes some forum-related 302 error and returns a corresponding message. The argument append is optional and describes the calling function.
Arguments
- location (string)
- optional append (string)
Returns
(Promise)
- (Error)
Gets a general X-CSRF-TOKEN for APIs that don't return it after failure. This uses the https://api.roblox.com/sign-out/v1 API to get tokens.
Arguments
- url (string)
- optional jar (CookieJar)
Returns
(Promise)
- x-csrf-token (string)
Generates a unique hash for the given jar file jar or default if none is specified. Typically used to cache items that depend on session.
Arguments
- optional jar (CookieJar)
Returns
- hash (string)
Returns verification inputs on the page with the names in find - or all inputs if not provided. Typically used for ROBLOX requests working with ASP.NET.
Arguments
- html (string)
- optional find (array)
Returns
- inputs (Object)
- name (string): value (string)
Gets the user ID of the current logged in user and caches it permanently. This is needed for some functions.
Arguments
- optional jar (CookieJar)
Returns
(Promise)
- userId (number)
Gets the .ROBLOSECURITY session cookie from jar, which is the default jar file if not specified.
Arguments
- optional jar (CookieJar)
Returns
- session (string)
Gets verification inputs off of url using jar and caches them. If getBody is true, the body and inputs will both be returned in an object. The header is the value of the __RequestVerificationToken cookie if it exists. If ignoreCache is enabled, the resulting tokens will not be cached.
Arguments
- url (string)
-
optional ignoreCache (boolean)
- default false
-
optional getBody (boolean)
- default false
- optional jar (CookieJar)
Returns
(Promise)
- response (Object)
- optional body: body (string)
- inputs: name (string): value (string)
- header (string)
Gets verification inputs from html. Short for getInputs(html,['__VIEWSTATE','__VIEWSTATEGENERATOR','__EVENTVALIDATION, '__RequestVerificationToken']'). Typically used for ROBLOX requests working with ASP.NET. If you have already loaded html with a parser you can pass the selector directly.
Arguments
- html (string)
- or selector (function)
Returns
- inputs (Object)
- name (string): value (string)
Sends an http request to url with options. If ignoreLoginError is true the function will not error when the user is redirected to the ROBLOX login page, otherwise it will as detection for failed logins and preventing further errors. The custom option verification adds the token to the cookies as __RequestVerificationToken. Note that if jar is a key in the options object but is still null, the default jar will be used
Arguments
- url (string)
-
optional options (Object)
- optional verification (string)
- optional ignoreLoginError (boolean)
Returns
(Promise)
- body (string)
Creates a jar file based on sessionOnly. Normally you will not need this argument as the function will use the default from settings.json. If for some other reason you need a jar file you can collect it this way, but without changing the settings it will not work.
Arguments
- sessionOnly (boolean)
Returns
- jar (CookieJar)
This is the base for events that do not rely on true streams. The getLatest function receives some value that represents the latest version of something (eg. a date or unique ID) and determines if there is new information, every time it is fired it waits delay ms before being fired again. Every time it must return an object with the field latest, representing the latest value (which will not change if new information was not received), and an array data which has the new values (if there are multiple they each have their own index, if there is only one then it is by itself in the array). If latest is equal to -2, the returned data will be processed even if it is the initial run (which usually only establishes the latest value). If the return object has a true repeat value, the function latest will be run again immediately after. If delay is a string it will take the number from that string key in the event object of the settings.json file.
When the function is first called it will initialize getLatest with the value -1 and then emit the connect event. Whenever data is received, it will emit the data event for each value. If the close event is emitted the function will no longer run. If an error occurs the error event will be emitted, the function will log a retry and after the number of max retries as specified by settings, it will emit the close event.
The getLatest function will be marked as failed if it does not resolve within timeout ms (which can be disabled if timeout is negative). If getLatest fails for any reason (including timeout) it will be retried maxRetries times before stopping.
Arguments
- getLatest (function)
- delay (string/number)
-
optional timeout (number)
- Defaults to the timeout setting
Settings
- event
- maxRetries (number)
- timeout (number)
Returns
(EventEmitter)
Will run getPage (which should return a promise) for every number starting from start and ending at end - 1. At any one time only maxThreads number will be running. This for functions that require a large number of requests but actually makes it practical to use them because it doesn't prepare all the requests at once, taking up all available memory.
Errors will not stop the thread from running, instead the request will be tried 3 times after with 5 seconds between each retry. If it still does not succeed it will be skipped and a warning will be printed but will still not end threaded.
Returns a promise with the additional function properties getStatus, getCompleted, getExpected which represent the percent completion, the current number of completed threads, and the total number of threads for completion.
Arguments
- getPage (function)
- start (number)
- end (number)
Settings
- maxThreads (number)
Returns
(Promise)
This wiki is currently outdated. It will be kept for reference purposes. It is highly recommended you visit https://noblox.js.org instead to see the latest documentation.