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

EN [Request] Notification Poke/Chat Servergroup

K1ller0561

Insider
Insider
Hello everybody,

I am looking for a script, which is linked to the verification php script. For example, if I have 3 server groups with 12+, 16+, and 18+, but a user does not have any of these 3 server groups, he should get a poke / chat message. Is that possible or not? Because the scripts (download section) I was looking for were not quite right. I look forward to your suggestions.

- Killer0561
 
To poke/message a User when he is not in Servergroup x,y or z every t amount of time is possible. But it would be an Sinusbot script only, nothing linked to any extern php scripts.
 
You could link php and js script using database.
Although it would get really messy if php script is huge or the part you are trying to merge is huge, less data, the better.
 
E.g you could create mysql table, connect sinusbot script to that db, after user if verified (got his server group), put entry into db, with user uid, and set him as verified, then same connect into same table in your php script, and simply check if user is verified or not.
 
It does not necessarily have to be in mysql. For me that would be enough in javascript. Short query, if the user is in one of the 3 groups, if not, he gets a message via poke or chat.
 
If anyone won't create it before me, I will do it.

(If you just want a script, that pokes a client that doesn't have X or Y or Z group - every X seconds)

#imatschool
 
Last edited:
I'm really new at coding in js, so, hope it will work like you wanted, here you are:
(It was working really good for me)
JavaScript:
registerPlugin({
    name: 'Not In Group Poker',
    version: '0.1',
    backends: ['ts3'],
    description: 'Poke / message clients, that aren\'t in a specified group, every X seconds',
    author: 'DrWarpMan',
    vars: [
        {
            name: 'notinGroupPoker_status',
            title: 'Enabled?',
            type: 'select',
            options: [
                "Yes",
                "No"
            ]
        },
        {
            name: 'notinGroupPoker_time',
            title: 'Time (in seconds), how often will the bot poke / message the user - every X seconds',
            type: 'number',
            conditions: [
                { field: 'notinGroupPoker_status', value: 0 }
            ],
            placeholder: 120
        },
        {
            name: 'notinGroupPoker_message',
            title: 'Poke / Chat Message',
            type: 'string',
            conditions: [
                { field: 'notinGroupPoker_status', value: 0 }
            ]
        },
        {
            name: 'notinGroupPoker_messagetype',
            title: 'Message Type',
            type: 'select',
            options: [
                "Poke",
                "Chat"
            ],
            conditions: [
                { field: 'notinGroupPoker_status', value: 0 }
            ]
        },
        {
            name: 'notinGroupPoker_groups',
            title: 'Groups ID list',
            type: 'array',
            vars: [
                {
                title: 'Server Group ID',
                name: 'group_id',
                type: 'number'
                }
            ],
            conditions: [
                { field: 'notinGroupPoker_status', value: 0 }
            ]
        }
    ]
}, function (sinusbot, config) {
    var engine = require('engine');
    var backend = require('backend');
    
    var pTime;
    var pGroups = [];
    if(config.notinGroupPoker_status == 1) {
        engine.log("Group Poker is disabled. Script won\'t start!");
        return;
    }
    if(config.notinGroupPoker_groups == undefined) {
        engine.log("Groups are not defined! Script won\'t work!");
        return;
    } else 
    {
        for (var i = 0; i < config.notinGroupPoker_groups.length; i++) {
            pGroups.push(config.notinGroupPoker_groups[i].group_id.toString());
        }
    }
    if(config.notinGroupPoker_message == undefined) {
        engine.log("Group Poker message is undefined, poke / chat message will be send without a text!");
        config.notinGroupPoker_message = "";
    }
    if(config.notinGroupPoker_time == undefined) {
        engine.log("Group Poker time is undefined, changing to default - 120.");
        pTime = 120;
    } else if(config.notinGroupPoker_time < 1)
    {
        engine.log("Group Poker time is lower than number one, changing to default - 120.");
        pTime = 120;
    } else if(config.notinGroupPoker_time > 0)
    {
        pTime = config.notinGroupPoker_time;
    }
    setInterval(function(){
    
        if(backend.isConnected()) {
            backend.getClients().forEach(function(user) {
                checkGroups(user);
            });
          
        }
    }, pTime * 1000);
    function checkGroups(client)
    {
        var clientGroups = [];
        client.getServerGroups().forEach(
            function (group) {
                clientGroups.push(group.id());
            }
        )
        if(!ifArrContainsAnotherArr(pGroups, clientGroups))
        {
            var message = config.notinGroupPoker_message;
            if(config.notinGroupPoker_messagetype == undefined || config.notinGroupPoker_messagetype == 0) {
                client.poke(message);
            } else if(config.notinGroupPoker_messagetype == 1)
                client.chat(message);
        }
    }
    function ifArrContainsAnotherArr(fArr, sArr) {
        return sArr.some(function (v) {
            return fArr.indexOf(v) >= 0;
        });
    };
    
});

If you find any bugs, or things you want to add there, just write it.
 

Attachments

Last edited:
This Script works good, but how can i set, the message was directly send on connect to the server?

- Killer0561
 
So, that the message will be sent also, on client's connection? If he doesn't have that groups?
 
Correct. The message should get the client when it connects to the server. That would be great if that were possible.

- Killer0561
 
Again a question: Is it possible that Poke and Chat at the same time when connecting the server gets the client?

- Killer0561
 
I am actually about to finish the script: I mean it will be functional but it still needs some polishing before full publication into my resources.
 
Back
Top Bottom