• TeamSpeak has reported a vulnerability in it's client that can potentially lead to RCE. A new version has been released that fixes it. So please update the client in your bot installation as soon as possible as well. Click here for more information.
  • If you need help or want to discuss things, you now can also join us on our Discord Server!

EN [Request] What's wrong with that code?

Wedz0ff

New Member
Hello, i'm trying to modify a mass poke script to poke only specifics server groups, i dunno why it's not wrong.

Code:
registerPlugin({
    name: 'Privat message or poke to all clients',
    version: '1.0',
    description: 'Send privat message or poke to all clients',
    author: 'Filtik <[email protected]>',
    vars: [{
        name: 'adminarray',
        title: 'IDs which have allowed to send:',
        indent: 1,
        type: 'array',
        vars: [{
            name: 'ID',
            title: 'TS-Users ID',
            indent: 2,
            type: 'string'
        }]
    }]
}, function(sinusbot, config) {
    var engine = require('engine');
    var backend = require('backend');
    var event = require('event');
    require('event').on('load', function() {
        var lib = require ('OKlib.js');
        main(lib);
    });
    function main(lib){
        event.on('chat', function(ev) {
        if (!ev.client.isSelf()) {
            var parts = ev.text.split(" ");
            if (parts[0] == "!pmtoall" && parts[1] != "") {
                var client = ev.client;
                config.adminarray.forEach(function(row) {
                    if (row.ID == client.uid())
                    {
                        var clients = backend.getClients();
                        var currentClients = backend.getClients();
                        for (var i in  currentClients){
                            var currentClient = currentClients[i];
                            for (var j in config.serverGroups){
                                   if (lib.client.isMemberOfGroup(currentClient, 128)){
                                       currentClient.poke(ev.text.replace(parts[0]+" ", ""));
                                   }
                               }
                           }
                        return;
                    }
                });
            }
        }
    });
    } 
});
Can any1 help me? :)
 

Relentless

