Advertisement
Guest User

bot.js

a guest
Apr 24th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // EVERTYHING MARKED WITH DEBUG, HAS TO BE FIXED
  2.  
  3. var config = require('./config.js');
  4.  
  5. var Steam = require('steam');
  6. var SteamUser = require('steam-user');
  7. var TradeOfferManager = require('steam-tradeoffer-manager');
  8. var SteamTotp = require('steam-totp');
  9. var SteamConfirm = require('steamcommunity-mobile-confirmations');
  10. var TOTP = require('onceler').TOTP;
  11. var request = require('request');
  12.  
  13.  
  14. var sitepath = config.siteName;
  15. var sitename = config.siteName;
  16.  
  17. var apik = config.apiKey;
  18. var admin = config.adminSteam64;
  19. var botsteamid = config.botSteam64;
  20. var identitysecret = config.identity_secret;
  21. var sharedsecret = config.shared_secret;
  22. var pooling_interval  = config.interval;
  23. var rsecret=config.secret;
  24.  
  25. var p2=config.pot2;
  26.  
  27. var details = {
  28.     "accountName"   : config.accName,
  29.     "password"      : config.accPassword,
  30.     "twoFactorCode" : SteamTotp.generateAuthCode(sharedsecret)
  31. };
  32.  
  33. var client = new SteamUser();
  34.  
  35. var manager = new TradeOfferManager({
  36.     "steam"    : client,
  37.     "domain"   : "localhost",
  38.     "language" : "en"
  39. })
  40.  
  41. var deviceid=SteamTotp.getDeviceID(botsteamid);
  42.  
  43. if(p2==true)
  44. {
  45.     var pot2='p2';
  46. }
  47. else
  48. {
  49.     var pot2='';
  50. }
  51.  
  52. var GameTime = config.gameTime;
  53. var endtimer = -1;
  54.  
  55. var mysql = require('mysql');
  56. var connection = mysql.createConnection({
  57.     host     : config.mysqlHost,
  58.     user     : config.mysqlUser,
  59.     password : config.mysqlPassword,
  60.     database : config.mysqlDatabase
  61. });
  62.  
  63. connection.connect();
  64.  
  65. client.logOn(details);
  66.  
  67. function EndGame()
  68. {
  69.     endtimer = -1;
  70.     proceedWinners();
  71.     setTimeout(sendOffers,5000);
  72. }
  73.  
  74. function proceedWinners()
  75. {
  76.     console.log(config.botPrefix + 'Ending current game and choosing winner.');
  77.     var url = 'http://'+sitepath+'/'+pot2+'endround.php?secret='+config.secret+'';
  78.     request(url, function(error, response, body)
  79.     {
  80.         if(error)
  81.         {
  82.             console.log('Couldn\'t end round, error: '+error);
  83.         }
  84.     });
  85. }
  86.  
  87. setInterval(function () {
  88.     connection.query('SELECT 1');
  89. }, 5000);
  90.  
  91. function is_float(mixed_var)
  92. {
  93.    
  94.     return +mixed_var === mixed_var && (!isFinite(mixed_var) || !! (mixed_var % 1));
  95. }
  96.  
  97. function isNumeric(n){
  98.     return (typeof n == "number" && !isNaN(n));
  99. }
  100.  
  101.  
  102. function getUserInfo(steamids,callback)
  103. {
  104.     var url = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key='+apik+'&steamids='+ steamids + '&format=json';
  105.     request({
  106.         url: url,
  107.         json: true
  108.         }, function(error, response, body){
  109.         if(!error && response.statusCode === 200){
  110.             callback(null, body);
  111.             } else if (error) {
  112.             getUserInfo(steamids,callback);
  113.         }
  114.     });
  115. }
  116.  
  117.  
  118. function addslashes(str)
  119. {
  120.     str=str.replace(/\\/g,'\\\\');
  121.     str=str.replace(/\'/g,'\\\'');
  122.     str=str.replace(/\"/g,'\\"');
  123.     str=str.replace(/\0/g,'\\0');
  124.     return str;
  125. }
  126.  
  127. client.on('loggedOn', function(details){
  128.     client.on('webSession', function(sessionID, cookies){
  129.         manager.setCookies(cookies, function(err) {
  130.             if(err) {
  131.                 console.log('setCookies error: '+err);
  132.                 process.exit(1); // Fatal error since we couldn't get our API key
  133.                 return;
  134.             }
  135.             var steamapi=manager.apiKey;
  136.             var SteamcommunityMobileConfirmations = require('steamcommunity-mobile-confirmations');
  137.             var steamcommunityMobileConfirmations = new SteamcommunityMobileConfirmations(
  138.             {
  139.                 steamid:         botsteamid,
  140.                 identity_secret: identitysecret,
  141.                 device_id:       deviceid,
  142.                 webCookie:       cookies,
  143.             });
  144.             setInterval(function(){
  145.                 checkConfirmations(steamcommunityMobileConfirmations)
  146.             }, pooling_interval);
  147.             console.log("[Bot] Logged in.");
  148.             client.addFriend(admin);
  149.             client.chatMessage(admin, "[Bot] Successfully logged in!");
  150.             client.setPersona(Steam.EPersonaState.LookingToTrade);
  151.             client.gamesPlayed(config.siteName);
  152.            
  153.             setTimeout(function()
  154.             {
  155.                 connection.query('SELECT `value` FROM `'+pot2+'info` WHERE `name`=\'current_game\'', function(err, rows, fields)
  156.                 {
  157.                     if(err)
  158.                     {
  159.                         return;
  160.                     }
  161.                     connection.query('SELECT `starttime` FROM `'+pot2+'games` WHERE `id`=\''+rows[0].value+'\'', function(errs, rowss, fieldss)
  162.                     {
  163.                         if(errs)
  164.                         {
  165.                             return;
  166.                         }
  167.                         var timeleft;
  168.                         if(rowss[0].starttime == 2147483647)
  169.                         {
  170.                             timeleft = GameTime;
  171.                         }
  172.                         else
  173.                         {
  174.                             var unixtime = Math.round(new Date().getTime()/1000.0);
  175.                             timeleft = rowss[0].starttime+GameTime-unixtime;
  176.                             if(timeleft < 0)
  177.                             {
  178.                                 timeleft = 0;
  179.                             }
  180.                         }
  181.                         if(timeleft != GameTime && endtimer==-1)
  182.                         {
  183.                             setTimeout(EndGame,timeleft*1000);
  184.                             console.log('[SERVER] Restoring the latest game with '+timeleft+' seconds left!');
  185.                         }
  186.                     });
  187.                 });
  188.             },1500);
  189.            
  190.         });
  191.     });
  192. });
  193.  
  194.  
  195. manager.on('newOffer', function(offer)
  196. {
  197.     var proceed=true;
  198.     var steamid=offer.partner.getSteamID64();
  199.     getUserInfo(steamid, function(error, data)
  200.     {
  201.         if(error)
  202.         {
  203.             console.log('getUserInfo error: '+error);
  204.             proceed=false;
  205.             offer.decline(function(err)
  206.             {
  207.                 console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: getUserInfo error');
  208.                 if (err)
  209.                 {
  210.                     console.log('Decline error: '+err);
  211.                 }
  212.                 connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: Steam Servers are busy, try again in a minute!\',\'25\',\'1\')', function(err, row, fields) {});
  213.             });
  214.             return;
  215.         }  
  216.         var datadec = JSON.parse(JSON.stringify(data.response));
  217.         var name = addslashes(datadec.players[0].personaname);
  218.         var avatar = (datadec.players[0].avatarfull);
  219.        
  220.         console.log(config.botPrefix + 'Processing offer #'+offer.id+' from '+name+' (ID:'+steamid+').');
  221.        
  222.         if(offer.itemsToGive.length!=0)
  223.         {
  224.             proceed=false;
  225.             offer.decline(function(err)
  226.             {
  227.                 console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: Asked for a skin on the Bot');
  228.                 if (err)
  229.                 {
  230.                     console.log('Decline error: '+err);
  231.                 }
  232.                 connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: Asking for any of the bots items? Brave!\',\'25\',\'1\')', function(err, row, fields) {});
  233.             });
  234.             return;
  235.         }
  236.         offer.getEscrowDuration(function(err, daysTheirEscrow, daysMyEscrow)
  237.         {
  238.            
  239.             if(err)
  240.             {
  241.                 console.log('getEscrowDuration error: '+err);
  242.                 proceed=false;
  243.                 offer.decline(function(err)
  244.                 {
  245.                     console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: Steam Servers are busy, couldn\'t get escrow duration');
  246.                     if (err)
  247.                     {
  248.                         console.log('Decline error: '+err);
  249.                     }
  250.                     connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: Steam Servers are busy, couldnt get escrow duration!\',\'25\',\'1\')', function(err, row, fields) {});                      
  251.                 });
  252.                 return;
  253.                 return;
  254.             }
  255.             else
  256.             {
  257.                 if (daysTheirEscrow != 0)
  258.                 {
  259.                     proceed=false;
  260.                     offer.decline(function(err)
  261.                     {
  262.                         console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User is in Escrow for '+daysTheirEscrow+' days');
  263.                         if (err)
  264.                         {
  265.                             console.log('Decline error: '+err);
  266.                         }
  267.                         connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: You are in Escrow for '+daysTheirEscrow+' days!\',\'25\',\'1\')', function(err, row, fields) {});                       
  268.                     });
  269.                     return;
  270.                 }
  271.                 else
  272.                 {
  273.                     connection.query('SELECT * FROM `'+pot2+'info`', function(err, row)
  274.                     {
  275.                         var minbet = row[3].value;
  276.                         var maxbet = row[7].value;
  277.                         var maxitems = row[4].value;
  278.                         var maxritems = row[10].value;
  279.                         if(offer.itemsToReceive.length>maxitems)
  280.                         {
  281.                             proceed=false;
  282.                             offer.decline(function(err)
  283.                             {
  284.                                 console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User sent more than '+maxitems+' skins');
  285.                                 if (err)
  286.                                 {
  287.                                     console.log('Decline error: '+err);
  288.                                 }
  289.                                 connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: We only accept up to '+maxitems+' skins!\',\'25\',\'1\')', function(err, row, fields) {});                      
  290.                                
  291.                             });
  292.                             return;
  293.                         }
  294.                        
  295.                         var items = offer.itemsToReceive;
  296.                         var totaldeposit=0;
  297.                         var depitems=[],skinssent=0;
  298.                         items.forEach(function(item, i , arr)
  299.                         {
  300.                             if (item.appid != 730)
  301.                             {
  302.                                 proceed=false;
  303.                                 offer.decline(function(err)
  304.                                 {
  305.                                     console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User sent a Non-CSGO skin');
  306.                                     if (err)
  307.                                     {
  308.                                         console.log('Decline error: '+err);
  309.                                     }
  310.                                 });
  311.                                 connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: We only accept CSGO skins!\',\'25\',\'1\')', function(err, row, fields) {});                    
  312.                                 return;
  313.                             }
  314.                             if(item.market_hash_name.indexOf("Souvenir") != -1)
  315.                             {
  316.                                 proceed=false;
  317.                                 offer.decline(function(err)
  318.                                 {
  319.                                     console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User sent a Souvenir Skin');
  320.                                     if (err)
  321.                                     {
  322.                                         console.log('Decline error: '+err);
  323.                                     }
  324.                                 });
  325.                                 connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: No souvenir skins allowed!\',\'25\',\'1\')', function(err, row, fields) {});                    
  326.                                 return;
  327.                             }
  328.                             depitems[i]=[];
  329.                             depitems[i].name=item.market_name;
  330.                             depitems[i].color=item.name_color;
  331.                             depitems[i].url=item.icon_url;
  332.                             depitems[i].value=0;
  333.                             var itemname = item.market_name;
  334.                             console.log(encodeURIComponent(itemname));
  335.                             var url = 'http://api.CSGOUnity.de/price/'+encodeURIComponent(itemname)+'/'+config.priceKey;
  336.                            
  337.                             (function(someshit) {
  338.                                 request(url, function(error, response, body)
  339.                                 {
  340.                                     if(!error && response.statusCode === 200)
  341.                                     {
  342.                                         if(body == "notfound")
  343.                                         {
  344.                                             proceed=false;
  345.                                             offer.decline(function(err)
  346.                                             {
  347.                                                 console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: Steam Market Issues (Can\'t get the skin\'s value)');
  348.                                                 if (err)
  349.                                                 {
  350.                                                     console.log('Decline error: '+err);
  351.                                                 }
  352.                                             });
  353.                                             connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: Steam Market issues!\',\'25\',\'1\')', function(err, row, fields) {});                      
  354.                                             return;
  355.                                         }
  356.                                         else
  357.                                         {
  358.                                             depitems[i].value = parseFloat(body);
  359.                                             totaldeposit+=depitems[i].value;
  360.                                             if(depitems[i].value=="notfound" || depitems[i].value=="NaN" || depitems[i].value=="null" || depitems[i].value=="undefined" || depitems[i].value==0 || !depitems[i].value)
  361.                                             {
  362.                                                 proceed=false;
  363.                                                 offer.decline(function(err)
  364.                                                 {
  365.                                                     console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: Steam Market Issues (Can\'t get the skin\'s value)');
  366.                                                     if (err)
  367.                                                     {
  368.                                                         console.log('Decline error: '+err);
  369.                                                     }
  370.                                                 });
  371.                                                 connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: Steam Market issues!\',\'25\',\'1\')', function(err, row, fields) {});                      
  372.                                                 return;
  373.                                             }
  374.                                         }
  375.                                     }  
  376.                                     else
  377.                                     {
  378.                                         proceed=false;
  379.                                         offer.decline(function(err)
  380.                                         {
  381.                                             console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: Steam Market Issues (Can\'t get the skin\'s value)');
  382.                                             if (err)
  383.                                             {
  384.                                                 console.log('Decline error: '+err);
  385.                                             }
  386.                                         });
  387.                                         connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: Steam Market issues!\',\'25\',\'1\')', function(err, row, fields) {});                      
  388.                                         return;
  389.                                     }
  390.                                 });
  391.                             })(i)
  392.                             skinssent++;
  393.                            
  394.                            
  395.                         });
  396.                        
  397.                         setTimeout(function()
  398.                         {  
  399.                            
  400.                             if(totaldeposit>maxbet)
  401.                             {
  402.                                 proceed=false;
  403.                                 offer.decline(function(err)
  404.                                 {
  405.                                     console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User sent too much in skin value');
  406.                                     if (err)
  407.                                     {
  408.                                         console.log('Decline error: '+err);
  409.                                     }
  410.                                 });
  411.                                 connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: You can deposit more than $'+maxbet+'\',\'25\',\'1\')', function(err, row, fields) {});                     
  412.                                 return;
  413.                                
  414.                                
  415.                             }
  416.                             if(totaldeposit<minbet)
  417.                             {
  418.                                 proceed=false;
  419.                                 offer.decline(function(err)
  420.                                 {
  421.                                     console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User sent below the minimal bet amount ($'+minbet+')');
  422.                                     if (err)
  423.                                     {
  424.                                         console.log('Decline error: '+err);
  425.                                     }
  426.                                 });
  427.                                 connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: Minimum deposit value: $'+minbet+'\',\'25\',\'1\')', function(err, row, fields) {});                    
  428.                                 return;
  429.                             }
  430.                             if(skinssent>maxitems)
  431.                             {
  432.                                 proceed=false;
  433.                                 offer.decline(function(err)
  434.                                 {
  435.                                     console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User sent too many skins');
  436.                                     if (err)
  437.                                     {
  438.                                         console.log('Decline error: '+err);
  439.                                     }
  440.                                 });
  441.                                 connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: We only accept up to '+maxitems+' skins!\',\'25\',\'1\')', function(err, row, fields) {});                      
  442.                                 return;
  443.                                
  444.                             }
  445.                             if(proceed=true)
  446.                             {
  447.                                 connection.query('SELECT * FROM `'+pot2+'info`', function(err, row)
  448.                                 {
  449.                                    
  450.                                     var cg = row[0].value;
  451.                                     connection.query('SELECT COUNT(value) as skinsin,SUM(value) as moneyin FROM `'+pot2+'game'+cg+'` WHERE `userid`=\''+steamid+'\'', function(err, row, fields)
  452.                                     {
  453.                                         skinsin = row[0].skinsin;
  454.                                         skinsin=skinsin+skinssent;
  455.                                         moneyin = row[0].moneyin;
  456.                                         moneyin=moneyin+totaldeposit;
  457.                                        
  458.                                         if(skinsin>maxitems)
  459.                                         {
  460.                                             offer.decline(function(err)
  461.                                             {
  462.                                                 console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: RECHECK - User sent too many skins');
  463.                                                 if (err)
  464.                                                 {
  465.                                                     console.log('Decline error: '+err);
  466.                                                 }
  467.                                             });
  468.                                             connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: You can not deposit more than '+maxitems+' skins\',\'25\',\'1\')', function(err, row, fields) {});
  469.                                             return;
  470.                                         }
  471.                                        
  472.                                         if(moneyin > maxbet)
  473.                                         {
  474.                                             offer.decline(function(err)
  475.                                             {
  476.                                                 console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: RECHECK - User sent too much in skin value');
  477.                                                 if (err)
  478.                                                 {
  479.                                                     console.log('Decline error: '+err);
  480.                                                 }
  481.                                             });
  482.                                             connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: You can deposit more than $'+maxbet+'\',\'25\',\'1\')', function(err, row, fields) {});
  483.                                             return;
  484.                                         }
  485.                                         for(var i=0; i < skinssent; i++)
  486.                                         {
  487.                                             if(!isNumeric(depitems[i].value))
  488.                                             {
  489.                                                 offer.decline(function(err)
  490.                                                 {
  491.                                                     console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: RECHECK - Steam Market Issues (Can\'t get the skin\'s value) ');
  492.                                                     if (err)
  493.                                                     {
  494.                                                         console.log('Decline error: '+err);
  495.                                                     }
  496.                                                 });
  497.                                                 connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: Steam Market issues!\',\'25\',\'1\')', function(err, row, fields) {});                      
  498.                                                 return;
  499.                                             }
  500.                                         }
  501.                                        
  502.                                         connection.query('SELECT * FROM `users` WHERE `steamid`=\''+steamid+'\'', function(err, row, fields)
  503.                                         {
  504.                                             if(err)
  505.                                             {
  506.                                                 console.log('MYSQL Error: '+err);
  507.                                                 offer.decline(function(err)
  508.                                                 {
  509.                                                     console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: MYSQL Error (as seen above) ');
  510.                                                     if (err)
  511.                                                     {
  512.                                                         console.log('Decline error: '+err);
  513.                                                     }
  514.                                                 });
  515.                                                 connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: MYSQL Error\',\'25\',\'1\')', function(err, row, fields) {});
  516.                                                 return;
  517.                                             }
  518.                                             if(row.length!=0)
  519.                                             {
  520.                                                 ban=row[0].ban;
  521.                                                 tlink=row[0].tlink;
  522.                                                 if(ban==1)
  523.                                                 {
  524.                                                     proceed=false;
  525.                                                     offer.decline(function(err)
  526.                                                     {
  527.                                                         console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User is banned');
  528.                                                         if (err)
  529.                                                         {
  530.                                                             console.log('Decline error: '+err);
  531.                                                         }
  532.                                                     });
  533.                                                     connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: You are banned from betting\',\'25\',\'1\')', function(err, row, fields) {});
  534.                                                     return;
  535.                                                 }
  536.                                                 if(!tlink)
  537.                                                 {
  538.                                                     offer.decline(function(err)
  539.                                                     {
  540.                                                         console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User doesn\'t have a TradeLink set ');
  541.                                                         if (err)
  542.                                                         {
  543.                                                             console.log('Decline error: '+err);
  544.                                                         }
  545.                                                     });
  546.                                                     connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: No Trade URL Set\',\'25\',\'1\')', function(err, row, fields) {});
  547.                                                     return;
  548.                                                 }
  549.                                                 connection.query('SELECT * FROM `'+pot2+'games` WHERE `id`=\''+cg+'\'', function(err, row, fields)
  550.                                                 {
  551.                                                     itemsin=row[0].itemsnum;
  552.                                                     offer.accept(function(err)
  553.                                                     {
  554.                                                         if(err)
  555.                                                         {
  556.                                                             console.log('Accept error: '+err);
  557.                                                             /*if(err!="error: http error 503") Experimental function please do not use
  558.                                                                 {
  559.                                                                 return;
  560.                                                             }*/
  561.                                                             doPoll(); // Also experimental
  562.                                                             return;
  563.                                                         }
  564.                                                         for(var i=0; i < skinssent; i++)
  565.                                                         {
  566.                                                             var itemname = addslashes(depitems[i].name);
  567.                                                             connection.query('INSERT INTO `'+pot2+'game' +cg+ '` (`userid`,`username`,`item`,`offerid`,`color`,`value`,`avatar`,`image`) VALUES (\'' + steamid + '\',\'' + name + '\',\'' + itemname + '\',\''+offer.id+'\',\'' + depitems[i].color + '\',\'' + depitems[i].value + '\',\'' + avatar + '\',\'' + depitems[i].url + '\')', function(err, row, fields)
  568.                                                             {
  569.                                                                 if(err)
  570.                                                                 {
  571.                                                                     console.log(err);
  572.                                                                 }
  573.                                                             });
  574.                                                             connection.query('UPDATE `'+pot2+'games` SET `itemsnum`=`itemsnum`+1, `cost`=`cost`+\''+depitems[i].value+'\' WHERE `id` = \''+cg+'\'', function(err, row, fields) {});
  575.                                                         }
  576.                                                         connection.query('UPDATE `users` SET `skinssent`=`skinssent`+'+skinssent+' WHERE `steamid` = \'' + steamid + '\'', function(err, row, fields) {});
  577.                                                         console.log(config.botPrefix + 'Accepted offer #'+offer.id+' from '+name+' (ID:'+steamid+').');
  578.                                                         offer.getReceivedItems(function(err, items)
  579.                                                         {
  580.                                                             if(err)
  581.                                                             {
  582.                                                                 console.log('getReceivedItems SERIOUS GAME BREAKING error: '+err);
  583.                                                             }
  584.                                                             items.forEach(function(item)
  585.                                                             {
  586.                                                                 var itemn=addslashes(item.market_name);
  587.                                                                 connection.query('UPDATE `'+pot2+'game'+cg+'` SET `assetid`=\''+item.id+'\' WHERE `userid` = \'' + steamid + '\' AND `item`=\''+itemn+'\' AND `assetid`=\'\' LIMIT 1', function(err, row, fields) {});
  588.                                                             })
  589.                                                         });
  590.                                                         connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'success\',\'0\',\''+steamid+'\',\'Trade Offer Accepted (Game #'+cg+')!\',\'We wish you Good luck and happy betting!\',\'25\',\'1\')', function(err, row, fields) {});
  591.                                                         connection.query('SELECT COUNT(DISTINCT userid) AS playersCount FROM `'+pot2+'game'+cg+'`', function(err, rows)
  592.                                                         {  
  593.                                                             players = rows[0].playersCount;
  594.                                                             // Debug
  595.                                                             if(players == 2 && skinssent > 0 && endtimer==-1)
  596.                                                             {
  597.                                                                 console.log(config.botPrefix + 'Starting the countdown for Game #'+cg+'');
  598.                                                                 endtimer = setTimeout(EndGame,GameTime*1000);
  599.                                                                 connection.query('UPDATE `'+pot2+'games` SET `starttime`=UNIX_TIMESTAMP() WHERE `id` = \'' + cg + '\'', function(err, row, fields) {});
  600.                                                             }
  601.                                                             if(itemsin > maxritems)
  602.                                                             {
  603.                                                                 clearTimeout(endtimer);
  604.                                                                 endtimer = -1;
  605.                                                                 EndGame();
  606.                                                             }
  607.                                                            
  608.                                                         });
  609.                                                     });
  610.                                                    
  611.                                                    
  612.                                                 });
  613.                                             }
  614.                                             else
  615.                                             {
  616.                                                 offer.decline(function(err)
  617.                                                 {
  618.                                                     console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User is not in the MYSQL Database');
  619.                                                     if (err)
  620.                                                     {
  621.                                                         console.log('Decline error: '+err);
  622.                                                     }
  623.                                                 });
  624.                                                 return;
  625.                                             }
  626.                                            
  627.                                             return;
  628.                                            
  629.                                         });
  630.                                        
  631.                                        
  632.                                     });
  633.                                 });
  634.                             }
  635.                             else
  636.                             {
  637.                                
  638.                                 offer.decline(function(err)
  639.                                 {
  640.                                     console.log(config.botPrefix + 'Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: Unkown error (proceed = false in node) - Probably Steam Issues');
  641.                                     if (err)
  642.                                     {
  643.                                         console.log('Decline error: '+err);
  644.                                     }
  645.                                 });
  646.                                 connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: Steam Issues\',\'25\',\'1\')', function(err, row, fields) {});
  647.                                 return;
  648.                             }
  649.                            
  650.                            
  651.                         },2000);
  652.                     });
  653.                 }
  654.             }
  655.         });
  656.     });
  657. });
  658.  
  659.  
  660. client.on('friendMessage#'+admin+'', function(steamID, message)
  661. {
  662.    
  663.     console.log("[u1Bot] Admin to Bot: " + message);
  664.     if(message.indexOf("/sendrake") == 0)
  665.     {
  666.         client.chatMessage(admin, config.botPrefix + 'Calling the sendRake function (sends the latest query, call it more times if needed)');
  667.         sendRake(1);
  668.     }
  669.     if(message.indexOf("/sendoffers") == 0)
  670.     {
  671.         client.chatMessage(admin, config.botPrefix + 'Calling the sendOffers function (sends the latest query, call it more times if needed)');
  672.         sendOffers(1);
  673.     }
  674.     if(message.indexOf("/end") == 0)
  675.     {
  676.         client.chatMessage(admin, config.botPrefix + 'Ending the current game!');
  677.         if(endtimer != -1) clearTimeout(endtimer);
  678.         EndGame();
  679.     }
  680.     if(message.indexOf("/code") == 0)
  681.     {
  682.         var code = SteamTotp.generateAuthCode(sharedsecret);
  683.         client.chatMessage(admin, config.botPrefix + '2FA code: ' + code);
  684.     }
  685.     if(message.indexOf("/offers") == 0)
  686.     {
  687.         connection.query('SELECT ID FROM `'+pot2+'queue` WHERE `status`=\'active\' GROUP BY `id` DESC', function(err, row, fields)
  688.         {
  689.             if(row.length!=0)
  690.             {
  691.                 console.log(row);
  692.                 client.chatMessage(admin, config.botPrefix + 'Check your console for the ID\'s!');
  693.             }
  694.             else
  695.             {
  696.                 client.chatMessage(admin, config.botPrefix + 'There aren\'t any active queue ID\'s.');
  697.             }
  698.         });
  699.     }
  700.     if(message.indexOf("/rakes") == 0)
  701.     {
  702.         connection.query('SELECT ID FROM `'+pot2+'rakeitems` WHERE `status`=\'active\' GROUP BY `id` DESC', function(err, row, fields)
  703.         {
  704.             if(row.length!=0)
  705.             {
  706.                 console.log(row);
  707.                 client.chatMessage(admin, config.botPrefix + 'Check your console for the ID\'s!');
  708.             }
  709.             else
  710.             {
  711.                 client.chatMessage(admin, config.botPrefix + 'There aren\'t any active rake ID\'s.');
  712.             }
  713.         });
  714.     }
  715. });
  716.  
  717. function sendOffers(param)
  718. {
  719.     connection.query('SELECT * FROM `'+pot2+'queue` WHERE `status`=\'active\' GROUP BY `id` DESC LIMIT 1', function(err, row, fields)
  720.     {
  721.         if(row.length!=0)
  722.         {
  723.             var assetids=(row[0].assetid).split('/');
  724.             manager.loadInventory(730, 2, true, function (err, inventory)
  725.             {
  726.                 if (err)
  727.                 {
  728.                     console.log(err);
  729.                     if(param==1)
  730.                     {
  731.                         client.chatMessage(admin, config.botPrefix + 'Error while loading the Bot\'s Inventory, try again later boss!');
  732.                     }
  733.                     return;
  734.                    
  735.                 }
  736.                 else
  737.                 {
  738.                     var token=row[0].token;
  739.                     var gameid=row[0].id;
  740.                     // Debug
  741.                     var message="Congratulations, you won game #"+gameid+" on CSGOUnity.de!";
  742.                     var offer = manager.createOffer(row[0].userid);
  743.                    
  744.                     inventory.forEach(function(item)
  745.                     {
  746.                         assetids.forEach(function(asset)
  747.                         {
  748.                             if(item.id==asset)
  749.                             {
  750.                                 offer.addMyItem(item);
  751.                             }
  752.                         })
  753.                     })
  754.                     setTimeout(function()
  755.                     {
  756.                         offer.send(message, token, function(err)
  757.                         {
  758.                             if(err)
  759.                             {
  760.                                 console.log('Error sending Trade Offer for Game #'+gameid+':');
  761.                                 console.log(err);
  762.                                 if(param==1)
  763.                                 {
  764.                                     client.chatMessage(admin, config.botPrefix + 'Error while sending the tradeoffer, try again later boss!');
  765.                                 }
  766.                                 return;
  767.                             }
  768.                             connection.query('UPDATE `'+pot2+'queue` SET `status`="sent" WHERE `id`=\''+gameid+'\'');
  769.                             console.log(config.botPrefix + 'Trade Offer for Game #'+gameid+' has been successfully sent and is awaiting mobile confirmation.');
  770.                             if(param==1)
  771.                             {
  772.                                 client.chatMessage(admin, config.botPrefix + 'Successfully sent the trade for Game #'+gameid+'!');
  773.                             }                          
  774.                         });
  775.                        
  776.                     },2000);
  777.                 }
  778.             });
  779.         }
  780.         else
  781.         {
  782.             if(param==1)
  783.             {
  784.                 client.chatMessage(admin, config.botPrefix + 'No more Winnings Queries!');
  785.                 return;
  786.             }
  787.         }
  788.     });
  789. }
  790.  
  791. function sendRake(param)
  792. {
  793.     connection.query('SELECT * FROM `'+pot2+'rakeitems` WHERE `status`=\'active\' GROUP BY `id` DESC LIMIT 1', function(err, row, fields)
  794.     {
  795.         if(row.length!=0)
  796.         {
  797.             var assetids=(row[0].assetid).split('/');
  798.             manager.loadInventory(730, 2, true, function (err, inventory)
  799.             {
  800.                 if (err)
  801.                 {
  802.                     if(param==1)
  803.                     {
  804.                         client.chatMessage(admin, config.botPrefix + 'Error while loading the Bot\'s Inventory, try again later boss!');
  805.                     }
  806.                     return;
  807.                 }
  808.                 else
  809.                 {
  810.                     var token=row[0].token;
  811.                     var gameid=row[0].id;
  812.                     var value=row[0].value;
  813.                     var message='Rake for Game #'+gameid+' ($'+value+')';
  814.                     var offer = manager.createOffer(row[0].userid);
  815.                    
  816.                     inventory.forEach(function(item)
  817.                     {
  818.                         assetids.forEach(function(asset)
  819.                         {
  820.                             if(item.id==asset)
  821.                             {
  822.                                 offer.addMyItem(item);
  823.                             }
  824.                         })
  825.                     })
  826.                     setTimeout(function()
  827.                     {
  828.                         offer.send(message, token, function(err)
  829.                         {
  830.                             if(err)
  831.                             {
  832.                                 console.log('Error sending Rake for Game #'+gameid+':');
  833.                                 console.log(err);
  834.                                 if(param==1)
  835.                                 {
  836.                                     client.chatMessage(admin, config.botPrefix + 'Error while sending the tradeoffer for the rake, try again later boss!');
  837.                                     return;
  838.                                 }
  839.                                 return;
  840.                             }
  841.                             connection.query('UPDATE `'+pot2+'rakeitems` SET `status`="sent" WHERE `id`=\''+gameid+'\'');
  842.                             console.log(config.botPrefix + 'Rake for Game #'+gameid+' has been successfully sent and is awaiting mobile confirmation.');
  843.                             if(param==1)
  844.                             {
  845.                                 client.chatMessage(admin, config.botPrefix + 'Successfully sent the rake for Game #'+gameid+'!');
  846.                             }  
  847.                         });
  848.                        
  849.                     },2000);
  850.                 }
  851.             });
  852.         }
  853.         else
  854.         {
  855.             if(param==1)
  856.             {
  857.                 client.chatMessage(admin, config.botPrefix + 'No more Rake Queries!');
  858.                 return;
  859.             }
  860.         }
  861.     });
  862. }
  863.  
  864. function checkConfirmations(steamcommunityMobileConfirmations){
  865.     steamcommunityMobileConfirmations.FetchConfirmations((function (err, confirmations)
  866.     {
  867.         if (err)
  868.         {
  869.             console.log(err);
  870.             return;
  871.         }
  872.         if(confirmations.length>0)
  873.         {
  874.             console.log(config.botPrefix + 'Received ' + confirmations.length + ' confirmations');
  875.         }
  876.         if ( ! confirmations.length)
  877.         {
  878.             return;
  879.         }
  880.         steamcommunityMobileConfirmations.AcceptConfirmation(confirmations[0], (function (err, result)
  881.         {
  882.             if (err)
  883.             {
  884.                 console.log(err);
  885.                 return;
  886.             }
  887.             console.log(config.botPrefix + 'Confirmation handling result: ' + result);
  888.         }).bind(this));
  889.     }).bind(this));
  890. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement