Deprecated: Use of "parent" in callables is deprecated in /var/www/html/forum/src/vendor/league/flysystem-eventable-filesystem/src/EventableFilesystem.php on line 431
  • 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] Write BOT add ServerGroup

Fellow

Helping Hand
Hey, any script for this:

BOT says:

Choose one group (Age):
A - 12
B - 14
C- 16

After wirte a correct awnser, BOT give question:

Choose one group (Gender)
A - Male
B - Female

Ty guys.
 

Montiary

Active Member
Contributor
here we go, fully tested and its working.

you can add unlimeted question each question can have unlimeted answers.

first you need to add a quest
than add a message : How old are you ? Answer 0 = >16 1 = >18 .....
Than you need to set the group id for each answer and there you go :D


Code:
registerPlugin({
    name: 'Montys Choice Group',
    version: '0.1.0',
    backends: ['ts3'],
    engine: '>= 0.13.37',
    description: 'User can choice groups',
    author: 'Montiary',
    vars: [{
        name: 'ShowLog',
        indent: 1,
        title: 'Show Logs?',
        type: 'select',
        options: [
            'NO',
            'YES'
        ]
    }, {
        name: "Quest",
        title: 'Quest',
        type: 'array',
        vars: [{
            name: 'Message',
            indent: 1,
            title: 'Message',
            type: 'string'
        }, {
            name: 'GroupIDs',
            indent: 1,
            title: 'GroupIDs',
            type: 'array',
            vars: [{
                name: 'GroupID',
                indent: 1,
                title: 'Group ID',
                type: 'number'
        }]}]
    }]
},     function(sinusbot, config) {
        var engine = require('engine');
        var backend = require('backend');
        var event = require('event');


        var ShowLog = config.ShowLog;

        if (typeof ShowLog == "undefined" || ShowLog == '') {
            ShowLog = false;
        }

        var init = config.Quest;

        if (init === undefined) {
            engine.log('Not definated - beark loading');
            return;
        }

        event.on('chat', function(ev) {
            var Message = ev.text;
            var Client = ev.client;
            
            if(Client.isSelf()){
                return;
            }
            
            if(ShowLog){engine.log('Got message "'+ Message +'" from '+ Client.name());}
            
            if(isNaN(Message) == false){
                var QuestNumber = nextQuest(Client,false);
                if(ShowLog){engine.log('QuestNumber "'+ QuestNumber);}
                if (typeof QuestNumber === "undefined") {
                    // no more quest
                }else{
                    if(parseInt(Message) >= init[QuestNumber].GroupIDs.length){
                        //invalid number
                    }else{
                        Client.addToServerGroup(init[QuestNumber].GroupIDs[parseInt(Message)].GroupID);
                        nextQuest(Client,true);
                    }
                }
            }
        });

        event.on('clientMove', function(ev) {
            var Client = ev.client;
            var Channel = ev.toChannel;

            if (typeof FromChannel == 'undefined' || FromChannel == '') { // joined
                nextQuest(Client,true);
            }
            
        });
        
        
        function nextQuest(Client,SendMessage) {
            var ClientServerGroups = Client.getServerGroups();
            var tmp = true;
            for(var i = 0; i < init.length; i++){
                tmp = true;
                for(var j = 0; j < init[i].GroupIDs.length; j++){
                    for(var n = 0; n < ClientServerGroups.length; n++){
                        if(ClientServerGroups[n].id() == init[i].GroupIDs[j].GroupID){
                            tmp = false;
                        }
                    }
                }
                if(tmp == true && SendMessage == true){
                    Client.chat(init[i].Message);
                    return;
                }else if(tmp == true && SendMessage == false){
                    return i;
                }
            }
        }
        
    }
);
 

Fellow

Helping Hand
here we go, fully tested and its working.

you can add unlimeted question each question can have unlimeted answers.

first you need to add a quest
than add a message : How old are you ? Answer 0 = >16 1 = >18 .....
Than you need to set the group id for each answer and there you go :D


Code:
registerPlugin({
    name: 'Montys Choice Group',
    version: '0.1.0',
    backends: ['ts3'],
    engine: '>= 0.13.37',
    description: 'User can choice groups',
    author: 'Montiary',
    vars: [{
        name: 'ShowLog',
        indent: 1,
        title: 'Show Logs?',
        type: 'select',
        options: [
            'NO',
            'YES'
        ]
    }, {
        name: "Quest",
        title: 'Quest',
        type: 'array',
        vars: [{
            name: 'Message',
            indent: 1,
            title: 'Message',
            type: 'string'
        }, {
            name: 'GroupIDs',
            indent: 1,
            title: 'GroupIDs',
            type: 'array',
            vars: [{
                name: 'GroupID',
                indent: 1,
                title: 'Group ID',
                type: 'number'
        }]}]
    }]
},     function(sinusbot, config) {
        var engine = require('engine');
        var backend = require('backend');
        var event = require('event');


        var ShowLog = config.ShowLog;

        if (typeof ShowLog == "undefined" || ShowLog == '') {
            ShowLog = false;
        }

        var init = config.Quest;

        if (init === undefined) {
            engine.log('Not definated - beark loading');
            return;
        }

        event.on('chat', function(ev) {
            var Message = ev.text;
            var Client = ev.client;
          
            if(Client.isSelf()){
                return;
            }
          
            if(ShowLog){engine.log('Got message "'+ Message +'" from '+ Client.name());}
          
            if(isNaN(Message) == false){
                var QuestNumber = nextQuest(Client,false);
                if(ShowLog){engine.log('QuestNumber "'+ QuestNumber);}
                if (typeof QuestNumber === "undefined") {
                    // no more quest
                }else{
                    if(parseInt(Message) >= init[QuestNumber].GroupIDs.length){
                        //invalid number
                    }else{
                        Client.addToServerGroup(init[QuestNumber].GroupIDs[parseInt(Message)].GroupID);
                        nextQuest(Client,true);
                    }
                }
            }
        });

        event.on('clientMove', function(ev) {
            var Client = ev.client;
            var Channel = ev.toChannel;

            if (typeof FromChannel == 'undefined' || FromChannel == '') { // joined
                nextQuest(Client,true);
            }
          
        });
      
      
        function nextQuest(Client,SendMessage) {
            var ClientServerGroups = Client.getServerGroups();
            var tmp = true;
            for(var i = 0; i < init.length; i++){
                tmp = true;
                for(var j = 0; j < init[i].GroupIDs.length; j++){
                    for(var n = 0; n < ClientServerGroups.length; n++){
                        if(ClientServerGroups[n].id() == init[i].GroupIDs[j].GroupID){
                            tmp = false;
                        }
                    }
                }
                if(tmp == true && SendMessage == true){
                    Client.chat(init[i].Message);
                    return;
                }else if(tmp == true && SendMessage == false){
                    return i;
                }
            }
        }
      
    }
);

Instalation? Normal script? Im a beginner on sinusbot.
Ty for help.
 

Montiary

Active Member
Contributor
save the code in a javascript file (example.js) and than but it into the script folder and restart the bot
 

Fellow

Helping Hand
Its working but...

Next message dont appear.
Just bot talk if dont have all groups.
And see image :)
 

Attachments

  • Sem Título.png
    Sem Título.png
    243.7 KB · Views: 24
Last edited:

Fellow

Helping Hand
Age, Gender and Friends... But if you have already Age group, bot just give two awnser...

Sorry for my english, I'm Portuguese.
 

Fellow

Helping Hand
If you are already in a group, BOT will only ask you for the others and next awnser d'ont appear...
 
Last edited:
Top