• If you need help or want to discuss things, you now can also join us on our Discord Server!
  • A first preview of the unlimited version of SinusBot can be found in the Upcoming Changes thread. A version for Windows will follow, but we don't have a release date, yet.
OKlib

OKlib 1.0.8

No permission to download
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

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.
Author
Diesmon
Downloads
2,929
Views
18,415
First release
Last update
Rating
4.00 star(s) 7 ratings

More resources from Diesmon

  • Default-Channel+
    TS3 Default-Channel+
    The bot moves itself back into an default channel if the current channel gets empty.
  • Server Rules
    TS3 Server Rules
    Messages clients the server rules (on connect or channel join) and can assign groups or kick them
  • AFK Mover
    AFK Mover
    Moves users when they are AFK (Away, Muted, Deaf) to an AFK-Channel
  • Channel Lift
    Channel Lift
    Provides enter and exit channels for "fast-travelling" on large servers

Latest updates

  1. 1.0.8 - Derp

    Forgot to increase the version string in the last update... NOT THIS TIME. This is now the...
  2. 1.0.7 - Small bug fix

    This update only fixes a wrong return value in one of the array functions. This means the...
  3. Version 1.0.6

    Added: helper.generatePassword Added the generate Password function to the lib which creates a...

Latest reviews

on Debian 9, and with 0 error on logs when i add that script toggether with "Deault-channel+" sinusbot take disconnect from teamspeak after 1-2h online. when i remove it is totaly ok so is for sure problem of that 2 scripts.
Nutze die Lib für einen Großteil meiner Scripts. Sie ist praktisch und spart eine Menge Zeit, da sie mit sinnvollen und benötigten Funktionen hilft. Wenn man ein Fehler drin ist, kann man sich direkt an die freundlichen Coder wenden und es wird sofort behoben. Ich kann die Library nur empfehlen.
Hello, great script:D

If you need a new update, because some scripts don’t change anymore, here’s the message:
2019-01-15T18:37:21+01:00 [AutomaticServerGroupAssigner:133:20] OKlib could not be loaded or is not compatible with this script. Make sure the latest OKlib version is installed. The latest version can always be downloaded from https://forum.sinusbot.com/resources/oklib.325/
Diesmon
Diesmon
SInusbot 1.0.0? If so then that is a bug, since there is no later version and it is probably due to an loading error in the new version. Aka the ServerGroupAssinger loads before the bot loads the OKlib. This results in an empty import and the triggering of the message. In the old version they got loaded in order, but maybe that broke in the 1.0.0

I'm currently looking into this and talking with flyth about this.
Guess would be great, but doesnt work for me :/
This script simply doesnt load when restarting the bot. I was trying to use DefaultChannel+ with your library but both of them dont show up in the scripts tab
Diesmon
Diesmon
Sound like not the latest SinusBot version. Minimum is 0.13.37 :) :)
Its OK i guess
Macht das was es machen soll.
Weiter so ihr beiden
Top