• 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 requestExtendedServerInfo()

Zmeja

Member
Hello dear Community.
Right now. I am writing a small script for our server, which will kick people in regard to their Idle time. I want the script to only kick someone, if the teamspeak is almost filled. For that, I need the current amount of Users on the server. Of course I could iterate through all clients and count it myself, however, I found a neat function in the API that should do what I want to do.

https://sinusbot.github.io/scripting-docs/#teamspeakextendedserverinfo
Right here, I have the function, 'maxClients()'. However. I can not get TeamSpeakExtendedServerInfo. Because of the following problem.

let ts3ExtendedInfo = backend.extended().requestExtendedServerInfo().clientsOnline();

This right here. Will not work. Because
backend.extended().requestExtendedServerInfo();
Will NOT give me the TeamSpeakExtednedServerInfo Object as said in the documentation right here:
https://sinusbot.github.io/scripting-docs/#extendedts3

Instead. It returns a bool. After a bit of digging I found this little piece of information.
https://github.com/SinusBot/scripting-docs/issues/22
Which tells me that apparently this 'triggers serverinfo_int event with extended server info object'.

My question now. How can I receive my extended server info object? And I suspect the documentation here is also at fault as well then.

Thank you for reading and taking a bit of time out of your day to help me.
I'm very grateful for any answer.
 

DrWarpMan

Well-Known Member
Contributor
Insider
I do not have an answer to your question, but I have something about this..

For that, I need the current amount of Users on the server. Of course I could iterate through all clients and count it myself.

backend.getClients().length is too hard?
 

Zmeja

Member
I never said it's not possible to do so. Of course you can just count the occurances with the function you have given above. As stated in my first thread. However, if a function exists for specifically getting the amount of users on a server, but the API is not giving correct information, I wanted to elaborate on it.
If I would want to get the maximum amount of clients to compare both values. I also can not receive it due to this. Which has to be put in manually of course.

Thank you for your answer nevertheless. Much appreciated.
 

TwentyFour

BinusSot Junkie
V.I.P.
Contributor
Insider
Actually I like your approach. Consider that those functions are quite new (since 1.0.0-alpha.6), maybe there is something not working as intended, and just nobody besides you really tried to use that so far.
I think as soon as @flyth or @irgendwr sees this topic, you will get your answer (and maybe your solution in an upcoming version).

EDIT:
Did you try using backend.extended().requestExtendedServerInfo().asObject()?
This should (if working as described) return the serverinfo as stringifyable object... maybe you can get your data with a little workaround, while direct access is not working so far.

Or could it be a permission thing? That if you cannot retrieve the ServerInfo-Object, it returns false instead of the actual object?
 
Last edited:

irgendwr

no longer active, "retired" staff member
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
This right here. Will not work. Because
backend.extended().requestExtendedServerInfo();
Will NOT give me the TeamSpeakExtednedServerInfo Object as said in the documentation right here:
https://sinusbot.github.io/scripting-docs/#extendedts3

Instead. It returns a bool. After a bit of digging I found this little piece of information.
https://github.com/SinusBot/scripting-docs/issues/22
Which tells me that apparently this 'triggers serverinfo_int event with extended server info object'.
Phew, yeah that's a mistake in the scripting documentation. Whoops.
I normally don't notice if you post something in the forum so in case you find mistakes in the doc you can either open an issue on github and wait for someone to fix it or submit a pullrequest to fix it yourself. ^^

My question now. How can I receive my extended server info object? And I suspect the documentation here is also at fault as well then.
As you found out by my comment on github:
apparently this 'triggers serverinfo_int event with extended server info object'
So register for the event and receive the object, as it says:
JavaScript:
// register event first
event.on("serverinfo_int", serverinfo => {
    // here you can use serverinfo.clientsOnline()
})
// request extendedServerInfo (will trigger the event above)
backend.extended().requestExtendedServerInfo();
As it's async though, this will often be harder to implement in many use-cases.
And yes that's kinda weird, a callback or - even better - a promise would have been more intuitive. Not sure why it was implemented as an event instead.

If you're looking for an easy way of getting the total number of visible clients then the suggestion from DrWarpMan is indeed easier:
backend.getClients().length

Edit 1: fixed typo in example code
Edit 2: I corrected the documentation (see
#26).
 
Last edited:

Lukas Westholt

Well-Known Member
Contributor
@flyth @irgendwr ,
i found a typo in sinusbot code: backend.extended().getServerInfo().defaultServerGorup() and backend.extended().getServerInfo().DefaultServerGorup(). Please fix this in next version :D
 
Top