Advertisement
Guest User

Untitled

a guest
Nov 27th, 2018
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.48 KB | None | 0 0
  1. const SteamUser = require('steam-user');
  2. const SteamTotp = require('steam-totp');
  3. const SteamCommunity = require('steamcommunity');
  4. const TradeOfferManager = require('steam-tradeoffer-manager');
  5. const TeamFortress2 = require('tf2');
  6. const config = require('./config.json');
  7. const client = new SteamUser();
  8. const tf2 = new TeamFortress2(client);
  9. const community = new SteamCommunity();
  10. const manager = new TradeOfferManager ({
  11. steam: client,
  12. community: community,
  13. language: 'en'
  14. });
  15.  
  16. const logOnOptions = {
  17. accountName: config.username,
  18. password: config.password,
  19. twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
  20. }
  21.  
  22. client.logOn(logOnOptions);
  23.  
  24. client.on('loggedOn', () => {
  25. console.log('Úspěšné přihlášení.');
  26. client.setPersona(SteamUser.Steam.EPersonaState.Online);
  27. client.gamesPlayed(["Homemade 24/7 Bot",440]);
  28. });
  29.  
  30. client.on('friendRelationship', (steamid, relationship) => {
  31. if (relationship === 2) {
  32. client.addFriend(steamid);
  33. client.chatMessage(steamid, 'Hello there! Thanks for adding me! This bot is still in development and can not send offers through Steam chat. Please type !help to see what you can do from here or !donate to show some love. If you donate more than 2 euros ask my owner and he will reward you with mysterious item! Make sure to show him the proof it was you.');
  34. }
  35. });
  36.  
  37. client.on("friendMessage", function(steamID, message) {
  38. if (message == "!help") {
  39. client.chatMessage(steamID, "Theres few things you can do: 1) Add my owner and see what is he selling ( https://steamcommunity.com/id/ITrolYou/ ). 2) You can visit my backpack.tf profile to see which things I´m currently buying or selling ( https://backpack.tf/classifieds?steamid=76561198866655074 ) 3) Add my owner if you want me to beat other buyers or sellers on backpack.tf Thats all, feel free to keep me in friends or remove me, have a nice day!");
  40. }
  41. });
  42.  
  43. client.on("friendMessage", function(steamID, message) {
  44. if (message == "!donate") {
  45. client.chatMessage(steamID, "Heres is my trade offer link ( https://steamcommunity.com/tradeoffer/new/?partner=906389346&token=U2M_IFTq ). Once the offer has been accepted, add my owner. If the donation was higher than 2 euros you will also to receive a mystery item! If you dont know who is my owner, type !owner");
  46. }
  47. });
  48.  
  49. client.on("friendMessage", function(steamID, message) {
  50. if (message == "!owner") {
  51. client.chatMessage(steamID, "Heres the link to profile of my owner. https://steamcommunity.com/id/ITrolYou/");
  52. }
  53. });
  54. client.on('webSession', (sessionid, cookies) => {
  55. manager.setCookies(cookies);
  56.  
  57. community.setCookies(cookies);
  58. });
  59.  
  60. client.on('webSession', (sessionid, cookies) => {
  61.  
  62. sendRandomItem();
  63. });
  64.  
  65. /* Crafting */
  66.  
  67. var scrapAmt = 25;
  68. var pollCraft = 30;
  69.  
  70. tf2.on('connectedToGC', function() {
  71. console.log("Připojeno k TF2 serverům.");
  72. });
  73.  
  74. tf2.on('backpackLoaded', function () {
  75. console.log("Backpack byl načten.");
  76. });
  77.  
  78. function craftS(amtNeedScrap) {
  79. if (tf2.backpack == undefined) {
  80. console.log("Nemohli jsme načíst backpack, nelze craftovat.");
  81. return
  82. } else {
  83. console.log("Zkouším craftovat");
  84. var amtOfScrap = 0;
  85. for (var i = 0; i <tf2.backpack.length; i++) {
  86. if (tf2.backpack[i].defIndex === 5000) {
  87. amtOfScrap++;
  88. }
  89. }
  90. for (var i = 0; i <tf2.backpack.length; i++) {
  91. if (tf2.backpack[i].defIndex === 5002) {
  92. amtOfScrap +=9;
  93. var beep = new Array;
  94. beep.push(parseInt(tf2.backpack[i].id));
  95. tf2.craft(beep);
  96.  
  97. } else if (tf2.backpack[i].defIndex === 5001) {
  98. amtOfScrap +=3;
  99. var beep = new Array;
  100. beep.push(parseInt(tf2.backpack[i].id));
  101. tf2.craft(beep);
  102. }
  103. if (amtOfScrap >= amtNeedScrap) {
  104. break;
  105. }
  106. }
  107.  
  108.  
  109. }
  110. }
  111.  
  112. tf2.on('craftingComplete', function(e) {
  113. console.log("Craftování bylo dokončeno.");
  114. });
  115.  
  116. client.on('friendMessage#'+76561198154182487, function(steamID, message) {
  117. if (message == "craft") {
  118. craftS(scrapAmt);
  119. console.log("Dostali jsme příkaz ke craftění od admina.")
  120. } else {
  121. console.log("craft error.")
  122. }
  123. });
  124.  
  125. setInterval(function() {
  126. craftS(scrapAmt);
  127. }, 1000 * 60 * pollCraft)
  128.  
  129. client.on('friendRelationship', function(sid, relationship) {
  130. if (relationship == SteamUser.EFriendRelationship.RequestRecipient) {
  131. console.log("We recieved a friend request from "+sid);
  132. client.addFriend(sid, function (err, name) {
  133. if (err) {
  134. console.log(err);
  135. return;
  136. }
  137. console.log("Accepted user with the name of "+name)
  138. })
  139. }
  140.  
  141. })
  142.  
  143. client.on('groupRelationship', function(sid, relationship) {
  144. if (relationship == SteamUser.EClanRelationship.Invited) {
  145. console.log("We were asked to join steam group #"+sid);
  146. client.respondToGroupInvite(sid, true);
  147. }
  148. })
  149.  
  150. client.on('friendsList', function() {
  151. for (var sid in client.myFriends);
  152. var relationship = client.myFriends[sid]
  153. if (relationship == SteamUser.EFriendRelationship.RequestRecipient) {
  154. console.log("(offline) We recieved a friend request from "+sid);
  155. client.addFriend(sid, function (err, name) {
  156. if (err) {
  157. console.log(err);
  158. return;
  159. }
  160. console.log("(offline) Accepted user with the name of "+name)
  161. })
  162. }
  163. })
  164.  
  165. client.on('groupList', function() {
  166. for (var sid in client.myGroups);
  167. var relationship = client.myGroups[sid];
  168. if (relationship == SteamUser.EClanRelationship.Invited) {
  169. console.log("(offline) We were asked to join steam group #"+sid);
  170. client.respondToGroupInvite(sid, true);
  171. }
  172. })
  173.  
  174. // Variables
  175. var admin_steamID = '76561198154182487'
  176.  
  177. // Chat listener
  178. client.on('friendMessage', (steamID, message) => {
  179. if (steamID == admin_steamID) {
  180. // Print to console that the chat message was detected for an admin.
  181. console.log(' Chat From ' + steamID + ': ' + message);
  182.  
  183. if (message.match('!pomoc')) {
  184. client.chatMessage(steamID, `
  185. --------[ Bot příkazy ]--------
  186. ● !pomoc - Ukáže list příkazů.
  187. ● !vzít-vše (možnost) - Vem si všechny věci z inventáře bota.
  188. ↪ steamkarty, csgo, tf2
  189. ● !dát-vše (možnost) - Dej všechny svoje věci do inventáře bota..
  190. ↪ steamkarty, csgo, tf2
  191. ● !relog - Opětovné přihlášení do bota.
  192. ● !vypnout - Vypni bota.`);
  193.  
  194. } else if (message.includes("!vzít-vše")) {
  195. if (message.match('!vzít-vše steamkarty')) {
  196. client.chatMessage(steamID, '\nPřevádím všechny STEAMKARTY na tebe! Prosím počkej.');
  197. vzítVše(steamID, 753, 6, false);
  198. } else if (message.match('!vzít-vše csgo')) {
  199. client.chatMessage(steamID, '\nPřevádím všechny CSGO věci na tebe! Prosím počkej');
  200. vzítVše(steamID, 730, 2, false);
  201. } else if (message.match('!vzít-vše tf2')) {
  202. client.chatMessage(steamID, '\nPřevádím všechny TF2 věci na tebe. Prosím počkej.');
  203. vzítVše(steamID, 440, 2, false);
  204. } else {
  205. client.chatMessage(steamID, '\nChybná !vzít-vše možnost. Zkus to znovu');
  206. }
  207. } else if (message.includes("!dát-vše")) {
  208. if (message.match('!dát-vše steamkarty')) {
  209. client.chatMessage(steamID, '\nPřevádím všechny tvoje STEAMKARTY na sebe. Prosím počkej');
  210. dátVše(steamID, 753, 6, false);
  211. } else if (message.match('!dát-vše csgo')) {
  212. client.chatMessage(steamID, '\nPřevádím všechny tvoje CSGO věci na sebe. Prosím počkej');
  213. dátVše(steamID, 730, 2, false);
  214. } else if (message.match('!dát-vše tf2')) {
  215. client.chatMessage(steamID, '\nPřevádím všechny tvoje TF2 věci na sebe. Prosím počkej');
  216. dátVše(steamID, 440, 2, false);
  217. } else {
  218. client.chatMessage(steamID, '\nChybná !dát-vše možnost. Zkus to znovu');
  219. }
  220.  
  221. }
  222. } if (message.match('!restart')) {
  223. console.log('Příkaz na restart byl aktivován.')
  224. client.chatMessage(steamID, '\nOdhlasím se a opět přihlásím, hned jsem zpátky ;)' );
  225. client.relog();
  226. } if (message.match('!vypnout')) {
  227. client.chatMessage(steamID, '\nBot se vypíná. Sbohem.');
  228. client.shutdown();
  229. console.log('Příkaz na vypnutí byl aktivován.')
  230. }
  231. });
  232.  
  233.  
  234. // Functions
  235.  
  236. // dátVše
  237. function dátVše(steamID, appid, contextid, key_only) {
  238. manager.loadInventory(appid, contextid, true, (err, inventory) => {
  239. if (err) {
  240. console.log(err);
  241. client.chatMessage(steamID, '\nNastala chyba. Podívej se do konzole.');
  242. } else {
  243. const offer = manager.createOffer(steamID);
  244.  
  245. manager.loadUserInventory(steamID, appid, contextid, true, (err, theirInv) => {
  246. const theirItem = theirInv;
  247.  
  248. offer.addTheirItems(theirItem);
  249. offer.setMessage(`Tady je moje nabídka!`);
  250. offer.send((err, status) => {
  251. if (err) {
  252. console.log(err);
  253. console.log(' ');
  254. } else {
  255. console.log(` [NABÍDKA ODESLÁNA] Offer ID: (` + offer.id + `)` + ` | SteamID: ` + steamID);
  256. client.chatMessage(steamID, '\n Nabídka odeslána. (' + offer.id + ')\n Může to trvat až 30 vteřin než ti nabídka přijde.');
  257. }
  258. });
  259. });
  260. }
  261. });
  262. };
  263.  
  264. // vzítVše
  265. function vzítVše(steamID, appid, contextid, key_only) {
  266. manager.loadInventory(appid, contextid, true, (err, inventory) => {
  267. if (err) {
  268. console.log(err);
  269. client.chatMessage(steamID, '\nNastala chyba. Podívej se do konzole.');
  270. } else {
  271. const offer = manager.createOffer(steamID);
  272. const items = inventory;
  273. offer.addMyItems(items);
  274. offer.setMessage(`Tady je moje nabídka!`);
  275. offer.send((err, status) => {
  276. if (err) {
  277. console.log(err);
  278. console.log(' ');
  279. } else {
  280. console.log(` [NABÍDKA ODESLÁNA] Offer ID: (` + offer.id + `)` + ` | SteamID: ` + steamID);
  281. client.chatMessage(steamID, '\n Nabídka odeslána. (' + offer.id + ')\n Může to trvat až 30 vteřin než ti nabídka přijde.');
  282. }
  283. });
  284. }
  285. });
  286. };
  287.  
  288. function sendRandomItem() {
  289. const partner = '76561198154182487';
  290. const appid = 440;
  291. const contextid = 2;
  292.  
  293. const offer = manager.createOffer(partner);
  294.  
  295. manager.loadInventory(appid, contextid, true, (err, myInv) => {
  296. if (err) {
  297. console.log(err);
  298. } else {
  299. const myItem = myInv[Math.floor(Math.random() * myInv.length - 1)];
  300. offer.addMyItem(myItem);
  301.  
  302. manager.loadUserInventory(
  303. partner,
  304. appid,
  305. contextid,
  306. true,
  307. (err, theirInv) => {
  308. if (err) {
  309. console.log(err);
  310. } else {
  311. const theirItem =
  312. theirInv[Math.floor(Math.random() * theirInv.length - 1)];
  313. offer.addTheirItem(theirItem);
  314.  
  315. offer.setMessage(
  316. `Vyměnil by jsi ${theirItem.name} za můj ${myItem.name}?`
  317. );
  318. offer.send((err, status) => {
  319. if (err) {
  320. console.log(err);
  321. } else {
  322. console.log(`Nabídka byla poslána. Status: ${status}.`);
  323. }
  324. });
  325. }
  326. }
  327. );
  328. }
  329. });
  330. }
  331.  
  332. client.on('friendMessage', (steamid, message) => {
  333. if (message === "!comment") {
  334. client.chatMessage(steamid,"Commenting on your profile!");
  335. community.postUserComment(steamid, "My comment");
  336. } else if (message === "!remove") {
  337. client.chatMessage(steamid,"See you again later...")
  338. client.removeFriend(steamid)
  339. }
  340. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement