Advertisement
Guest User

Untitled

a guest
Jun 4th, 2017
969
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.55 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5. } else if (MSG.toUpperCase().indexOf("!BUYGEMS") >= 0) {
  6. if (botSets) {
  7. let n = MSG.toUpperCase().replace("!BUYGEMS ", ""),
  8. amountofsets = parseInt(n) * 1;
  9.  
  10. if (!isNaN(n)) {
  11. if (n <= 10) {
  12. let t = manager.createOffer(SENDER.getSteamID64());
  13. t.getUserDetails((ERR, ME, THEM) => {
  14. if (ERR) {
  15. console.log(getHourNow() + " !!! An error occurred while checking trade holds (!buygems): " + ERR);
  16. client.chatMessage(SENDER, ":exclamationPointRed: An error occurred while checking your Steam trade holds. Please try again in 2 minutes.");
  17. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  18. n = parseInt(n);
  19.  
  20.  
  21. var item = [];
  22.  
  23. client.chatMessage(SENDER, ":revclock: Processing your request...");
  24. manager.getUserInventoryContents(SENDER.getSteamID64(), 753, 2, true, (ERR, INV, CURR) => {
  25. if (ERR) {
  26. console.log(getHourNow() + " !!! An error occurred while loading Steam inventory inventory (!buygems): " + ERR);
  27. client.chatMessage(SENDER, ":exclamationPointRed: An error occurred while loading your Steam inventory. Please try again in 2 minutes.");
  28. } else {
  29. if (!ERR) {
  30. for (let i = 0; i < INV.length; i++) {
  31. var gems = INV[i];
  32. var amountNeeded = 10 * n;
  33. if (gems.market_hash_name === "753-Gems"){
  34. if(gems.amount >= amountNeeded){
  35. item.push({assetid: gems.id, appid: '753', contextid: '6', amount: amountNeeded});
  36. console.log(item);
  37. }
  38. }
  39. }
  40. }
  41. if (item.length != 1) {
  42. client.chatMessage(SENDER, ":exclamationPointRed: You don't have enough gems.");
  43. client.chatMessage(SENDER, "This BOT accepts any CS:GO case keys. If you purchased your keys at Steam market or CS:GO in-game store, your keys will have a 7 day trade restriction. You may check your keys by clicking on them at your inventory." + "\n" + "\n" + ":ns_key: Tradeable keys I can see in your inventory: " + theirGems.length);
  44. } else {
  45. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  46. if (!ERR) {
  47. if (!ERR) {
  48. let b = {}; // List with badges that CAN still be crafted
  49. if (DATA) {
  50. for (let i = 0; i < Object.keys(DATA).length; i++) {
  51. if (DATA[Object.keys(DATA)[i]] < 6) {
  52. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  53. }
  54. }
  55. } else {
  56. console.log(getHourNow() + " # Badges are empty, sending offer without checking badges. (!buy)")
  57. client.chatMessage(SENDER.getSteamID64(), ":exclamationPointRed: Your badges are empty, sending an offer without checking badges.");
  58. }
  59. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  60. // 1: GET BOTS CARDS. DONE
  61. // 2: GET PLAYER's BADGES. DONE
  62. // 3: MAGIC
  63. let hisMaxSets = 0,
  64. botNSets = 0;
  65. // Loop for sets he has partially completed
  66. for (let i = 0; i < Object.keys(b).length; i++) {
  67. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  68. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  69. }
  70. }
  71. // Loop for sets he has never crafted
  72. for (let i = 0; i < Object.keys(botSets).length; i++) {
  73. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  74. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  75. hisMaxSets += 5;
  76. } else {
  77. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  78. }
  79. }
  80. botNSets += botSets[Object.keys(botSets)[i]].length;
  81. }
  82. // HERE
  83. if (amountofsets <= hisMaxSets) {
  84. hisMaxSets = amountofsets;
  85. sortSetsByAmount(botSets, (DATA) => {
  86. firstLoop: for (let i = 0; i < DATA.length; i++) {
  87. if (b[DATA[i]] == 0) {
  88. continue firstLoop;
  89. } else {
  90. if (hisMaxSets > 0) {
  91. if (b[DATA[i]] && botSets[DATA[i]].length >= b[DATA[i]]) {
  92. // BOT HAS ENOUGH SETS OF THIS KIND
  93. sLoop: for (let j = 0; j < 5 - b[DATA[i]]; j++) {
  94. if (j + 1 < b[DATA[i]] && hisMaxSets > 0) {
  95. t.addMyItems(botSets[DATA[i]][j]);
  96. hisMaxSets--;
  97. } else {
  98. continue firstLoop;
  99. }
  100. }
  101. } else if (b[DATA[i]] && botSets[DATA[i]].length < b[DATA[i]]) {
  102. // BOT DOESNT HAVE ENOUGH SETS OF THIS KIND
  103. continue; // *
  104. } else if (!b[DATA[i]] && botSets[DATA[i]].length < 5 && botSets[DATA[i]].length - b[DATA[i]] > 0) { // TODO NOT FOR LOOP WITH BOTSETS. IT SENDS ALL
  105. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  106. bLoop: for (let j = 0; j < botSets[DATA[i]].length - b[DATA[i]]; j++) {
  107. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  108. t.addMyItems(botSets[DATA[i]][j]);
  109. hisMaxSets--;
  110. } else {
  111. continue firstLoop;
  112. }
  113. }
  114. }
  115. else if (hisMaxSets < 5) {
  116. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS 5 SETS:
  117. tLoop: for (let j = 0; j != hisMaxSets; j++) {
  118. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  119. t.addMyItems(botSets[DATA[i]][j]);
  120. hisMaxSets--;
  121. } else {
  122. continue firstLoop;
  123. }
  124. }
  125. } else {
  126. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS LESS THAN 5 SETS:
  127. xLoop: for (let j = 0; j != 5; j++ && hisMaxSets > 0) {
  128. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  129. t.addMyItems(botSets[DATA[i]][j]);
  130. hisMaxSets--;
  131. } else {
  132. continue firstLoop;
  133. }
  134. }
  135. }
  136. } else {
  137. break firstLoop;
  138. }
  139. }
  140. }
  141. if (hisMaxSets > 0) {
  142. client.chatMessage(SENDER, ":exclamationPointRed: There are not enough sets. Please try again later.");
  143. } else {
  144. console.log(getHourNow() + " # Sending trade offer... (!buy)");
  145. t.addTheirItems(item);
  146. t.data("commandused", "Buy");
  147. t.data("amountofkeys", n);
  148. t.data("amountofsets", amountofsets.toString());
  149. t.setMessage("Here are " + t.data("amountofsets") + " cards sets in exchange for " + t.data("amountofkeys") + " CS:GO keys.")
  150. t.send((ERR, STATUS) => {
  151. if (ERR) {
  152. console.log(getHourNow() + " !!! An error occurred while sending trade (!buy): " + ERR);
  153. client.chatMessage(SENDER, ":exclamationPointRed: An error occurred while sending your trade. Steam Trades could be down. Please try again in 2 minutes.");
  154. loadSets();
  155. } else {
  156. console.log(getHourNow() + " # Trade offer sent! (!buy)");
  157. client.chatMessage(SENDER, ":clickpointer: Trade offer sent! Check your Steam notifications or click here to accept: https://steamcommunity.com/tradeoffer/" + t.id);
  158. }
  159. });
  160. }
  161. });
  162. } else {
  163. client.chatMessage(SENDER, ":exclamationPointRed: There are currently not enough sets that you have not used in stock for this amount of keys. Please try again later. If you want the BOT to ignore your current badges use !buyany.");
  164. }
  165. // TO HERE
  166. } else {
  167. console.log(getHourNow() + " !!! An error occurred while getting buyer badges (!buy): " + ERR);
  168. }
  169. } else {
  170. console.log(getHourNow() + " !!! An error occurred while loading buyer badges (!buy): " + ERR);
  171. client.chatMessage(SENDER, ":exclamationPointRed: An error occurred while checking your badges. Please try again in 2 minutes.");
  172. }
  173. });
  174. }
  175. } else {
  176. console.log(getHourNow() + " !!! An error occurred while loading buyer's CS:GO inventory (!buy): " + ERR);
  177. client.chatMessage(SENDER, ":exclamationPointRed: An error occurred while loading your CS:GO inventory. Please make sure it's set to public.");
  178. }
  179. }
  180. });
  181. } else {
  182. client.chatMessage(SENDER, ":exclamationPointRed: Please make sure you don't have a trade hold. If you don't own a smartphone, use SteamDesktopAuthenticator." + "\n" + "\n" + "https://help.steampowered.com/pt-br/wizard/HelpWhyCantITrade");
  183. }
  184. });
  185. } else {
  186. client.chatMessage(SENDER, ":exclamationPointRed: You can buy up to " + 10 + " keys at once.");
  187. }
  188. } else {
  189. client.chatMessage(SENDER, ":exclamationPointRed: Please provide a valid amount of keys - example: !buy 2");
  190. }
  191. } else {
  192. client.chatMessage(SENDER, ":exclamationPointRed: Please try again later.");
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement