Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // NPM shit
- require('console-stamp')(console, 'HH:MM:ss');
- const colors = require('colors');
- 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 request = require('request');
- var webshot = require('webshot');
- const Prices = require('./configstuff/prices.json');
- const config = require('./configstuff/config.json');
- const bplists = require('./configstuff/listings.js')
- const client = new SteamUser();
- const tf2 = new TeamFortress2(client);
- const community = new SteamCommunity();
- const manager = new TradeOfferManager ({
- steam: client,
- community: community,
- language: 'en'
- });
- // Colours
- colors.setTheme({
- log: 'green',
- info: 'blue',
- warn: 'yellow',
- error: 'red'
- });
- /*
- var options = {
- screenSize: {
- width: 1500
- },
- shotSize: {
- height: 'all',
- quality : 85
- },
- phantomConfig: {
- 'ignore-ssl-errors': 'true'
- },
- cookies: [
- {
- name: 'Steam_Language',
- value: 'english',
- domain: '.steamcommunity.com',
- path: '/'
- },
- {
- name: 'sessionid',
- value: 'd422cfcbb41de3f4aaa4fc8d',
- domain: '.steamcommunity.com',
- path: '/'
- },
- {
- name: 'steamLogin',
- value: '76561197969827060%7c%7c580E063115E83A5ADF1397DA4BFE0232445DCDFC',
- domain: '.steamcommunity.com',
- path: '/'
- },
- {
- name: 'steamLoginSecure',
- value: '76561197969827060%7c%7c9904D2962EDDA36BC88DAF497701AB24636A2838',
- domain: '.steamcommunity.com',
- path: '/'
- }
- ]
- };
- webshot('steamcommunity.com/id/ScrapWhore/tradeoffers', 'tradeoffer.png', options, function(err) {
- if (err) {
- console.log(err);
- } else {
- console.log('Saved!');
- }
- }); */
- // Discord stuff
- var discord = require('discord.io');
- var Dbot = new discord.Client({
- token: "Mzc3ODAxMDg4NzcxOTQ4NTQ0.DZBTUw.pObzG6keTOHiiRAR1Tf4aXZVHB8",
- autorun: true
- });
- Dbot.on('ready', function() {
- console.log('Logged in as %s - %s\n', Dbot.username, Dbot.id);
- });
- Dbot.on('message', function(user, userID, channelID, message, event) {
- if (message === "checkStatus") {
- Dbot.sendMessage({
- to: channelID,
- message: "I am still online :D"
- });
- }
- });
- // Steam login
- const logOnOptions = {
- accountName: config.username,
- password: config.password,
- twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
- };
- client.setOption("promptSteamGuardCode", false);
- client.logOn(logOnOptions);
- client.on('loggedOn', () => {
- console.log(colors.log('Logged into Steam! Sending a heartbeat every 120 seconds'));
- client.setPersona(SteamUser.Steam.EPersonaState.LookingToTrade);
- client.gamesPlayed(["Trading Items! 24/7!", 440]); /* 440 is TF2 */
- });
- // Accepting friend requests + messages
- client.on('friendRelationship', (steamID, relationship) => {
- if (relationship === 2) {
- console.log(colors.log("Friend request received: " + steamID))
- client.addFriend(steamID);
- console.log(colors.log("Sending add message"))
- client.chatMessage(steamID, config.addMessage);
- }
- });
- client.on("friendMessage", function(steamID, message) {
- if (message == "!info") {
- client.chatMessage(steamID, config.infoMessage);
- } else {
- client.chatMessage(steamID, "Command not recognized, type !info to get some information about the bot!");
- }
- });
- client.on('webSession', (sessionid, cookies) => {
- manager.setCookies(cookies);
- community.setCookies(cookies);
- community.startConfirmationChecker(20000, config.identitySecret);
- });
- // Handling trade offers
- function acceptOffer(offer, steamID) {
- offer.accept((err) => {
- community.checkConfirmations();
- console.warn(colors.warn("Accepted an offer from " + offer.partner))
- if (err) console.error(colors.error("There was an error accepting the offer: " + err));
- });
- }
- function declineOffer(offer, steamID) {
- offer.decline((err) => {
- console.warn(colors.warn("Declined an offer from " + offer.partner))
- if (err) console.error(colors.error("There was an error declining the offer: " + err));
- });
- }
- function roundRefined(float){
- var int = Math.floor(float);
- var r = Math.round((float-int) / 0.11 );
- return(int + (9 === r ? 1 : 0.11*r)).toFixed(2)
- }
- function smoothRefined(float){
- return float%1!==0&&(float-Math.floor(float)).toPrecision(2)*100%11!==0?(float-0.01).toFixed(2):float;
- }
- manager.on('receivedOfferChanged', function(offer, oldState) {
- console.log(`Offer #${offer.id} changed: ${TradeOfferManager.ETradeOfferState[oldState]} -> ${TradeOfferManager.ETradeOfferState[offer.state]}`);
- Dbot.sendMessage({
- to: '425024336529981460', message: `Offer #${offer.id} changed: ${TradeOfferManager.ETradeOfferState[oldState]} -> ${TradeOfferManager.ETradeOfferState[offer.state]}`});
- if (offer.state == TradeOfferManager.ETradeOfferState.Accepted) {
- offer.getExchangeDetails((err, status, tradeInitTime, receivedItems, sentItems) => {
- if (err) {
- console.log(`Error ${err}`);
- return;
- }
- // Create arrays of just the new assetids using Array.prototype.map and arrow functions
- let newReceivedItems = receivedItems.map(item => item.market_hash_name);
- let newSentItems = sentItems.map(item => item.market_hash_name);
- Dbot.sendMessage({
- to: '425024336529981460', message: `**status:** ${TradeOfferManager.ETradeStatus[status]} \n **Received items:** ${newReceivedItems.join(', ')} \n **Sent Items:** ${newSentItems.join(', ')}`
- });
- var listings = [];
- var options = {
- uri:"https://backpack.tf/api/classifieds/list/v1",
- json: true,
- method: "POST",
- gzip: true,
- qs: {
- token: config.token
- }
- }
- let CKey;
- if(Prices["Mann Co. Supply Crate Key"])
- CKey = roundRefined(Prices["Mann Co. Supply Crate Key"].sell * 0.11);
- receivedItems.forEach(item => {
- if(Prices[item.market_hash_name].sell){
- if(!CKey)
- throw new Error("Cannot use undefined key value.");
- let metal = roundRefined(Prices[item.market_hash_name].sell * 0.11);
- let keys = CKey && metal > CKey ? Math.floor(metal / CKey) : 0;
- metal = keys > 0 ? smoothRefined(metal % CKey) : metal;
- listings.push({
- intent: 1,
- id: item.new_assetid,
- offers: 1,
- buyout: 1,
- promoted: 0,
- currencies: {
- keys: keys,
- metal: metal
- },
- details: config.listingComment
- });
- }
- });
- setTimeout(() => {
- refreshInventory((err) => {
- if(!err){
- options["body"] = {listings: listings};
- request(options, function (error, response, body) {
- if(!error){
- console.log("Created new Sell Listings");
- console.log(body);
- } else {
- console.log(error);
- }
- });
- }
- });
- }, 1000 * 60 * 5);
- })
- }
- });
- function refreshInventory(callback){
- request("https://backpack.tf/_inventory/"+client.steamID.getSteamID64()+"?time=&source=steam", (err, response, body) => {
- if(!err && response.statusCode === 200) {
- callback(null);
- } else {
- return refreshInventory(callback);
- }
- });
- }
- function processOffer(offer) {
- if (offer.isGlitched() || offer.state === 11) {
- console.warn(colors.warn("Offer was unavailable, declining."));
- declineOffer(offer);
- Dbot.sendMessage({
- to: '425024336529981460', message: "Declined an offer, offer unavailable"});
- } else if (offer.partner.getSteamID64() === config.owner1) {
- console.info(colors.info("Offer recieved from Procave, accepting."))
- acceptOffer(offer);
- Dbot.sendMessage({
- to: '425024336529981460', message: "Offer recieved from Procave, accepting."});
- } else if (offer.partner.getSteamID64() === config.owner2) {
- console.info(colors.info("Offer recieved from Zeus, accepting."))
- acceptOffer(offer);
- Dbot.sendMessage({
- to: '425024336529981460', message: "Offer recieved from Zeus, accepting."});
- } else if (offer.partner.getSteamID64() === config.owner3) {
- console.info(colors.info("Offer recieved from Lemons, accepting."))
- acceptOffer(offer);
- Dbot.sendMessage({
- to: '425024336529981460', message: "Offer recieved from Lemons, accepting."});
- } 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.warn(colors.warn("Item we're giving doesn't have a value: declining."))
- ourValue+= 99999;
- }
- }
- for (var i in theirItems) {
- var item = theirItems[i].market_name;
- if(Prices[item]) {
- theirValue += Prices[item].buy;
- } else {
- console.warn(colors.warn("Item they're giving doesn't have a value: declining."))
- }
- }
- console.info(colors.info("Our value: " + ourValue));
- console.info(colors.info("Their value: " + theirValue));
- if (ourValue <= theirValue) {
- acceptOffer(offer);
- client.chatMessage('76561198144346135', "Accepted an offer, their value: " + theirValue+ " and our value: " + ourValue);
- Dbot.sendMessage({
- to: '425024336529981460', message: "Accepted an offer, their value: " + theirValue+ " and our value: " + ourValue});
- } else {
- declineOffer(offer);
- client.chatMessage('76561198144346135', "Declined an offer, their value: " + theirValue+ " and our value: " + ourValue);
- Dbot.sendMessage({
- to: '425024336529981460', message: "Declined an offer, their value: " + theirValue+ " and our value: " + ourValue});
- }
- }
- }
- manager.on('newOffer', (offer) => {
- console.info(colors.info("New offer received from " + offer.partner))
- processOffer(offer);
- if (offer.itemsToGive.length === 0) {
- offer.accept((err, status) => {
- if (err) {
- console.error(colors.error(err));
- } else {
- console.info(colors.info(`Donation accepted.`));
- }
- });
- }
- });
- // heartbeat
- var timeout = setInterval(function() {
- heartbeat();
- }, 120000); // 2 minutes
- function heartbeat () {
- request.post(
- 'https://backpack.tf/api/aux/heartbeat/v1',
- { json:
- {
- token: config.token, // <--
- automatic: 'all',
- i_understand_the_risk: 'true',
- }
- },
- function (error, response, body) {
- console.log(body);
- }
- );
- }
- // getPrices
- var timeoutprices = setInterval(function() {
- getPrices();
- }, 300000); // 5 minutes
- function getPrices () {
- request.get(
- 'https://backpack.tf/api/IGetPrices/v4',
- { json:
- {
- format: 'json',
- callback: 'getPrices',
- key: config.apiKey, // <--
- raw: "1",
- }
- });
- }
- // getCurrency
- var timeoutcurrency = setInterval(function() {
- getCurrency();
- }, 300000); // 5 minutes
- function getCurrency () {
- request.get(
- 'https://backpack.tf/api/IGetCurrencies/v1',
- { json:
- {
- format: 'json',
- callback: 'getCurrency',
- key: config.apiKey, // <--
- raw: "1",
- }
- }
- );
- }
- // listings
- var timeoutlistings = setInterval(function() {
- postListings();
- }, 2100000); // 2100000 MS = 35 minutes
- function postListings () {
- request.post(
- 'https://backpack.tf/api/classifieds/list/v1',
- { json:
- {
- token: config.token, // <--
- listings: bplists
- },
- },
- function (error, response, body) {
- console.log(body);
- }
- );
- }
- // lists on startup
- postListings();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement