• 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

DrWarpMan

Well-Known Member
Contributor
Insider
Here you are, with the connect notification and "both" poke & chat message type. (If you want to poke & chat only on connection, say it)
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",
                "Both (Poke and Chat)"
            ],
            conditions: [
                { field: 'notinGroupPoker_status', value: 0 }
            ]
        },
        {
            name: 'notinGroupPoker_groups',
            title: 'Groups ID list (that if user is not in, he will get notified)',
            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 event = require('event');
 
    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);
            else if(config.notinGroupPoker_messagetype == 2)
            {
                client.chat(message);
                client.poke(message);
            }
        }
    }
    function ifArrContainsAnotherArr(fArr, sArr) {
        return sArr.some(function (v) {
            return fArr.indexOf(v) >= 0;
        });
    };
    setTimeout(function(){
            
        event.on('clientMove', function (ev) {
            if(ev.fromChannel == null)
            {
                checkGroups(ev.client);
            }
        });
        
    }, 5000);
 
});

It should work xd
 

Attachments

  • notingrouppoker.js
    4.5 KB · Views: 10

r3flex

Active Member
Contributor
So basicly there is alot yet to stylize but overall conception I think is good.
There might be some bugs tho.
 

Attachments

  • groupVerifier.js
    6.9 KB · Views: 7

Vxrious

Helping Hand
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.

New in js coding, Kappa
Youre good in js code! Wish i could understand that too...
:D
 
Top