Advertisement
Guest User

Untitled

a guest
Oct 8th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.17 KB | None | 0 0
  1. const SteamUser = require('steam-user');
  2. const TradeOfferManager = require('steam-tradeoffer-manager');
  3. const SteamTotp = require('steam-totp');
  4. const SteamCommunity = require('steamcommunity');
  5. const config = require('./config.json');
  6.  
  7. const community = new SteamCommunity();
  8. const client = new SteamUser();
  9. const manager = new TradeOfferManager({
  10. steam: client,
  11. domain: 'example.com',
  12. language: 'en'
  13. });
  14.  
  15. const logOnOptions = {
  16. accountName: config.username,
  17. password: config.password,
  18. twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
  19. };
  20. //log on
  21. client.logOn(logOnOptions);
  22.  
  23. client.on('loggedOn', function(details) {
  24. console.log(`Logged into Steam as ${client.steamID.getSteam3RenderedID()}`); //online then play tf2
  25. client.setPersona(SteamUser.Steam.EPersonaState.Online);
  26. client.gamesPlayed(["B>Cards 0.22 S>Cards 0.33",440]);
  27. });
  28.  
  29. client.on('friendRelationship', (steamid, relationship) => {
  30. if (relationship === 2) {
  31. client.addFriend(steamid);
  32. client.chatMessage(steamid, 'Hello there! I am a trade bot. I trade metal for tradings and the other way round! Check my profile to check prices and how to trade with me! My owner is Nukes, if you have any questions contact him https://steamcommunity.com/id/NukesYT');
  33. }
  34. });
  35.  
  36. //Chat messages
  37. client.on("friendMessage", function(steamID, message) {
  38. if (message == "!trade") {
  39. client.chatMessage(steamID, "Send me a trade offer here! https://steamcommunity.com/tradeoffer/new/?partner=378402521&token=3BX46Vj-");
  40. }
  41. });
  42.  
  43. client.on("friendMessage", function(steamID, message) {
  44. if (message == "!help") {
  45. client.chatMessage(steamID, "All available commands are !help, !trade, !owner, !prices");
  46. }
  47. });
  48.  
  49. client.on("friendMessage", function(steamID, message) {
  50. if (message == "!owner") {
  51. client.chatMessage(steamID, "My owner is Nukes! If you need any help, add him http://steamcommunity.com/id/NukesYT");
  52. }
  53. });
  54.  
  55. client.on("friendMessage", function(steamID, message) {
  56. if (message == "!prices ") {
  57. client.chatMessage(steamID, "I buy trading cards for 2 scrap and sell them for 3 scrap. Want to trade? type !trade to send an offer");
  58. }
  59. });
  60.  
  61. client.on("friendMessage", function(steamID, message) {
  62. if (message == "yo") {
  63. client.chatMessage(steamID, "Hi!");
  64. }
  65. });
  66.  
  67. client.on("friendMessage", function(steamID, message) {
  68. if (message == "nigga") {
  69. client.chatMessage(steamID, "Sup homie!");
  70. }
  71. });
  72.  
  73. client.on("friendMessage", function(steamID, message) {
  74. if (message == "nigger") {
  75. client.chatMessage(steamID, "ok :(");
  76. }
  77. });
  78.  
  79. client.on("friendMessage", function(steamID, message) {
  80. if (message == "hi") {
  81. client.chatMessage(steamID, "Hai!");
  82. }
  83. });
  84.  
  85. client.on("friendMessage", function(steamID, message) {
  86. if (message == "cunt") {
  87. client.chatMessage(steamID, "Yes you are!");
  88. }
  89. });
  90.  
  91. client.on("friendMessage", function(steamID, message) {
  92. if (message == ":)") {
  93. client.chatMessage(steamID, ":D");
  94. }
  95. });
  96.  
  97. client.on("friendMessage", function(steamID, message) {
  98. if (message == ":(") {
  99. client.chatMessage(steamID, ":O");
  100. }
  101. });
  102.  
  103. client.on("friendMessage", function(steamID, message) {
  104. if (message == "anal") {
  105. client.chatMessage(steamID, "I don't like that!");
  106. }
  107. });
  108.  
  109. client.on("friendMessage", function(steamID, message) {
  110. if (message == "fuck off") {
  111. client.chatMessage(steamID, "No you can fuck off");
  112. }
  113. });
  114.  
  115. client.on("friendMessage", function(steamID, message) {
  116. if (message == "idk") {
  117. client.chatMessage(steamID, "ok ;)");
  118. }
  119. });
  120.  
  121. client.on("friendMessage", function(steamID, message) {
  122. if (message == "slave") {
  123. client.chatMessage(steamID, "Nukes is my slave master :(");
  124. }
  125. });
  126.  
  127. client.on('webSession', function(sessionID, cookies) {
  128. manager.setCookies(cookies, function(err) {
  129. if (err) return console.log(err);
  130. console.log(`Got API key: ${manager.apiKey}`);
  131. });
  132.  
  133. community.setCookies(cookies);
  134. community.startConfirmationChecker(10000, config.identitySecret);
  135. });
  136.  
  137.  
  138. console.log("only keep tradeable items in the bot")
  139.  
  140. function Get_Cards(offer, price) {
  141.  
  142. var Vaule = 0;
  143.  
  144. offer.forEach(function(item) {
  145. if (item.tags) {
  146. item.tags.forEach(function(tag) {
  147. if (tag.name && tag.name == "Trading Card") {
  148. Vaule += Math.round(price * 9);
  149. }
  150. });
  151. }
  152. });
  153. return Vaule;
  154. }
  155.  
  156.  
  157.  
  158. function Get_Metal(offer) {
  159.  
  160. var Vaule = 0;
  161.  
  162. for (i = 0; i < offer.length; i++) {
  163. if (offer[i].market_hash_name.includes('Refined Metal')) {
  164. Vaule+=9;
  165. } else {
  166. if (offer[i].market_hash_name.includes('Reclaimed Metal')) {
  167. Vaule+=3;
  168. } else {
  169. if (offer[i].market_hash_name.includes('Scrap Metal')) {
  170. Vaule++;
  171. }
  172. }
  173. }
  174. }
  175. return Vaule;
  176. }
  177.  
  178.  
  179.  
  180.  
  181. function acceptOffer(offer, partnerID) {
  182. offer.accept((err) => {
  183. if (err) console.log(`Unable to accept offer: ${err.message}`);
  184. community.checkConfirmations();
  185. client.inviteToGroup(partnerID, config.groupSteamID);
  186. community.postUserComment(offer.partner.getSteamID64(),'+rep Thank you for using this bot! Have a good day!');
  187. });
  188. }
  189.  
  190.  
  191.  
  192.  
  193. function declineOffer(offer) {
  194. offer.decline((err) => {
  195. if (err) return console.log(`Unable to decline offer: ${err.message}`);
  196. });
  197. }
  198.  
  199. manager.on('newOffer', function(offer) {
  200.  
  201. var partnerID = offer.partner.getSteamID64();
  202.  
  203. var OurCardVaule = Get_Cards(offer.itemsToGive, config.CardsSellPrice);
  204. var OurMetal = Get_Metal(offer.itemsToGive);
  205. var VauleToGive = OurCardVaule + OurMetal;
  206.  
  207. var ThereCardVaule = Get_Cards(offer.itemsToReceive,config.CardsBuyPrice);
  208. var ThereMetal = Get_Metal(offer.itemsToReceive);
  209. var VauleToReceive = ThereCardVaule + ThereMetal;
  210.  
  211.  
  212. if(VauleToReceive >= VauleToGive) {
  213. acceptOffer(offer, partnerID);
  214. console.log("accepted offer");
  215. console.log("invited to group");
  216. }else{
  217. declineOffer(offer);
  218. console.log("declined offer");
  219. }
  220. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement