• 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] Change channel codec

Status
Not open for further replies.

Niggolo

Helping Hand
Hello,

If it not hard or long can someone write a simple command like !codec and make it switch from opus music to opus voice and viceversa?

thank you
 

good_live

Active Member
Tier III
is awesome!
V.I.P.
Contributor
Insider
Here you go:

Code:
registerPlugin({
    name: 'Change codec',
    version: '1.0',
    description: 'This script implements the .codec command to change the bot channels codec.',
    author: 'good_live',
    vars: {
        cmd: {
            title: 'The command to trigger. (Exampel .codec)',
            type: 'string',
            placeholder: '.codec'
        }
    }
}, function(sinusbot, config, info) {



    // -- Load messages --
    log('Loading...');
    var author = info.author.split(',');
    if(author.length == 1){
        author = author[0];
        author = author.replace(/<.*>/gi, '').trim();
    } else {
        author = author.map(function(e){
            return e.replace(/<.*>/gi, '').trim();
        });
        author = author.join(' & ');
    }
    log(info.name + ' v' + info.version + ' by ' + author + ' for SinusBot v0.9.9-50e8ba1 (and above)');
   
   
    // -- 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;
        };
    }
   
    //Loading cmd variable
    if(typeof config.cmd == "undefined" || !config.cmd) {
        var cmd = '.codec';
        log('No cmd set ... using the default one: ".codec"');
    }else{
        var cmd = config.cmd;
    }

    sinusbot.on('chat', function(ev) {
        if(ev.mode != 1) return;
        if(ev.msg.startsWith(cmd)){
            var buffer = ev.msg.replace(cmd, '').trim().toLowerCase();
            switch(true) {
                case buffer.startsWith('narrow'):
                    channelUpdate(getCurrentChannelId(), { codec: 0 });
                    break;
                case buffer.startsWith('wide'):
                    channelUpdate(getCurrentChannelId(), { codec: 1 });
                    break;
                case buffer.startsWith('ultrawide'):
                    channelUpdate(getCurrentChannelId(), { codec: 2 });
                    break;
                case buffer.startsWith('mono'):
                    channelUpdate(getCurrentChannelId(), { codec: 3 });
                    break;
                case buffer.startsWith('voice'):
                    channelUpdate(getCurrentChannelId(), { codec: 4 });
                    break;
                case buffer.startsWith('music'):
                    channelUpdate(getCurrentChannelId(), { codec: 5 });
                    break;
                case buffer.startsWith('help'):
                    chatPrivate(ev.clientId, 'Help page for the ' + cmd + ' command:');
                    chatPrivate(ev.clientId, cmd + ' narrow (changes the codec to Narrowband)');
                    chatPrivate(ev.clientId, cmd + ' wide (changes the codec to Wideband)');
                    chatPrivate(ev.clientId, cmd + ' ultrawide (changes the codec to Ultra-wideband)');
                    chatPrivate(ev.clientId, cmd + ' mono (changes the codec to CELT Mono)');
                    chatPrivate(ev.clientId, cmd + ' voice (changes the codec to Opus Voice)');
                    chatPrivate(ev.clientId, cmd + ' music (changes the codec to Opus Music)');
                    break;
                default:
                    chatPrivate(ev.clientId, 'Usage: ' + cmd + ' <narrow|wide|ultrawide|mono|voice|music|help>');
                    break;
            }
        }
        return;
    });
   
   
    // -- Information --
    log('Loaded !');
});

You have to use cmd <narrow|wide|ultrawide|mono|voice|music|help> to switch between the codecs. The cmd is set in the webinterface.
 

Attachments

  • codec.js
    3 KB · Views: 58

Niggolo

Helping Hand
thank you!
i just asked it to work with 2 codecs because i didnt want to make it longer to code and because others are rarely used :p
 

Niggolo

Helping Hand
something like what i wrote, !command (it get the channel code if it is 4 then change it to 5, same if it is 5 change it to 4) with only 1 command
This one is ok, i just want to know if that is possible :)
 

good_live

