Skip to content

Commit

Permalink
moved try-catch inside removePosition
Browse files Browse the repository at this point in the history
  • Loading branch information
harryxu2626 committed Feb 11, 2025
1 parent fc97c91 commit 31774b3
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,24 @@ const clearRatings = async (client) => {
}

const removePosition = async (client) => {
const clientDbid = client.propcache.clientDatabaseId;
const serverGroupsById = await teamspeak.serverGroupsByClientId(clientDbid);
try{
const clientDbid = client.propcache.clientDatabaseId;

const serverGroupsById = await teamspeak.serverGroupsByClientId(clientDbid);

const positionToDelete = serverGroupsById.find((item) => item.name.includes("_"));
const positionToDelete = serverGroupsById.find((item) => item.name.includes("_"));

if(positionToDelete){
await teamspeak.serverGroupDelClient(clientDbid, positionToDelete.sgid);
await teamspeak.serverGroupDel(positionToDelete.sgid);
if(positionToDelete){
await teamspeak.serverGroupDelClient(clientDbid, positionToDelete.sgid);
await teamspeak.serverGroupDel(positionToDelete.sgid);
}
}catch(err){
console.log("error in removePosition")
console.log(err);
}
}


teamspeak.on("ready", async () => {
positionUpdate();
setInterval(positionUpdate,60*1000);
Expand Down Expand Up @@ -234,11 +241,7 @@ teamspeak.on("clientconnect", async (connected) => {

teamspeak.on("clientdisconnect", async (connected) => {
const client = connected.client;
try{
removePosition(client);
}catch(err){
console.log(err);
}
removePosition(client);
});

teamspeak.on("close", async () => {
Expand Down

0 comments on commit 31774b3

Please sign in to comment.