• 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 Get client's group

DrWarpMan

Well-Known Member
Contributor
Insider
First, is this code right?
Second, If I have a group named "test", will this return true? Or how can I get "if a client has specified group"?

Code:
if(ev.client.getServerGroups().includes('test'))
 

DrWarpMan

Well-Known Member
Contributor
Insider
But there I didn't ask how to get "if user has specified client's group".. or maybe I am blind..
 

DrWarpMan

Well-Known Member
Contributor
Insider
But.. I want to get clients group.. what should I do? This?

Code:
var group = ev.client.getServerGroupByName("test")

if (!group) {
    // does not exist
} else {
    // does exist
}
 

Everlike

Well-Known Member
Contributor
This Code won’t work.
I would do it like this.
var servergroupsOfUser = ev.client.getServerGroups();
function checkIfUserIsInGroup(servergroupsOfUser) {
var allserverIdsOfUser = new Array;
for (i = 0; i < servergroupsOfUser.length ; i++) {
allserverIdsOfUser.push(servergroupsOfUser.channel.id()
}
return allserverIdsOfUser;
}
if (checkIfUserIsInGroup(servergroupsOfUser).indexOf(insertAServergroupIdHere) >= 0) {
engine.log(„he is in the group“);
}



I can’t check if the code works, but I have working functions like this in some of my script, just check out my „servergroup switcher, and, or „admin % Moderator status“ script. There you should find good examples.
 

Everlike

Well-Known Member
Contributor
Well, Iam on my phone, all this typing for nothing. Fukk me.
But afaik „.includes()“ does not work, I would recommend the .indexOf() <=0 thing.
 

irgendwr

no longer active, "retired" staff member
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
It's not that hard and there are multiple ways to do it, basic js:
JavaScript:
if (hasServerGroupWithName(client, "foogroup")) {
    // do stuff
}

function hasServerGroupWithName(client, name)
    return client.getServerGroups().some(function (group) {
        return group.name() == name
    })
}
(also not tested, may contain traces of typos™)
Edit: fixed typo™
 
Last edited:

DrWarpMan

Well-Known Member
Contributor
Insider
Somehow it ain't working.

Code:
                if(hasServerGroupWithName(ev.client, "Magic") {
                    ev.client.chat('test');
                }

    function hasServerGroupWithName(client, name){
        return client.getServerGroups().some(function (group) {
            return group.name() == name
        })
    }
 

DrWarpMan

Well-Known Member
Contributor
Insider
The problem is.. where can I find the log.. and I do not think that it is Instance or Bot log..
 

Everlike

Well-Known Member
Contributor
You can set the log path in your config.ini. f.e. /opt/sonusbot/logs.
But as @irgendwer teached me, the instamce/webinterface log should be such as good.
 

DrWarpMan

Well-Known Member
Contributor
Insider
Now I wanted to change it, but suddenly, my config.ini just have this

ListenPort = 8087
ListenHost = "ip(hidden)"
TS3Path = "/home/sinusbot/TeamSpeak3-Client-linux_amd64/ts3client_linux_amd64"

inside, and I remember months ago, that I had more than 50 lines of text.
 
Top