Donor
is awesome!
is uber awesome!
Contributor
First of all, you have the event module defined two times. If you write:
JavaScript:
var event = require('event')
You don't need to define it before the event. You can just write:
JavaScript:
event.on('load', () => { // the arrow only works with sinus 1.0.0
event.on('load', function (){ // this is for below 1.0.0
However, I recoded it a bit for you. You can take a look and adjust it as your needs. It's
not tested but I guess it should work.
JavaScript:
//@ts-check
//@ts-check
registerPlugin({
  name: 'Privat message or poke to all clients',
  version: '1.0',
  description: 'Send privat message or poke to all clients',
  author: 'Filtik <[email protected]>',
  vars: [
    {
      name: 'senderWhitelist',
      title: 'Whitelisted Client UIDs who are allowed to send the command',
      type: 'strings'
    },
    {
      name: 'targetWhitelist',
      title: 'Whitelisted Servergroup IDs which are allowed to be messaged when someone entered the command',
      type: 'strings'
    }
  ]
},
function (sinusbot, config) {
  const engine = require('engine');
  const backend = require('backend');
  const event = require('event');
  event.on('load', () => {
    const lib = require('OKlib.js');
    main(lib);
  });
  function main(lib) {
    // Global Vars
    const senderWhitelist = config.senderWhitelist;
    const targetWhitelist = config.targetWhitelist;
    // Chat Event
    event.on('chat', ev => {
      let client = ev.client;
      if (client.isSelf()) return
      let msg = ev.text;
      let msgParts = msg.split(' ');
      if (senderWhitelist.includes(client.uid()) && msgParts[0] == '!pmtoall' && msgParts[1] != '') {
        let clients = backend.getClients();
        clients.forEach(e => {
          if (lib.client.isMemberOfOne(e, targetWhitelist))
            e.poke(msg.replace(msgParts[0] + ' ', ''));
        });
      }
    })
  }
});
 

Relentless

Donor
is awesome!
is uber awesome!
Contributor
somehow it didn't work, it doesn't appear on Scripts tab.
You are probably using an old version which doesn't support this type of code.
Tell me what version of Sinus you use and I'll rewrite it for you.
 

Relentless

Donor
is awesome!
is uber awesome!
Contributor
Solltest du Version behalten wollten, sollte das Script folgendermaßen funktionieren:
JavaScript:
registerPlugin({
  name: 'Privat message or poke to all clients',
  version: '1.0',
  description: 'Send privat message or poke to all clients',
  author: 'Filtik <[email protected]>',
  vars: [
    {
      name: 'senderWhitelist',
      title: 'Whitelisted Client UIDs who are allowed to send the command',
      type: 'strings'
    },
    {
      name: 'targetWhitelist',
      title: 'Whitelisted Servergroup IDs which are allowed to be messaged when someone entered the command',
      type: 'strings'
    }
  ]
},

function (SinusBot, config) {

  var engine = require('engine');
  var backend = require('backend');
  var event = require('event');

  event.on('load', function () {
    var lib = require('OKlib.js');
    main(lib);
  });

  function main(lib) {

    // Global Vars
    var senderWhitelist = config.senderWhitelist;
    var targetWhitelist = config.targetWhitelist;

    // Chat Event
    event.on('chat', function (ev) {
      var client = ev.client;
      if (client.isSelf()) return
      var msg = ev.text;
      var msgParts = msg.split(' ');
      if (senderWhitelist.indexOf(client.uid()) > -1 && msgParts[0] == '!pmtoall' && msgParts[1] != '') {
        var clients = backend.getClients();
        clients.forEach(function (e) {
          if (lib.client.isMemberOfOne(e, targetWhitelist))
            e.poke(msg.replace(msgParts[0] + ' ', ''));
        });
      }
    });
  }
});
 

Wedz0ff

New Member
Thank you! I changed to check if sender is member of group as well, just a last thing, how can I send a message to sender like: "Done! You sent a poke to XX clients".

Actual code:
Code:
registerPlugin({
  name: 'Mass Poke',
  version: '1.0',
  description: 'Send private message or poke to all clients',
  author: 'abcd',
  vars: [
    {
      name: 'senderWhitelist',
      title: 'Whitelisted Servergroup IDs who are allowed to send the command',
      type: 'strings'
    },
    {
      name: 'targetWhitelist',
      title: 'Whitelisted Servergroup IDs which are allowed to be messaged when someone entered the command',
      type: 'strings'
    }
  ]
},

function (SinusBot, config) {

  var engine = require('engine');
  var backend = require('backend');
  var event = require('event');

  event.on('load', function () {
    var lib = require('OKlib.js');
    main(lib);
  });

  function main(lib) {

    // Global Vars
    var senderWhitelist = config.senderWhitelist;
    var targetWhitelist = config.targetWhitelist;

    // Chat Event
    event.on('chat', function (ev) {
      var client = ev.client;
      if (client.isSelf()) return
      var msg = ev.text;
      var msgParts = msg.split(' ');
      if (lib.client.isMemberOfOne(client, senderWhitelist) && msgParts[0] == '!poke' && msgParts[1] != '') {
        var clients = backend.getClients();
        clients.forEach(function (e) {
          if (lib.client.isMemberOfOne(e, targetWhitelist))
            e.poke(msg.replace(msgParts[0] + ' ', ''));
        });
       }
    });
  }
})
 
Last edited:

Relentless

Donor
is awesome!
is uber awesome!
Contributor
With the following code, the sender will get poke with the amount of clients
that were messaged. If you want the sender to be messaged and not poked
change client.poke to client.chat
Here you go:
JavaScript:
/* eslint-disable semi */
registerPlugin({
  name: 'Mass Poke',
  version: '1.0',
  description: 'Send private message or poke to all clients',
  author: 'abcd',
  vars: [
    {
      name: 'senderWhitelist',
      title: 'Whitelisted Servergroup IDs who are allowed to send the command',
      type: 'strings'
    },
    {
      name: 'targetWhitelist',
      title: 'Whitelisted Servergroup IDs which are allowed to be messaged when someone entered the command',
      type: 'strings'
    }
  ]
},

function (SinusBot, config) {

  var engine = require('engine');
  var backend = require('backend');
  var event = require('event');

  event.on('load', function () {
    var lib = require('OKlib.js');
    main(lib);
  });

  function main(lib) {

    // Global Vars
    var senderWhitelist = config.senderWhitelist;
    var targetWhitelist = config.targetWhitelist;

    // Chat Event
    event.on('chat', function (ev) {
      var client = ev.client;
      if (client.isSelf()) return
      var msg = ev.text;
      var msgParts = msg.split(' ');
      if (lib.client.isMemberOfOne(client, senderWhitelist) && msgParts[0] == '!poke' && msgParts[1] != '') {
        var clients = backend.getClients();
        var clientCount = 0;
        clients.forEach(function (e) {
          if (lib.client.isMemberOfOne(e, targetWhitelist)) {
            e.poke(msg.replace(msgParts[0] + ' ', ''));
            clientCount++;
          }
        });
        client.poke('Done! You sent a poke to ' + clientCount + 'clients.');
      }
    });
  }
});
 

Wedz0ff

New Member
With the following code, the sender will get poke with the amount of clients
that were messaged. If you want the sender to be messaged and not poked
change client.poke to client.chat
Here you go:
JavaScript:
/* eslint-disable semi */
registerPlugin({
  name: 'Mass Poke',
  version: '1.0',
  description: 'Send private message or poke to all clients',
  author: 'abcd',
  vars: [
    {
      name: 'senderWhitelist',
      title: 'Whitelisted Servergroup IDs who are allowed to send the command',
      type: 'strings'
    },
    {
      name: 'targetWhitelist',
      title: 'Whitelisted Servergroup IDs which are allowed to be messaged when someone entered the command',
      type: 'strings'
    }
  ]
},

function (SinusBot, config) {

  var engine = require('engine');
  var backend = require('backend');
  var event = require('event');

  event.on('load', function () {
    var lib = require('OKlib.js');
    main(lib);
  });

  function main(lib) {

    // Global Vars
    var senderWhitelist = config.senderWhitelist;
    var targetWhitelist = config.targetWhitelist;

    // Chat Event
    event.on('chat', function (ev) {
      var client = ev.client;
      if (client.isSelf()) return
      var msg = ev.text;
      var msgParts = msg.split(' ');
      if (lib.client.isMemberOfOne(client, senderWhitelist) && msgParts[0] == '!poke' && msgParts[1] != '') {
        var clients = backend.getClients();
        var clientCount = 0;
        clients.forEach(function (e) {
          if (lib.client.isMemberOfOne(e, targetWhitelist)) {
            e.poke(msg.replace(msgParts[0] + ' ', ''));
            clientCount++;
          }
        });
        client.poke('Done! You sent a poke to ' + clientCount + 'clients.');
      }
    });
  }
});
Thanks! now it's working like I wanted.
 

Similar threads

Top