OKlib
by Tuetchen and Diesmon
This is a powerful Library for the SinusBot Script Engine,
which will simplify many common use cases for the ‘everyday’ script functions and tasks
The minimum needed SinusBot version is: 0.13.37
by Tuetchen and Diesmon
This is a powerful Library for the SinusBot Script Engine,
which will simplify many common use cases for the ‘everyday’ script functions and tasks
The minimum needed SinusBot version is: 0.13.37
For Users:
If your log says something like: “OKlib is missing, please install the OKlib in order to use this script”
Then you simply just need to download this Resource, drop it into your Script folder and restart your Bot.
After that you can forget about it and don’t need to read any further. Have a super OK day.
For Script Developers:
Full documentation can be found here
The Library is heavily Array orientated so you can reduce your script code that comes from bulk tasks by a lot.
If you want to contribute to it, feel free to make a pull request on GitHub
In order to use the OKlib inside your scripts you need to import it first. This can be done via:
Code:
var lib = require ('OKlib.js');
But because the SinusBot loads scripts in a undefined order, you need to place your whole Scriptcode inside a on-load event, in order to be sure that the OKlib is loaded and ready to use when you start calling lib-functions in your script.
Code:
event.on('load', function() {
});
Example code for this would be
Code:
registerPlugin({
name: 'Name',
version: '1.0',
description: 'Description',
author: 'Author',
}, function(sinusbot, config) {
require('event').on('load', function() {
var lib = require ('OKlib.js');
main(lib);
});
function main(lib){
/*
*All of your code
*/
}
});
To make sure that the script user has also the OKlib installed you can use this bit of code inside your script to make sure every user knows how to install the OKlib.
Code:
var lib = require('OKlib.js');
var version = '1.0.6'; //version you want of the lib
if(!lib || !lib.general.checkVersion(version)){
require('engine').log("OKlib could not be loaded or the installed version is not compatible with this script. The required version is: " + version + ". The latest version can always be downloaded from https://forum.sinusbot.com/resources/oklib.325/");
return;
}
main(lib);
Here an example with filled code
Code:
registerPlugin({
name: 'Example',
version: '13.37',
description: 'Perfect 5/7',
author: 'OK',
}, function(sinusbot, config) {
require('event').on('load', function() {
var lib = require('OKlib.js');
var version = '1.0.6'; //version you want of the lib
if(!lib || !lib.general.checkVersion(version)){
require('engine').log("OKlib could not be loaded or the installed version is not compatible with this script. The required version is: " + version + ". The latest version can always be downloaded from https://forum.sinusbot.com/resources/oklib.325/");
return;
}
main(lib);
});
function main(lib){
var backend = require('backend');
var engine = require('engine');
//This code will print out every client on the server with the string 'bot' inside his name
engine.log("Clients with 'bot' in name: " + lib.array.toString(lib.client.getClients("name", "bot", backend.getClients(), lib.comparator.containsIgnoreCase)));
//Or this code here to get all clients with a packetloss lower than 10% returned as a Client-Object array into the variable
var clients_with_low_packetloss = lib.client.getClients("getPacketLoss", 10, backend.getClients(), lib.comparator.less);
engine.log("clients with packetloss = " + lib.helper.printObject(clients_with_low_packetloss));
//now we can easily make a new array by filtering out every client with a certain servergroup
var filltered_by_Servergroups = [];
for(var i = 0; i < clients_with_packetloss.length; i++){
if(!lib.client.isMemberOfGroup(clients_with_low_packetloss[i], 11))
filltered_by_Servergroups.push(clients_with_low_packetloss[i]);
}
engine.log("clients with under 10% packetloss but without servergroup 11: " + lib.helper.printObject(filltered_by_Servergroups));
//you can also convert many types of objects to one of its attribute. Here the example Clients-Objects to UIDs
var clientUIDs = lib.client.toUIDs(filltered_by_Servergroups);
engine.log("UIDs of clients with under 10% packetloss and not servergroup 11: " +lib.helper.printObject(clientUIDs));
}
});
The full Documentation for all function calls and how to use them properly can be found here
Make sure to check it out to fully understand the Library.
Full script template for you to use:
Code:
registerPlugin({
name: '',
version: '',
description: '',
author: '',
}, function(sinusbot, config) {
require('event').on('load', function(){
var lib = require('OKlib.js');
var version = '1.0.6'; //version you want of the lib
if(!lib || !lib.general.checkVersion(version)){
require('engine').log("OKlib could not be loaded or the installed version is not compatible with this script. The required version is: " + version + ". The latest version can always be downloaded from https://forum.sinusbot.com/resources/oklib.325/");
return;
}
main(lib);
});
function main(lib){
//All of your codes goes here
}
});
This Library will also get improved constantly. There are many more things we want to include into it.
If you also got some ideas on what to add, feel free to discuss it in on the Discussion page. Don't use the review function for that.
We hope this Library will get used a lot and does indeed help to make better or more complex scripts with less effort and way less copy&paste work.
If you also got some ideas on what to add, feel free to discuss it in on the Discussion page. Don't use the review function for that.
We hope this Library will get used a lot and does indeed help to make better or more complex scripts with less effort and way less copy&paste work.
I'm currently looking into this and talking with flyth about this.