The documentation I had already found, but I did not understand how to use it.
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();
}
});
So you think as it is, the code is good?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.
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>
Hi? I didn't understand, sorry!Still old engine tho using the sinusbot object is a no no
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)
})
}
})
var cid = client.getChannels()[0].id()
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
Should also return multiple clients in that case^^getClientByUniqueID(unique)
returns an (online) client by its permanent id