Active Member
Tier III
is awesome!
V.I.P.
Contributor
Insider
Yeah sure thats possible:
Code:
registerPlugin({
    name: 'Change codec',
    version: '1.0',
    description: 'This script implements the .codec command to change the bot channels codec.',
    author: 'good_live',
    vars: {
        cmd: {
            title: 'The command to trigger. (Exampel .codec)',
            type: 'string',
            placeholder: '.codec'
        }
    }
}, function(sinusbot, config, info) {



    // -- Load messages --
    log('Loading...');
    var author = info.author.split(',');
    if(author.length == 1){
        author = author[0];
        author = author.replace(/<.*>/gi, '').trim();
    } else {
        author = author.map(function(e){
            return e.replace(/<.*>/gi, '').trim();
        });
        author = author.join(' & ');
    }
    log(info.name + ' v' + info.version + ' by ' + author + ' for SinusBot v0.9.9-50e8ba1 (and above)');
   
    // -- 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;
        };
    }
   
    //Loading cmd variable
    if(typeof config.cmd == "undefined" || !config.cmd) {
        var cmd = '.codec';
        log('No cmd set ... using the default one: ".codec"');
    }else{
        var cmd = config.cmd;
    }

    sinusbot.on('chat', function(ev) {
        if(ev.mode != 1) return;
        if(ev.msg.startsWith(cmd)){
            var channels = getChannels();
            var i;
            for (i=0; i<channels.length; i++){
                if(channels[i].id == getCurrentChannelId()){
                    if(channels[i].codec == 5){
                        channelUpdate(getCurrentChannelId(), { codec: 4 });
                        chatPrivate(ev.clientId, 'Changed the codec to Voice.');
                    }else{
                        channelUpdate(getCurrentChannelId(), { codec: 5 });
                        chatPrivate(ev.clientId, 'Changed the codec to Music.');   
                    }
                }
            }   
        }
        return;
    });
   
   
    // -- Information --
    log('Loaded !');
});
 

Attachments

  • codec2.js
    2 KB · Views: 34

Niggolo

Helping Hand
I uploaded it and sinusbot load it, but it dont appear in scripts, and if i type .codec nothing happen and nothing in logs

Edit: idk if this is related
2015-11-19T18:52:22+01:00 Could not send config. Please make sure that the loopback interface is not firewalled.
2015-11-19T18:52:22+01:00 Could not send chat command

