BeepIsla / CSGO-Overwatch-Bot

Automatically solve CSGO Overwatch cases
GNU Affero General Public License v3.0
186 stars 41 forks source link

Automatic Reply #67

Closed chmosama closed 4 years ago

chmosama commented 4 years ago

I've been trying to add automatic reply functionality and It's almost done but I am facing one little problem with the sender name. I cannot set the sender's name before printing it in the console. Here's the code: async function automaticMsg(){ let friendName; steamUser.on("friendMessage", function (steamID, message) { //StartWebAPI if (config.parsing.steamWebAPIKey && config.parsing.steamWebAPIKey.length >= 10) { request("https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=" + config.parsing.steamWebAPIKey + "&format=json&steamids=" + steamID + "", { json: true }, (err, res, body) => { if (err) { return console.log(err); } var json = JSON.stringify(body); var jsonParsed = JSON.parse(json); friendName = jsonParsed.response.players[0].personaname; console.log("Sender: " + friendName); }); } //EndWebAPI steamUser.messageReceived = {}; console.log("[" + steamUser.accountInfo.name + "] Message from " + friendName + ": " + message); if (!this.messageReceived[steamID]) { steamUser.chatMessage(steamID, "[Automatic Message] I'm busy with automatic OverwatchBot."); this.messageReceived[steamID] = true; } }); }

Then I just call this function before : doOverwatchCase();

But the problem is with the variable name friendName It is not setting the value first time when someone sends a message and prints the first message with the undefined sender name. Can you look into this :)

BeepIsla commented 4 years ago

How is this related to my Overwatch bot? If you edit this script you are on your own. Do not come to me for help.