From 432921dff040fd1b26dfed7517a74bf61db21554 Mon Sep 17 00:00:00 2001 From: Braeden57 Date: Tue, 21 Sep 2021 15:00:01 -0700 Subject: [PATCH] 1.6.4 Fix multiple responce with socket --- LPS.js | 30 +++++++++++++++++++----------- config.json | 2 +- dev-config.json | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/LPS.js b/LPS.js index dac2837..33f19a2 100644 --- a/LPS.js +++ b/LPS.js @@ -11,8 +11,6 @@ class Bot { this.token = token; this.config = require(config); this.connectMongo(); - - this.socket = io.connect(this.config.socket); } async connectMongo() { @@ -108,8 +106,9 @@ class Bot { } } - this.socket.emit("bot_name_search", data); - this.socket.on("bot_name_search_results", results => { + const socket = io.connect(this.config.socket); + socket.emit("bot_name_search", data); + socket.on("bot_name_search_results", results => { if (results.user._id==user._id) { if (results.civilians.length == 0) { @@ -173,6 +172,7 @@ class Bot { message.channel.send(nameResult); } } + socket.disconnect(); }); } @@ -187,8 +187,9 @@ class Bot { activeCommunityID: user.user.activeCommunity } } - this.socket.emit('bot_plate_search', data); - this.socket.on('bot_plate_search_results', results => { + const socket = io.connect(this.config.socket); + socket.emit('bot_plate_search', data); + socket.on('bot_plate_search_results', results => { if (results.user._id==user._id) { if (results.vehicles.length == 0) { @@ -222,6 +223,7 @@ class Bot { message.channel.send(plateResult); } } + socket.disconnect(); }); } @@ -236,8 +238,9 @@ class Bot { activeCommunityID: user.user.activeCommunity } } - this.socket.emit('bot_firearm_search', data); - this.socket.on('bot_firearm_search_results', results => { + const socket = io.connect(this.config.socket); + socket.emit('bot_firearm_search', data); + socket.on('bot_firearm_search_results', results => { if (results.user._id==user._id) { if (results.firearms.length==0) { return message.channel.send(`No Firearms found ${message.author}`); @@ -262,6 +265,7 @@ class Bot { message.channel.send(firearmResult); } } + socket.disconnect(); }); } @@ -305,9 +309,11 @@ class Bot { onDuty: onDuty, updateDuty: updateDuty }; - this.socket.emit('bot_update_status', req); - this.socket.on('bot_updated_status', (res) => { + const socket = io.connect(this.config.socket); + socket.emit('bot_update_status', req); + socket.on('bot_updated_status', (res) => { message.channel.send(`Succesfully updated status to **${args[0]}** ${message.author}!`); + socket.disconnect(); }); } @@ -322,7 +328,9 @@ class Bot { userUsername: user.user.username, activeCommunity: user.user.activeCommunity } - this.socket.emit('panic_button_update', myReq); + const socket = io.connect(this.config.socket); + socket.emit('panic_button_update', myReq); + socket.disconnect(); // If panic is enabled, set status to Online (panic off) } else if (user.user.dispatchStatus=='Panic') { this.updateStatus(message, ['10-41'], null); diff --git a/config.json b/config.json index 1a38a59..9b19f24 100644 --- a/config.json +++ b/config.json @@ -2,7 +2,7 @@ "defaultPrefix": "?", "botID": "860298681047056434", "mongoURI": "mongodb+srv://lps_bot:ktSkHml2BU9EIQ0a@heroku-police-cad-dev.j7aom.mongodb.net/heroku_8pc4g86l?retryWrites=true&w=majority", - "version": "Beta 1.6.1", + "version": "Beta 1.6.4", "socket": "https://police-cad-dev.herokuapp.com/", "dbo": "heroku_8pc4g86l" } \ No newline at end of file diff --git a/dev-config.json b/dev-config.json index 6a03e83..ba96251 100644 --- a/dev-config.json +++ b/dev-config.json @@ -2,7 +2,7 @@ "defaultPrefix": "?", "botID": "860298681047056434", "mongoURI": "mongodb+srv://lps_bot:ktSkHml2BU9EIQ0a@heroku-police-cad-dev.j7aom.mongodb.net/heroku_8pc4g86l?retryWrites=true&w=majority", - "version": "Beta 1.6.1", + "version": "Beta 1.6.4", "socket": "http://localhost:8080", "dbo": "heroku_8pc4g86l" } \ No newline at end of file