Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const SteamUser = require('steam-user');
- const TradeOfferManager = require('steam-tradeoffer-manager');
- const SteamTotp = require('steam-totp');
- const SteamCommunity = require('steamcommunity');
- const config = require('./config.json');
- const winston = require('winston');
- const array = require("./price_accepted_keys.js");
- const community = new SteamCommunity();
- const client = new SteamUser();
- const manager = new TradeOfferManager({
- steam: client,
- domain: 'example.com',
- language: 'en'
- });
- /*
- edit these to add and remove listings
- SellPrices = Price to sell items at in keys
- BuyPrices = Price to buy items at in keys
- edit tutorial
- to add a listing to the bot simply follow the exsamples below
- var exsample = {'name':11, 'name 2':6, 'name3':75}
- var exsample2 = {'name':11, 'name 2':6}
- make sure to leave a comma and a space as can be seen between 'name1' and 'name2' but keep in mind do not do this at the end
- you can have as many as you like!
- bot aacepts all keys ask me if you want something diffrent
- */
- //edit these
- var SellPrices = require('./price_accepted_keys.js').SellPrices;
- var BuyPrices = require('./price_accepted_keys.js').BuyPrices;
- var acceptedKeys = require('./price_accepted_keys.js').acceptedKeys;
- //end editing here
- winston.add(winston.transports.File, {
- filename: 'events.log'
- });
- winston.remove(winston.transports.Console);
- const logOnOptions = {
- accountName: config.username,
- password: config.password,
- twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
- };
- //log on
- client.logOn(logOnOptions);
- client.on('loggedOn', function(details) {
- console.log(`Logged into Steam as ${client.steamID.getSteam3RenderedID()}`); //online then play tf2
- client.setPersona(SteamUser.Steam.EPersonaState.Online);
- client.gamesPlayed([440])
- });
- client.on('webSession', function(sessionID, cookies) {
- manager.setCookies(cookies, function(err) {
- if (err) return console.log(err);
- console.log(`Got API key: ${manager.apiKey}`);
- });
- community.setCookies(cookies);
- community.startConfirmationChecker(10000, config.identitySecret);
- });
- client.on('friendRelationship', (steamID, relationship) => { //freind requests
- if (relationship == 2) {
- client.addFriend(steamID);
- client.chatMessage(steamID, config.welcomeMessage);
- }
- });
- client.on('friendMessage', (steamID, message) => {
- if (message.startsWith("!buy prices")) {
- var Msg = JSON.stringify(BuyPrices) //converting buy array to a string
- var Msg = Msg.replace('{',''); //removing '{'
- var Msg = Msg.replace('}',''); //removing '}'
- client.chatMessage(steamID, Msg);
- }else {
- if (message.startsWith("!sell prices")) {
- var Msg = JSON.stringify(SellPrices) //converting buy array to a string
- var Msg = Msg.replace('{',''); //removing '{'
- var Msg = Msg.replace('}','');
- client.chatMessage(steamID, Msg);
- }
- }
- });
- function Get_Item_Vaule(offer, price) { //get the vaule of items in offer and count
- var name;
- var Vaule = 0;
- for (i = 0; i < offer.length; i++) {
- name = offer[i].market_hash_name;
- if (price[name]) {
- Vaule += price[name]
- }
- }
- return Vaule;
- }
- function Get_keys(offer, acceptedKeys) { //get accepted keys in offer and count
- var name;
- var Keys = 0;
- for (i = 0; i < offer.length; i++) {
- name = offer[i].market_hash_name;
- if (acceptedKeys.includes(name)){
- Keys += 1
- }
- }
- return Keys;
- }
- function acceptOffer(offer) {
- offer.accept((err) => {
- if (err) winston.info(`Unable to accept offer: ${err.message}`);
- community.checkConfirmations();
- });
- }
- function declineOffer(offer) {
- offer.decline((err) => {
- if (err) return winston.info(`Unable to decline offer: ${err.message}`);
- });
- }
- manager.on('newOffer', function(offer) {
- const partnerID = offer.partner.getSteamID64();
- winston.info("offer incoming from " + partnerID);
- var ThereItemVaule = Get_Item_Vaule(offer.itemsToReceive, BuyPrices);
- var ThereKeys = Get_keys(offer.itemsToReceive, acceptedKeys);
- var ThereTotalVaule = ThereKeys + ThereItemVaule;
- console.log(ThereTotalVaule);
- var OurItemVaule = Get_Item_Vaule(offer.itemsToGive, SellPrices);
- console.log(OurItemVaule);
- var OurKeys = Get_keys(offer.itemsToGive, acceptedKeys);
- console.log(OurKeys);
- var OurTotalVaule = OurKeys + OurItemVaule;
- console.log(OurTotalVaule);
- if (OurTotalVaule <= ThereTotalVaule) {
- acceptOffer(offer);
- winston.info("accepted offer from " + partnerID + " we made profit!");
- }else{
- declineOffer(offer);
- winston.info("declined offer from " + partnerID + " we would have lost money");
- }
- });
Add Comment
Please, Sign In to add comment