OpenBullet 2 supports and has integration with Node.js
Improvements this brings are
- Javascript
- New functions in versions of Javascript that Jint wasn’t ever updated for
- Importing of NPM Modules
- Far more support and versatility than jint.
- Faster and more stable then Iron Python
To start using Node.js you will first want to install Node.js on the system that OB2 is running on.
After that you will want to create a Script block inside of OB2 and select Node.js as the interpreter.
Lolicode snippet:
BLOCK:Script
INTERPRETER:NodeJS
INPUT x,y
BEGIN SCRIPT
var result = x + y;
END SCRIPT
OUTPUT Int @result
ENDBLOCK
This will create a block that uses node.js to add x and y. From this point you can build your javascript from here and it has support for importing multiple variables as well as exporting multiple variables.
Section 2: Importing NPM Modules to use with OB2 and Node.js
Node.js integration also supports the importing of modules and packages that can be used with OB2.
Here is a snippet of Javascript I wrote that generates Oauth signatures. It uses the imported Crypto Library.
module.exports = (callback, ) => {
const crypto = require("crypto");
function base64URLEncode(str) {
return str.toString('base64')
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=/g, '');
}
function sha256(buffer) {
return crypto.createHash('sha256').update(buffer).digest();
}
var VERIFIER = base64URLEncode(crypto.randomBytes(32));
var CHALLENGE = base64URLEncode(sha256(VERIFIER));
var noderesult = {
'VERIFIER': VERIFIER,
'CHALLENGE': CHALLENGE,
};
callback(null, noderesult);
}
Note: This code has been altered by coverting the config to a C# config. This adds the callbacks and the module callback lines that aren’t normally there.
To install a NPM package to use along side Node.js just open your OpenBullet 2 Folder and locate the “Scripts” Folder.
Inside of this folder open CMD or Terminal (depending on system)
From here just type npm init -y
and npm install <Package Name>
This will create a new folder inside the directory called node_modules. All installed packages will be placed there.
You can now just use const circle = require('circle.js');
or whatever your package’s name is.
Note: Configs using node.js that are shared will need the script to be shared as well if its converted to C#.
edit: Add fixes I looked over. Fixes from SirTenzin