I Need This Bot

enaxdao

New Member
Joined
Feb 24, 2018
Messages
0
Reaction score
2
Points
13
Hi..
I Need Bot Give every body in temporary channel servergroup if he go to permanent bot revoke this server group
 

kalle

high minded
Contributor
Joined
Oct 28, 2015
Messages
411
Reaction score
253
Points
178
Seems simple, I will look into this.
 

kalle

high minded
Contributor
Joined
Oct 28, 2015
Messages
411
Reaction score
253
Points
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
Joined
May 20, 2016
Messages
264
Reaction score
107
Points
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)
 

RaniPablo

Restricted
Joined
Jun 10, 2019
Messages
2
Reaction score
0
Points
8
Hi..
I Need Bot Give every body in temporary channel servergroup if he go to permanent bot revoke this server group
You want this bot to put it on danger community server ? haaha
 

kalle

high minded
Contributor
Joined
Oct 28, 2015
Messages
411
Reaction score
253
Points
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
Joined
May 20, 2016
Messages
264
Reaction score
107
Points
136
This condition with promise will always become true because it's not have value equal to

JavaScript:
false
undefined
NaN
null
0
''
 
Top