Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.42 KB | None | 0 0
  1. var Steam = require("steam");
  2. var SteamUser = require ("steam-user");
  3. var client = new SteamUser();
  4. var SteamTotp = require('steam-totp');
  5.  
  6. var friends = new Steam.SteamFriends(client.client);
  7.  
  8. var SteamCommunity = require('steamcommunity');
  9. var community = new SteamCommunity();
  10.  
  11. var client;
  12.  
  13. var TradeOfferManager = require('steam-tradeoffer-manager');
  14. var fs = require('fs');
  15. var request = require('request');
  16.  
  17. var SteamTrade = require("steam-trade");
  18. var steamTrade = new SteamTrade();
  19.  
  20. var adminid = '' //Admins Steam id
  21. var botid = '1'; //The ID of the bot..
  22.  
  23. var manager = new TradeOfferManager({
  24. "steam": client,
  25. "domain": "example.com",
  26. "language": "en"
  27. });
  28.  
  29. client.logOn({
  30. accountName: '',
  31. password: '',
  32. twoFactorCode: SteamTotp.generateAuthCode('shared')
  33. });
  34.  
  35.  
  36. client.on("loggedOn", function(details){
  37. console.log("Logged into Steam as " + client.steamID.getSteam3RenderedID());
  38. client.setPersona(SteamUser.Steam.EPersonaState.Online, "Nitro");
  39. client.gamesPlayed("Currently accepting donations!", 730);
  40. });
  41.  
  42. client.on('error', function (e) {
  43. console.log('ERROR: ' + e);
  44. });
  45. adminid = '76561198236904474';
  46. client.on('webSession', function (sessionID, cookies) {
  47. manager.setCookies(cookies, function (err) {
  48. if (err) {
  49. console.log(err);
  50. process.exit(1);
  51. return;
  52. }
  53. });
  54. community.setCookies(cookies);
  55. community.chatLogon();
  56. community.startConfirmationChecker(10000, 'insecret');
  57. });
  58.  
  59. manager.on('newOffer', function (offer) {
  60. console.log("New offer #" + offer.id + " from " + offer.partner.getSteamID64() + " - itemsToGive: " + offer.itemsToGive.length + " - itemsToReceive: " + offer.itemsToReceive.length);
  61. console.log("Note: " + offer.message);
  62.  
  63. if (offer.partner.getSteamID64() == adminid) {
  64. offer.accept();
  65. community.checkConfirmations();
  66. } else {
  67. offer.getUserDetails(function (err, me, them) {
  68. if (err) {
  69. console.log(err.message);
  70. } else {
  71. if (them.escrowDays > 0) {
  72. offer.decline();
  73. client.chatMessage(offer.partner.getSteamID64(), "You have " + them.escrowDays + " escrow days left, please try again later.");
  74. } else {
  75.  
  76. if (offer.itemsToReceive.length > 0 && offer.itemsToGive.length == 0) {
  77. offer.accept();
  78. } else {
  79. offer.decline();
  80. }
  81. }
  82. }
  83. });
  84. }
  85. });
  86.  
  87. //When a steam offer is recieved the bot will store the id and user, if the offer is a donation the bot will accept it, otherwise decline it.
  88. manager.on('receivedOfferChanged', function (offer, oldState) {
  89. //console.log(Offer #${offer.id} changed: ${TradeOfferManager.ETradeOfferState[oldState]} -> ${TradeOfferManager.ETradeOfferState[offer.state]});
  90. if (offer.state == TradeOfferManager.ETradeOfferState.Accepted) {
  91. offer.getReceivedItems(function (err, items) {
  92. if (err) {
  93. console.log("Couldn't get received items: " + err);
  94. } else {
  95. var names = items.map(function (item) {
  96. return item.name;
  97. });
  98. console.log("Received from " + offer.partner.getSteamID64() + ": " + names.join(', '));
  99. }
  100. });
  101. }
  102. });
  103.  
  104. client.on('newItems', function (count) {
  105. console.log(count + " new items in our inventory");
  106. });
  107.  
  108. //When another Steam user adds the bot, it will accept the user store their id and send them a message
  109. client.on('friendRelationship', function(steamid, relationship) {
  110. if (relationship === 2) {
  111. client.addFriend(steamid);
  112. console.log('Added ' + steamid  + ' to friendlist');
  113. client.chatMessage(steamid, 'Hello there, I\'m your new friend. I can\'t do much at the moment, so I apologise. ');
  114. console.log('Sent welcome message too ' + steamid);
  115. }
  116. });
  117.  
  118. //If a user sends the bot a message and the bot recognizes the word with a listed command or message it will reply with a pre-written message.
  119. friends.on("friendMsg", function(user, msg, type){
  120. if(type == Steam.EChatEntryType.ChatMsg){
  121. if(msg == "hi"){
  122. friends.sendMessage(user,"Sup bro, how's life?");
  123. }
  124. if(msg == "Hi"){
  125. friends.sendMessage(user,"Sup bro, how's life?");
  126. }
  127. }
  128. })
  129.  
  130. //Disabled, only used for testing
  131. client.on("tradeRequest", function(steamid, respond){
  132. console.log("Incoming trade request from " + steamid + ": Respond true");
  133. respond(true);
  134. })
  135.  
  136. client.on("tradeStarted", function(steamid){
  137. steamTrade.open(steamid);
  138. console.log("Successfully opened trade with " + steamid)
  139. })
  140.  
  141. //Still in the works
  142. steamTrade.on("chatMsg", function(steamid, msg, type) {
  143. if(type == Steam.EChatEntryType.ChatMsg){
  144. if(msg == "Hello") {
  145. steamTrade.chatMsg(steamid,"Please die");
  146. }
  147. }
  148. })
  149.  
  150. steamTrade.on("ready", function(steamid) {
  151. steamTrade.ready(function(steamid) {
  152. console.log("User" + steamid + "is ready");
  153. steamTrade.confirm();
  154. console.log("Confirming the trade with user" + steamid + "");
  155. })
  156. })
  157.  
  158. steamTrade.on('unready',function() {
  159. steamTrade.unready(function() {
  160. console.log("User" + steamid + "clicked unready");
  161. })
  162. })
  163.  
  164. //Still testing withdraw/adding items
  165. steamTrade.on("chatMsg", function(steamid, msg) {
  166. if (msg == '/tf2' && "76561198089922529") {
  167. console.log("Withdrawing TF2 items!");
  168. steamTrade.loadInventory(440,2, function(items){
  169. steamTrade.addItems(items);
  170. })
  171. }
  172. })
  173.  
  174. //Still testing withdraw/adding items
  175. steamTrade.on("chatMsg", function(msg) {
  176. if(msg == "!withdrawCSGO" && "76561198089922529") {
  177. console.log("Withdrawing CSGO items!");
  178. steamTrade.loadInventory(730,2, function(items){
  179. steamTrade.addItems(items);
  180. })
  181. }
  182. })
  183.  
  184. //Still testing withdraw/adding items
  185. steamTrade.on("chatMsg", function(msg) {
  186. if(msg == "!withdrawSTEAM" && "76561198089922529") {
  187. console.log("Withdrawing Steam items!");
  188. steamTrade.loadInventory(753,2, function(items){
  189. steamTrade.addItems(items);
  190. })
  191. }
  192. })
  193.  
  194. friends.on("friendMsg", function(user, msg, type){
  195. if(type == Steam.EChatEntryType.ChatMsg){
  196. if(msg == "!help"){
  197. friends.sendMessage(user,"Sup bro, how's life?");
  198. }
  199. if(msg == "!Help"){
  200. friends.sendMessage(user,"Sup bro, how's life?");
  201. }
  202. }
  203. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement