Advertisement
Guest User

Untitled

a guest
Jul 10th, 2018
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 KB | None | 0 0
  1. //CONST
  2. const SteamUser = require('steam-user');
  3. const SteamTotp = require('steam-totp');
  4. const SteamCommunity = require('steamcommunity');
  5. const TradeOfferManager = require('steam-tradeoffer-manager');
  6. const config = require('./config.json');
  7. const TeamFortress2 = require ('tf2');
  8. const Prices = require('./prices.json');
  9. const client = new SteamUser();
  10. const tf2 = new TeamFortress2(client);
  11. const community = new SteamCommunity();
  12.  
  13.  
  14.  
  15.  
  16. // CONST
  17.  
  18.  
  19.  
  20. //SKIT
  21. const manager = new TradeOfferManager ({
  22. steam: client,
  23. community: community,
  24. language: 'en'
  25. });
  26.  
  27.  
  28. const logOnOptions = {
  29. accountName: config.username,
  30. password: config.password,
  31. twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
  32. };
  33.  
  34. client.logOn(logOnOptions);
  35.  
  36. client.on('loggedOn', () => {
  37. console.log('Inloggad.');
  38. client.chatMessage(config.ownerID, "Inloggad");
  39.  
  40. client.setPersona(SteamUser.Steam.EPersonaState.Online);
  41. client.gamesPlayed(["Grinch is da bezt", 440]); // Custom game name HÄÄÄÄÄÄR!
  42. });
  43.  
  44. client.on('accountInfo', function(name, country) {});
  45. //SKIT
  46.  
  47.  
  48.  
  49. // FRIEND MESSAGES
  50. client.on("friendMessage", function(steamID, message) {
  51. if (message == "!commands") {
  52. client.chatMessage(steamID, "My commands are:");
  53. client.chatMessage(steamID, "!stock to get my current stock");
  54. client.chatMessage(steamID, "!owner to know who my owner is.");
  55. client.chatMessage(steamID, "!how2trade to know how to trade with me")
  56. client.getPersonas([steamID], function(personas) {
  57. var persona = personas[steamID.getSteamID64()];
  58. var name = persona ? persona.player_name : (`['${steamID.getSteamID64()}']`); {
  59. console.log(`${name} (${steamID.getSteamID64()}) Skrev help`);
  60. }
  61. });
  62. }
  63. else if (message == "!stock") {
  64. manager.getInventoryContents(440, 2, true, function (err, inventory) {
  65. if (err) {
  66. client.chatMessage(steamID, "Oooopsi daisy that didn't work.")
  67. return;
  68. }
  69. var refined, reclaimed, scrap, keys = 0;
  70. for (var i = 0; i < inventory.length; i++) {
  71. var item = inventory [i];
  72. var name = item.market_hash_name;
  73. if (name == "Refined Metal") {
  74. refined++;
  75. } else if (name == "Reclaimed Metal") {
  76. reclaimed++;
  77. } else if (name == "Scrap Metal") {
  78. scrap++
  79. } else if (name == "Mann Co.Supply Crate Key") {
  80. keys++
  81. }
  82.  
  83. }
  84. client.chatMessage(steamID, "Stock is ", keys, refined, reclaimed, scrap)
  85. })
  86. } else if (message == "!how2trade") {
  87. client.chatMessage(steamID, "You basically send a trade offer with the correct amount, you can check my listings here https://backpack.tf/classifieds?steamid=76561198846789568")
  88.  
  89. } else if (message == "!owner") {
  90. client.chatMessage(steamID, "I am coded by Aethez you can find his profile in my comments on my profile.")
  91.  
  92.  
  93. } else if (message == "!play" && steamID == config.ownerID) {
  94. message = message.replace("!play", "");
  95. client.gamesPlayed([message, 440])
  96. }
  97. });
  98.  
  99.  
  100.  
  101. //FRIEND MESSAGES
  102.  
  103.  
  104.  
  105.  
  106.  
  107. // TRADING
  108. client.on('webSession', (sessionid, cookies) => {
  109. manager.setCookies(cookies);
  110.  
  111. community.setCookies(cookies);
  112. community.startConfirmationChecker(20000, config.identitySecret);
  113. });
  114.  
  115. function acceptOffer(offer) {
  116. offer.accept((err) => {
  117. community.checkConfirmations();
  118. console.log("Jag accade ett trade offer");
  119. client.chatMessage(76561198403256399, "Jag gjorde ett trade!")
  120. if (err) console.log("There was an error accepting the offer.");
  121. });
  122. }
  123.  
  124. function declineOffer(offer) {
  125. offer.decline((err) => {
  126. console.log("Jag declinade ett trade offer");
  127. if (err) console.log("There was an error declining the offer.");
  128. });
  129. }
  130.  
  131. client.setOption("promptSteamGuardCode", false);
  132.  
  133. function processOffer(offer) {
  134. if (offer.isGlitched() || offer.state === 11) {
  135. console.log("Ett Trade offer var glitchad declinar traden på momangen.");
  136. declineOffer(offer);
  137. } else if (offer.partner.getSteamID64() === config.ownerID) {
  138. acceptOffer(offer);
  139. } else {
  140. var ourItems = offer.itemsToGive;
  141. var theirItems = offer.itemstoReceive;
  142. var ourValue = 0;
  143. var theirValue = 0;
  144. for (var i in ourItems) {
  145. var item = ourItems[i].market_name;
  146. if(Prices[item]) {
  147. ourValue += Prices[item].sell;
  148.  
  149. } else {
  150. console.log("Invalid Value.");
  151. ourValue += 99999;
  152. }
  153. }
  154. for(var i in theirItems) {
  155. var item= theirItems[i].market_name;
  156. if(Prices[item]) {
  157. theirValue += Prices[item].buy;
  158. } else {
  159. console.log("Their value was different.")
  160. }
  161. }
  162. }
  163. console.log("Our value: "+ourValue);
  164. console.log("Their Value: "+theirValue);
  165.  
  166. if (ourValue <= theirValue) {
  167. acceptOffer(offer);
  168. } else {
  169. declineOffer(offer);
  170. }
  171. }
  172.  
  173.  
  174. manager.on('newOffer', (offer) => {
  175. processOffer(offer);
  176. });
  177. //TRADING
  178.  
  179.  
  180.  
  181.  
  182.  
  183. //Friends!!!
  184. client.on('friendRelationship', function(sid, relationship) {
  185. if (relationship == SteamUser.EFriendRelationship.RequestRecipient) {
  186. console.log("We recieved a friend request from "+sid);
  187. client.addFriend(sid, function (err, name) {
  188. if (err) {
  189. console.log(err);
  190. return;
  191. } else {
  192. console.log("Accepted user with the name of "+name);
  193. client.chatMessage(config.ownerID, "Added 1 person, their name is: " +name);
  194. client.chatMessage(sid, "Hi thanks for adding me, type !commands to get my command list.");
  195. }
  196. });
  197. }
  198.  
  199. });
  200. //FRIENDS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement