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) {//StartWebAPIif (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);});}//EndWebAPIsteamUser.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 :)
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 theundefined
sender name. Can you look into this :)