Jump to content
McKay Development

SnaBe

Member
  • Posts

    43
  • Joined

  • Last visited

Everything posted by SnaBe

  1. Here's how you can check if an offer you sent has been accepted or declined. //When one of our trade offers changes states. manager.on('sentOfferChanged', function(offer, oldState) { //Alert us when an outgoing offer is accepted. if(offer.state == TradeOfferManager.ETradeOfferState.Accepted) { console.log('Our offer #' + offer.id + ' has been accepted.'); client.chatMessage(offer.partner.getSteamID64(), 'Thanks for the trade!'); } else if(offer.state == TradeOfferManager.ETradeOfferState.Declined) { console.log('Our offer #' + offer.id + ' has been declined.'); client.chatMessage(offer.partner.getSteamID64(), 'If you believe there\'s an error with your trade offer, please contact a staff member.'); } });
  2. To add an 'x' amount of keys to the array, just add an extra check in the if statement. (The one inside the for-loop) //Loop for(var n = 0; n < inventory.length; n++) { if(theirKeys.length < amountOfKeysToAddVariable && config.csgo.acceptedKeys.indexOf(inventory[n].market_hash_name) >= 0) { theirKeys.push(inventory[n]); console.log(inventory[n].market_hash_name); } } The item ids are stored inside the theirKeys array, adding them to a trade offer is very simple. offer.addTheirItems(theirKeys); I hope this helps!
  3. You're very close, here's how I would do it. //Load the inventory manager.getUserInventoryContents(steamID, 730, 2, true, function(err, inventory) { if(err) { console.log('Error getting their inventory: ' + err); } else { console.log('Checking if user: ' + steamID + ' has any CS:GO keys we accept.'); for(var n = 0; n < inventory.length; n++) { if(config.csgo.acceptedKeys.indexOf(inventory[n].market_hash_name) >= 0) { console.log(inventory[n].market_hash_name); } } } }); acceptedKeys is an array containing all the current CS:GO keys, you can always remove or add keys to meet your needs. "acceptedKeys": [ "Glove Case Key", "Spectrum Case Key", "Gamma 2 Case Key", "Clutch Case Key", "Huntsman Case Key", "Gamma Case Key", "Spectrum 2 Case Key", "Operation Breakout Case Key", "Shadow Case Key", "Chroma 3 Case Key", "Falchion Case Key", "Winter Offensive Case Key", "Revolver Case Key", "Chroma 2 Case Key" ] To store the keys for a possible trade offer, you would have to add them in a new array. Like so: (This should be done within the for-loop) //New empty array var theirKeys = []; //Add the keys to our array theirKeys.push(inventory[n]); After that, you can see how many keys the array contains. console.log('User has ' + theirKeys.length + ' key(s).'); I would suggest a custom function for easier use. function checkKeys(steamID) { //Their keys in a new array var theirKeys = []; //Load the inventory manager.getUserInventoryContents(steamID, 730, 2, true, function(err, inventory) { if(err) { console.log('Error getting their inventory: ' + err); } else { console.log('Checking if user: ' + steamID + ' has CS:GO keys.'); for(var n = 0; n < inventory.length; n++) { if(config.csgo.acceptedKeys.indexOf(inventory[n].market_hash_name) >= 0) { theirKeys.push(inventory[n]); console.log(inventory[n].market_hash_name); } } console.log('User has ' + theirKeys.length + ' key(s).'); } }); } Chat command example: client.on('friendMessage', function(steamID, message) { if(message.match('!check')) { client.chatMessage(steamID, 'Handling your request...'); checkKeys(steamID); } else { client.chatMessage(steamID, 'I don\'t know that command.'); } });
  4. Yes, this is possible. Use steam-tradeoffer-managers getUserInventoryContents to load the user's inventory, then loop through and search for the items you need. Make a variable that stores the specific keys you want and add up. If they have the required amount to purchase admin, store the keys in an array, if not simply notify the user and return true. As the final step, you need to create a new trade offer, add the items, send and confirm the trade offer. I hope this helps!
  5. 1. Start by learning the basics of Javascript. After that, you can jump to learning more about Node JS and server-side programming. 2. APIs are not needed for a basic chatbot. 3. Read Mckay's documentation on his Steam modules, these are essential for creating a Steam bot with Node JS. 4. Here's one I created, it comes with simple explanations for every line of code. This should give you an idea of how bots are constructed (After you've learned the basics). I hope this helps! If you have any questions feel free to ask.
  6. https://github.com/DoctorMcKay/node-tf2#deleteitemitem
  7. Here's how I would do it. const config = require('./config.json'); const SteamUser = require('steam-user'); const SteamCommunity = require('steamcommunity'); const client = new SteamUser(); const community = new SteamCommunity(); const user = "76561198089922529"; const message = "Hey bud."; //Our account details const logOnOptions = { accountName: config.account.username, password: config.account.password }; //Try to log on client.logOn(logOnOptions); //We logged on client.on('loggedOn', function(details) { console.log('Bot ' + client.steamID.getSteamID64() + ' successfully logged into Steam!'); client.setPersona(SteamUser.Steam.EPersonaState.LookingToTrade, config.bot.displayName); client.gamesPlayed(config.tf2.ID); }); //Error login to Steam client.on('error', function(err) { console.log('Error: ' + err); }); //Got web session and cookies client.on('webSession', function(sessionID, cookies) { console.log('Got web session from Steam.'); community.setCookies(cookies); //We can now post a comment commentOnUserProfile(user, message); }); //Custom function to post and log comments on steam profiles function commentOnUserProfile(steamID, message) { community.postUserComment(steamID, message, function(err) { if(err) { console.log(err); } else { console.log('Successfully commented: ' + message) } }); }
  8. The comment function will be called before the loggedOn is emitted successfully, that's how Javascript works. You can add a callback to ensure no function or method is called before the bot is logged in.
  9. Their profile must be set to allow comments, and even if they set it to allow comments, they may not allow it from people not on their friend's list.
  10. The settings on this account do not allow you to add comments. Your bot can't post a comment on the users profile due to their privacy settings I believe.
  11. You're using steamcommunity to log on instead of steam-user. Make a new instance with steam-user, name it client or user. const SteamUser = require('steam-user'); const client = new SteamUser(); Add your login details to the logOnOptions object. const logOnOptions = { accountName: config.username, password: config.password }; After that you can use your client instance to log on to Steam. client.logOn(logOnOptions); And when your client emits the event loggedOn, you can console log it loggin on to Steam. client.on('loggedOn', function(details) { console.log('Bot ' + client.steamID.getSteamID64() + ' successfully logged into Steam!'); client.setPersona(SteamUser.Steam.EPersonaState.Online, "Bot online!"); client.gamesPlayed(440); }); And if there's an error login on, you can log that error to the console aswell. client.on('error', function(err) { console.log('Error: ' + err); }); I hope this solves your current issue!
  12. Here's a how I would post a comment to a profile using Steamcommunitys postUserComment(). //Custom function to post and log a comment to a Steam profile function commentOnUserProfile(steamID, message) { community.postUserComment(steamID, message, function(err) { if(err) { console.log(err); } else { console.log('Successfully commented: ' + message) } }); } When you know which profile to post on (Steamid64) and the messsage, you can call the function like so: var user = "76561198089922529"; var message = "What do you think of this comment?"; commentOnUserProfile(user, message); To post every 3 seconds you would have to learn about setInterval etc. Creating the log-on shouldn't be hard, there's plenty of examples on the wiki page for newcomers like you. I hope this helps!
  13. I thought the loadInventory method was outdated?
  14. I made a quick one and uplaoded it to github - https://github.com/SnaBe/steam-bot-constructor
  15. Here's how I would get the users display name on any chat message: client.on('friendMessage', function(steamID, message) { //When we get a message show the users steamid64 and display name. client.getPersonas([steamID], function(personas) { var persona = personas[steamID.getSteamID64()]; var name = persona ? persona.player_name : ("[" + steamID.getSteamID64() + "]"); console.log('User: ' + steamID + '\'s display name is ' + name); }); }); An example of using setNickname to set a users nickname with a chat command: //Command for setting a nickname client.on('friendMessage', function(steamID, message) { //If the message meets the requirements. var setNick; if(setNick = message.match(/^!setnick (\d+) (\D+)/i)) { var id = setNick[1]; var nickname = setNick[2]; console.log('User: ' + steamID + ' would like to give user: ' + id + ' the nickname of: ' + nickname); //Set the nickname client.setNickname(id, nickname, function(err) { if(err) { console.log('Error giving the user a nickname.'); } else { console.log('Success setting user ' + id + '\'s nickname as ' + nickname + '.'); } }); } }); I hope this helps!
  16. You could create a constructor for you bot accounts.
  17. Old issue: I had no trobule working through 1-3 and setup 4. But I'm having troubles with how I should check how much ref to add until they don't have any more or the amount I need < 9. I tried to setup up some refToAdd variable, but it didn't work as I intended , not with the current methods I know. The bot would either add to much or to little. I think that issue came from how I was adding the items to the array. However, if you could give an example on how you would do it for refined. I would be able to figure out the rest. I also realised that a user might only have ref and would need change, but I'll figure that out ones I get the basics. Update: It can now find the users metal and calculate the prices in scrap. However, it will only create a trade offer if they have the right amount of refined, reclaimed and scrap. New issue: What I'm currently looking to get help with is how I can add a change system. So the user dosen't need the specfic amount of metal. Example, ther users has 32 ref and 3 rec, but the bot will only create a succesful trade if the user has 32 ref, 2 rec and 2 scrap. So here to bot should add the 32 ref and 3 rec and then add 1 scrap from its own inventory. Below is the solution I'm currently using. //Our custom function to let users buy keys. function buyKeys(steamID, keysToBuy) { if(!keysToBuy) { return true; } //Our items for the trade offer (Must be arrays) var ourKeys = []; var ourRefined = []; var ourReclaimed = []; var ourScrap = []; //Our metal needed for change var ourMetalAdded = 0; var ourRefAdded = 0; var ourRecAdded = 0; var ourScrAdded = 0; //Their items for the trade offer var theirRefined = []; var theirReclaimed = []; var theirScrap = []; //Their metal to purchase keys var theirMetalAdded = 0; var theirMetal = 0; var theirRefAdded = 0; var theirRecAdded = 0; var theirScrAdded = 0; //Their metal count in their inventory var theirInventoryRef = 0; var theirInventoryRec = 0; var theirInventoryScrap = 0; //Bools var DoneAddingOurMetal = false; var DoneAddingTheirMetal = false; var userNeedsChange = false; //Price to buy x amount of keys var buyPriceInScrap = config.trading.buyKey * keysToBuy; //Lets get started console.log('User: ' + steamID + ' has requested to buy ' + keysToBuy + ' key(s) for ' + buyPriceInScrap + ' metal.'); //Load the users inventory manager.getUserInventoryContents(steamID, 440, 2, true, function(err, inventory) { if(err) { console.log('Error getting their inventory: ' + err); client.chatMessage(steamID, "An error occurred while loading your inventory. Please again try later."); } else { //Loop through the users inventory to count metal for(var n = 0; n < inventory.length; n++) { if(inventory[n].name.indexOf('Refined Metal') >= 0) { theirInventoryRef += 1; theirMetal += 9; } else if(inventory[n].name.indexOf('Reclaimed Metal') >= 0) { theirInventoryRec += 1; theirMetal += 3; } else if(inventory[n].name.indexOf('Scrap Metal') >= 0) { theirInventoryScrap += 1; theirMetal += 1; } } //Log the users metal. console.log('User: ' + steamID + ' has ' + theirInventoryRef + ' refined, ' + theirInventoryRec + ' reclaimed & ' + theirInventoryScrap + ' scrap in their inventory.'); console.log('User: ' + steamID + ' has ' + theirMetal + ' scrap metal in total.'); //Check if the user has enough metal. if(theirMetal < buyPriceInScrap) { console.log('User: ' + steamID + ' dosen\'t have ' + buyPriceInScrap + ' scrap metal to buy ' + keysToBuy + ' key(s).'); client.chatMessage(steamID, ' You don\'t have ' + buyPriceInScrap + ' scrap metal to buy ' + keysToBuy + ' key(s).'); return true; } else if(theirMetal >= buyPriceInScrap) { console.log('User: ' + steamID + ' has enough scrap metal to buy ' + keysToBuy + ' key(s).'); //Check their inventory again for a more detailed count. while(!DoneAddingTheirMetal) { if(theirInventoryRef > 0 && theirMetalAdded + 9 <= buyPriceInScrap) { theirMetalAdded += 9; theirRefAdded++; theirInventoryRef--; } else if(theirInventoryRec > 0 && theirMetalAdded + 3 <= buyPriceInScrap) { theirMetalAdded += 3; theirRecAdded++; theirInventoryRec--; } else if(theirInventoryScrap > 0 && theirMetalAdded + 1 <= buyPriceInScrap) { theirMetalAdded += 1; theirScrAdded++; theirInventoryScrap--; } else if(theirInventoryScrap == 0 && theirMetalAdded + 2 == buyPriceInScrap) { console.log('User: ' + steamID + ' is missing 2 scrap to complete the trade.'); client.chatMessage(steamID, 'You\'re missing 2 scrap to complete this trade.'); DoneAddingTheirMetal = true; return true; } else if(theirInventoryScrap == 0 && theirMetalAdded + 1 == buyPriceInScrap) { console.log('User: ' + steamID + ' is missing 1 scrap to complete the trade.'); client.chatMessage(steamID, 'You\'re missing 1 scrap to complete this trade.'); DoneAddingTheirMetal = true; return true; } else if(theirMetalAdded == buyPriceInScrap) { console.log('Done calculatiing user ' + steamID + '\'s metal.'); client.chatMessage(steamID, 'You\'ve the right amount of refined, reclaimed & scrap for a succesful trade. I\'ll check if I\'ve ' + keysToBuy + ' key(s).'); DoneAddingTheirMetal = true; } } } console.log('User: ' + steamID + ' will give us ' + theirRefAdded + ' refined, ' + theirRecAdded + ' reclaimed & ' + theirScrAdded + ' scrap from their inventory.'); //Add their refined metal for(var n = 0; n < inventory.length; n++) { if(theirRefined.length < theirRefAdded && inventory[n].name.indexOf('Refined Metal') >= 0) { theirRefined.push(inventory[n]); } } console.log(theirRefined.length + ' refined has been added to the trade offer.'); //Add their reclaimed for(var n = 0; n < inventory.length; n++) { if(theirReclaimed.length < theirRecAdded && inventory[n].name.indexOf('Reclaimed Metal') >= 0) { theirReclaimed.push(inventory[n]); } } console.log(theirReclaimed.length + ' reclaimed has been added to the trade offer.'); //Add their scrap for(var n = 0; n < inventory.length; n++) { if(theirScrap.length < theirScrAdded && inventory[n].name.indexOf('Scrap Metal') >= 0) { theirScrap.push(inventory[n]); } } console.log(theirScrap.length + ' scrap has been added to the trade offer.'); } }); }
  18. I've been working on TF2 trade bot over the past days and as I got close to a solution for a buy/sell command, I ran into an issue. How can I calculate the amount of metal to add to a trade offer? I had a function that found the refined, reclaimed and scrap metal in a users inventory. The same way I find the keys in the bot's inventory. I had the bot calculate the key price in metal and split it up so it new what to add. However, the bot would only add specific items to do a successful trade. Meaning that if the key price was 32.22, it would add 32 ref and 2 scrap to the trade offer. But if the user dosen't have the exact amount of refined/scrap. Example, lets say they have 31 refined, 3 reclaimed and 2 scrap, (32.22 ref in total) it would cancel (return true). This function is not in the code below since I scrapped it. So I'm looking for a way that the bot can find the users metal from their inventory with getUserInventoryContents and then add the right amount of metal to the trade offer, regardless of a specific item count. As long as the users total metal count meets the key buy price in metal. If anyone can help me or come with suggetions on what I could do, I would be thankful! Below is my buy command with the matching function: //Command for buying keys client.on('friendMessage', function(steamID, message) { //If the message meets the requirements. var buyKeysCmd; if(buyKeysCmd = message.match(/^!buy (\d+)/i)) { var keysToBuy = buyKeysCmd[1]; if(keysToBuy > 0) { buyKeys(steamID, keysToBuy); client.chatMessage(steamID, 'Processing your request.'); } else { client.chatMessage(steamID, 'You can\'t buy 0 keys.'); } } }); //Function used to buy keys with metal function buyKeys(steamID, keysToBuy) { //No specific amount of keys to buy, cancel if(!keysToBuy) { return true; } //How many keys we've in our TF2 inventory var ourKeys = []; //How much the amount of keys will cost in metal. var priceInMetal = config.trading.buyKey * keysToBuy; //Display the request. console.log('User: ' + steamID + ' has requested to buy ' + keysToBuy + ' key(s) for ' + priceInMetal + ' metal.'); //Load our TF2 inventory manager.getInventoryContents(config.bot.gameID, 2, true, function(err, inventory) { if(err) { console.log('Error getting our inventory: ' + err); client.chatMessage(steamID, 'I encountered an error getting my inventory, please try again later.'); } else { //Go trough our inventory and search for accepted keys for(var n = 0; n < inventory.length; n++) { if(ourKeys.length < keysToBuy && config.acceptedKeys.indexOf(inventory[n].market_hash_name) >= 0) { ourKeys.push(inventory[n]); } } //We don't have any keys if(ourKeys.length === 0) { client.chatMessage(steamID, 'I don\'t have any keys. Please ask an admin to re-stock or wait for me to sell some keys.'); return true; //The user has requested to buy more keys than our current stock. } else if(keysToBuy > ourKeys.length) { console.log('I don\'t have ' + keysToBuy + ' key(s).'); client.chatMessage(steamID, 'I don\'t have ' + keysToBuy + ' key(s).'); return true; } //If we've the requested amount of keys console.log('Adding ' + ourKeys.length + ' key(s) to the trade offer.'); //Load their inventory manager.getUserInventoryContents(steamID, config.bot.gameID, 2, true, function(err, inventory) { if(err) { console.log('Error getting their inventory: ' + err); client.chatMessage(steamID, "An error occurred while loading your inventory. Please again try later."); } else { //This is where the users inventory is loaded //The bot should look trough the users tf2 inventory //Find the users refined metal, reclaimed metal and scrap metal //Add it all together and log it //If the user has enough metal to purchase the requested amount of keys, continue //The bot can now add the metal to the trade offer below. var offer = manager.createOffer(steamID); //Setup the trade details. offer.addMyItems(ourKeys); //offer.addTheirItems(their metal for buying x amount of keys); offer.setMessage('You\'re buying ' + ourKeys.length + ' key(s) for ' + priceInMetal); offer.send(function(err, status) { if(err) { console.log('Error sending the trade offer: ' + err); client.chatMessage(steamID, 'Something went wrong. There was an error sending you the trade offer, please contact support if this continues.'); } else if(status == 'pending') { console.log(`Trade offer #${offer.id} is validated, but awaiting confirmation.`); client.chatMessage(steamID, 'The trade offer is validated, but awaiting confirmation.'); community.acceptConfirmationForObject(config.account.identitySecret, offer.id, function(err) { if(err) { console.log('Error confirming trade offer: ' + offer.id); client.chatMessage(steamID, 'Error confirming trade offer, declining.'); offer.decline(); } else { console.log(`Trade offer #${offer.id} confirmed.`); client.chatMessage(steamID, 'The trade offer was sent successfully. You can accept it here: http://steamcommunity.com/tradeoffer/' + offer.id); } }); } }); } }); } }); }
×
×
  • Create New...