New repo and lib - OWOP.js_v2
The library for using OWOP API in Node.JS!
- Fixed protocol change.
Here is a basic example, evaluating the library.
var OwopJS = require('owop-js'); //Include the OWOP.js library
var OJS = new OwopJS.OJS();
OJS.on("open", function () { //Modify what happens when our app creates a connection to the server
OJS.world.join('main'); //Join the world named 'main', the default world.
OJS.chat.nick('OJS Bot'); //Set our nickname to 'OJS Bot'
OJS.interact.controller(); //Start controller
});
OJS.on("message", function (data) { //Modify what happens upon receiving a message.
//For these two lines, see below for more info.
OJS.chat.recvModifier(data.data)
OJS.util.messageHandler(data.data);
});
OJS.on("close", function () {
console.log('[OWOP.js]: Disconnected.'); //Let us know that we have been disconnected.
process.exit(); //Exit Node
});
Here we are just importing OJS and adding some events. When a connection is established, we join the world, set a nick, and start the controller (see below for more information about the controller).
To install OJS, execute npm install owop-js
. It will install dependencies too.
If you don't set anything, OJS will run in default mode, and connect to original OWOP. When you initiate OJS, you can set some options.
Example:
var OJS = new OwopJS.OJS({option: value});
matrix
VALUES: true
Just enjoy the messages from OWOP.
var OJS = new OwopJS.OJS({matrix: true});
ws && origin
You can use these options to connect to OWOP clones. Both of those options need to be defined in order to make it work properly.
var OJS = new OwopJS.OJS({ws: "ws://104.237.150.24:1337", origin: "http://augustberchelmann.com/owop/"});
disableoutput
VALUES: true
Use this option to disable console.log
-ing messages.
var OJS = new OwopJS.OJS({disableoutput: true});
agent
You can set agent for bots.
const SocksProxyAgent = require('socks-proxy-agent');
const OWOP_js = require('owop-js');
const Proxy = "192.168.1.1"; // Your proxies.
/* ... */
var OJS = new OWOP_js.OJS({agent: new SocksProxyAgent(Proxy)});
OJS supports a majority of what the normal OWOP client can do.
OJS.events.owop
You can use some events like in original OWOP.
List of events:
{
OJS.events.owop.connect: 0, // Triggers when you joining the world.
OJS.events.owop.disconnect: 1, // Triggers when you leave the world.
OJS.events.owop.id: 2, // Triggers when you get ID.
OJS.events.owop.update: 3, // Triggers when players moved, changed, etc.
OJS.events.owop.rank: 4, // Triggers when you get rank.
OJS.events.owop.move: 5 // Triggers when you move.
}
Example use of events:
OJS.on(OJS.events.owop.id, function(id) {
console.log(`Got id: ${id}`);
});
Nothing interesting here, just a ranks as in original OWOP.
ADMIN: 3
;
MODERATOR: 2
;
USER: 1
;
NONE: 0
;
OJS has powerful chat features for easy working with it!
Login to admin. If you type wrong pass you will get kicked!
OJS.chat.adminlogin(OJS.util.localStorage.getItem('adminlogin'));
The same as OJS.chat.adminlogin()
, but for moderators.
OJS.chat.modlogin(OJS.util.localStorage.getItem('modlogin'));
With this function you can easily set your bot nickname.
OJS.chat.nick('OJS Bot');
Send private messages to other people.
OJS.chat.tell(126, 'TellMessage from OJS!');
Just send a message to chat! Don't forget that you have chatSend delay, and you can't send messages super fast. (if you are not admin)
OJS.chat.send('Message from OJS!')
This function is for handling messages. You need to put it inside the message
event.
Also with this function you can make commands for your bot. It's really same as OWOP API, so I don't think I should show how you can make commands.
ws.onmessage = function (data) {
msg = data.data;
OJS.chat.recvModifier(msg);
OJS.util.messageHandler(msg):
}
This function is for handling sendMessages.
OJS.chat.sendModifier = (msg) => {
if(msg == "!test") {
console.log('Test command.')
} else {
ws.send(msg + OJS.options.misc.chatVerification)
}
}
> OJS.chat.send('!test')
// -> Test command.
> OJS.chat.send('Hi')
// -> [OWOP.js]: [128] OJS Bot: Hi
Returns the first message that was received.
OJS.chat.firstMessage() // <style> ... </style>
Returns the last message that was received.
OJS.chat.lastMessage() // [128] dimden: Hi
OJS has interacting features for communicating with OWOP in console.
This function will make forever-chat-input in Console.
ws.onopen = async function () {
await OJS.world.join('main');
await OJS.interact.input(); // You will able to chat in console!
}
/* Console:
> hi
[OWOP.js]: [128] OJS Bot: hi
*/
This function is like OJS.INTERACT.INPUT()
but it runs only once.
Example:
ws.onopen = async function () {
await OJS.world.join('main');
await OJS.interact.ask(); // Console will ask to send message once.
}
/* Console:
> hello
[OWOP.js]: [128] OJS Bot: hello
*/
This feature will enable infinite input in the command line that will evaluate inputted code.
Example:
ws.onopen = async function () {
await OJS.world.join('main');
await OJS.interact.controller(); // Console will let you type code.
}
/* Console:
> OJS.chat.send('hello')
[OWOP.js]: [128] OJS Bot: hello
*/
It's like OJS.interact.controller()
but it will ask you to type code only once.
Example:
ws.onopen = async function () {
await OJS.world.join('main');
await OJS.interact.eval(); // Console will ask to type code once.
}
/* Console
> OJS.chat.send('F')
[OWOP.js]: [128] OJS Bot: F
*/
Methods for interacting with OWOP's world!
Use this to join worlds.
OJS.world.join('main');
Use this to leave the current world.
OJS.world.leave()
This will move your bot cursor.
OJS.world.move(999, 999);
Use this to place pixels. (tileXY) PixelQuota for bots are same as for normal players!
OJS.world.setPixel(0, 0, [0,0,0]);
If color isn't defined (OJS.world.setPixel(X, Y)
) then it will take the color from OJS.player.color
. So, if you need to place many pixels with one color, use:
OJS.world.setColor([r, g, b]);
OJS.world.setPixel(0,0);
You can clear chunks with this function. (Admin/mod rank is required.)
OJS.world.clearChunk(0,0)
You can protect chunks with this function. (Admin/mod rank is required.)
OJS.world.protectChunk(0, 0, 1)
Choose the selected color of bot, as shown above.
OJS.world.setColor([255, 255, 255])
You can choose the selected tool of the bot.
OJS.world.setTool(4);
List of id-tools:
0: 'cursor',
1: 'move',
2: 'pipette',
3: 'eraser',
4: 'zoom',
5: 'fill',
6: 'paste',
7: 'export',
8: 'line',
9: 'protect'
Teleports to player with the specified ID. Sometimes it might not work.
Example:
OJS.world.tp(128);
Follow player by ID. Sometimes it might not work.
Enabling:
OJS.world.follow.enable(128);
Disabling:
OJS.world.follow.disable();
Player values!
Returns the ID of the bot.
Returns the rank of the bot.
Returns the X coordinate of the bot.
OJS.player.x // 156
Returns the Y coordinate of the bot.
OJS.player.y // 24
Returns the selected color of the bot.
OJS.player.color // [135, 54, 45]
Returns all players that was found. (Might not be very accurate).
It has all options that the original OWOP client has.
class: null,
chunkSize: 16,
netUpdateSpeed: 20,
clusterChunkAmount: 64,
maxWorldNameLength: 24,
worldBorder: 0xFFFFF,
chatBucket: [4, 6]
Returns ID of tools
Every verification-keys here.
Returns OpCodes.
Utilities, which make programming MUCH easier. Expect to use them all over your code.
One of most important functions. You need to paste it in message
event.
Example:
ws.onmessage = function(data) {
OJS.chat.recvModifier(data.data)
OJS.util.messageHandler(data.data)
};
The localStorage emulation in Node.JS by me. :) It will be saved even after closing app.
In the beginning of localStorage using you need to create the localStorage database, and only after that use all functions of it.
Usage:
function OJS_LS() {
OJS.util.localStorage.setItem('b', 'c')
}
if(!OJS.util.localStorage.isCreated()) {
await OJS.util.localStorage.create()
setTimeout(function () {
OJS_LS()
},200)
} else {
OJS_LS()
}
Default function from browser. Set item to localStorage.
OJS.util.localStorage.setItem('a', 'b');
Get item from localStorage.
OJS.util.localStorage.getItem('a'); // 'b'
Remove item from localStorage.
OJS.util.localStorage.removeItem('a')
Clear everything from localStorage.
OJS.util.localStorage.clearStorage()
Checks if localStorage is created. Returns a boolean value.
OJS.util.localStorage.isCreated() // true
That's all! Thank you for reading the documentation. Ask your questions in my Discord: Eff the cops#1877