Jump to content
McKay Development

TextDynasty

Member
  • Posts

    144
  • Joined

  • Last visited

Posts posted by TextDynasty

  1. Thanks for your help in my other question. I think this is what you want, getting the type of the metals and accept the offer right?

     

    This is my script and I hope it can help a little bit.

    //Price of items
    //They are all in scrap
    //Calculate it in : https://calculator.tf/
    //sell order
    var sellkeyprice = 249
    var buykeyprice = 248
    
    
    
    manager.on("newOffer", function(offer) {
    	console.log(colors.bgBlue(timestamp("[hh:mm:ss] Incoming offer from " + offer.partner.toString())));
    
    	var Rkey = 0
    	var Gkey = 0
    	var Gmetal = 0
    	var Rmetal = 0
    
    	var user = offer.partner.getSteam3RenderedID()
    	
    	offer.itemsToReceive.forEach(function(item) {
    		if (item.name == "Mann Co. Supply Crate Key"){
    			return Rkey++
    		}
    		else if (item.name == "Tour of Duty Ticket"){
    			return RToD++
    		}
    		else if (item.name == "Refined Metal"){
    			return Rmetal += 9
    		}
    		else if (item.name == "Reclaimed Metal"){
    			return Rmetal += 3
    		}
    		else if (item.name == "Scrap Metal"){
    			return Rmetal++
    		}}
    	);
    	
    	offer.itemsToGive.forEach(function(item) {
    		if (item.name == "Mann Co. Supply Crate Key"){
    			return Gkey++
    		}
    		else if (item.name == "Tour of Duty Ticket"){
    			return GToD++
    		}
    		else if (item.name == "Refined Metal"){
    			return Gmetal += 9
    		}
    		else if (item.name == "Reclaimed Metal"){
    			return Gmetal += 3
    		}
    		else if (item.name == "Scrap Metal"){
    			return Gmetal++
    		}
    	});
    		
    	//sell key
    	if (Gkey > 0) {
    		currency = Rmetal - Gmetal
    		if (currency === Gkey * sellkeyprice + GToD * selltodprice) {
    		offer.accept(function(err) {
    		if (err) 
    			console.log(err);
    		else 
    			console.log(colors.bgGreen(timestamp("[hh:mm:ss] Sold " + Gkey + " Keys and " + GToD + " Tour of Duty Tickets.")));
    			console.log(colors.bgGreen(timestamp("[hh:mm:ss] Amount Correct! Accepting the trade offer.")));
    			if (Gkey > 0) {
    			client.chatMessage(admin, "Sold " + Gkey + " Mann Co. Supply Keys.");
    			} else {
    			client.chatMessage(admin, "Sold " + GToD + " Tour Of Duty Tickets.");
    			}
    			setTimeout(function() {client.chatMessage(user, "Thanks for using AshleyBot. http://steamcommunity.com/id/AshleyBot")}, 5000);
    		});
    	}
    	else {
    		offer.decline(function(err) {
    			if (err)
    				console.log(err);
    				else 
    					console.log(colors.bgRed(timestamp("[hh:mm:ss] Trade offer not validated. Declining")));
    					client.chatMessage(admin, "They are buying it for " + currency + " Refined Metal.");
    					client.addFriend(user);
    					setTimeout(function() {client.chatMessage(user, "Your offer is incorrect. Please check it again or resent it later.")}, 10000);
    		});
    	}}
    	
    	//buy key
    	else if (Rkey > 0) {
    		currency = Gmetal - Rmetal
    		if (currency === Rkey * buykeyprice + RToD * buytodprice) {
    		offer.accept(function(err) {
    		if (err) 
    			console.log(err);
    		else 
    			console.log(colors.bgGreen(timestamp("[hh:mm:ss] Bought " + Rkey + " Keys and " + RToD + " Tour of Duty Tickets.")));
    			console.log("Amount Correct! Accepting the trade offer.");
    			if (Rkey > 0) {
    			client.chatMessage(admin, "Bought " + Rkey + " Mann Co. Supply Keys.");
    			} else {
    			client.chatMessage(admin, "Bought " + RToD + " Tour Of Duty Tickets.");	
    			}
    			setTimeout(function() {client.chatMessage(user, "Thanks for using AshleyBot. http://steamcommunity.com/id/AshleyBot")}, 5000);
    		});
    	}
    	else {
    		offer.decline(function(err) {
    			if (err) console.log(err);
    				else 
    					console.log("Trade offer not validated. Declining");
    					client.chatMessage(admin, "They are selling it for " + currency + " Refined Metal.");
    					client.addFriend(user);
    					setTimeout(function() {client.chatMessage(user, "Your offer is incorrect. Please check it again or resent it later.")}, 15000);
    		});
    	}}
    	
    	//other offers will be declined
    	else {
    		offer.decline(function(err) {
    			if (err) 
    				console.log(err);
    				else 
    					console.log(colors.bgRed(timestamp("[hh:mm:ss] Trade offer not validated. Declining")));
    					client.chatMessage(admin, "User provided a wrong offer. Declined.");
    					client.addFriend(user);
    					setTimeout(function() {client.chatMessage(user, "Your offer is incorrect. Please check it again or resent it later.")}, 15000);
    		});
    	}});
    

    And also one more question if you can help me a bit. I don't know how to craft any metal by the bot

    1. rec is an array of objects. If you want to craft a single reclaimed metal into scrap, then you need to extract a single one (say, element #0) and put it in an array by itself.

    So in order to craft one reclaimed into scrap, you want to do tf2.craft(rec[0].id);

     

    Sorry. What do you mean by element #0?

  2. You need to pass an array. [rec[0].id]

    Do you mean by replacing the [rec[0].id] by the reclaimed metal asset ID itself?

    if (scrap.length < 3) {
    				console.log("Crafting more scrap...");
    				tf2.craft([5345296927]); // The assetID? or what should i put in an array
    				console.log("Done.");
    			}
    

    Or this?

    if (scrap.length < 3) {
    				console.log("Crafting more scrap...");
    				tf2.craft(rec[0].assetid);
    				console.log("Done.");
    			}
    
  3. No, that's very wrong. Where you create your client, you need to also create your tf2.

    Do you mean by this?

    var Winston           = require('winston'); // For logging
    var SteamUser         = require('steam-user'); // The heart of the bot.  We'll write the soul ourselves.
    var TradeOfferManager = require('steam-tradeoffer-manager'); // Only required if you're using trade offers
    var config2           = require('./config2.js');
    var fs                = require('fs'); // For writing a dope-ass file for TradeOfferManager
    var SteamTotp         = require('steam-totp')
    var Steamcommunity    = require('steamcommunity');
    var Steam 			  = require('steam');
    var colors 			  = require('colors');
    var TeamFortress2 	  = require('tf2');
    var Language 		  = require('./language.js');
    var timestamp 		  = require('console-timestamp');
    var TeamFortress2 	  = require('tf2');
    
    var handlers = TeamFortress2.prototype._handlers;
    var client = new SteamUser();
    var tf2 = new TeamFortress2(client); //So i created tf2 here?
    
    client.on('loggedOn', function (details) {
        console.log(timestamp("[hh:mm:ss] Logged into Steam as " + config2.username.green));
        client.gamesPlayed([440]); //Connected to TF2 GC?
    });
    
    if (scrap.length < 3) {
    				console.log("Crafting more scrap...");
    				tf2.craft(rec[0].id);
    				console.log("Done.");
    			}
    
    

    But it didn't work also

  4.  

    1. You need to be connected to the TF2 GC in order to craft. This means that you can't simply construct a new TeamFortress2 object whenever you want to craft something; you need to create one global one so it can remain connected.

     

    client.on('loggedOn', function (details) {
        console.log(timestamp("[hh:mm:ss] Logged into Steam as " + config2.username.green));
        client.gamesPlayed([440]); //Connected to TF2 GC?
    })
    
    if (haveGCSession = true) {
    			var tf2 = new TeamFortress2(user);
    			if (scrap.length < 3) {
    				console.log("Crafting more scrap...");
    				tf2.craft(rec[0].id);
    				console.log("Done.");
    			}} else {
    				console.log("We didn't connected to TF2 GC")
    			}
    
  5.  

    1. You need to be connected to the TF2 GC in order to craft. This means that you can't simply construct a new TeamFortress2 object whenever you want to craft something; you need to create one global one so it can remain connected.
    2. You can't pass an object to craft, it needs to be an item ID.
    3. rec is an array of objects. If you want to craft a single reclaimed metal into scrap, then you need to extract a single one (say, element #0) and put it in an array by itself.

    So in order to craft one reclaimed into scrap, you want to do tf2.craft(rec[0].id);

     

    Thanks for the answer. The errors are gone, but it didn't craft any metal out...

    var tf2 = new TeamFortress2(user);
    			if (scrap.length < 3) {
    				user.gamesPlayed([440]);
    				console.log("Crafting more scrap...")
    				tf2.craft(rec[0].id);
    				console.log("Done.")
    			}
    
  6. Hi.

    I used the node tf2 for crafting metal, but i found out some problems in my coding that it didn't work.

    manager.loadInventory(440, 2, true, function(err, inventory) {
    			if (err) {
    				console.log(err);
    				return;
    			}
    
    			if (inventory.length == 0) {
    				// Inventory empty
    				console.log("TF2 inventory is empty");
    				return;
    			}
    			console.log(colors.bold.green.bgYellow("Backpack has " + inventory.length + " items"));
    			var key = inventory.filter(function (item) {
                    return item.name == 'Mann Co. Supply Crate Key'
                });
    			var ref = inventory.filter(function (item) {
                    return item.name == 'Refined Metal'
                });
    			var rec = inventory.filter(function (item) {
                    return item.name == 'Reclaimed Metal'
                });
    			var scrap = inventory.filter(function (item) {
                    return item.name == 'Scrap Metal'
                });
    			
    			var tf2 = new TeamFortress2(user);
    			if (scrap.length < 3) {
    				console.log("Crafting more scrap...")
    				tf2.craft(rec) //craft a reclaimed metal when there are not enough scrap
    			}
    		});
    

    Error:

    node_modules\bytebuffer\dist\ByteBufferNB.js:1067
                        throw TypeError("Illegal value: "+value+" (not an integer or Long)");
                        ^
    
    TypeError: Illegal value: [object Object] (not an integer or Long)
        at TypeError (native)
  7. That is happening because log is not defined. You want to move the polldata-reading block of code beneath where you define your logger, and change log.verbose to logger.verbose.

    Thanks for answering. But i got this after i changed to this coding

    var logger = new (Winston.Logger)({
            transports: [
                new (Winston.transports.Console)({
                    colorize: true, 
                    level: 'debug'
                }),
                new (Winston.transports.File)({
                    level: 'info', 
                    timestamp: true, 
                    filename: 'cratedump.log', 
                    json: false
                })
            ]
    });
    
    if(fs.existsSync(POLLDATA_FILENAME)) {
    	try {
    		manager.pollData = JSON.parse(fs.readFileSync(POLLDATA_FILENAME));
    	} catch(e) {
    		logger.verbose("polldata.json is corrupt");
    	}
    }
    
    manager.on('pollData', function(pollData) {
    	fs.writeFile(POLLDATA_FILENAME, JSON.stringify(pollData));
    });
    

    Error

    verbose: polldata.json is corrupt
    Welcome back my master.
    Found previous trade offer poll data.  Importing it to keep things running smoothly.
    undefined:1
    
    
    
    SyntaxError: Unexpected end of input
        at Object.parse (native)
        at C:\Users\kingwang\Desktop\Trade Offer Bot\bot2.js:93:32
        at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
     Press any key to continue . . .
    
  8. Hi.

    I got a problem like this and i don't know how to fix it.

                    log.verbose("polldata.json is corrupt");
                    ^
    
    ReferenceError: log is not defined
        at Object.<anonymous> (C:\Users\kingwang\Desktop\Trade Offer Bot\bot2.js:55:3)
        at Module._compile (module.js:409:26)
        at Object.Module._extensions..js (module.js:416:10)
        at Module.load (module.js:343:32)
        at Function.Module._load (module.js:300:12)
        at Function.Module.runMain (module.js:441:10)
        at startup (node.js:139:18)
        at node.js:974:3
    

    And here is my code

    if(fs.existsSync(POLLDATA_FILENAME)) {
    	try {
    		manager.pollData = JSON.parse(fs.readFileSync(POLLDATA_FILENAME));
    	} catch(e) {
    		log.verbose("polldata.json is corrupt");
    	}
    }
    
    manager.on('pollData', function(pollData) {
    	fs.writeFile(POLLDATA_FILENAME, JSON.stringify(pollData));
    });
    
    var logger = new (Winston.Logger)({
            transports: [
                new (Winston.transports.Console)({
                    colorize: true, 
                    level: 'debug'
                }),
                new (Winston.transports.File)({
                    level: 'info', 
                    timestamp: true, 
                    filename: 'cratedump.log', 
                    json: false
                })
            ]
    });
    
    var client = new SteamUser();
    var offers = new TradeOfferManager({
        steam:        client,
        domain:       config2.domain, 
        language:     "en", 
        pollInterval: 10000, 
        cancelTime:   50000 
    });
    
    fs.readFile('polldata.json', function (err, data) {
        if (err) {
            logger.warn('Error reading polldata.json. If this is the first run, this is expected behavior: '+err);
        } else {
            console.log('Welcome back my master.'.green);
    		console.log("Found previous trade offer poll data.  Importing it to keep things running smoothly.".info);
            offers.pollData = JSON.parse(data);
        }
    });
    
    client.logOn({
        accountName: config2.username,
        password: config2.password,
    });
    
    client.on('loggedOn', function (details) {
        console.log(timestamp("[hh:mm:ss] Logged into Steam as " + config2.username.green));
        // If you wanted to go in-game after logging in (for crafting or whatever), you can do the following
        client.gamesPlayed(440);
    });
    
    client.on('webSession', function (sessionID, cookies) {
        console.log("Got web session".info);
        client.setPersona(1)
        offers.setCookies(cookies, function (err){
            if (err) {
                logger.error('Unable to set trade offer cookies: '+err);
                process.exit(1); 
            }
            logger.info("Trade offer cookies set.");
    		manager.loadInventory(440, 2, true, function(err, inventory) {
    			if (err) {
    				console.log(err);
    				return;
    			}
    
    			if (inventory.length == 0) {
    				// Inventory empty
    				console.log("TF2 inventory is empty");
    				return;
    			}
    			console.log("Found " + inventory.length + " TF2 items");
    			var ref = inventory.filter(function (item) {
                    return item.name == 'Refined Metal'
                });
    			var rec = inventory.filter(function (item) {
                    return item.name == 'Reclaimed Metal'
                });
    			var scrap = inventory.filter(function (item) {
                    return item.name == 'Scrap Metal'
                });
    			console.log("Found " + ref.length + " Refined Metal");
    			console.log("Found " + rec.length + " Reclaimed Metal");
    			console.log("Found " + scrap.length + " Scrap Metal");
    			
    			var inventory = inventory.filter(function (item) {
                    return item.name == 'Refined Metal'
                });
    			
    			var trade = offers.createOffer(admin);
    			trade.addMyItems(inventory);
    			trade.setMessage("Here, have some items!");
    			trade.send(function(err, status) {
    				if (err) {
    					console.log(err);
    				} else {
    					console.log("Success. Offer was sent to admin.")
    				}
    			});
    		});
    	});
    });
    

    Any ideas how to fix this problem? Also, my bot is working fine before

  9. Hi there. I found a code from gihub and idk if it is working... because it doesnt do anything.

    user.on('inventory', function (backpack, craft, err) {
    	var inventory = backpackLoaded
    	var random_refined = getRandomRefinedID(inventory);
    	tf2.craftItems([random_refined]); // will smelt first refined found in the inventory
    	setTimeout(function() {
        steamTrade.loadInventory(440, 2, function(inventory1) { // reload inventory
            console.log("loaded new inventory 1");
            if (JSON.stringify(inventory1) !== JSON.stringify(inventory)) { // if inventory has changed
                console.log("got the new backpack!");
                var random_reclaimed = getReclaimedIDs(inventory1, inventory); //get the id of a reclaimed smelted before
                tf2.craftItems([random_reclaimed]); // smelt it to a scrap
                setTimeout(function() {
                    steamTrade.loadInventory(440, 2, function(inventory2) { // reload inventory
                        console.log("loaded new inventory 2");
                        if (JSON.stringify(inventory2) !== JSON.stringify(inventory1)) { // if inventory has changed
                            console.log("Yes, new backpack!");
                            inventory = inventory2;
                        } else {
                            console.log("oh no , still the old one");
                        }
                    });
                }, 10000);
            } else {
                console.log("still as the old one :(");
            }
        });
    }, 10000);
    })
    
  10. Like Dr. McKay said, you can use the event friendOrChatMessage to find out if someone send you a message, so you can respond to them.

     

    I have the other method friendMessage, which will only send something back when you get a message from a friend.

    // When we get a message, send back a response and log to console
    client.on("friendMessage", function(steamID, message) {
    		console.log("Friend message from " + steamID+ ": " + message);
    		if (message == "Ping") {
    			client.chatMessage(steamID, "Pong");
    			console.log("Send back: Pong");
    		} else {
    			client.chatMessage(steamID, config.greetMsg);
    			console.log("Send back the standard reply");
    		}
    	});
    });
    

    When your bot gets the message 'Ping' it will send back 'Pong'.

    If your bot gets a different message, it will respond with a standard reply which you should create in your config.json file.

     

    If you want more reply options, I'd suggest creating a switch statement with several cases.

     

    Thanks for the explanation.

  11. I only need to make bot run Sign Ä°n command.

    Are you using node to login?

    If yes, i hope it would help

    var client = new SteamUser();
    client.logOn({
        accountName: config.username, //type your username
        password: config.password,  //type your password
    	"twoFactorCode": SteamTotp.getAuthCode("shared_secret")  //type your shared secret
    });
    
  12. I have no idea what's up with the crafting event, but unless you're emitting it yourself you shouldn't be using it.

     

    You don't need to specify any appid or contextid (there is no such thing as a contextid outside of the Steam econ server). node-tf2 knows what TF2's appid is.

     

    You need to pass an array of item IDs to craft.

    Array is like this?

    {
        "appid": 440,
        "contextid": 2,
        "amount": 1,
        "assetid": "1627590398"
    }
    

    But i tried that, he said i "appid" is need to follow by ")". i don't know what to do

  13. Why are you editing the library's code? Don't do that.

    sorry, I thought it was an example...

     

    but i don't really understand about the backpack....

     

    sorry about i may be annoying...

     

    I have tried my best

    client.on('crafting', function(err, craftItems) {
    	craftItems(440, 2, 5193739645)
            //can we skip the recipe part and get assetid from backpack directly replace the code?
    	console.log("Crafted Metals")
    });
    
  14. That's up to you. Look at the contents of backpack and find what you're looking for.

     

    I've seen you example but i still don't understand what to do with the recipe because it doesn't do anything to my metal

    handlers[Language.CraftResponse] = function(body) {
    	var blueprint = body.readInt16(); // recipe ID??
    	var unknown = body.readUint32(); 
    	
    	var idCount = body.readUint16();
    	var idList = [440, 2, 5193739645]; // 5193739645 is my assetid
    	
    	for(var i = 0; i < idCount; i++) {
    		var id = body.readUint64().toString();
    		idList.push(id); // item id
    	}
    	
    	this.emit('craftingComplete', blueprint, idList);
    };
    
×
×
  • Create New...