Arcana / node-dota2-bot

Wrapper around the node-dota2 library which handles all log-in shenanigans
MIT License
9 stars 7 forks source link

Bot keeps changing name back... #5

Closed ProbablyPeps closed 7 years ago

ProbablyPeps commented 7 years ago

Hi. (Sorry for posting in wrong repo last time)

My bot keeps changing it's name back from Profile name -> Steam account name every time it goes online. Even if im using dota.steamFriends.setPersonaName("Profile name"); it gets changed :( If i log into account and change manually it will stay that way, but get changed back almost every time at login. (not always..dont know why)

const Discord = require("discord.js"); 
const DotaBot = require("dota2-bot");

const discordToken = process.env["DISCORD_TOKEN"];
let discordChannel = null;

const steamLogin = { "account_name": process.env['STEAM_USER'], "password": process.env['STEAM_PASS'] };

const debug = true; 
const debugMore = true; 

const discord = new Discord.Client();
const dota = new DotaBot(steamLogin, debug, debugMore);

discord.on("message", msg => { // Prevent explosion
    if (msg.author.id !== "12345678" && msg.channel.name === 'hunchat') { 
        dota.schedule(() => {
            dota.Dota2.sendMessage('Budapest, Hungary', msg.author.username + ": " + msg.content, 0); 
        }); 
    } 
});

dota.Dota2.on("chatMessage", (channel, sender, txt, msg) => { // Prevent explosion 
    if (sender !== steamLogin.account_name) {
    discordChannel.sendMessage(`**${sender}**: ${txt}`);
    } 
});

discord.on("ready", () => { // Make sure discord part is ready before joining chat channel 
  dota.schedule(() => dota.Dota2.joinChat('Budapest, Hungary', 0));
    discordChannel = discord.channels.get("12345678");
});
dota.steamClient.on('logOnResponse', function(res) {
dota.steamFriends.setPersonaName("Profile name");
});
discord.login(discordToken); 
dota.connect();

Here is a screenshot of what happens when i run the bot: https://cloud.githubusercontent.com/assets/25479451/23907362/28034a54-08d1-11e7-95b3-5103e02aaf49.png

Crazy-Duck commented 7 years ago

At the moment this is "normal" behavior of the bot. Check index.js at line 46. I set the personaname to the account name. I'm going to have to add a parameter to the logindetails for that.

The reason why setting the persona name in your code works once in a while is because of how node js handles events. When an event fires, it will call all its listeners in random order. So if your listener gets called after the bot's, then the persona name is changed. If it's the other way around it isn't changed. What you could do is attach your listener to the ready event instead (with a once call), that way you're sure your handler will be called after the bot's.

ProbablyPeps commented 7 years ago

Hey duck.

Thanks for the reply, unfortunately i got this attached code written to me, cause i know coding as much as a potato. Would it be a huge favour to ask: if you could insert this line into the correct place into my code please? ^^

Crazy-Duck commented 7 years ago

It's already updated on the master branch, I just need to push it to npm