• 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 Getting client from name

Status
Not open for further replies.

Ron

Donor
is awesome!
Hey, writing a script right now that uses a command.

!command <Client-Name> <Message>

But I don't really know how to get the the client info (where I can also related to mode, clientUid, clientID, etc) from the name.

I'd appreciate any help.

Thanks.
 

mxschmitt

Moderator
Staff member
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
For that, you need to be in the 'Chat' Event
Code:
sinusbot.on('chat', function(ev) {
sinusbot.log(ev.clientId);
});
 

Ron

Donor
is awesome!
Nah you didn't get me, I know how to create a command, but I want to be able to target people. For example:

!command maxibanki

And then be able to do something to you.
 

mxschmitt

Moderator
Staff member
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
Thats not available you need to make substring or Split by spaces but thats more complicated
 
Last edited:

Ron

Donor
is awesome!
Obviously splitting it to get the username by itself, but is there no way to get a client info from the name in the current API? couldn't find any documentation.
 

xDefcon

Well-Known Member
Contributor
You could iterate all channels and subchannels in search of that nickname string, when you found the position of desidered user, you can get informations about that client.
For more information go on your sinus dashboard, then go on help, and Scripting. You can find a documentation in that section.

Code snippet
Code:
var c = sinusbot.getChannels();
        for (var i = 0; i < c.length; i++){
            for (var j = 0; j < c[i].clients.length; j++){
                // do something
            }
        }
 

Ron

Donor
is awesome!
@xDefcon

Hey, 2 questions. With this code:
PHP:
function findClientFromName(clientName) {
    var allChannels = sinusbot.getChannels();
    var foundClient    = 'nothing';
  
    for (var i = 0; i < allChannels.length; i++) {
        for (var = j = 0; j < allChannels[j].clients.length; j++) {
          
        }
    }
  
    return foundClient;
}

The plugin doesn't launch and isn't even recognized. Why's that?

Also what does allChannels.clients[j] represent? An ev array like all the other functions?

Cheers.
 
Last edited:

Ron

Donor
is awesome!
Never mind. Turns out I did my bit wrong.

Ready function for future visitors:

PHP:
function findClientFromName(searchName) {
    var foundClient    = 'N0TH!NG';
    searchName         = searchName.toLowerCase();
    allChannels          = sinusbot.getChannels();
  
    allChannels.forEach(function(channelInfo) {
        channelClients              = channelInfo['clients'];
        channelClients.forEach(function(clientInfo) {
            clientName               = clientInfo['nick'];
            clientID                    = clientInfo['id'];
            clientUID                  = clientInfo['uid'];
            clientServerGroups    = clientInfo['g'];
          
            clientNameParse        = clientName.toLowerCase().split(" ")[0];
          
            if (clientNameParse == searchName) {
                foundClient        = {
                                    name: clientName,
                                    id: clientID,
                                    uid: clientUID,
                                    groups: clientServerGroups
                                };
            }
        });
    });
  
    return foundClient;
}
 
Last edited:
Status
Not open for further replies.
Top