Edit 2: NVM the update messed something, after killed the process and this error gone but the command still no work :(

i get this: 2015-11-19T20:00:27+01:00 TS |INFO |ClientUI |1 |Ignored text message by Riggola: .codec
Btw everyone can run the command?
 
Last edited:

good_live

Active Member
Tier III
is awesome!
V.I.P.
Contributor
Insider
Here you go:

Code:
registerPlugin({
    name: 'Change codec',
    version: '1.1',
    description: 'This script implements the .codec command to change the bot channels codec.',
    author: 'good_live',
    vars: {
        cmd: {
            title: 'The command to trigger. (Exampel .codec)',
            type: 'string',
            placeholder: '.codec'
        }
        groupids: {
            title: 'IDs of the groups or clients that are allowed to use the command. (Leave it empty to allow everybody)',
            type: 'string',
            placeholder: '12 120 319EN4I/TuSji8VPdK7drJtELn0= 49'
        }
    }
}, function(sinusbot, config, info) {



    // -- Load messages --
    log('Loading...');
    var author = info.author.split(',');
    if(author.length == 1){
        author = author[0];
        author = author.replace(/<.*>/gi, '').trim();
    } else {
        author = author.map(function(e){
            return e.replace(/<.*>/gi, '').trim();
        });
        author = author.join(' & ');
    }
    log(info.name + ' v' + info.version + ' by ' + author + ' for SinusBot v0.9.9-8f70ff3 (and above)');
   
    // -- 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;
        };
    }
   
    //Loading cmd variable
    if(typeof config.cmd == "undefined" || !config.cmd) {
        var cmd = '.codec';
        log('No cmd set ... using the default one: ".codec"');
    }else{
        var cmd = config.cmd;
    }
   
    //Loading group/clientids
    if(typeof config.groupids == 'undefined' || config.groupids == '') {
        log('No group/client ids set! Everybody is allowed to create a private channel.');
        var groupids = "0";
    }else{
        var groupids = config.groupids.split(' ');
    }
    //Function to check if a user has the permission to execute the cmd
    function haspermission(clientUid, clientGroups){
        var j;
        for (j=0; j<groupids.length; j++){
            if(groupids[j] == clientUid){
                return true;
            }else{
                var s;
                for(s=0; s<clientGroups.length; s++){
                    if (clientGroups[s].i == groupids[j]) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
   
    sinusbot.on('chat', function(ev) {
        if(ev.mode != 1) return;
        if(ev.msg.startsWith(cmd)){
            if(groupids == '0' || haspermission(ev.clientUid, ev.clientServerGroups)){
                var channels = getChannels();
                var i;
                for (i=0; i<channels.length; i++){
                    if(channels[i].id == getCurrentChannelId()){
                        if(channels[i].codec == 5){
                            channelUpdate(getCurrentChannelId(), { codec: 4 });
                            chatPrivate(ev.clientId, 'Changed the codec to Voice.');
                            return;
                        }else{
                            channelUpdate(getCurrentChannelId(), { codec: 5 });
                            chatPrivate(ev.clientId, 'Changed the codec to Music.');
                            return;
                        }
                    }
                }
            }
        }
        return;
    });
   
   
    // -- Information --
    log('Loaded !');
});
For me everything works fine, but you need the newest version of the Beta and of course the bot needs the permission to change the channels codec.
 

Attachments

  • codec2.js
    3 KB · Views: 36

Niggolo

Helping Hand
i will try this one asap,yeah the bot have the permission and the new version is installed

Thank you
 

Niggolo

Helping Hand
Ok i think im noob...
I cant get this work, what im missing?

1)
2015-11-21T00:40:07+01:00 [codec] Loaded !
2015-11-21T00:40:07+01:00 [codec] No group/client ids set! Everybody is allowed to create a private channel.
2015-11-21T00:40:07+01:00 [codec] Change codec v1.1 by good_live for SinusBot v0.9.9-8f70ff3 (and above)
2015-11-21T00:40:07+01:00 [codec] Loading...

2) http://prntscr.com/953ah9

3) i type .codec (the channel is voice) but it dont switch :(
 

rialTresH

Member
good day to all.
mb someone upgrade the scripts, if posible!

when the bot come in the room, then codec was changed to opus music
when the bot leave the room, then codec was changed to opus voice
 

3RR0R

Donor
is awesome!
good day to all.
mb someone upgrade the scripts, if posible!

when the bot come in the room, then codec was changed to opus music
when the bot leave the room, then codec was changed to opus voice

that would be a nice feature! :)
 

good_live

Active Member
Tier III
is awesome!
V.I.P.
Contributor
Insider
good day to all.
mb someone upgrade the scripts, if posible!

when the bot come in the room, then codec was changed to opus music
when the bot leave the room, then codec was changed to opus voice
Ive done something like that already. Should be somewhere around in the forum :D
 

good_live

Active Member
Tier III
is awesome!
V.I.P.
Contributor
Insider
Hey,

ich hab das ganze mal mehr oder weniger umgesetzt: musicchannel.
Allerdings kann/wird es Probleme geben, wenn mehrere musicbots in einem Channel sind.

Außerdem wird der Codec beim disconnect nicht zurückgesetzt (geht iwie nicht mit der disconnect Funktion :/), aber sobald der bot wieder drauf joint prüft er den alten Channel nochmal und setzt den Codec da auch ggf wieder zurück.

Du kannst das script ja mal ausgiebig testen und dich mit Verbesserungswünschen melden. :)

Sorry its in german and not that well coded ^^ Im not sure if its still working. You can try :)
 
Last edited:

Erne Nino

Member
Hello, the script dosen't work for me,
Can you help me pls.

2c48e26cdd.png


95dbc1a901.png


Thank you MrErne
 

Idler

Member
Would it be possible to auto change the codec to opus music or a specific codec as soon as the bot is moved to/enters a channel?
 

good_live

Active Member
Tier III
is awesome!
V.I.P.
Contributor
Insider
Would it be possible to auto change the codec to opus music or a specific codec as soon as the bot is moved to/enters a channel?
Maybe you should read just a few posts above.
 
Status
Not open for further replies.
Top