• 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.

How to use the new documentation?

Status
Not open for further replies.

LmGOD

New Member
I've been trying to figure out how to use the new documentation (v2), and I don't have found this anywhere! For example, a simple code: cause the client kick (from channel) if starts a recording in specific channel. (with new documentation only)
 
Last edited:

LmGOD

New Member
The documentation I had already found, but I did not understand how to use it.

I got what I wanted, but the code got really confusing and dumb, look:
Code:
registerPlugin({
    name: 'No Recording On Channel!',
    version: '1.0',
    description: 'User will be kicked of the specifics channels, if start recording.',
    author: 'Luiz Matheus',
    vars: [
    {
        name: 'message',
        title: 'Message that will be sent to the client that will be kicked.',
        type: 'string'
    },{
          name: 'channels',
          title: 'Canal:',
          type: 'array'
          vars:    [{
                   name: 'channel',
                   title: 'Channels IDs',
                   type: 'channel'
          }]
    }
    ]
}, function(sinusbot, config) {
    var backend = require('backend');

    sinusbot.on('record', function(ev) {
        verifyChannels(ev);
    });

    sinusbot.on('clientMove', function(ev){
        if(backend.getClientByID(ev.clientId).isRecording()){
            verifyChannels(ev);
        }
    });

    function verifyChannels(ev){
        var clientChannel = getChannelByClientId(ev.clientId);
        for(i = 0; i < config.channels.length; i++){
            if(config.channels[i].channel == clientChannel){
                sinusbot.log('Client ' + ev.clientNick + ' (ID: '+ev.clientId+')' +  ' has been kicked from channel (ID: '+ clientChannel +') because recording!');
                sinusbot.kickChannel(ev.clientId, config.message);
            }
        }
    }

    function getChannelByClientId(clientId){
      return backend.getClientByID(clientId).getChannels()[0].id();
    }

});

How to migrate this to new documentation, and improve the code?
 

LmGOD

New Member
Hi.

You already have improved your code ^^
The documentation just explains the existing functions and "modules" .
It is OOP (-> https://en.wikipedia.org/wiki/Object-oriented_programming) Style Javascript like Node.JS.
So you think as it is, the code is good?

And in the only part where I used some of the new documentation, I get error in the LOGs, so I did not know how to use it..
Code:
2017-09-11T06:48:59-03:00 TypeError: Cannot access member 'isRecording' of undefined at NoRecordingOnChannel.js:30:6 at EventDispatcher (<anonymous>:144:69) at Event (<anonymous>:59:17) at <unknown>

Still old engine tho using the sinusbot object is a no no
Hi? I didn't understand, sorry! :(
 

Tuetchen

Diesmon Dominator
is awesome!
Contributor
Insider
You need to use the New events and not the sinusbot.on stuff.
Cant write Code right now im on a Phone... Just take a Look at some of the recently released scripts how Events are handled there

Same with sinusbot.log and sinusbot.kick
Dont use these anymore
 

Multivitamin

Well-Known Member
Tier III
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
I am not able to test the code by myself currently, but it should look like this:
HTML:
registerPlugin({
    name: 'No Recording On Channel!',
    version: '1.0',
    description: 'User will be kicked of the specifics channels, if start recording.',
    author: 'Luiz Matheus',
    vars: [
    {
        name: 'message',
        title: 'Message that will be sent to the client that will be kicked.',
        type: 'string'
    },{
          name: 'channels',
          title: 'Canal:',
          type: 'array'
          vars:    [{
                   name: 'channel',
                   title: 'Channels IDs',
                   type: 'channel'
          }]
    }
    ]
}, function(sinusbot, config) {
    /*We dont want to use the Sinusbot variable anymore
    since it holds stuff from the old scripting engine which gets replaced
    so we can just assign a new value to it*/
    var sinusbot = null

    var engine = require("engine")
    var event = require("event")
  
    //https://www.sinusbot.com/docs/scripting/#eventclientrecord
    event.on('clientRecord', function(client) {
        verifyChannels(client)
    })
  
    //https://www.sinusbot.com/docs/scripting/#eventclientmove
    event.on('clientMove', function(ev){
        if(!ev.client.isRecording()) return
        verifyChannels(ev.client)
    })

    function verifyChannels(client){
        var cid = client.getChannels()[0].id()
        config.channels.forEach(function(id) {
            if(id != cid) return
            engine.log('Client '+ client.nick() +' (ID: '+ client.id() +') has been kicked from channel (ID: '+ cid +') because recording!')
            client.kickFromChannel(config.message)
        })
    }


})
 

Tuetchen

Diesmon Dominator
is awesome!
Contributor
Insider
Dont really like the
Code:
var cid = client.getChannels()[0].id()
Cant a user be in multiple channels at the same time? I think when a user joines the same server with multiple tabs its still counted as one user beeing in multiple channels? And in that case it will fail
 

Multivitamin

Well-Known Member
Tier III
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
A new User will have a new id aswell, that does not work on teamspeak

If you have another Client with the same Identity it will be a new Client Object
 

Tuetchen

Diesmon Dominator
is awesome!
Contributor
Insider
The client ID is different? I think at least the database and the Unique - of course- are equal if i connect to one server with the same identity multiple times... have to check that - but yeah even then - only a solution for teamspeak
 

Multivitamin

Well-Known Member
Tier III
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
returns an array of all channels the client is in; even if TS only uses one channel for a client at a time, other backends might provide several
 
Status
Not open for further replies.
Top