Guest User

Untitled

a guest
May 18th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let SteamCommunity;
  2. let TradeOfferManager;
  3. let Winston;
  4.  
  5. try {
  6.     SteamCommunity = require('steamcommunity');
  7.     TradeOfferManager = require('steam-tradeoffer-manager');
  8.     Winston = require('winston');
  9. } catch (ex) {
  10.     console.error("Missing dependencies. Install a version with dependencies (not 'download repository') or use npm install.");
  11.     process.exit(1);
  12. }
  13.  
  14. const Utils = require('./utils');
  15. const vers = (require('../package.json') || {version: "(unknown)", beta: ""});
  16. let version = vers.version;
  17. if (vers.beta && vers.beta !== version) {
  18.     version = vers.beta + " beta-" + vers.betav;
  19. }
  20.  
  21. const Config = require('./config');
  22. const logging = require('./logging');
  23. const trade = require('./trade');
  24. const steam = require('./steamclient');
  25. const backpack = require('./backpacktf');
  26.  
  27. let configlog = Config.init();
  28.  
  29. let Automatic = {
  30.     version,
  31.     getOwnSteamID() {
  32.         return Automatic.steam.steamID.getSteamID64();
  33.     },
  34.     apiPath(fn) {
  35.         return (Automatic.config.get().backpackDomain || 'https://backpack.tf') + '/api/' + fn;
  36.     },
  37.     buyOrdersEnabled() {
  38.         return !!Automatic.config.get().buyOrders;
  39.     },
  40.     confirmationsMode() {
  41.         return Automatic.config.get().confirmations || "all";
  42.     },
  43.     inverseCurrency(from) { return from === "metal" ? "keys" : "metal"; },
  44.     currencyAvg(cur) {
  45.         let c = Automatic.currencies[cur];
  46.         return c ? (c.low + c.high) / 2 : 0;
  47.     },
  48.     mayExchangeToCurrency(to) {
  49.         const config = Automatic.config.get();
  50.         if (typeof config.currencyExchange !== "object") return false;
  51.         if (config.currencyExchange[Automatic.inverseCurrency(to) + "->" + to] === true) {
  52.             return true;
  53.         }
  54.         return false;
  55.     },
  56.     currencies: {},
  57.     buyOrders: [],
  58.     buyOrdersEtag: "",
  59. };
  60.  
  61. Automatic.config = Config;
  62. Automatic.steam = new SteamCommunity();
  63. Automatic.steam.username = null;
  64. Automatic.manager = new TradeOfferManager({
  65.     "language": "en",
  66.     community: Automatic.steam,
  67.     "domain": "backpack.tf",
  68.     "pollInterval": 10500
  69. });
  70. let log = Automatic.log = new Winston.Logger({
  71.     "levels": logging.LOG_LEVELS,
  72.     "colors": logging.LOG_COLORS
  73. });
  74.  
  75. function register(...args) {
  76.     args.forEach(component => {
  77.         if (typeof component === 'string') {
  78.             component = require('./' + component);
  79.         }
  80.         component.register(Automatic);
  81.     });
  82. }
  83.  
  84. register(
  85.     logging,
  86.     trade,
  87.     backpack,
  88.     steam,
  89.     // use strings as confirmations requires AutomaticOffer, which returns a ref to exports, but the module's exports are overriden
  90.     // with a new ref to class AutomaticOffer (so it's {} inside confirmations)
  91.     'automatic-offer',
  92.     'confirmations'
  93. );
  94.  
  95. if (configlog) log.info(configlog);
  96. log.info("backpack.tf Automatic v%s starting", version);
  97. if (vers.beta) {
  98.     log.warn("This is a beta version, functionality might be incomplete and/or broken. Release versions can be found here:");
  99.     log.warn("https://bitbucket.org/jessecar/backpack.tf-automatic/downloads");
  100.     log.warn("In case you are running this build to test (or because it fixes a particular bug you have with older versions), you can report issues here:");
  101.     log.warn("https://bitbucket.org/jessecar/backpack.tf-automatic/issues?status=new&status=open")
  102. }
  103.  
  104. process.nextTick(steam.connect);
  105.  
  106. // Check if we're up to date
  107. Utils.getJSON({
  108.     url: "https://bitbucket.org/jessecar/backpack.tf-automatic/raw/master/package.json"
  109. }).then(([body]) => {
  110.     if (!body.version) {
  111.         return log.warn("Cannot check for updates: malformed response");
  112.     }
  113.  
  114.     let current = version.split('.');
  115.     let latest = body.version.split('.');
  116.  
  117.     let curv = current[0] * 100000 + current[1] * 10000 + current[2] * 1000;
  118.     let latestv = latest[0] * 100000 + latest[1] * 10000 + latest[2] * 1000;
  119.     if (latestv > curv) {
  120.         log.info("===================================================");
  121.         log.info("Update available! Current: v%s, Latest: v%s", version, body.version);
  122.         log.info("Download it here: https://bitbucket.org/jessecar/backpack.tf-automatic/downloads");
  123.         log.info("===================================================");
  124.     }
  125. }).catch((msg) => {
  126.     log.warn("Cannot check for updates: " + msg);
  127. });
  128.  
  129. process.on('uncaughtException', (err) => {
  130.     log.error([
  131.         "backpack.tf Automatic crashed! Please create an issue with the following log:",
  132.         `crash: Automatic.version: ${Automatic.version}; node: ${process.version} ${process.platform} ${process.arch}; Contact: ${Automatic.getOwnSteamID()}`,
  133.         `crash: Stack trace::`,
  134.         require('util').inspect(err)
  135.     ].join('\r\n'));
  136.     log.error("Create an issue here: https://bitbucket.org/jessecar/backpack.tf-automatic/issues/new");
  137.     process.exit(1);
  138. })
  139.  
  140. log.warn("Currency exchange is disabled in this release (1.3.1) due to a" +
  141.     " vulnerability. This feature will be enabled again in the" +
  142.     " future.");
Add Comment
Please, Sign In to add comment