Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const SteamUser = require('steam-user');
- const SteamTotp = require('steam-totp');
- const SteamCommunity = require('steamcommunity');
- const TradeOfferManager = require('steam-tradeoffer-manager');
- const TeamFortress2 = require('tf2');
- const Prices = require('./prices.json');
- const config = require('./config.json');
- const client = new SteamUser();
- const tf2 = new TeamFortress2(client);
- const community = new SteamCommunity();
- const manager = new TradeOfferManager ({
- steam: client,
- community: community,
- language: 'en'
- });
- const logOnOptions = {
- accountName: config.username,
- password: config.password,
- twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
- };
- client.logOn(logOnOptions);
- client.on('loggedOn', () => {
- console.log('successfully logged on.')
- client.setPersona(SteamUser.Steam.EPersonaState.Online);
- client.gamesPlayed([440]);
- });
- client.on("friendMessage", function(steamID, message) {
- if (message == "!help") {
- client.chatMessage(steamID, "Hey! I'm an actual trader, but the bot is still a work-in-progress. Just go by the classifieds and, hopefully, it should work. Thanks again!");
- }
- });
- client.on('webSession', (sessionid, cookies) => {
- manager.setCookies(cookies);
- community.setCookies(cookies)
- community.startConfirmationChecker(20000, config.identitySecret);
- });
- function acceptOffer(offer) {
- offer.accept((err) => {
- community.checkConfirmations();
- console.log("We accepted an offer!");
- if (err) console.log("Oof! That's not radical. There was an error with accepting the offer, man.");
- });
- }
- function declineOffer(offer) {
- offer.decline((err) => {
- console.log("We declined an offer.");
- if (err) console.log("Oof! That's not radical. There was an error with declining the offer, man.");
- });
- }
- function processOffer(offer) {
- if (offer.isGlitched() || offer.state === 11) {
- console.log("Ooohhh.... that's not good. The offer's glitched. Declining...");
- declineOffer(offer);
- } else if (offer.partner.getSteamID64() === config.ownerID) {
- acceptOffer(offer);
- } else {
- var ourItems = offer.itemsToGive;
- var theirItems = offer.itemsToReceive;
- var ourValue = 0;
- var theirValue = 0;
- for (var i in ourItems) {
- var item = ourItems[i].market_name
- if(Prices[item]) {
- ourValue += Prices[item].sell;
- } else {
- console.log("Woah, slow down there, dude! That's the invalid value.")
- ourValue += 99999;
- }
- }
- for(var i in theirItems) {
- var item= theirItems[i].market_name;
- if(Prices[item]) {
- theirValue += Prices[item].buy;
- } else {
- console.log("Dude, their value was different.")
- }
- }
- }
- console.log("Our value: "+ourValue);
- console.log("Their value: "+theirValue);
- if (ourValue <= theirValue) {
- acceptOffer(offer);
- } else {
- declineOffer(offer);
- }
- }
- client.setOption("promptSteamGuardCode", false);
- manager.on('newOffer', (offer) => {
- processOffer(offer);
- });
- /* Crafting */
- var scrapAmt = 25;
- var pollCraft = 30;
- tf2.on('connectedToGC', function() {
- console.log("Gnarly, bro! Just connected to the TF2 game server.")
- });
- tf2.on('backpackLoaded', function () {
- console.log("Backpack just got loaded, bro.");
- });
- function craftS(amtNeedScrap) {
- if (tf2.backpack == undefined) {
- console.log("Damnit, we can't load the backpack! No crafting here.");
- return
- } else {
- console.log("Hang on, bro. We're attempting to craft...")
- var amtOfScrap = 0;
- for (var i = 0; i < tf2.backpack.length; i++) {
- if (tf2.backpack[i].defIndex === 5000) {
- amtOfScrap++;
- }
- }
- for (var i = 0; i < tf2.backpack.length; i++) {
- if (tf2.backpack[i].defIndex = 5002) {
- amtOfScrap+=9;
- var beep = new Array;
- beep.push(parseInt(tf2.backpack[i].id));
- tf2.craft(beep);
- } else if (tf2.backpack[i]defIndex === 5001) {
- amtOfScrap +=3;
- var beep = new Array;
- beep.push(parseInt(tf2.backpack[i].id));
- tf2.craft(beep);
- }
- if (amtOfScrap >= amtNeedScrap) {
- break;
- }
- }
- }
- }
- tf2.on('craftingComplete', function(e) {
- conosle.log("Finished crafting, dude!");
- });
- client.on('friendMessage#'+config.ownerID, function(steamID, message) {
- if (message == "!craft") {
- craft(scrapAmt);
- console.log("Received order to craft!")
- } else {
- console.log("Damn! Craft error, man.")
- }
- });
- setInterval(function() {
- craftS(scrapAmt);
- }, 1000 * 60 * pollCraft)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement