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 remove key , create a channel with password / set channel admin

Status
Not open for further replies.

good_live

Active Member
Tier III
is awesome!
V.I.P.
Contributor
Insider
Hey,
i have some questions:
1. Is it possible to remove a value that is stored with the set() function?
2. Is it possible to add a Channel with a password?
3. Is it possible to promote a user in a certain channel to channeladmin?

Edit and it would be nice if the channelCreate function returns the channelid of the created channel, so i could save the channel by channelid instead of name (because the name could be doubled).

For better understanding why this would be usefull i've added my current script here:

Code:
registerPlugin({
    name: 'Private Channel',
    version: '0.1',
    description: 'Allows certain users to create their own private channel',
    author: 'good_live',
    vars: {
        parentid: {
            title: 'ID of the parent Chanel',
            type: 'number'
            placeholder: '0'
        },
        groupid: {
            title: 'ID of the group that is allowed to create a Channel',
            type: 'number'
            placeholder: '0'
        },
    }
}, function(sinusbot, config) {
    sinusbot.on('chat', function(ev) {
        if(ev.msg.indexOf('!private') == 0){
            var groupid = config.groupid;
            var i = ev.clientServerGroups.length;
            while (i--) {
                if (ev.clientServerGroups[i].i == groupid) {
                    var cname = ev.msg.replace("!private", "");
                    var key = ev.clientUid + "_private";
                    var obj = get(key);
                    if(cname == ""){
                        chatPrivate(ev.clientId, 'Usage: !private <channelname>');
                    }else if(obj != undefined){
                        chatPrivate(ev.clientId, 'You already have a private channel: ' + obj);
                    }else{
                        channelCreate({ name: cname, parent: config.parentid, topic: ev.clienNick, enc: 1, perm: 1, sperm: 0, order: 0, maxClients: 10 });
                        chatPrivate(ev.clientId, 'Channel: ' + cname + ' created.');
                        set(key, cname);
                    }
                    return true
                }
            }
            chatPrivate(ev.clientId, 'You are not allowed to create a private Channel');
        }
    });
});

Edit:It would be nice if the channelCreate function returns the channelid of the created channel, so i could save the channel by channelid instead of name (because the name could be doubled).
 
Last edited:

Raphraph

Donor
is awesome!
Contributor
Insider
1. I don't know. Asking @flyth
2. I don't know... Asking @flyth
3. No, this feature isn't available for know.

Yes this would be a great feature, but do you know that there cannot be 2 channels with the exactly same name? :)

And I read your plugin and I saw that there are some kind of errors :)
I rewrote it a little bit...

Code:
registerPlugin({
    name: 'Private Channel',
    version: '0.1',
    description: 'Allows certain users to create their own private channel',
    author: 'good_live',
    vars: {
        parentid: {
            title: 'ID of the parent Chanel',
            type: 'number',
            placeholder: '0'
        },
        groupid: {
            title: 'ID of the group that is allowed to create a Channel',
            type: 'number',
            placeholder: '0'
        } // removed a comma
    }
}, function(sinusbot, config) {

    // -- Recreating "startsWith()" function which isn't included in ECMAScript 5 --
    if (!String.prototype.startsWith) {
        String.prototype.startsWith = function(searchString, position) {
            position = position || 0;
            return this.indexOf(searchString, position) === position;
        };  
    }

    sinusbot.on('chat', function(ev) {
        if(ev.mode != 1) return; // checks if the message is written in the private-chat. 1 is private-chat, 2 is channel-chat, 3 is server-chat
        if(ev.msg.startsWith('!private')){ // replaced the 'indexOf()' by 'startsWith()' defined above -> it's easier to read I think
            var groupid = config.groupid;
            var i = ev.clientServerGroups.length;
            while (i--) {
                if (ev.clientServerGroups[i].i == groupid) {
                    var cname = ev.msg.replace("!private", "").trim(); // added 'trim()' which removes the whitespaces at the start and the end of the string
                    var key = ev.clientUid + "_private";
                    var obj = get(key);
                    if(cname == ""){
                        chatPrivate(ev.clientId, 'Usage: !private <channelname>');
                    }else if(obj != undefined){
                        chatPrivate(ev.clientId, 'You already have a private channel: ' + obj);
                    }else{
                        channelCreate({ name: cname, parent: config.parentid, topic: ev.clientNick, enc: 1, perm: 1, sperm: 0, order: 0, maxClients: 10 });
                        chatPrivate(ev.clientId, 'Channel: ' + cname + ' created.');
                        set(key, cname);
                    }
                    return true;
                }
            }
            chatPrivate(ev.clientId, 'You are not allowed to create a private Channel');
        }
    });
});

If you want the code without any comment:

Code:
registerPlugin({
    name: 'Private Channel',
    version: '0.1',
    description: 'Allows certain users to create their own private channel',
    author: 'good_live',
    vars: {
        parentid: {
            title: 'ID of the parent Chanel',
            type: 'number',
            placeholder: '0'
        },
        groupid: {
            title: 'ID of the group that is allowed to create a Channel',
            type: 'number',
            placeholder: '0'
        }
    }
}, function(sinusbot, config) {

    // -- Recreating "startsWith()" function which isn't included in ECMAScript 5 --
    if (!String.prototype.startsWith) {
        String.prototype.startsWith = function(searchString, position) {
            position = position || 0;
            return this.indexOf(searchString, position) === position;
        }; 
    }

    sinusbot.on('chat', function(ev) {
        if(ev.mode != 1) return;
        if(ev.msg.startsWith('!private')){
            var groupid = config.groupid;
            var i = ev.clientServerGroups.length;
            while (i--) {
                if (ev.clientServerGroups[i].i == groupid) {
                    var cname = ev.msg.replace("!private", "").trim();
                    var key = ev.clientUid + "_private";
                    var obj = get(key);
                    if(cname == ""){
                        chatPrivate(ev.clientId, 'Usage: !private <channelname>');
                    }else if(obj != undefined){
                        chatPrivate(ev.clientId, 'You already have a private channel: ' + obj);
                    }else{
                        channelCreate({ name: cname, parent: config.parentid, topic: ev.clientNick, enc: 1, perm: 1, sperm: 0, order: 0, maxClients: 10 });
                        chatPrivate(ev.clientId, 'Channel: ' + cname + ' created.');
                        set(key, cname);
                    }
                    return true;
                }
            }
            chatPrivate(ev.clientId, 'You are not allowed to create a private Channel');
        }
    });
});
 

flyth

is reticulating splines
Staff member
Developer
Contributor
1 & 2 will be available in the next version (may take a few days, though).
3 will take a little longer.
 

good_live

Active Member
Tier III
is awesome!
V.I.P.
Contributor
Insider
Yes this would be a great feature, but do you know that there cannot be 2 channels with the exactly same name? :)

And I read your plugin and I saw that there are some kind of errors :)
I rewrote it a little bit...
1. Nope i never tried that :D i just thought that it might be a problem.
But still you can only delete a channel by his id and it could be hard to find the id which matches the name ^^

and thanks for fixes :)

@flyth
Thanks. 1&2 are helping already :)
 
Last edited:
Status
Not open for further replies.
Top