I Need This Bot

kalle

high minded
Contributor
Oct 28, 2015
411
253
178
Download node.js and run it.
Also download this npm package npm install --save ts3-nodejs-library

JavaScript:
const { TeamSpeak } = require("ts3-nodejs-library")
const groupToAssign = 7;


const teamspeak = new TeamSpeak({
  host: "127.0.0.1",
  queryport: 10011,
  password: '6ohDFLjr',
  username: 'serveradmin',
  serverport: 9987,
})

teamspeak.on("ready", () => {
    Promise.all([
        teamspeak.registerEvent("server"),
        teamspeak.registerEvent("channel", 0),
        teamspeak.registerEvent("textserver"),
        teamspeak.registerEvent("textchannel"),
        teamspeak.registerEvent("textprivate")
    ])


})

teamspeak.on("clientmoved", info  => {
    
    switch (info.channel.flagPermanent) {
        case 1:
                if(!info.client.servergroups.includes(groupToAssign) && teamspeak.getClientByDBID(info.client.databaseId).then(groups => {groups.getGroups().contains(groupToAssign)}))
                    teamspeak.clientAddServerGroup(info.client.databaseId,groupToAssign);
                
            break;

        default:
                if(info.client.servergroups.includes(groupToAssign)){               
                    teamspeak.clientDelServerGroup(info.client.databaseId,groupToAssign);
                }   
            break;
    }

});
 

FromLondon

Honk Honk
TeamSpeak Developer
VIP
May 20, 2016
264
107
136
@kalle

JavaScript:
teamspeak.on("clientmoved", async info  => {
   
  // wrap it all in try catch i dont know :D

  switch (info.channel.flagPermanent) {
      case 1:
        const is_client_contain_group = info.client.servergroups.includes(groupToAssign)
        const is_server_have_group  = await teamspeak.getClientByDBID(info.client.databaseId).then(groups => groups.getGroups().contains(groupToAssign))// .catch(err=> console.log("err on [server_have_group]")) kind of to debug on possible errors
          if(!is_client_contain_group && server_have_group ))
            await teamspeak.clientAddServerGroup(info.client.databaseId, groupToAssign);
        break;

      default:
              if(info.client.servergroups.includes(groupToAssign)){              
                  await teamspeak.clientDelServerGroup(info.client.databaseId,groupToAssign);
              }  
          break;
  }

});

Would be bettet to write event handler like that (might not be 100% working cause i writing it while chilling).
Keep in mind lib is promise based. Using await will be better solution in 99.9% cases.
`teamspeak.getClientByDBID(info.client.databaseId).then(groups...` wil return Promise<pending> value (not boolean).

Why you choose Array.prototype.includes and Array.prototype.contains instead one of this ?


Also would be cool with usage if instead switch with one value (less code, and if works faster :D)
 

kalle

high minded
Contributor
Oct 28, 2015
411
253
178
@kalle

JavaScript:
teamspeak.on("clientmoved", async info  => {
 
  // wrap it all in try catch i dont know :D

  switch (info.channel.flagPermanent) {
      case 1:
        const is_client_contain_group = info.client.servergroups.includes(groupToAssign)
        const is_server_have_group  = await teamspeak.getClientByDBID(info.client.databaseId).then(groups => groups.getGroups().contains(groupToAssign))// .catch(err=> console.log("err on [server_have_group]")) kind of to debug on possible errors
          if(!is_client_contain_group && server_have_group ))
            await teamspeak.clientAddServerGroup(info.client.databaseId, groupToAssign);
        break;

      default:
              if(info.client.servergroups.includes(groupToAssign)){            
                  await teamspeak.clientDelServerGroup(info.client.databaseId,groupToAssign);
              }
          break;
  }

});

Would be bettet to write event handler like that (might not be 100% working cause i writing it while chilling).
Keep in mind lib is promise based. Using await will be better solution in 99.9% cases.
`teamspeak.getClientByDBID(info.client.databaseId).then(groups...` wil return Promise<pending> value (not boolean).

Why you choose Array.prototype.includes and Array.prototype.contains instead one of this ?


Also would be cool with usage if instead switch with one value (less code, and if works faster :D)
Thank you for watching into code, yes my bad for not reasearching promise in full. Rn it doenst return bool, returns pending like u said, but still this condition passes so its kinda good -.-' .
Idk rly why I wrote contains and includes , probably editor suggestion and my bad for not watching.
I like to use switch in cases like this, not fan anymore of if stuff where can I use thing meant for that usage.
And one thing that bugs me out is that snake_case_thing so writeItInCamelCase.:D
 

FromLondon

Honk Honk
TeamSpeak Developer
VIP
May 20, 2016
264
107
136
This condition with promise will always become true because it's not have value equal to

JavaScript:
false
undefined
NaN
null
0
''
 
Top